Repository navigation
feat(errors)!: add the TargetFailure model, its projection table and conformance registry - #14247
Conversation
…conformance registry Introduce one domain-owned TargetFailure value whose kind alone derives the public code, category, retryability, recovery and details, for CLI and MCP alike. Selected-file malformed and truncated refusals are the first area on it: AnalysisMalformedTargetError is replaced by AnalysisTargetFailureError, and ParseFailure's byte-structure variants are TargetFailure variants rather than a parallel type. The shared stableArtifactParserFailureCli loop is replaced by a declarative registry (tests/support/targetFailure/readers/*.ts) and one generated suite that runs every registered case through the CLI and MCP. BREAKING CHANGE: selected-file malformed and truncated refusals add details.failure_kind, and a truncated target's remediation now says to re-acquire the complete file instead of choosing another target. Codes are unchanged. Affected operations: every operation that refuses a selected file's malformed or truncated bytes, including the ELF, PE, Mach-O, DWARF, Go, Rust, BEAM, pyc, devicetree, Apple IPS, kernel module, binary hardening, managed PE/CLI and IL2CPP readers.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
[High impact] The reviewed revision appears safe to merge with the verified dependent fix in #14265. SummaryAdds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Reader establishes TargetFailure] --> B[AnalysisTargetFailureError]
B --> C[Shared error projection]
C --> D[CLI diagnostic]
C --> E[MCP isError result]
E --> F[Transport removes private structuredContent]
F --> G[Client reads JSON text]
Reviews (12) · Last reviewed commit: "test(errors): check the MCP target failu..." · Reviewed by Greptile |
#14225 refuses a non-regular dyld input as ArtifactReaderFailure("path"); dylibFileLifetime still expected "format" and fails on main's shard 9.
stableArtifact expected "format" for an impossible descriptor byte count (now io) and an invalid chunk size (now InternalInvariantError); directoryArtifactReaderOpen expected "format" for a non-file entry (now path, the same change as #14238). All three fail on main.
… reference page artifact_integrity_mismatch's projection schema requires declared and calculated digests, which a TargetFailure of kind integrity does not carry, so the kind now projects artifact_operation_failed with category integrity_mismatch. The model test validates every kind's projection against analysisErrorProjectionSchema. The reference page joins the documentation sidebar.
…odel # Conflicts: # tests/boundary/filesystem/stableArtifact.test.ts
…d drop their per-command copies The non-MZ PE imports and load-config cases (PE32/PE32+, ZZ and high-bit signatures) and the truncated Apple IPS body move into the conformance registry, which runs them through the CLI and MCP and now also checks that a refusal leaves the selected file unchanged. The per-command tests keep only their valid-image controls.
…etry from it Apply the owner review on #14239 to the TargetFailure model: - remove details.format_failure; failure_kind is the only identifier; - give integrity, conflict and io their own codes (target_integrity_mismatch, input_conflict, host_io_failed) and derive inventory malformed, truncated and unsupported codes from the same table; - add a retry hint (none, backoff, after_change) derived from the kind, with io refined by its transient errno fact; retryable stays the unchanged-retry flag and is true exactly for backoff; - rename the limit-cut result code and category truncated to partial; - drop cancelled and resource from the target kinds and spell identifiers in American English (unrecognized); - return a target failure a tool handler throws as a projected isError result instead of letting the SDK flatten it to text. BREAKING CHANGE: details.format_failure is removed (read details.failure_kind). The truncated result code and category are now partial. Target integrity failures report target_integrity_mismatch, host read failures host_io_failed and disagreeing inputs input_conflict. Inventory operations (inventory_artifact, inspect_artifact, extract_artifact and the other inventory callers) report truncated container bytes as unsupported_target. Every target failure carries a top-level retry hint.
…odel # Conflicts: # src/domain/analysisErrorProjection.ts # src/domain/parseFailure.ts # tests/acceptance/stableArtifactParserFailureCli.test.ts # tests/boundary/cli/managedMemberComparisonCli.test.ts
The limit-cut code is partial; this Windows-lane test arrived from main with the old truncated spelling.
|
CI note on the
These are PE header admission decisions that #14253 owns, so I have not changed them here. Whether Also fixed on this branch: a Windows-lane test from main still expected the old |
…odel # Conflicts: # docs/.vitepress/documentation.ts # docs/README.md # tests/boundary/go/goBinaryProvider.test.ts # tests/boundary/mcp/nodeSeaMcp.test.ts # tests/fixtures/go/image.ts
The stdio transport removes the private structured carrier from every isError result, so the conformance suite asserted a field that never reaches clients and failed every case. The projected diagnostic is checked from the JSON text instead.
…nonicalize Resolve src/resources/AsarHeader.ts and adapt the canonicalize ASAR path to upstream's breaking reader-failure vocabulary change (morluto#14247/morluto#14265/morluto#14277): - readAsarHeader: keep the extracted parseAsarHeaderJson helper our feature reuses, over upstream's new integrity read-coverage short-read refusal. - parseAsarHeaderExtents now returns plain refusal tags; expose the owner's tag->failure mapping as asarExtentRefusal so admitAsarHeader and the canonicalize adapter build the one owned failure rather than each spelling the message, offset and reason. - CanonicalizeProvider.unclassified now delegates to translateArtifactFailure, so a malformed/truncated ASAR header becomes the target failure of the selected path instead of naming an operation reason the vocabulary no longer permits; asarCanonicalize's defensive JSON fallback uses malformedArtifact. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Brings in the failure-model stack (#14247, #14265, #14268, #14272, #14277, #14281, #14289). Target failures reach MCP through toErrorToolResult and the CLI through projectCliAnalysisResult; neither path calls the budget decision, so their projection is unchanged. Conflicts: the Android verifiers keep main's sha256File helper and this branch's complete-evidence wrappers; the ELF and Rust MCP tests and the EVM description take main's version, since the harness default already requests complete Evidence. A leftover delivery reassignment in the EvidenceMcpServerCore constructor, already set by its parameter property, is removed.
First PR of the #14239 stack. It adds the
TargetFailuremodel, its single projection table and the declarative conformance registry, and migrates the first area onto them: selected-file malformed and truncated refusals.Root cause
The same fact ("why could this target not be read") is spelled in several vocabularies:
ArtifactReaderFailure.reason,ParseFailure.kind,ArtifactOperationError.reason,MachoReadIssueand per-adapter mappers. The classification is keyed by error tag and reason, so each consumer re-derives the class, and a new reader can pick any of them. The sharedstableArtifactParserFailureCliloop also became a merge hotspot (#14224 and #14225 conflicted there, and a row-shape mismatch broke typecheck on #14233).Structural fix
src/domain/targetFailure.ts).TargetFailureis a discriminated union of 10 kinds:selection,unrecognized,unsupported,malformed,truncated,integrity,conflict,changed,accessandio. All kinds shareformat,detail,offsetandfield. Some variants add their own facts:unsupported.undecodedContent,truncated.availableBytes/requiredBytes,conflict.inputs(a list of{ field, path }) andio.transient, the owner's errno fact.failure_kindis the primary identifier, in the sense of an RFC 9457 problem type.TARGET_FAILURE_PROJECTIONSderives everything else from it:title, a coarsecode,category, theretryhint and the recovery. The table is checked withsatisfies Record<TargetFailureKind, …>, and the switches are exhaustive, ending inunhandledTargetFailureCase(never).unsupported_target, because each needs a different target or tool.integrity→target_integrity_mismatch,conflict→input_conflict,io→host_io_failed,changed→artifact_changed,access→access_denied,selection→invalid_request. Inventorymalformed,truncatedandunsupportedreasons take their codes from the same table.retryisnone,backofforafter_change, after gRPC's status semantics.iogivesbackoffonly when its errno is transient.retryablekeeps its shared-contract meaning, that the unchanged request may succeed, so it istrueexactly forbackoff.truncatedare renamed topartial.failure_kind: "truncated"is the only use of the word left.AnalysisCancelledErrorandAnalysisResourceConstraintError. Identifiers use American spelling.AnalysisMalformedTargetErroris replaced byAnalysisTargetFailureError(operation, path, failure).ParseFailure'smalformed,truncatedandunsupportedvariants are theTargetFailurevariants.details.format_failureis removed, andfailure_kindis the only identifier.EvidenceMcpServer's single tool wrapper returns a target failure that a handler throws as a projectedisErrorresult. Before this, the SDK flattened it into a plain-text "Malformed …". No target failure maps to a JSON-RPC error.tests/support/targetFailure/). Each area exportstargetFailureReaders([...])from its own module. One generated suite runs every case through the compiled CLI and the stdio MCP, and asserts the contract fromTARGET_FAILURE_CONTRACT,isError, and that the selected file is unchanged.Design notes
Research and its sources are on #14239 (comment). In short:
kind,never-checked switches, andsatisfies Recordtables, so the compiler finds every consumer of a new kind.codestays the primary identifier andfailure_kindis an extension member.message,remediation.actionanddetails.reasonare for people. The error reference tells clients to keep a default arm for kinds they don't know, as with Rust's#[non_exhaustive]io::ErrorKind.changed(ABORTED: retry the whole read) andcancelledare retryable.selectionandconflictare INVALID_ARGUMENT-like.malformed,truncated,unsupportedandunrecognisedneed another target or tool.integrityis a declared-checksum contradiction (DATA_LOSS), kept apart fromchanged.access(FAILED_PRECONDITION) is split fromio.iostays non-retryable, because REA cannot tell transient EIO from a failing device.malformedsays "choose another target or a well-formed copy".truncatedsays "re-acquire the complete file; do not pad or cut". These are the samecodewith differentfailure_kind. Thetruncatedcode keeps its one meaning, a result cut short by a limit.format_failureare unchanged. Areas that change codes (inventorytruncated, the container readers'format, the six adapters) declare it in their own PRs.Where later PRs attach
readers/<area>.tsmodule with its cases, and constructsAnalysisTargetFailureError(or, for inventory, carries the sameTargetFailure) at its owner. It deletes its old reason path in the same PR.scripts/verify/architecture-guards.mjsthat rejects the old reason vocabularies, plus a repo-wide search as evidence.targetFailureRecovery, keyed by kind and owner facts.Removed tests and the registry case that covers each
tests/support/targetFailure/readers/)stableArtifactParserFailureCli: "refuses a truncated ELF header as a malformed target", 18 commandsselectedFileFormats.ts,<operation>/elf-magic-onlystableArtifactParserFailureCli: managedpe-clisection past EOF, 3 commandsselectedFileFormats.ts,inspect_managed_*/pe-cli-section-past-eofstableArtifactParserFailureCli: overlapping universal Mach-O, 4 commandsselectedFileFormats.ts,*/macho-overlapping-slicesstableArtifactParserFailureClibody table: truncated BEAM and short certificate headerinspect_erlang_beam/beam-form-header-only,inspect_pe_certificates/short-certificate-headerpeImportsCli: "rejects non-MZ PE32/PE32+ imports across CLI and MCP" (ZZ and high-bit)peHeaders.ts,inspect_pe_imports/pe{32,64}-{zz,high-bit}-dos-signaturepeLoadConfigCli: "rejects non-MZ PE32/PE32+ load config across CLI and MCP"peHeaders.ts,inspect_pe_load_config/pe{32,64}-{zz,high-bit}-dos-signatureappleIpsCli: "reports a truncated IPS as a malformed target"selectedFileFormats.ts,inspect_apple_ips/ips-truncated-bodyThe generated suite also checks the invariants the removed PE tests asserted: that the refusal leaves the selected file unchanged, and that both adapters report it. The PE tests keep their valid-image controls. The foreign-bytes identity loop stays in
stableArtifactParserFailureCliuntil the unsupported and unrecognised refusals migrate.Mutation checks on the removals, using the registry run in-process from source:
MZsignature fails the 4*-zz-dos-signaturecases.inspect_apple_ips/ips-truncated-body.Both pass after revert.
Behaviour changes
details.format_failureis removed. Readdetails.failure_kind.retry.truncatedresult code and category becomepartial. This covers artifact reader limits, browser payload limits and registry limits.unsupported_targetinstead oftruncated.target_integrity_mismatch,input_conflictandhost_io_failed.docs/user-visible-errors.csvanddocs/error-contract.schema.jsonwere regenerated from source withtsx, because the generators readdist/.docs/reference/target-failures.md, linked fromdocs/README.mdand the documentation sidebar.Validation
npx vitest runonsrc/domain,src/resources,src/native,src/electron,src/dotnet,src/il2cppand the touched boundary suites (filesystem, go, gpu, il2cpp, model, native selection, MCP format-failure suites): every run passed (14756 tests across the domain, resources, managed and IL2CPP sweep after mergingmain).createCli(serveInProcessCli) and the MCP server. All CLI paths passed, and all MCP paths passed except the 3 managed tools, which need a deep-provider session in the in-process harness. The compiled-adapter suite in CI covers them.ioretrybackofffails the contract and errno tests; letting the server wrapper rethrow a target failure fails the MCP tool-result test (the result degrades to plain text). Both pass after revert.tscover the changed files and their import closure (1091 source files): no errors except the pre-existingfridatyping errors. Also clean:oxfmt,oxlint(no new warnings) andarchitecture-guards.tests/acceptance/*(needsdist/), the full typecheck,knipanddocs:check.codechanges in this PR. The first code-changing PR of the stack records one.Real-provider verification scope
None needed. The affected readers are local static parsers.
Remaining cleanup
The rest of the stack, each PR deleting its old path:
ArtifactReaderFailure("format"));truncated;AnalysisUnsupportedTargetErrorand the foreign-bytes identity loop;