WEB-4679: declare a scan manifest so the backend can prune uninstalled tools#187
Conversation
…d tools The discovery agent never told the backend which tools were still installed, so an uninstalled tool's row persisted on the dashboard forever. The completed scan event now carries a manifest of the (home_user, tool_name) pairs successfully scanned this run plus covered_home_users, letting the backend reconcile by set-difference and soft-delete what's gone. - ai_tools_discovery.py: accumulate scanned_manifest on the send-success and dedup hash-match paths only (a tool that errored on read is left out so it is never mistaken for uninstalled); pass manifest + covered_home_users (= all enumerated OS users, so a user who removed their last tool is still in scope) to the completed send_scan_event. - utils.py: send_scan_event gains optional manifest / covered_home_users, inserted into the payload only when present (backward compatible). Stdlib-only; the accumulation is pure in-memory and cannot raise. Pairs with the ai-gateway-data WEB-4679 reconcile change (forward/backward compatible: an old backend simply ignores the new fields). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…covery-never-prunes-uninstalled-tools-removed-tools
Addresses Greptile P2: accumulate the manifest as a set of tuples (a pair can never be double-recorded) and serialize to a sorted list of dicts at the send site. Functionally equivalent today (the success and hash-match branches are mutually exclusive, one entry per (tool, user)), but removes the latent duplicate risk and makes the output deterministic. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tighten comments Greptile flag: a tool whose READ succeeded but whose upload failed transiently was dropped from the manifest, so the backend could mistake a network blip for an uninstall and prune a live tool (enforce mode). Record it in the send-failure branch too — the manifest tracks what was SEEN, not what uploaded. Adds a regression test (read-success + upload-failure stays in the manifest). Also condense the WEB-4679 comments to concise one-liners. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ve tool A tool whose read errors without a scan_event=failed (the generic per-user except, the per-tool except, or a PermissionError whose failed-event send itself fails) leaves the manifest possibly missing an installed tool — the backend would then set-diff it as uninstalled and wrongly prune it. Track scanned_manifest_complete and send manifest=None (backend treats as legacy = no prune) when the run wasn't fully read, deferring cleanup to a clean run. Adds a test forcing a generic (non-Permission) read error -> manifest=None. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… success A read/extraction error no longer drops a live tool from the manifest (presence is recorded before extraction) and never fail-closes the whole manifest to None — so one tool's failure can't block pruning every other tool on the device. A detector that errors is kept in the manifest (presence unknown, not an uninstall). Removes the global scanned_manifest_complete fail-close. Tests rewritten to the new contract. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bcb482e. Configure here.
🛡️ Automated Security Review (consensus)1 finding — 0 high-confidence, 1 to triage. Reviewers: Cursor, Claude, Semgrep, Gitleaks. Findings🟡 TRIAGE: Device-wide error over-expands manifest across all users
Impact: On a device-wide processing exception, the handler adds Fix: On device-wide failure, add manifest entries only for users where the tool was actually detected this run (e.g., track per-user detection before the outer Flagged by: Cursor Notes
🤖 consensus review · reviewers: Cursor,Claude,Semgrep,Gitleaks · head |
…talled-tools-removed-tools Conflicts were purely additive — union both sides: - utils.send_scan_event: keep staging's system_user param alongside WEB-4679's manifest + covered_home_users (and their docstrings); body already adds all three. - ai_tools_discovery completed event: pass system_user + manifest + covered_home_users. Manifest-from-presence fix auto-merged cleanly. Manifest tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🛡️ Automated Security Review (consensus)1 finding — 0 high-confidence, 1 to triage. Reviewers: Cursor, Claude, Semgrep, Gitleaks. Findings🟡 TRIAGE: Device-wide
|
|
|
||
| try: | ||
| # Record presence before extraction so a read error below can't drop a live tool. | ||
| scanned_manifest.add((user_name, tool_name)) |
There was a problem hiding this comment.
Tracks phantom ownership
This adds the tool for every user in all_users, but the tool list was deduped globally by tool name and path before this loop. If Alice still has a user-scoped tool and Bob removed it, Alice's detection can keep one global tool entry, then this line adds (Bob, tool_name) even though Bob did not detect it. Only Copilot CLI and Augment have a later ownership discard, so other user-scoped tools can remain in Bob's manifest and the backend will never prune Bob's stale row.
| ) | ||
| # Detector errored -> presence unknown -> keep it in the manifest (don't treat as uninstalled). | ||
| for failed_tool_name in user_detect_failures: | ||
| scanned_manifest.add((user, failed_tool_name)) |
There was a problem hiding this comment.
Uses umbrella names
This records detector failures with detector.tool_name, but some detectors protect rows whose successful tool['name'] values are different. For example, a Copilot detector failure can add GitHub Copilot, while existing rows may be GitHub Copilot (VS Code) or other surface-specific names. The backend set-diffs exact (home_user, tool_name) pairs, so a transient detector error can still prune the real surface row and keep only a phantom umbrella-name entry. The failure path needs to protect the concrete row names that the detector owns, or skip pruning that detector namespace for the user.

Summary
The discovery agent never told the backend which tools were still installed, so an uninstalled tool's row persisted on the dashboard forever. The
completedscan event now carries a manifest of the(home_user, tool_name)pairs successfully scanned this run, pluscovered_home_users, so the backend can reconcile by set-difference and soft-delete what's gone.Changes
ai_tools_discovery.py: accumulatescanned_manifeston the send-success and dedup hash-match paths only — a tool that errored on read is deliberately left out so it's never mistaken for uninstalled. Passmanifest+covered_home_users(= all enumerated OS users, so a user who removed their last tool is still in scope) to the completedsend_scan_event.utils.py:send_scan_eventgains optionalmanifest/covered_home_users, inserted into the payload only when present (backward compatible).Stdlib-only; the accumulation is pure in-memory and cannot raise (runs on customer machines).
Cross-repo
Pairs with the ai-gateway-data WEB-4679 PR (reconcile +
removed_atsoft-delete). Forward/backward compatible — an old backend simply ignores the new fields, deploy order independent.Test plan
tests/test_scan_completed_manifest.py(8 tests): manifest carried on the completed event; success + hash-match included, errored read excluded;covered_home_usersincludes a zero-tool user; legacy call omits both keys; non-completed events carry no manifest.🤖 Generated with Claude Code
Note
Medium Risk
Changes backend reconciliation semantics: incorrect manifest entries could soft-delete live tools or leave stale rows, though the PR deliberately errs toward keeping tools on ambiguous failures.
Overview
WEB-4679 lets the backend stop showing tools that were uninstalled by reconciling against what the agent actually saw this run. The
completedscan event now includes amanifestof(home_user, tool_name)pairs andcovered_home_users(all enumerated OS users), so the gateway can set-diff and soft-delete rows outside that scope.Manifest entries are driven by detection/presence, not whether config read or upload succeeded. Each per-user pass records the tool before filtering/extraction; Copilot/Augment ownership skips
discardthe optimistic entry. Detector exceptions add the tool via a newfailuresset ondetect_all_tools; device-wideprocess_single_toolfailures add the tool for every covered user. Upload/hash-match outcomes no longer gate inclusion.send_scan_eventaccepts optionalmanifestandcovered_home_usersand only adds them when notNone(legacy callers unchanged).tests/test_scan_completed_manifest.pycovers payload shaping, CLI completed events, and in-process presence semantics (read errors, upload failures, detector errors).Reviewed by Cursor Bugbot for commit e7e7a9e. Bugbot is set up for automated code reviews on this repo. Configure here.
Greptile Summary
This PR adds scan manifests so the backend can prune removed discovery tools. The main changes are:
(home_user, tool_name)pairs during discovery.manifestandcovered_home_userson completed scan events.Confidence Score: 4/5
This should be fixed before merging.
scripts/coding_discovery_tools/ai_tools_discovery.py
Important Files Changed
Comments Outside Diff (2)
scripts/coding_discovery_tools/ai_tools_discovery.py, line 2646-2649 (link)When
send_report_to_backendreturns(False, retryable=True), the report is queued for the next run but the tool is never appended toscanned_manifest. The backend then receives acovered_home_usersentry for the user but no manifest entry for this tool, which it may interpret as "tool uninstalled" and issue a soft-delete — even though the tool is still present; the upload just failed transiently.The PR description states the exclusion criterion as "a tool that errored on read", and the comment on line 2644 echoes "Successfully read and uploaded." Upload failures are not read failures, so by the stated design intent the tool should still be manifested. The fix is to record the tool in
scanned_manifestas soon asfilter_tool_projects_by_userandgenerate_single_tool_reportsucceed (i.e., after the report is built), independent of whether the HTTP upload succeeds.scripts/coding_discovery_tools/ai_tools_discovery.py, line 2712-2736 (link)The existing
sentry_metrics_payload(sent viasend_discovery_metrics) trackstool_countanduser_count, but adds nothing for the new manifest. Without manifest-specific metrics it will be impossible to diagnose backend pruning anomalies in production. Concrete metrics to add to themetadatablock:manifest_size:len(scanned_manifest)— how many (tool, user) pairs were recorded this run.manifest_excluded_reads: tools that errored on read (the key correctness signal for the errored-read exclusion logic).Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (6): Last reviewed commit: "Merge origin/staging into nanda/web-4679..." | Re-trigger Greptile