Skip to content

Commit da012af

Browse files
Say why an apply failed in its telemetry and --json events (#2247)
* Say why an apply failed in its telemetry and --json events 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> * Say in telemetry whether a run is in CI `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> * Name an apply failure's cause only where the path that failed it knows 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> * Keep a whole-base refusal in telemetry beside its applied copies `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> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8c2b260 commit da012af

16 files changed

Lines changed: 774 additions & 91 deletions

File tree

‎crates/socket-patch-cli/src/commands/agent_download.rs‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,11 +2072,7 @@ pub(crate) fn record_apply_outcome(
20722072
.iter()
20732073
.find(|f| apply_key_covers(&f.purl, purl))
20742074
{
2075-
env.record(
2076-
PatchEvent::new(EventAction::Failed, purl.as_str())
2077-
.with_uuid(uuid.as_str())
2078-
.with_error(failure.code.as_str(), failure.error.as_str()),
2079-
);
2075+
env.record(failure.event(purl.as_str()).with_uuid(uuid.as_str()));
20802076
failed_any = true;
20812077
} else if let Some(skip) = report.skipped.iter().find(|skip| {
20822078
!unsupported_copy(skip)
@@ -2175,8 +2171,7 @@ pub(crate) fn record_apply_outcome(
21752171
continue;
21762172
}
21772173
appended.push(&failure.purl);
2178-
let mut event = PatchEvent::new(EventAction::Failed, failure.purl.as_str())
2179-
.with_error(failure.code.as_str(), failure.error.as_str());
2174+
let mut event = failure.event(failure.purl.as_str());
21802175
if let Some(uuid) = uuid_of(&failure.purl) {
21812176
event = event.with_uuid(uuid);
21822177
}

0 commit comments

Comments
 (0)