Skip to content

fix(artifacts): route native images to static readers and name their architecture - #14189

Merged
morluto merged 5 commits into
mainfrom
fix/inspect-artifact-native-routing
Nov 24, 2026
Merged

morluto merged 5 commits into
mainfrom
fix/inspect-artifact-native-routing

Conversation

@morluto

@morluto morluto commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Fixes #14157

Root cause

Two owners dropped facts they already had:

  • Inventory classification (classifyArtifactBytes) decided pe, elf and mach-o from the same header parsers target admission uses, but returned only the format. createArtifactNode then hard-coded architecture: null for every node, and subjectFor in ArtifactProvider copied the target's selection, but not the architecture target admission had parsed.
  • probesForFormat in src/domain/artifactInspection.ts mapped PE to inspect_managed_artifact then open_binary, and ELF or Mach-O to open_binary only. Inspection never saw the native image facts that target admission had parsed: the format, and for PE whether it declares a CLI header (BinaryTarget.managed). So an executable that inventories as an embedded package also lost its native side.

Structural fix

Architecture

  • readNativeHeaderFormat returns { format, architecture }. The new classifyArtifactHeader returns format and architecture together. For PE it runs the same record parser as target admission (parsePeRecordFacts). classifyArtifactBytes is now a projection of it.
  • Root nodes, embedded members and universal slices are created with the header's architecture. An undecoded machine stays null. A universal container node also stays null, because each slice node names its own architecture.
  • When the inventory root is the open target's own bytes in the same format, the inspection subject carries target.architecture, alongside the selection it already carried. For universal Mach-O this is the selected slice.

Next probes

  • ArtifactProvider passes inspection the native image facts target admission parsed for the root's bytes (ArtifactInspectionRootImage).
  • One owner, nativeImageProbes, lists the provider-free readers per format (STATIC_READERS), then open_binary:
    • PE: inspect_pe_imports, inspect_native_exports, inspect_pe_load_config, inspect_pe_resources, inspect_binary_hardening, audit_release_exposure
    • ELF: inspect_elf_dependencies, inspect_native_exports, inspect_binary_hardening, audit_release_exposure
    • Mach-O: inspect_macho, inspect_signature, inspect_binary_hardening, audit_release_exposure
  • inspect_managed_artifact depends on the CLI header:
    • The PE declares one: it comes first.
    • The PE declares none: it is omitted.
    • The declaration is unknown (directory members): it is a conditional probe.
  • The "PE may be managed or native" hypothesis now appears only in the unknown case.
  • Carrier executables (owner decision). When inventory reads the root as an embedded package (Godot PCK, PyInstaller, Node SEA, Deno, Bun, .NET bundle), the file is still a native image. The package reader comes first, then the carrier's static readers, then open_binary. Combined lists are deduplicated by operation, and deep-provider probes always come last.
  • Probe shape (token decision). The next-probe schema names exactly one operation per entry. Grouping the static readers into one entry would change the advertised schema, so they stay separate rows. They share one short rationale ("Execution-free header read of the native image; no deep provider."), because each tool's own description already says what it reads.
  • The old PE and native probe branches are removed. No contract or schema changed: nodes[].architecture and subject.identity.architecture already existed and were nullable.

Validation

  • npx vitest run tests/boundary/mcp/pyinstallerArtifactMcp.test.ts tests/boundary/providers/native src/domain/artifactInventoryEvidence.test.ts src/artifacts/inventory tests/boundary/filesystem/elfDeclaredRanges.test.ts: 877 of 879 passed. The two failures are in nativeSignatureTargetBinding.test.ts (codesign unavailable through xcrun on this host). They fail the same way on unmodified main.
  • An earlier run on this branch: 88 files and 1,951 tests across inventory, analysis-view, release-exposure, Mach-O, uImage, Android boot and binaryTarget, all passed.
  • npx oxfmt --check and npx oxlint on the changed files: clean apart from warnings that are already present. node scripts/verify/architecture-guards.mjs: passed.
  • New test artifactProvider.nativeImageProbes.test.ts goes through the public inspect_artifact workflow with fixtures built in the test. It covers:
    • an ARM64 PE: arm64, static readers, no managed probe
    • a managed PE: managed probe first
    • a ZIP of ARM64, undecoded LoongArch and ELF images: per-member architecture, unknown kept null
    • an ELF and a thin Mach-O
    • a universal Mach-O: slice architectures, and the selected slice in the subject
    • a Godot PCK inside an ELF: no architecture on the package subject, and the ELF readers kept
    • Deno carried in an ELF, a Mach-O and a PE: extract_artifact, then that carrier's readers, then open_binary
  • Updated carrier expectations:
    • The in-process pyinstallerArtifactMcp.test.ts passes.
    • The compiled acceptance tests for PyInstaller, .NET bundle, Bun and Deno were edited but not run locally, because they need dist/. I took the expected carrier formats from running the same fixtures in-process; the Bun fixture I took from its builder name (elfAppendedBunPayload), because my in-process probe of it failed.

Not run locally: the full typecheck, and tests that need dist/ (compiled MCP, CLI-process and JavaScript-worker tests). CI covers both. I did not run this against real release binaries.

Remaining cleanup

…architecture

inspect_artifact sent every PE, ELF and Mach-O root straight to
open_binary (PE first to inspect_managed_artifact, whatever its CLI
header) and left architecture null on every inventory node and on the
inspection subject, although the header parsers already know the CPU.

Inventory classification now returns the header's CPU family with the
format, from the same ELF, Mach-O and PE record parsers target admission
uses, so each thin image node (including universal slices and archive
members) names its architecture; an undecoded machine stays null, and a
universal container node names none. When the inventory root is the
open target's own bytes, its Evidence subject carries the architecture
target admission parsed, as it already carried the selection.

Native next probes now list the provider-free readers for the format
before open_binary: PE imports, exports, load config, resources,
hardening and release exposure; ELF dependencies, exports, hardening and
release exposure; Mach-O inspect_macho, inspect_signature, hardening and
release exposure. inspect_managed_artifact leads only when the PE
declares a CLI header, is omitted when it declares none, and stays a
conditional probe for directory members whose declaration is unknown.
The PE hypothesis that inventory cannot tell managed from native is kept
only for that unknown case.

Fixes #14157
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-23T22:07:39.905506Z
We couldn’t complete this review. Comment @codex review to try again.
9baa773 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR keeps native architecture facts in artifact inventory and recommends static readers before deep native analysis.

  • Artifact inventory keeps each native image's CPU family.
  • Artifact inspection lists static native readers before deeper analysis.

Review used source inspection; no tests were run. Whether another PR supersedes this one could not be checked because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Target admission] --> B[Native format and managed declaration]
  C[Inventory bytes] --> D[Artifact format and architecture]
  D --> E[Inventory evidence]
  B --> F{Root digest matches?}
  E --> F
  F -->|Yes| G[Package readers plus native readers]
  F -->|No| H[Inventory-based readers]
  G --> I[Remove repeated operations]
  H --> I
  I --> J[Deep native provider last]
Loading

Reviews (5) · Last reviewed commit: "Merge main into fix/inspect-artifact-nat..." · Reviewed by Greptile

Comment thread src/domain/artifactInspection.ts Resolved
An executable whose contents inventory as an embedded package (Godot
PCK, PyInstaller, Node SEA, Deno, Bun or a .NET single-file bundle) is
also a native image. Previously inspection proposed only the package
reader and hid the native side.

The inspection now takes the native image facts that target admission
parsed for the root's own bytes, not only the PE CLI-header flag. When
inventory reads those bytes as a package, the package reader comes
first, then the carrier's static readers, then open_binary.

A probe names exactly one operation, so the static readers cannot be
grouped into one entry without changing the advertised schema. They
stay separate rows and share one short rationale, because each tool's
description already says what it reads. Each format's reader list is
now a table.
@morluto
morluto force-pushed the fix/inspect-artifact-native-routing branch from 202d83e to 38ffd78 Compare November 23, 2026 22:50
… boundary

A PE declaring a CLI header recommended open_binary with generic
function-level advice, so pure managed assemblies were steered to a
deep native provider. Its rationale again requires managed inspection
to report a native or mixed boundary, and a PE whose header is unknown
states the same condition.
…probe snapshots

The universal Mach-O test assumed slice inventory on every host, but the
slice reader runs native lipo and is skipped off macOS, so it failed on the
Linux test shards and portable tests. The test now selects the host platform
through a HostPlatform mock: the slice inventory case runs only on a macOS
host, and the other-host case asserts unknown container coverage with only
the file occurrence on every host. Both keep the selected-slice subject
architecture and static reader order.

Pruning in the probe tests:
- Merge the ARM64 PE, ELF and Mach-O single-image probe tests into one
  parameterised case that asserts subject and root-node architecture, the
  complete static reader list, and that open_binary is the only probe beyond
  artifact bytes.
- Remove the Deno carrier ordering case from the native image probe test;
  the Deno CLI acceptance test covers the same three carriers through the
  public workflow and now asserts the same ordering and authority facts.
- Replace full next-probe arrays in the Bun, Deno, dotnet-bundle and
  PyInstaller CLI/MCP tests with a shared carrier assertion: package readers
  lead, the carrier's format reader is present, and open_binary is last and
  the only non-artifact-bytes probe. The per-format reader list stays owned
  by the native image probe test.

Malformed-header (undecoded machine), unknown architecture and package
subject identity coverage are unchanged.
@morluto
morluto enabled auto-merge (squash) November 23, 2026 23:19
@morluto
morluto merged commit 8ed8195 into main Nov 24, 2026
42 checks passed
@morluto
morluto deleted the fix/inspect-artifact-native-routing branch November 24, 2026 00:27
2SinceJuly added a commit to 2SinceJuly/rea that referenced this pull request Nov 24, 2026
…main

Merging main brought two contract changes these tests still asserted the old shape for: morluto#14225 moved an invalid chunk size to an internal invariant violation and an impossible descriptor byte count to io, and morluto#14189 added contentArchitecture to the classification role. The auditd role test added here predates the new field, so Source tests failed on contentArchitecture: null and shard 9 failed on the two stable-artifact reasons.

Assert the reasons and fields the producers now return so both lanes match the intended contract.
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction 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: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] inspect-artifact routes native PE/ELF/Mach-O only to open_binary and leaves architecture null

1 participant