Skip to content

refactor: send device_discovery_id on the discovery wire - #380

Merged
AakashVelusamy merged 23 commits into
stagingfrom
aakashvelusamy/web-5977-send-device-discovery-id-wire-key
Nov 29, 2026
Merged

AakashVelusamy merged 23 commits into
stagingfrom
aakashvelusamy/web-5977-send-device-discovery-id-wire-key

Conversation

@AakashVelusamy

@AakashVelusamy AakashVelusamy commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Final piece of WEB-5977. gateway-data renamed the device-discovery serial column to device_discovery_id and now accepts both wire keys (ai-gateway-data#2978). This flips the discovery tool to send the new key.

⚠️ DEPLOY ORDER — do not merge/release before ai-gateway-data#2978 is live

gateway-data must be accepting device_discovery_id before any client starts sending it. #2978 accepts both keys, so once it's deployed this is safe; released before it, discovery ingestion would 400.

That covers the memory-fix endpoints too, not just report ingestion: /api/v1/ai-tools/memory-fixes/ and /memory-fixes/results/ both resolve the device through device_discovery_id_from_report in #2978, so they take either key. Before #2978 is live they require device_id, and a memory-fix fetch sent with the new key alone would come back empty rather than failing loudly.

What changed

The payload key device_id → device_discovery_id across every outbound path:

  • the single-tool report and generate_report (ai_tools_discovery.py)
  • the scan-event and metrics payloads (utils.py)
  • the S3 meta_body (upload-url) and notify_body (from-s3) (s3_uploader.py)
  • the memory-fix fetch and results POSTs (memory_fix.py)

The S3 uploader reads the new key with a fallback to device_id, so any old-format payload already sitting in the offline retry queue still uploads after an upgrade.

Internal names (get_device_id, DeviceIdExtractor, local vars) are left as-is — they never cross the wire, so renaming them would be churn.

Backward-compatibility (both directions)

  • Deployed old clients keep sending device_id; gateway-data still accepts it (#2978). Nothing in the field breaks.
  • This client's own offline queue may hold old-format payloads written before the upgrade; the fallback read handles them.

Testing

  • Full affected suite green (s3-uploader, send-and-persist, discovery-flow, scan-manifest, container-attribution): 62 + 54 passed.
  • Guard proven: reverting the construction to main makes the updated test_detect_and_report_flow fail with 'device_discovery_id' not found — the test genuinely guards the new wire key.
  • The old-key input fixtures now double as fallback coverage (old-key payload in → new-key sent out).

🤖 Generated with Claude Code


Note

Medium Risk
This is a coordinated API contract change across all discovery upload paths; releasing before the backend accepts the new key would break ingestion, though S3 queue fallback limits risk for in-flight retries only.

Overview
Renames the discovery client’s wire field from device_id to device_discovery_id so payloads match gateway-data’s renamed column (WEB-5977). The new key is used on every outbound path: full/single-tool reports, scan lifecycle events, discovery metrics, and the S3 upload-url plus /from-s3/ notification bodies.

The S3 uploader reads device_discovery_id with a fallback to device_id so payloads already queued before upgrade still upload. Internal helpers and variables (get_device_id, Sentry device_id tags) are unchanged.

Deploy order: gateway-data must accept device_discovery_id (dual-key support) before this client ships; otherwise ingestion can 400. Tests now assert device_discovery_id on the affected payloads.

Reviewed by Cursor Bugbot for commit 7df8465. Bugbot is set up for automated code reviews on this repo. Configure here.

Unbound Review · Score 3/5 (1 P1) · 360dfc1

  • codex (own score 5/5): The PR changes discovery reports, scan events, metrics, S3 metadata, and memory-fix requests to send device_discovery_id. The S3 uploader also accepts queued reports using the old key. I found no verified defects or applicable rule violations in the changed code.
  • claude (own score 3/5): The PR changes the outbound wire key from device_id to device_discovery_id on the report, scan-event, metrics and S3 paths. The S3 uploader falls back to the old key, so payloads already in the offline queue still upload. Those paths are consistent and tested, and nothing in the client still reads device_id from a payload except the intended fallback. The PR also renames the key in the memory-fix endpoints, but the description leaves them o

findings: 0 P0 · 1 P1 · 0 P2 (top 5 P0/P1 inline) · engines: codex ✅ · claude ✅

rules applied: CLAUDE.md

Renames the payload key device_id -> device_discovery_id across the report,
scan-event, metrics, and S3 (meta + notify) payloads. The S3 uploader reads the
new key with a fallback to device_id so any old-format payloads already queued
offline still upload. Deploy AFTER gateway-data accepts both keys.

Updated the wire-key assertions in the discovery-flow, s3-uploader and
send-and-persist tests.
@AakashVelusamy
AakashVelusamy requested a review from a team September 29, 2026 10:21

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: Claude, Semgrep, Gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 7df8465e · 2026-09-29T10:31Z

zeus-12 and others added 19 commits October 7, 2026 11:57
chore: release_09_10_2026_v1
chore: release_28_10_2026_v1
chore: release_03_11_2026_v1
chore: release_11_11_2026_v1
Staging to main release 16_11_26
…#409)

fix(discovery): keep Cowork and plugin skills on root/MDM scans

Co-authored-by: Vignesh Subbiah <51325334+vigneshsubbiah16@users.noreply.github.com>
Merge pull request #410 from websentry-ai/web-6771-plugins-per-user
chore: release_17_11_2026_v1
* WEB-6766: Cowork and Desktop rows stop listing claude.ai connectors the user removed (#418)

* Cowork and Desktop rows drop claude.ai connectors the user removed (WEB-6766)

When the CLI and the desktop app share an account, take the list from the
CLI org's desktop session files of the last 30 days instead of the CLI's
"ever connected" names. Anything else falls back to today's output.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Date desktop sessions by last activity, not file time (WEB-6766)

The desktop app re-saves old session files, so file time made old
sessions look recent and kept removed connectors past the 30-day window.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Count only sessions used in the window toward the 200-session cap (WEB-6766)

Re-saved old sessions have fresh file times and could fill the cap before
the last-activity check dropped them. Open up to 1000 files to find 200.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Keep the 200 most recently used sessions, not the first 200 found (WEB-6766)

The scan stopped at 200 sessions in file-time order, so re-saved sessions
could push out a more recently used one and hide its connectors.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Skip the session rule when there are too many files to read (WEB-6766)

Reading only the 1000 newest-saved files could miss a more recently used
session and hide its connectors. Past that count, keep today's list.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Skip the session rule when a session file can't be read (WEB-6766)

An oversized or cut-off session was skipped while the rest replaced the
list, hiding a connector only that session listed. Keep today's list.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Skip the session rule when a session folder can't be listed or is redirected (WEB-6766)

A folder that failed to list, or one redirected out of the home on an
admin scan, was treated as empty while the rest replaced the list.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Use every session in the window; keep tools from the newest listing that has them (WEB-6766)

The 200-session cap is gone: above 1000 files the rule is already skipped,
so the cap only blurred which sessions count. A newer listing without a
tool list no longer discards an older one that has it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

* WEB-6771: Admin scans no longer hang on, or read across users through, planted claude.ai connector or plugin files (#419)

* claude.ai connector readers no longer block on pipes or follow links into other homes (WEB-6771)

Session files, ~/.claude.json, the desktop config.json and the auth cache
now go through the bounded reader, contained to the owner's home on
root and other-user scans.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Claude Code config reader skips pipes too (WEB-6771)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Count Windows administrators and SYSTEM as elevated scans (WEB-6771)

One elevation check for the claude.ai readers; the session reader uses it too.
Tests: own-home cases no longer depend on who runs the suite.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Plugin MCP reader stays inside the owner's home on admin scans (WEB-6771)

Plugin JSON is read through the bounded reader and, on an elevated or
other-user scan, only when it resolves inside that user's home. The
own-home tests now fake the Windows elevation checks too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Claude Code config and plugin registry reads stay inside the owner's home (WEB-6771)

On an admin scan, a Claude Code config that links out of its home is not
read, and the plugin registry files get the same boundary as plugin files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Claude Code config is read in one contained step on admin scans (WEB-6771)

The path check and the read were separate, so a hard link, or a link
swapped in between, still reached another user's config. The read now
goes through the contained reader, skipping only the owner check.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Size limits no longer bring back uninstalled plugins or drop the fallback config (WEB-6771)

The plugin registry is read with the 64 MB limit, so a large one stays
authoritative, and a main Claude Code config over its limit gives way to
the fallback file instead of yielding nothing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* Use the fallback Claude Code config whenever the main one can't be read (WEB-6771)

On a user's own scan the fallback was used only when the main config was
over the size limit. A pipe, a malformed file, or one the home boundary
refuses now gives way to it too; one that reads with no servers does not.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
… (WEB-6727) (#420) (#424)

* Send each memory credential's exact position and upload only flagged files (WEB-6727)

Every regex match is reported with its span and the span of the secret value,
plus the content hash, so the backend can mask without its own regex.
MEMORY.md is sent only when it has a finding, and URL-only files only when
the backend turns URL scanning on.



* Spend the memory upload budget on findings in every folder before URL-only files (WEB-6727)



* Keep at most one upload budget of URL-only memory content in memory while scanning (WEB-6727)

Files with findings spend the budget as each folder is scanned. URL-only files
are held, up to one budget's worth, and take what is left after every folder.



* Apply the per-folder file cap before holding URL-only memory files (WEB-6727)



* Pick URL-only memory files against the real remaining budget, without holding their content (WEB-6727)

While folders are scanned only each URL-only file's path and size are kept.
Once every folder's findings have spent the budget, the files that still fit
are read again and sent, so a small file is never dropped for a larger one.



* Always upload memory files that hold a URL, without a backend switch (WEB-6727)

A file is uploaded when it has a credential finding or a URL host. The
memory_url_scan_enabled flag and its plumbing are gone; the upload budget
still sends files with findings first.



* Send a re-read memory file even when it gained a credential during the scan (WEB-6727)



---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* Report claude.ai connectors from desktop sessions on the Claude Code entry (WEB-6766) (#425)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Merge pull request #422 from websentry-ai/WEB-6710

feat(skills): send each skill's whole folder, not just SKILL.md [WEB-6710]

* chore(skills): revert sending skill folders until big-skill scoring is fixed [WEB-6710] (#426)

* feat(skills): send each skill's whole folder, not just SKILL.md [WEB-6710]

* test(skills): write test files as exact bytes so Windows keeps their line endings [WEB-6710]

* fix(skills): never walk a skill folder linked to a user's home [WEB-6710]

* fix(skills): guard every account's home, not just the scanning user's [WEB-6710]

* fix(skills): name every folder the walk could not finish [WEB-6710]

* fix(skills): bound folder reads, fingerprint unhashed files, refuse links into another user's home [WEB-6710]

* fix(skills): send only real sha256 digests and make folder output independent of timing [WEB-6710]

* fix(skills): hash every file whole, leave out only the skill's own SKILL.md, cap binary heads [WEB-6710]

* fix(skills): attach folders to skills only, never to commands or agents named SKILL.md [WEB-6710]

* fix(skills): skip hashing files over 100 MiB in a skill folder [WEB-6710]

* fix(skills): walk skill folders in a home reached through a linked /home [WEB-6710]

* fix(skills): keep folder reads inside the checked root and send odd names safely [WEB-6710]

* chore(skills): revert sending skill folders until big-skill scoring is fixed [WEB-6710]

* Merge pull request #427 from websentry-ai/WEB-6831

fix(device-id): read only the hardware serial on Windows and macOS [WEB-6831]

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Iyad Zargar <iyad.zargar@gmail.com>
Co-authored-by: Iyad Zargar <dev@iyadzargar.com>
Co-authored-by: pugazhendhi-m <132246623+pugazhendhi-m@users.noreply.github.com>
…10] (#430)

* feat(skills): send each skill's folder with its SKILL.md again [WEB-6710]

* feat(skills): list credential files by name only and keep their contents on the device [WEB-6710]

* fix(skills): redact folder files in the payload log and check secrets folders first [WEB-6710]

* fix(skills): withhold hidden credential files, auth.json and terraform state [WEB-6710]

* fix(skills): withhold never-template key files before the template rule and match terraform variants [WEB-6710]

* fix(skills): match credential backups, env variants, token files and service-account keys by pattern [WEB-6710]

* fix(skills): stop the backup-name loop on a bare .bak and withhold credential-named data files [WEB-6710]

* fix(skills): withhold private keys found by their first bytes and password or api key files [WEB-6710]

* fix(skills): withhold .envrc and .dev.vars variants [WEB-6710]

* fix(skills): withhold data files in credential tool folders and pem files holding a private key block [WEB-6710]

* fix(skills): withhold credential-named files of any type and data files holding a private key [WEB-6710]
Skip code calls in the generic token rule for memory files (WEB-6727)…
…[WEB-6710]

fix(skills): fit skill folders to a report budget, never drop a report [WEB-6710]
Staging to main release 26_11_26
[WEB-5602] Promote Coding Discovery Tool staging to main

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: claude, semgrep, gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 0dfd6d37 · 2026-11-27T17:11Z

@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

/review

@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

@cursoragent review

@cursor

cursor Bot commented Nov 27, 2026

Copy link
Copy Markdown

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: claude, semgrep, gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 0dfd6d37 · 2026-11-27T17:15Z

Every S3 fixture built its payload with the legacy device_id, so the tests
only ever exercised the uploader's fallback branch while production now
sends device_discovery_id. The default fixture now matches what the device
builds, and a separate test covers a report queued before the rename.

Verified the new test fails without the fallback and passes with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: claude, semgrep, gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 3f4c70a0 · 2026-11-27T17:31Z

The metrics POST piggybacks on the report endpoint and carries the device
key like any other payload, but nothing asserted it. A regression to the old
key would have shipped silently.

Verified the guard bites: reverting just the metrics key makes this test fail
with a KeyError, and it passes again once restored.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

/review

@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

@cursoragent review

@cursor

cursor Bot commented Nov 28, 2026

Copy link
Copy Markdown

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: claude, semgrep, gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 5c1544cf · 2026-11-28T10:32Z

@AakashVelusamy

AakashVelusamy commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Comment disposition audit · head 5c1544c

Unbound Review — codex + claude

Finding Disposition
P2 Metrics payload key rename has no test Fixed in this push. test_metrics_payload_names_the_device_with_the_new_key drives send_discovery_metrics against the suite's real local HTTP server and asserts the posted body carries device_discovery_id and no longer carries device_id.

The guard was proven to bite rather than merely added: reverting only the metrics key to device_id makes the new test fail with KeyError: 'device_discovery_id', and it passes again once restored. Full file green at 27 passed.

Both engines noted the backend must accept the new key before this ships. That ordering holds — the ingestion endpoints already take either key, so already-deployed clients sending device_id keep working indefinitely.

Cursor

No findings to disposition. Cursor could not run on this PR — it returned a spend-limit error. This check is unmet.

Security consensus — Claude, Semgrep, Gitleaks

No issues found. Clean.


Update · head 360dfc1

Finding Disposition
P1 Memory-fix endpoints renamed without stated backend support Fixed in the description. The endpoints were a real omission from the "What changed" list and the deploy-order note — my own, introduced along with the key change. Both now name them.

For the record, the backend support does exist: ai-tools/memory-fixes/ and ai-tools/memory-fixes/results/ both resolve the device through _agent_json → device_discovery_id_from_report in ai-gateway-data#2978, so they accept either key. The deploy-order constraint is unchanged and still binding — before #2978 is live those handlers require device_id, and a memory-fix fetch sent with only the new key returns empty rather than erroring, which is the failure mode worth stating out loud.

Cursor

Unmet, and accepted as such by the author. Cursor returned "You need to increase your spend limit or enable usage-based billing" on every trigger, so it has reviewed none of this branch's current code.

The memory-fix fetch and results POSTs were the last outbound paths still
naming the device with the legacy key, so the claim that every path moved was
not yet true. Nothing breaks either way today because the backend accepts both
names, but it would once the legacy key is retired.

The payload assertions move with it and stay exact-match, so a regression to
the old key still fails them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

/review

@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

@cursoragent review

@cursor

cursor Bot commented Nov 28, 2026

Copy link
Copy Markdown

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: Claude, Semgrep, Gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 360dfc12 · 2026-11-28T11:35Z

"""Every answer the backend gave for the posted files, or None when the post failed."""
files = [{key: entry[key] for key in ("home_user", "file_path", "sha256")} for entry in posted]
answer = _post_json(link, FIXES_PATH, {"device_id": link.device_id, "files": files})
answer = _post_json(link, FIXES_PATH, {"device_discovery_id": link.device_id, "files": files})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 · Memory-fix endpoints renamed without stated backend support (claude)

The PR also changes the key sent to /api/v1/ai-tools/memory-fixes/ and /memory-fixes/results/, but the description's 'What changed' list and deploy-order note only cover the discovery ingestion paths that ai-gateway-data#2978 makes accept both keys. Suppose the memory-fix handlers still require device_id. Then _placements gets no answer and returns None, so no fixes are applied. Worse, _post_result runs after the file edit has already been made on disk. If that post is rejected, the backend never records that the fix happened, and it will keep reissuing the fix.

memory_fix.py:23-24 (FIXES_PATH/RESULTS_PATH are separate memory-fix endpoints); memory_fix.py:208 and :215 now send device_discovery_id; memory_fix.py:213-216 docstring says the result is posted after 'the edit is already made'. The PR description lists ai_tools_discovery.py, utils.py and s3_uploader.py only and never mentions memory_fix.py.

@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: Claude, Semgrep, Gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 360dfc12 · 2026-11-28T11:40Z

@AakashVelusamy

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Security consensus: no issues found. (reviewers: Claude, Semgrep, Gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 360dfc12 · 2026-11-28T17:46Z

@AakashVelusamy
AakashVelusamy changed the base branch from main to staging November 29, 2026 21:17
@AakashVelusamy
AakashVelusamy merged commit d1ea227 into staging Nov 29, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants