Repository navigation
refactor(pe): move the PE resource parser into domain with domain parse failures - #11550
Conversation
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. |
[Medium impact] The change reaches several PE parsing and embedded-carrier workflows. Fix the Deno PE failure mapping before merging so physical read failures stay separate from cancellation.
|
…se failures The I/O-free PE resource tree parser moves from src/artifacts/pe to src/domain/pe and reports malformed structure, decode budgets and cancellation through the domain parse failure algebra. artifactParseFailure in src/resources maps those onto artifact reader reasons at each provider's boundary, so native no longer imports artifacts. Fixes #11527
75c8eae to
3db4cba
Compare
|
@greptileai review |
| } catch (cause) { | ||
| throw artifactParseFailure(cause, carrier.signal); |
There was a problem hiding this comment.
Read failures become cancellation
If readExact rejects with a file-read error that is also used to abort carrier.signal, this new catch relabels the read failure as cancelled. Another caller sharing ArtifactPreparation may then retry it instead of receiving the actual failure. This violates the repository directive that a caller's abort reason cannot establish failure origin.
Carrier reads already wrap genuine cancellation. Leave their physical failures untouched and reserve raw-reason cancellation mapping for the full-buffer parser.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/artifacts/deno/DenoStandaloneLocation.ts
Line: 866-867
Comment:
**Read failures become cancellation**
If `readExact` rejects with a file-read error that is also used to abort `carrier.signal`, this new catch relabels the read failure as `cancelled`. Another caller sharing `ArtifactPreparation` may then retry it instead of receiving the actual failure. This violates the repository directive that a caller's abort reason cannot establish failure origin.
Carrier reads already wrap genuine cancellation. Leave their physical failures untouched and reserve raw-reason cancellation mapping for the full-buffer parser.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.- Move PeRichHeaderPort to src/ports/binaryDiagnostics (morluto#11208). The provider now implements it, like the other PE providers. - Import the artifact toolkit from src/resources, BinaryContainer from src/domain/binaryContainer and readPeHeaders from src/domain/pe. - List PeRichHeaderProvider among native's entry files. - Map failures with projectPeBinaryFailure, as PeImportsProvider and PeLoadConfigProvider do. The new guards forbid a hand-built resource-constraint refusal and an inline error message; the shared PE projection already owns both, so the provider adds neither. The structural allowance's recovery now carries its ceiling (morluto#11651). - Tests: the Evidence subject names its target identity (morluto#11416), and readPeHeaders now throws a malformed ParseFailureError (morluto#11550). - Re-record the advertised schema summary: the output hash now matches inspect_pe_imports after Evidence format revision 2.
Summary
Moves the PE resource tree parser from the artifacts provider into
src/domain/pe/, as decided on #11527:src/artifacts/pe/PeResourceTreeFacts.ts->src/domain/pe/peResourceTreeFacts.ts(unchanged);src/artifacts/pe/PeResourceLayout.ts->src/domain/pe/peResourceLayout.ts(header admission, RVA mapping, bounded named-resource walk over an injected reader);src/artifacts/pe/PeResourceParser.ts(and test) ->src/domain/pe/peResourceInventory.ts(parsePeResources);src/artifacts/pe/PeResources.fixture.ts->src/domain/pe/peResources.fixture.ts.Native (
PeResourcesProvider,PeCertificateParser) and artifacts (NodeSeaLocation,DenoStandaloneLocation) now import the domain parser, sonative -> artifacts(2) leaves thecrossProviderbaseline.Fixes #11527. Refs #11359. Part of plan W9.
Problem and expected behavior
The PE resource parser lived in the artifacts provider, and native imported it from there (#11331 had only reversed the edge). Expected: I/O-free format parsing lives in domain (as the Mach-O and plist readers moved to
src/domain/apple/), the parser reports failures in the domain's parse failure algebra, and each provider maps them to its own failure at its boundary.Change and scope
ArtifactReaderFailure, which belongs tosrc/resources:malformedInput("pe", message)(ParseFailureError, kindmalformed); the message text is unchanged;decodeLimit("pe", message, { name, maximum })withmax_entries(the caller's entry budget) orpe_resource_metadata_bytes(the fixed 8 MiB allowance).peResourceLimitBoundary(limit)names the bound each one constrains (capacityormemory);signal.throwIfAborted(), so the caller'ssignal.reasonpropagates;BinaryFormatFailure("unsupported")for DOS and non-PE MZ images is unchanged.artifactParseFailure(cause, signal, limitBoundary?)insrc/resources/ArtifactFileOperation.tsmaps a domain parse failure onto the reader's reasons: the caller's ownsignal.reason->cancelled,malformed/truncated->format,limit->limitwith the named boundary. Unsupported forms and any other cause pass through. The original failure is kept ascause.PeResourcesProvider(after its stable file read),PeCertificateParser(header admission),NodeSeaLocationandDenoStandaloneLocation(their carrier reads) each map at the call site.NodeSeaLocationkeeps its "not an admitted PE, so not a SEA carrier" decision by catching the domainmalformedfailure fromreadPeResourceLayout.raw-buffer-readguard baseline (rekeyed by the shrink), and one path indocs/specs/artifacts/deno-standalone/plan.md.Not included:
dosMz,peCoffHeader,peSectionHeaderandpeOptionalHeaderstay at the domain root; grouping domain subsystems is W10's work.Contract and boundary impact
ArtifactReaderFailuretoParseFailureError. The providers' public results and errors are unchanged: they map the domain failure back to the same reader reasons before their existing projections run.src/domain/pe/, wrappers stay with their provider).ArtifactReaderFailure("cancelled")carrying the caller's reason, soartifactReadCancelledByand cleanup ownership are unchanged.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
Tests added or updated: the moved parser test now asserts the domain failures (
kind: "malformed"in place ofreason: "format", alimitfailure namingmax_entrieswhose boundary iscapacity, and cancellation rejecting with the caller's reason). Provider tests are unchanged and cover the mapping end to end: entry budget ->capacity, metadata allowance ->memory, truncated table -> malformed refusal (PeResourcesProvider.test.ts), cancellation during admitted parsing (tests/process-global/peResourcesLifetime.test.ts), and Node SEA / Deno PE carriers.Base reproduction or other evidence:
node scripts/verify-module-boundaries.mjs --shrink-layer-baselinereportednative -> artifacts: 0, baseline 2(theartifacts <-> nativecycle record already went with refactor(providers): move the native command runner into the shared provider core #11462).User-visible CLI/MCP output (if applicable): none.
Remaining proof gaps: I did not run the acceptance tests (
tests/acceptance/applications/peResources.test.ts, which needs a build) ortests/boundary/cli/callerPathSymlinkParentCli.test.ts; both only change a fixture import specifier.Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npm run check:fast: passed, including the architecture guards.node scripts/verify-module-boundaries.mjs --shrink-layer-baselineandnode scripts/verify/architecture-guards.mjs --shrink-baselines: passed.npm run test:focused --withsrc/domain/pe/peResourceInventory.test.ts,src/native/pe/PeResourcesProvider.test.ts,tests/conformance/formats/mzPeAdmission.test.ts: 3 files, 68 tests passed.npm run test:focused --withtests/process-global/peResourcesLifetime.test.ts,src/artifacts/NodeSeaArtifactReader.test.ts,src/artifacts/deno/DenoStandaloneArtifactReader.test.ts: 3 files, 149 tests passed.npm run test:focused --withsrc/native/pe/PeCertificateParser.test.ts,src/native/pe/PeCertificatesProvider.test.ts,src/native/pe/PeUnsupportedTargets.test.ts,src/application/binaryDiagnostics/PeResourcesService.test.ts,tests/boundary/filesystem/peResources.test.ts: 5 files, 109 tests passed.npm run test:focused --withtests/conformance/providerCompletion.test.ts,tests/boundary/providers/nativeArtifactFinalization.test.ts: 2 files, 42 tests passed.Compatibility, safety, and release
Not a pure move (failure types change), so the squash commit should not go in
.git-blame-ignore-revs.Author readiness
Human owner:
Before merge
type(scope): outcome.