Skip to content

Report which patches each run acted on, and count downloads, vendoring and rollbacks correctly - #2178

Merged
Mikola Lysenko (mikolalysenko) merged 6 commits into
mainfrom
fix/telemetry-coverage
Nov 20, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 6 commits into
mainfrom
fix/telemetry-coverage

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

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 to metadata:

Field Value
patches At most 50 {uuid, ecosystem, mode, outcome, code?} entries, one per patch and mode, failed ones first
patches_truncated true when the cap dropped entries
outcomes Exact count of patches per outcome over the whole run
ecosystems, modes Their distinct values

The entries are derived from the run's own --json events, so telemetry and --json cannot disagree.

This changes what telemetry sends. Until now only get sent 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.md and CLI_CONTRACT.md now 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

Before After
Agent-mode downloads were reported only by get <uuid> scan and get <package|advisory> report the patch records they download, as one patch_fetched per run
vendor --revert reported nothing It reports each entry it takes out as patch_removed
Vendor events had no mode; vendor and agent applies always reported the command vendor / apply mode: "vendored", and the command the user ran (scan, get)
A dry-run rollback looked like a rollback Rollback events carry dry_run, and targeted (the user named the patches)
remove sent 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-rollback refusal) One event per run
A remove whose hosted restore stopped on one pin had no way to say which pins it did restore Restored pins are reported as removed, the refused one as failed
Two scan failure exits reported nothing They report patch_scan_failed
A partly failed apply or vendor run lost what it did apply The failure event carries patches_count and the per-patch outcomes, including the patches whose download failed
scan reported ecosystems as a list only Also packages_by_ecosystem, patches_by_ecosystem and dry_run

Failures carry a code

Every failure event has error_code: the code the run's --json envelope 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_failed and vex_failed carry 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 context now carries channel: npm, cargo, homebrew, pypi or launcher_cache when the binary sits where that tool puts it, and standalone for anywhere else (the install script, a downloaded binary, a container image). It is the detection --update already 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 --update itself: 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 a cargo install on Windows, or under a home directory reached through a symlink, read as standalone and --update would replace it in place. The roots are canonical now, and --update refuses 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_count now counts patches taken out (it was manifest records, and 0 under --preserve-state), and remove no longer reports failures on a --dry-run, matching its success.

Testing

  • Unit tests for the new metadata (cap, failures-first order, exact counts, the size bound, error truncation) and for the event-to-outcome mapping.
  • End-to-end tests that run the binary against a recording endpoint and assert the exact event for: apply (applied, then already patched), rollback (whole project, targeted dry run, no match), remove (removed, dry run, no match), an agent-mode scan (scanned, fetched, applied under one session), a hosted scan (success, failure with and without --json), and a vendored scan followed by vendor --revert.
  • cargo clippy --locked --workspace --all-features -- -D warnings and cargo fmt --check pass. Core and CLI unit tests pass (8,232 and 1,030), as do the cli, apply, get, remove, repair, rollback, scan, vendor, vex, scan_vendor_e2e, in_process_vendor, in_process_rollback_hosted and in_process_remove_repair_lifecycle suites.

Review

/code-review high ran on the first commit and found ten issues; the second commit fixes all of them, each with a regression test: an interactive agent-mode scan reporting under get, vendored download failures missing from the failure event, vendor crediting 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, remove exits that still sent nothing, an event sent after its envelope printed, three failure events without error_code, and ecosystem names that did not match scan's.

/code-review high ran again on the install-channel commit and found five issues; the commit after it fixes all five: cli_updated losing its channel on Linux because the event is built after the swap, a cargo install read as standalone on 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

…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>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 20, 2026 13:42
@cursor

cursor Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Broad CLI-path changes are mostly additive telemetry, but events now include patch UUIDs and richer failure metadata, which affects privacy expectations and downstream dashboards.

Overview
Telemetry now identifies which patches each run touched by deriving per-patch entries from the same --json PatchEvents the CLI already emits. Patch-related events gain metadata.patches (UUID, ecosystem, mode, outcome, optional code), plus outcomes, ecosystems, and modes; failure events also carry error_code matching the JSON envelope.

A new telemetry_outcomes module folds multiple events per patch into a single reported outcome and is wired through apply, scan/get (agent, hosted, vendored), remove, rollback, vendor (including --revert as patch_removed), and repair. Nested apply/download steps report under the user-facing command (scan/get), not only apply/vendor. Scan telemetry adds packages_by_ecosystem / patches_by_ecosystem, agent-mode patch_fetched, and failure reporting on previously silent exits; remove/rollback failures name matched patches and partial hosted restores.

README and CLI_CONTRACT.md document patch UUIDs in events, payload size limits (~9k), and updated event tables. E2E and unit tests assert telemetry matches CLI behavior (including dry-run and not-found cases).

Reviewed by Cursor Bugbot for commit b89eee6. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ 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>
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 20, 2026
Merged via the queue into main with commit ecba20e Nov 20, 2026
50 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/telemetry-coverage branch November 20, 2026 19:06
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Nov 20, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants