Repository navigation
Report which patches each run acted on, and count downloads, vendoring and rollbacks correctly - #2178
Conversation
…g and rollbacks correctly Telemetry could say that a rollback happened, never of which patch, so a patch that is being rolled back far more than the others was invisible. Several counts were also wrong or missing. Events about specific patches (apply, hosted pins, vendor, download, remove, rollback) now name each one: the patch UUID with its ecosystem, mode and outcome, at most 50 per event with failures first, plus exact per-outcome counts for the whole run. They are derived from the run's own `--json` events, so the two cannot disagree. No package name, path or file list is added; the docs say plainly that a patch UUID tells Socket which package version a patch is for. Counting fixes: - Agent-mode downloads were reported only by `get <uuid>`. `scan` and `get <package|advisory>` now report the patch records they download. - `vendor --revert` reported nothing. It now reports each entry it takes out as a removal. - Vendor events carry `mode: "vendored"`, and vendor and agent applies report the command the user ran (`scan`, `get`) instead of always `vendor` / `apply`. - A rollback reports `dry_run` and whether its targets were named, so a preview is no longer counted as a rollback. - `remove` sent a failure and a removal of zero for one run when every match was kept, and nothing at all on several failure exits (an unreadable vendor ledger, a refused hosted restore, an ambiguous target). It now sends one event per run. - Two `scan` failure exits reported nothing. - A failed apply or vendor run reports what it did apply. Every failure event carries `error_code`, the code the `--json` envelope reports, so a mistyped target is distinguishable from a patch that would not come off; hosted failures report the same code with and without `--json`. Error messages are cut to 1,000 characters so an event stays small enough for the server to read. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… size for any message - An interactive agent-mode `scan` reported its download and apply under the command `get`: that path ran the download engine over a `get` envelope. It now fills a scan envelope, and the end-to-end test covers the run with and without `--json`. - A vendored `scan` / `get` whose download failed sent a failure event that named no patch: the vendor step only sees the records that did download. The download phase's failures are now added to the event. - `vendor` could credit an event to the wrong patch. The manifest's record now wins over a stale ledger entry, base purls are no longer recorded beside keys (an ambiguous one named an arbitrary release), and a swept orphan directory is no longer credited to the patch the ledger records for the same package. - A `remove` whose hosted leg stopped on one pin reported every matched pin as failed, including the ones it had restored. Restored pins are reported as removed. - The 10,000 character bound on an event did not hold for a message that grows when JSON escapes it. The serialized event is now fitted to 9,000 bytes: the tail of the error message goes first, then entries off the end of the patch list. - `remove` now reports on the failure exits that still sent nothing (an unreadable manifest path, a bare project, contested hosted wiring, a `--skip-rollback` refusal, a ledger write failure), and the ledger-only path sends its event before printing its envelope. - `patch_fetch_failed`, `patch_repair_failed` and `vex_failed` carry `error_code` like the other failure events. - Events spell an ecosystem by its CLI name, as `scan` does, so the two join. The docs say which runs still report nothing in any command: a usage error, and a run that could not take the apply lock. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview A new README and Reviewed by Cursor Bugbot for commit b89eee6. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b89eee6. Configure here.
…ighbours `run_removes_matching_patch_and_exits_zero` ran `remove` in-process with `offline: true`. `run()` mirrors that flag into the process environment, where the parse tests of the same binary read it: one that parsed after it saw `offline: true` and failed its defaults check. The coverage build lost that race in CI. The test only needs no telemetry call, which `no_telemetry: true` already gives it (and that variable is one the parse tests expect), so the offline flag is dropped. Nothing in the run reaches the network. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The telemetry context said which version, platform and command an event came from, but not how the binary got onto the machine. Each event now carries `context.channel`: `standalone` (the install script or a downloaded binary), `npm`, `cargo`, `homebrew`, `pypi` or `launcher_cache`. It is the detection `--update` already uses, from the binary's canonical path, worked out once per process. It names the channel and never the path, reads no project file and makes no request. When the binary's own path cannot be read, the field is left out. With it, usage can be broken down by distribution channel: which of the ways to install socket-patch the people applying patches came through. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… installs behind a symlinked home Review of the install-channel commit found five things. A successful `--update` on Linux sent `cli_updated` without its channel. The event is built after the swap, and by then the path of the binary that ran reads as deleted, so it could not be resolved. `--update` now works the channel out before it replaces anything. A `cargo install` was reported as `standalone` on Windows, and on Unix when the home directory is reached through a symlink. The executable's path is canonical and the roots it was compared with (`CARGO_HOME`, the home directory, the cache directories) were taken raw from the environment, so they were never a prefix of it. The roots are canonical now. This is the detection `--update` uses too: there it let a cargo-managed binary be replaced in place, which it now refuses as documented. Building an event could ask the user database for a home directory when `HOME` and `CARGO_HOME` were both unset. The telemetry context now reads environment variables alone. The docs said every event has the field and that `standalone` means the install script. The field is left out when the binary cannot read its own location, and `standalone` is any location no package manager owns. Two tests assumed the build directory is not under a path a package manager owns. They check the id against the binary's own channel instead, and new tests cover the channel after a self-update and a binary inside `node_modules`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two review comments on the standalone `vendor` command. It read the patch UUIDs its event names after releasing the apply lock. Another run on the same project could rewrite the ledger and the manifest in between, and this run's event would be credited to that run's patches. They are read while the lock is still held, as the vendor step of `scan` and `get` already does from its own records. It printed the `--json` envelope and only then started its event, including the removal event of `vendor --revert`. `remove` and the hosted flow start the event first, so that a consumer that closes stdout on the envelope cannot drop it. `vendor` does the same now. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main (#2178) gave track_outcomes_for_vendor the patch uuids of each run and changed its inline eject-refused block; this branch had moved that block into eject_refused(). Keep the helper and pass it the pins' uuids, so both of its callers, the hosted-pin refusals and the Bazel declines, send the new event. Assisted-by: Claude Code:claude-opus-5-5

Why
Telemetry could say that a rollback happened, but never of which patch. If one patch is being rolled back or removed far more than the others, nothing showed it. Looking at what the events actually record also turned up counts that were wrong or missing.
What changes
Events name the patches they are about
Events about specific patches (
patch_applied,patch_apply_failed,patch_vendored,patch_vendor_failed,patch_fetched,patch_removed,patch_remove_failed,patch_rolled_back,patch_rollback_failed) add tometadata:patches{uuid, ecosystem, mode, outcome, code?}entries, one per patch and mode, failed ones firstpatches_truncatedtruewhen the cap dropped entriesoutcomesecosystems,modesThe entries are derived from the run's own
--jsonevents, so telemetry and--jsoncannot disagree.This changes what telemetry sends. Until now only
getsent a patch UUID, and the docs said events hold "no package list". A patch UUID tells Socket which package version a patch is for, so naming the patches a run applied or rolled back is naming those package versions. No package name, path or file list is added, and the README,docs/configuration.mdandCLI_CONTRACT.mdnow say this plainly. The UUIDs are what let Socket see when a patch breaks in the field: one that fails to apply, or that people roll back, far more than the others. The project owner approved sending them on 2026-11-20.Counts that were wrong or missing
get <uuid>scanandget <package|advisory>report the patch records they download, as onepatch_fetchedper runvendor --revertreported nothingpatch_removedmode; vendor and agent applies always reported the commandvendor/applymode: "vendored", and the command the user ran (scan,get)dry_run, andtargeted(the user named the patches)removesent a failure and a removal of zero when every match was kept, and nothing on several failure exits (unreadable vendor ledger, refused hosted restore, ambiguous target, missing manifest, contested hosted wiring, a--skip-rollbackrefusal)removewhose hosted restore stopped on one pin had no way to say which pins it did restorescanfailure exits reported nothingpatch_scan_failedpatches_countand the per-patch outcomes, including the patches whose download failedscanreported ecosystems as a list onlypackages_by_ecosystem,patches_by_ecosystemanddry_runFailures carry a code
Every failure event has
error_code: the code the run's--jsonenvelope reports. A mistyped rollback target (patch_not_found) is now distinguishable from a patch that would not come off (rollback_failed). Hosted failures report the same code with and without--json.patch_fetch_failed,patch_repair_failedandvex_failedcarry it too.Two kinds of run still report nothing, in every command, as before: one that exits 2 on a usage error, and one that could not take the apply lock. The docs now say so.
Event size
The server cannot read an event body past 10,000 characters, so the serialized event is kept under 9,000 bytes: at most 50 patches per event, error messages cut to 1,000 characters, and an event that still does not fit (a message that grows when JSON escapes it) gives up the tail of its message, then entries off the end of its patch list. A unit test builds the largest possible event with plain, quote-heavy, control-character, Windows-path and wide-character messages and checks the bound.
Events say how the CLI was installed
Every event's
contextnow carrieschannel:npm,cargo,homebrew,pypiorlauncher_cachewhen the binary sits where that tool puts it, andstandalonefor anywhere else (the install script, a downloaded binary, a container image). It is the detection--updatealready uses, worked out once per process from the binary's canonical path. It names the channel and never the path, reads no project file, makes no request, and is left out when the binary cannot read its own location. It lets usage be broken down by distribution channel.This fixed one thing in
--updateitself: the directories a binary is compared with (CARGO_HOME, the home directory, the cache directories) were taken raw from the environment while the binary's path is canonical, so acargo installon Windows, or under a home directory reached through a symlink, read asstandaloneand--updatewould replace it in place. The roots are canonical now, and--updaterefuses there as documented.Compatibility
No event type is added, so nothing has to be deployed on the server first. Every existing field keeps its name and meaning, with two deliberate changes:
removed_countnow counts patches taken out (it was manifest records, and 0 under--preserve-state), andremoveno longer reports failures on a--dry-run, matching its success.Testing
apply(applied, then already patched),rollback(whole project, targeted dry run, no match),remove(removed, dry run, no match), an agent-modescan(scanned, fetched, applied under one session), a hostedscan(success, failure with and without--json), and a vendoredscanfollowed byvendor --revert.cargo clippy --locked --workspace --all-features -- -D warningsandcargo fmt --checkpass. Core and CLI unit tests pass (8,232 and 1,030), as do thecli,apply,get,remove,repair,rollback,scan,vendor,vex,scan_vendor_e2e,in_process_vendor,in_process_rollback_hostedandin_process_remove_repair_lifecyclesuites.Review
/code-review highran on the first commit and found ten issues; the second commit fixes all of them, each with a regression test: an interactive agent-modescanreporting underget, vendored download failures missing from the failure event,vendorcrediting an event to a stale or ambiguous patch UUID, a swept orphan directory credited to the patch the ledger records, restored hosted pins reported as failed, the size bound not holding for escape-heavy messages,removeexits that still sent nothing, an event sent after its envelope printed, three failure events withouterror_code, and ecosystem names that did not matchscan's./code-review highran again on the install-channel commit and found five issues; the commit after it fixes all five:cli_updatedlosing its channel on Linux because the event is built after the swap, acargo installread asstandaloneon Windows and under a symlinked home, a possible user-database lookup while building an event, docs that overstated the field, and two tests that depended on where the build directory sits.One part of one finding from the first review is not fixed: a run that cannot take the apply lock still reports nothing. That is true of every command and predates this change; the docs now state it instead of claiming an event on every exit.
🤖 Generated with Claude Code