You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ecba20e
Browse filesBrowse the repository at this point in the historyBrowse files
Report which patches each run acted on, and count downloads, vendoring and rollbacks correctly (#2178)
* Report which patches each run acted on, and count downloads, vendoring 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>
* Address review: name the right patch and command, and bound the event 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>
* Keep an in-process remove test from setting SOCKET_OFFLINE for its neighbours
`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>
* Report the install channel with each telemetry event
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>
* Address review: keep the channel through a self-update, and see cargo 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>
* Name `vendor`'s patches under the lock, and report before printing
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>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: crates/socket-patch-cli/CLI_CONTRACT.md
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2087,9 +2087,13 @@ State lives at `$XDG_CACHE_HOME`|`~/.cache` (Unix/macOS) or `%LOCALAPPDATA%` (Wi
2087
2087
2088
2088
## Telemetry
2089
2089
2090
-
Telemetry is **on by default**. Each command reports its outcome as one JSON event per row of the table below (a `scan` or `get` that also applies sends two).
2090
+
Telemetry is **on by default**. Each command reports its outcome as one JSON event per row of the table below (a `scan` or `get` that also downloads and applies sends up to three; a `scan` over several project directories reports each).
2091
2091
2092
-
**What is sent.** `{event_sender_created_at, event_type, context: {version, platform, arch, command}, session_id, metadata?, error?: {type, message}}`; no `event_kind`, so the backend stores it as a required event. `context` is the client version, `std::env::consts::OS` / `ARCH` and the subcommand. `session_id` is a random UUID generated per process and never stored, so it links the events of one run and nothing else. `metadata` holds only the per-event fields in the table. `error.message` (failure events) has every URL redacted (userinfo, grant tokens, signed query values) and the home directory replaced by `~`; it can otherwise quote a package name or a path. The request carries `User-Agent: SocketPatchCLI/<version>` and, on the org route, `Authorization: Bearer <token>`. Nothing else is sent: no package list, no file contents, no machine identifier.
2092
+
**What is sent.** `{event_sender_created_at, event_type, context: {version, platform, arch, command, channel?}, session_id, metadata?, error?: {type, message}}`; no `event_kind`, so the backend stores it as a required event. `context` is the client version, `std::env::consts::OS` / `ARCH`, the subcommand, and `channel`: the install channel of the running binary (`npm`, `cargo`, `homebrew`, `pypi`, `launcher_cache`, or `standalone` for any location none of those owns; the same detection `--update` uses, from the binary's canonical path, read from environment variables alone and resolved before `--update` swaps the binary), omitted when that path cannot be read. `session_id` is a random UUID generated per process and never stored, so it links the events of one run and nothing else. `metadata` holds only the per-event fields in the table. `error.message` (failure events) has every URL redacted (userinfo, grant tokens, signed query values), the home directory replaced by `~`, and is cut to 1,000 characters; it can otherwise quote a package name or a path. The request carries `User-Agent: SocketPatchCLI/<version>` and, on the org route, `Authorization: Bearer <token>`. Nothing else is sent: no package name, no file contents, no machine identifier. The patches an event names are named by patch UUID (see below), which identifies a patched package version to Socket.
2093
+
2094
+
**Patches.** An event about specific patches (the rows marked *patches*) adds to `metadata`: `patches`, at most 50 `{uuid, ecosystem, mode, outcome, code?}` entries, one per patch and mode, failed ones first (`mode`: `agent` / `hosted` / `vendored`; `outcome`: `applied`, `downloaded`, `rolled_back`, `removed`, `rebuilt`, `verified` (a dry run), `skipped`, `failed`; `code` is the event's `errorCode`, on `skipped` and `failed` only); `patches_truncated: true` when the cap dropped entries; `outcomes`, the count of patches per outcome over the whole run; and `ecosystems` / `modes`, their distinct values. They are derived from the run's `--json` events, so the two cannot disagree: several events for one patch (one per installed copy) fold into the one that says most (a failure over a change, a change over a preview, a preview over a skip). A run that named no patch adds none of these. The event body stays under 9,000 bytes (the server's dashboards cannot read one past 10,000 characters): an event that would not fit gives up the tail of its error message, down to 200 characters, and then entries off the end of its patch list.
2095
+
2096
+
**Failures.** Every failure event carries `error_code`: the code the run's `--json` envelope reports as its `error.code` (`patch_not_found`, `rollback_failed`, `vendor_revert_kept`, …), so a mistyped target is distinguishable from a patch that failed. It is the same with and without `--json`. A run whose envelope has failed events and no top-level error reports `apply_failed`, `vendor_failed`, `hosted_failed` or `repair_failed`. Two kinds of run report nothing, in every command: one that exits 2 on a usage error, and one that could not take the apply lock.
2093
2097
2094
2098
**Where.** `POST <api>/v0/orgs/<org>/telemetry` with the bearer when the run has a token and an org, else anonymously `POST <proxy>/patch/telemetry` (`--api-url` / `--proxy-url` and their env vars move both). The route is the run's API client's when the run built one, so telemetry follows the same host and org as its API calls. A run that built no client (see [API client construction](#api-client-construction)) takes the route from the configured credentials alone (flag → env → socket-cli config, no network): a token with no configured org then reports anonymously, because the org is never looked up only to address an event.
2095
2099
@@ -2110,14 +2114,16 @@ Every `event_type` must be in the Socket API's patch event map, or it is stored
2110
2114
2111
2115
| Command | Success | Failure | Metadata |
2112
2116
|---|---|---|---|
2113
-
| `scan` | `patch_scanned` | `patch_scan_failed` | `packages_scanned`, `free_patches`, `paid_patches`, `can_access_paid`, `ecosystems` (found by the crawl), `fallback_to_proxy`, `mode` (requested: `hosted` / `vendored` / `agent`, or `report` with none), `project_modes` (already wired: `hosted` lockfile pins, `vendored` ledger, `agent` manifest) |
| `apply` (and the nested apply of `scan`/`get --mode agent`, reported under `scan` / `get`) | `patch_applied` | `patch_apply_failed` | `mode: "agent"`, `patches_count` (packages patched; on a failure, what the run did apply), `dry_run`, *patches* |
2120
+
| `scan --mode agent`, `get <purl\|advisory>` in agent mode (a run that reached a patch) | `patch_fetched` | — | `mode: "agent"`, `patches_count` (records downloaded), `download_mode`, *patches* (`downloaded`, `skipped` / `already_in_manifest`, `failed`) |
0 commit comments