Repository navigation
Say why an apply failed in its telemetry and --json events - #2247
Conversation
A failed in-place apply reported the same `apply_failed` code for every cause, so the patch-lifecycle events could not tell a hash mismatch from a missing blob, a write error or an uninstalled package. - core: `ApplyResult.cause` (`ApplyFailureCause`), set at each failure of the in-place engine: hash_mismatch, file_not_found, unsafe_path, shared_store, conda_build, blob_missing, blob_corrupt, write_failed, sidecar_failed; Maven refusals keep their own codes. A failure that sets none falls back to the file that stopped it, else `unclassified`, so the unexplained share stays measurable. A failed store copy hands its cause to the package. - --json: a failed apply event keeps `errorCode: apply_failed` and adds `cause` (additive; nested get/scan envelopes carry it too). - telemetry: each failed patch's `code` is its cause; failures with no package result (no release variant matched, a Maven base refused as a whole, a manifest patch whose package is not installed) are named too; `failure_codes` counts failed patches per code over the whole run; a run stopped before patching reports `sources_download_failed` / `offline_missing_sources` as its `error_code`. Exit codes and what counts as a failure are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`context.ci` is `true` when `CI` is set to anything but empty, `0` or `false`, or `GITHUB_ACTIONS` is set: the same rule the update notifier already used, now shared from core. It tells CI runs from a developer's machine without naming the provider, repository or job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes: - Drop the fallback that guessed a cause from the verified files: a step after a successful engine run (a failed native rebuild, a `--force` skip) could leave the last file describing something else. A failure with no cause set is `unclassified`. - Set the cause where results are failed outside the engine: gem refusals and `native_extension_build_failed`, Gradle's stale transform copies, a failed `go.mod` edit (`write_failed`). `Refused` becomes `Coded` and the enum is `#[non_exhaustive]`. - A copy no release variant matches is reported as `no_matching_variant`, not `package_not_installed`; once per record, never a record another copy applied; Maven entries come from the manifest-filtered variants. - A failed store copy's cause is read before its files move. - The contract says which causes reach `--json` and which only telemetry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR SummaryMedium Risk Overview The patch engine records Separately, telemetry Reviewed by Cursor Bugbot for commit b7a8965. Configure here. |
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.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b7a8965. Configure here.
…lemetry # Conflicts: # crates/socket-patch-cli/src/commands/apply.rs
`gradle_ro_cache_shadows` fails the run while the writable copies are patched; only a record no copy matched is left out when another copy applied it. Drop the configuration and contract doc edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main gained the PyPI and RubyGems vendored refusals (#2208) and the reason of a failed apply in its telemetry and `--json` events (#2247). #2208 is the squash of the branch that the merge before this one brought in. Main's tree is that branch merged with #2247, so the seven files that conflicted there conflict here again, with the same two sides: `vendor/refusals.rs`, `bazel/built.rs`, `bazel/maven.rs`, `args.rs`, `CLI_CONTRACT.md`, `docs/ecosystems.md` and `scripts/loc-budget.json`. Each is what the merge before this one made of it, and #2247 touches none of them. So this tree is the last one with #2247 added and nothing else: 16 files, none of which this branch changes. The cap of the `bazel` group in `scripts/loc-budget.json` stays 5300, the one value every open change of this series sets so that they stop conflicting on that line; the count of this tree is 4638. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Why
A failed in-place (agent mode) apply reports
error_code: apply_failedand, per patch,code: apply_failedwhatever went wrong. The patch-lifecycle events therefore cannot tell a hash mismatch (a different build of the version, or a local edit) from a missing blob, a write error, a release variant that does not match, or a manifest patch whose package is not installed. Several of those fail the run with no per-package result at all, so the event names no patch either.What changes
Commit 1: why an apply failed
core:
ApplyResult.cause(ApplyFailureCause,#[non_exhaustive]) is set where a result is failed:hash_mismatch,file_not_found,unsafe_path,shared_store,conda_build,blob_missing,blob_corrupt,write_failed,sidecar_failed;native_extension_build_failed;go.modedit (write_failed).A path that sets none is
unclassified. The cause is never guessed from the verified files, which a later step can leave describing something else, and the unexplained share stays measurable. A failed pnpm/vlt store copy hands its cause to the package.--json: a failed apply event keepserrorCode: apply_failed(consumers route on it) and addscause. This is additive; nestedget/scanenvelopes carry it too.telemetry:
codeis its cause;package_not_installed). These appear in telemetry only;--jsonoutput is unchanged for them;failure_codescounts failed patches per code over the whole run, so a run over 50 patches is not cut off;sources_download_failed,offline_missing_sources) as itserror_code.Exit codes, human output and what counts as a failure are unchanged.
Commit 2:
context.ci(separate on purpose: it's a new environment signal, so it's the maintainer's call whether to keep it)truewhenCIis set to anything but empty,0orfalse, orGITHUB_ACTIONSis set. This is the rule the update notifier already used, now shared from core. It names no provider, repository or job. Drop the commit to ship without it.Tests
tests/cli/telemetry_e2e.rs): hash mismatch, missing file, corrupt blob, package not installed, failed blob download. Each asserts the telemetrycode,failure_codes,error_code, the envelope'scause, and that no package name leaks.failure_codescounting, CI detection.cargo test -p socket-patch-core -p socket-patch-clipasses locally, except two old-toolchain Cargo e2e tests that need x86 binaries this arm64 Mac can't run.cargo clippy --workspace --all-features -D warningsandcargo fmt --checkare clean.Not in this PR
unclassified. That share is now visible and can be narrowed later.ApplyResultgains a public field, so code outside this workspace that builds it with a struct literal must addcause. Nothing in the workspace is affected; the enum is#[non_exhaustive]so later causes don't break matches.🤖 Generated with Claude Code