Skip to content

fix(errors)!: report inventory refusals as target failures of the selected path - #14277

Merged
morluto merged 98 commits into
mainfrom
fix/inventory-target-failure-path
Nov 25, 2026
Merged

morluto merged 98 commits into
mainfrom
fix/inventory-target-failure-path

Conversation

@morluto

@morluto morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Depends on #14272. The base branch is #14272's, so the diff shows only this PR.

Fifth PR of the #14239 stack: inventory status and details.path, and the container cases in the conformance registry.

Root cause

An inventory, inspection or extraction refused damaged container bytes as ArtifactOperationError with reason: "malformed" | "truncated" | "unsupported". That reason repeated the kind the format owner had already put in parseFailure, so the same fact lived in two fields, and the error classified the target with its own rows. The refusal carried no path and no retry, so it differed from the same bytes refused by a selected-file operation, and the conformance registry could not express container cases. Readers' unsupported refusals (no .NET bundle header, no PyInstaller cookie, a dylib root that is not Mach-O, a managed coverage gap) carried no format facts at all.

Structural fix

  • One error type per fact. translateArtifactFailure(operation, path, cause) now takes the selected target and returns the reader's TargetFailure as AnalysisTargetFailureError, with the reader's cleanup, completed observation and cleanup leases. translateArtifactOperationFailure(operation, failure) handles reader failures of the operation itself (cancellation, cleanup) and needs no path.
  • Deleted from ArtifactOperationError: the malformed, truncated and unsupported reasons, the parseFailure field, their three classification rows, the presentation branch and the projection of parseFailure into its details. The compiler then found every producer that passed a reader reason through: Playwright trace, web artifact reads, web script export and publication, the offline-artifact fallback and the asset catalog's assetutil rejection. Each now raises the target failure or uses artifactOperationReason, which treats a target reason without the owner's facts as a reader defect (InternalInvariantError).
  • Readers raise unsupported with facts. unsupportedArtifact(format, detail, { undecodedContent }) joins malformedArtifact and truncatedArtifact. artifactParseFailure keeps the owner's facts for unsupported too. DesktopFileInspection reads a managed issue through managedIssueTargetFailure, the single interpretation fix(errors)!: report managed coverage gaps and IL2CPP pair conflicts as target failures #14272 introduced.
  • Selected files too. projectOwnedArtifactInputFailure no longer builds AnalysisUnsupportedTargetError for a reader's unsupported reason: the reader's facts make it a target failure like malformed and truncated.
  • Registry. TargetFailureReader.session marks an MCP tool that reads the session's open target, so the generated suite calls open_binary first. readers/containers.ts registers four inspect_artifact cases.

Design notes

  1. The selected target is the subject. A container refusal names the file the caller selected, whichever member the reader was reading. A member's logical path stays in the owner's reason. The asset catalog's assetutil rejection names the catalog file on disk, because REA read that file directly.
  2. A reason is not a classification. ArtifactOperationError now only describes operation outcomes (limit, integrity, path, unavailable, cancelled, io). Every refusal of the target's bytes goes through TARGET_FAILURE_PROJECTIONS, so inventory and selected-file refusals of the same bytes report the same code, retry, recovery and details.
  3. Fail closed on missing facts. A target reason without facts can no longer be projected. It is reported as a reader defect rather than guessed.

Removed tests and the registry case that covers each

Removed Registry case (tests/support/targetFailure/readers/containers.ts)
hexRecordsCli: "rejects a malformed record through the CLI" inspect_artifact/intel-hex-record-checksum (same bytes, full owner reason)
firmwareContainersCli: "refuses a conflicting UF2 rewrite through the CLI" inspect_artifact/uf2-conflicting-rewrite
artifactZipCurrentDirectory: "classifies a ZIP local-header offset beyond EOF as malformed input" inspect_artifact/zip-member-past-eof (same mutation of the local-header offset)
nodeSeaCli: "rejects a malformed SEA blob through the CLI" inspect_artifact/node-sea-blob-magic

The registry cases also check MCP, details.path, retry and that the selected file is unchanged, which the removed CLI-only tests did not. The MCP boundary tests for S-record and Node SEA refusals stay, because they cover a second format variant and a session sequence.

Mutation checks, using the registry cases run in-process through createCli: disabling the Intel HEX record checksum fails intel-hex-record-checksum, and disabling the Node SEA blob magic check fails node-sea-blob-magic. Both pass after revert.

Tests

  • ArtifactOperationFailure.test.ts: an inventory refusal of malformed, truncated and unsupported bytes is the same target failure of the selected path as the selected-file refusal, through descriptor cleanup.
  • Updated expectations from details.reason: "<kind>" plus details.detail to failure_kind, path and reason: Bun, Deno, Godot, keyed archive (XML numbers, scalar kinds), JavaScript source selection (CLI and MCP), UnityFS, Node SEA and S-record MCP, web module artifacts, and the asset catalog rejection.
  • The catalogue tests no longer list the deleted reasons.

Validation

  • npx vitest run src/resources src/domain src/artifacts: 15,749 tests, all passed after the updates. src/{browser,application,nuget,java,providers,javascript,dotnet,electron}: 7,334 tests passed. Two timing-sensitive tests failed under load and passed when rerun alone.
  • All 41 registry cases ran in-process from source through createCli. Every CLI path passed. The MCP path was checked for the non-session readers, except the SQLite and managed cases, which need dist/ or a deep-provider session. CI covers MCP for the new session cases.
  • Scoped tsc over the 588 files that name these types, and their import closure, is clean apart from the pre-existing frida errors. Also clean: oxfmt, oxlint (no new warnings), architecture-guards and verify:module-boundaries.
  • docs/user-visible-errors.csv was regenerated from source with tsx, because the generator reads dist/. Its three deleted ArtifactOperationError rows are gone.
  • Not run locally, so CI must confirm: tests that need the compiled CLI or JavaScript workers (tests/acceptance, the compiled-CLI boundary suites) and the full typecheck.
  • No public-corpus before/after pass in this PR. The stack's final PR records one across the whole migration.

Behaviour changes

  • inventory_artifact, inspect_artifact, extract_artifact, inspect_desktop_application, inspect_keyed_archive, inspect_asset_catalog, inspect_nuget_nupkg, inspect_maven_gradle_metadata and analyze_javascript_application report a refused target with details.path, top-level retry, and details.reason set to the owner's description. details.detail is removed from these refusals.
  • A reader's unsupported refusal now reports failure_kind: "unsupported" and its format on both the inventory and selected-file paths.
  • docs/reference/target-failures.md describes the change under Migration.

Real-provider verification scope

None needed. The affected readers are local static parsers.

Remaining cleanup

…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.
#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.
…cated targets

Delete the ambiguous `format` reason from ArtifactReaderFailure and
ArtifactOperationError. Each container reader now raises its owner's
fact once, through malformedArtifact / truncatedArtifact, with format,
offset, field and measured extents. Short reads inside a measured extent
are read-coverage integrity failures, path-kind refusals are `path`,
foreign or recovery-requiring inputs are `unsupported`, host tool output
is `io`, and REA defects are InternalInvariantError.

The trace, NTFS journal, release exposure, web capture, native macOS and
web artifact adapters project the reader's parsed facts as
AnalysisTargetFailureError instead of invalid_request. Inventory
malformed, truncated, unsupported and cancelled reasons take their code
from the TargetFailure projection table, so a truncated container is
unsupported_target with failure_kind "truncated" on both paths.

BREAKING CHANGE: inventory_artifact, inspect_artifact, extract_artifact,
analyze_javascript_application, inspect_desktop_application,
inspect_keyed_archive, inspect_asset_catalog, inspect_nuget_nupkg,
trace_dylib_resolution, trace_web_module_imports and
trace_web_source_location report damaged container bytes as
unsupported_target (details.reason "malformed" or "truncated", with
failure_kind and format) instead of artifact_operation_failed with
reason "format", and a truncated container as unsupported_target instead
of truncated. inspect_playwright_trace, inspect_ntfs_journal,
audit_release_exposure, the web capture inspection operations and the
caller-selected import and source maps report damaged selected bytes as
unsupported_target instead of invalid_request. The `format` reason no
longer appears in details.reason.
…get failures

The SQLite engine's `format` reason is renamed to `malformed` at its
owner (SQLITE_INSPECTION_REASONS), and its refusal becomes an
AnalysisTargetFailureError at the selected path with format "sqlite".
The pwntools and EVM worker replies keep their wire reason "format",
which their workers define, and the adapters translate it once into a
malformed target failure with the profile's format (elf, elf-core,
evm-bytecode) instead of an invalid_format argument issue. SQLite joins
the target-failure conformance registry.

BREAKING CHANGE: inspect_sqlite_database, inspect_binary_layout,
inspect_recorded_crash and inspect_evm_interface report a selected
file's malformed bytes as unsupported_target with details.failure_kind
"malformed", format_failure, format and path, instead of invalid_request
with an invalid_format issue on path.
… 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
…p unsupported desktop probes local

A Bun or Node SEA short read inside a range already checked against the
measured size meant the file changed, not that it was truncated. The
carrier range reader and Bun's readExact now raise read-coverage
integrity for it, and keep 'outside the file' as the truncated case.
DesktopFileInspection records an unsupported managed-metadata probe as a
row issue again, so later file checks still run.
…ly suites

The literal-replacement scenario now reads the failure's detail instead
of an issues[] message, and a malformed reply wrapped by cleanup failure
reports category unsupported_target.
…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.
…ce registry covers

inspect_sqlite_database/not-a-database in the target-failure registry runs
the same non-SQLite bytes through the CLI and MCP, asserts the malformed
target facts and checks the selected file is unchanged.
…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.
…rget-failures

# Conflicts:
#	docs/reference/target-failures.md
#	src/domain/analysisErrorClassification.ts
#	src/resources/ArtifactOperationFailure.test.ts
#	tests/boundary/cli/artifactZstandardWindow.test.ts
…F declarations apart

PyInstaller reads inside the measured size, and .NET bundle manifest
refills, now raise read-coverage integrity on a zero-byte read instead of
truncated. A .NET bundle field and a Godot PCK directory entry that extend
past the file are truncated (with offset and extents) instead of
malformed. An absent or invalid ASAR packed offset is malformed; only a
valid range past the archive is truncated. The .NET manifest string
offset is reported in file coordinates.
The layout and recorded-crash workers raise a distinct truncated reason
when the file ends inside the ELF identification or header, and the
decoder projects it as failure_kind truncated instead of inferring it
from the message.
…as target failures

Managed readers interpret an issue code once, in managedIssueTargetFailure:
a coverage gap is an unsupported target, every other rule violation is a
malformed target, and the inventory metadata status is derived from that
same fact. managedInspectionTargetFailure now returns only
AnalysisTargetFailureError.

An IL2CPP binary that parses but does not link to its metadata is a
conflict target failure that lists both inputs and blames neither, in
place of an invalid_request with two issue entries. Metadata version 108
is an unsupported target. The CLI spells each conflict input's field by
the command's option name.

BREAKING CHANGE: inspect_managed_artifact, inspect_managed_members,
inspect_managed_native_boundaries and the managed comparison operations
report unsupported metadata or signature forms as an
AnalysisTargetFailureError (failure_kind unsupported, format pe-cli,
field, offset) instead of a bare unsupported target. inspect_il2cpp_metadata
reports a binary/metadata pair that does not link as code input_conflict
with failure_kind conflict and details.inputs, instead of invalid_request
with details.issues, and metadata version 108 with failure_kind
unsupported.
…odel

# Conflicts:
#	src/domain/analysisErrorProjection.ts
#	src/domain/parseFailure.ts
#	tests/acceptance/stableArtifactParserFailureCli.test.ts
#	tests/boundary/cli/managedMemberComparisonCli.test.ts
cursoragent and others added 5 commits November 25, 2026 00:55
…arget-failure-path

A malformed Node SEA blob stays an outer-format inventory with a
recognition limitation. Session conformance still opens the target
before a tool that reads the session.

Co-authored-by: morluto <[email protected]>
…ry case

details.reason is the owner's description, so the boot-image refusals
assert failure_kind and format. A malformed SEA blob inside an ELF stays
an outer-format inventory with a recognition limitation, which the Node
SEA reader tests already cover, so it is not an inspect_artifact refusal.

Co-authored-by: morluto <[email protected]>
translateArtifactFailure names the caller-selected path on a format
refusal. Directory inspection and a retained artifact scope both know
that path and now supply it.

Co-authored-by: morluto <[email protected]>
Comment thread src/artifacts/ArtifactProvider.ts Resolved
cursoragent and others added 13 commits November 25, 2026 01:33
The session keeps the digest it admitted, so replacing the executable and
repeating trace_dylib_resolution is not a retryable container change.

Co-authored-by: morluto <[email protected]>
…h' into fix/inventory-target-failure-path

Co-authored-by: morluto <[email protected]>
Base automatically changed from fix/managed-il2cpp-target-failure to main November 25, 2026 02:59
@morluto
morluto enabled auto-merge (squash) November 25, 2026 03:00
morluto and others added 2 commits November 24, 2026 22:09
details.reason is the owner's description. The compiled CLI refusal is
identified by failure_kind and format.

Co-authored-by: morluto <[email protected]>
@morluto
morluto merged commit c214fc4 into main Nov 25, 2026
56 checks passed
@morluto
morluto deleted the fix/inventory-target-failure-path branch November 25, 2026 03:51
leockl added a commit to leockl/rea that referenced this pull request Nov 25, 2026
…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]>
morluto added a commit that referenced this pull request Nov 25, 2026
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.
2SinceJuly added a commit to 2SinceJuly/rea that referenced this pull request Nov 26, 2026
main widened ArtifactOperationError's operation parameter to the public operation name in b7f662b (morluto#14277, morluto#14265) so every reader can raise it with one classification owner. This branch had kept the operation as a per-reader union sitting inside the constructor, so the two could not both stand. The merge takes main's widening: the union only helped the constructor's own type checking, and the reader name still reaches artifactDetailsMessage.

Run: vitest src/domain/evtxArchive (28 pass). A full typecheck still reports two errors in files this merge does not touch (javascriptSemanticExecutionPoints StructBody, releaseProposal release-please path).
@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants