Skip to content

fix(native): retain the dispatch reader failure when the symbol fallback fails - #8036

Closed
zw-g wants to merge 3 commits into
morluto:mainfrom
zw-g:zw/dispatch-fallback-reader-failure
Closed

zw-g wants to merge 3 commits into
morluto:mainfrom
zw-g:zw/dispatch-fallback-reader-failure

Conversation

@zw-g

@zw-g zw-g commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7651. When inspect-native-dispatch-metadata (MCP inspect_native_dispatch_metadata) falls back to the list_names symbol inventory because the native byte reader refused the target, and that fallback also fails or returns an invalid inventory, the final error now keeps the reader's refusal under details.diagnostics.binary_metadata_failure. Before, only the fallback's error reached the caller, so the reader's reason (for example Unsupported 32-bit Mach-O metadata for requested CPU type arm) was lost.

This carries forward e7884a7, which @morluto wrote on @dreinst's #7701. dreinst closed #7701 on 2026-10-29. Its other two parts landed separately as #8002 (#7696) and #8013 (#7652). This part is not on main yet.

Problem and expected behavior

Smallest trigger: a 28-byte thin 32-bit Mach-O header (0xfeedface, CPU 12/subtype 9 armv7, or 7/3 i386, MH_EXECUTE, no load commands) with no list_names provider configured.

inspectNativeDispatch (src/application/native/NativeDispatchMetadataInspection.ts) keeps binaryMetadata.error in a local variable. On the failed-fallback path it returns err(execution.error). On the invalid-inventory path it builds a new AnalysisOutputError. Neither carries the reader failure. AGENTS.md asks that partial facts and meaningful failure reasons be preserved, and docs/tool-design.md asks that relevant limitations stay with the returned result.

Expected: the caller sees both facts. The direct metadata operation was refused for a stated reason, and the symbol alternative could not run. The final error code and category stay those of the fallback (provider_unavailable, details.operation: list_names).

Change and scope

Both failure returns now attach the reader failure with the existing retainSecondaryFailure(binaryMetadata.error, { binary_metadata_failure: projectAnalysisError(binaryMetadata.error) }). The production change is e7884a7 unchanged. docs/guides/native/native-investigation.md (moved from docs/native-investigation.md by #2791) gains one sentence in the dispatch-fallback paragraph.

Scope decision: not applicable. This is an ordinary fix inside an existing read-only static workflow.

Not included:

Contract and boundary impact

  • Semantic owner and earliest changed stage: inspectNativeDispatch, the shared dispatch workflow that owns the direct-then-symbol fallback. The CLI and MCP adapters consume its error unchanged. No superseded paths.
  • Contribution scope fit and linked maintainer decision: ordinary fix, not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. On the two failure paths, error details.diagnostics gains a binary_metadata_failure entry. Code, category, retryability and the other details are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none. Successful results are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (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.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:

    • src/application/native/NativeDispatchMetadataInspection.fallback.test.ts (from e7884a7). It covers both failure paths: a failed fallback, and an invalid inventory that keeps its partial observation.
    • tests/boundary/mcp/nativeDispatchAvailability.test.ts, new case keeps the binary reader refusal when the symbol fallback is unavailable. This is the Linux-runnable public-boundary regression. It uses the production MCP server, open_binary on a real 28-byte armv7 file, the real NativeMacOSProvider byte reader with Darwin host support injected, and the real AnalysisProviderRegistry with one unconfigured list_names candidate. It asserts provider_unavailable for list_names, that candidate's availability rejection, a binary_metadata_failure whose reason matches /32-bit/, and that the unconfigured provider was never called.
    • tests/acceptance/nativeDispatchFallbackFailure.test.ts (from e7884a7). This is the issue's CLI reproduction. It is darwin-only and not part of the apple-artifacts CI list, so it runs only on a macOS developer machine.
  • Base reproduction: the first two files on base give Tests 3 failed | 8 passed | 1 skipped. The MCP case fails only on the missing details.diagnostics.binary_metadata_failure; code, operation and rejections already match on base. All pass with the fix. Commands and counts are under Validation.

  • User-visible CLI/MCP output: from the Linux VM, built CLI, armv7 header, isolated HOME/XDG, missing Hopper launcher. The i386 output has the same shape.

    node scripts/rea.mjs inspect-native-dispatch-metadata <armv7> --format json
    main: exit 1, code provider_unavailable, details.operation list_names, details.diagnostics: (absent)
    fix:  exit 1, code provider_unavailable, details.operation list_names,
          details.diagnostics.binary_metadata_failure: {
            code: capability_unavailable, category: unsupported_provider,
            details: { operation: inspect_native_dispatch_metadata,
                       reason: "Native macOS utilities require macOS." } }
    

    On Linux the byte reader refuses the host before it reads the file, so the retained reason is the platform refusal. With Darwin support injected (the MCP case above, plus a direct call to the built reader), the retained reason is Unsupported 32-bit Mach-O metadata for requested CPU type arm (x86 for i386).

  • Remaining proof gaps: I have not run the real CLI on macOS, where the issue was reported. The darwin-only acceptance test above would cover it. No real provider was configured.

Boundary regressions covered: preserved failure reasons across the CLI/MCP error boundary, and unknown or unavailable outcomes kept visible. No lifecycle stages are touched.

For evidence-bearing changes:

  • 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

Linux x86_64 (Ubuntu 24.04 VM), Node v24.22.1, rebased on 860fdd8.

  • npm run test:focused -- src/application/native/NativeDispatchMetadataInspection.fallback.test.ts tests/boundary/mcp/nativeDispatchAvailability.test.ts tests/acceptance/nativeDispatchFallbackFailure.test.ts:
    • base (production file from main): Test Files 2 failed | 1 skipped (3), Tests 3 failed | 8 passed | 1 skipped (12);
    • fix: Test Files 2 passed | 1 skipped (3), Tests 11 passed | 1 skipped (12). The skip is the darwin-only acceptance test.
  • npm run test:focused -- over the 33 test files that exercise native dispatch metadata, on the fix: Test Files 26 passed | 7 skipped (33), Tests 433 passed | 23 skipped (456). The skipped files are darwin-only.
  • npm run check:fast: pass.
  • npm run docs:check: pass (includes readmeConsistency.test.ts, 9 passed).
  • npx --no-install lint-staged and oxfmt --check on the changed files: pass, no modifications.
  • Not run: npm run test:fast and the full npm run check. The latter stops at an existing architecture guard that fails the same way on main.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. An optional diagnostics entry is added on two error paths; nothing is removed or renamed.
  • Real Hopper/Ghidra, browser, or OS coverage: none run. The real-provider fallback success path is unchanged and not exercised here. macOS CLI output: see Remaining proof gaps.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only. The retained diagnostic is the same projected reader error the workflow already produced; no paths or data beyond it are added.

Author readiness

Human owner: @zw-g

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

I searched open and closed PRs and issues for 7651, "dispatch fallback reader failure", "retain dispatch reader failure", binary_metadata_failure and inspectNativeDispatch. The only related PR is the closed #7701. The open PRs touching NativeDispatchMetadataInspection.ts or CapabilityFallback.ts do not change this function.

…ack fails

When the byte reader for inspect_native_dispatch_metadata refuses a target
(for example a 32-bit Mach-O) and the list_names symbol fallback then fails
or returns an invalid inventory, only the fallback's error reached the
caller. Retain the reader failure under diagnostics.binary_metadata_failure.

Fixes morluto#7651.

Carries forward e7884a7 (by @morluto, on @dreinst's morluto#7701).

Co-authored-by: morluto <[email protected]>
Signed-off-by: Zhaowei Gu <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T14:54:26.749881Z
We couldn’t complete this review. Comment @codex review to try again.
20efcd8 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

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

The PR preserves the native reader’s refusal when the symbol fallback fails or returns an invalid inventory.

  • Failed symbol fallbacks keep the native reader’s refusal.

Reviews (3) · Last reviewed commit: "test(native): pin IDA and Kuna in the di..." · Reviewed by Greptile

main moved docs/native-investigation.md to
docs/guides/native/native-investigation.md (morluto#2791). Git carries this
branch's four-line docs change over to the new path.

main also made `remediation` required on an unavailable
ProviderAvailability (morluto#8532), so the unconfigured symbol provider
fixture in nativeDispatchAvailability.test.ts now sets one. Without it
the merged tree fails `npm run typecheck` (TS2322).

Signed-off-by: Zhaowei Gu <[email protected]>
@CassieFox23

CassieFox23 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: On head 7ae095c, two of the 3 changed test files passed on three Node versions, with 11 tests each. The third, tests/acceptance/nativeDispatchFallbackFailure.test.ts, is macOS-only and skipped on my Linux VM. With the old src/application/native/NativeDispatchMetadataInspection.ts put back, 3 tests failed on each version.

Edit (9 Nov): I ran the new head, 2cba185, in a VM, and the results are here.

Results

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head 7ae095c, 3 test files Files: 2 passed, 1 skipped. Tests: 11 passed, 1 skipped Same counts Same counts
Red run: NativeDispatchMetadataInspection.ts from 72d5e72 Files: 2 failed, 1 skipped. Tests: 3 failed, 8 passed, 1 skipped Same counts Same counts

The PR changes 5 files against the merge base 72d5e72. Three are test files. The other two are docs/guides/native/native-investigation.md and src/application/native/NativeDispatchMetadataInspection.ts.

The 3 red-run failures on Node 24.22.1 were:

  • retains both the reader refusal and malformed symbol observation in src/application/native/NativeDispatchMetadataInspection.fallback.test.ts
  • retains the binary reader refusal when the symbol fallback also fails in src/application/native/NativeDispatchMetadataInspection.fallback.test.ts
  • native dispatch availability at the public MCP boundary > keeps the binary reader refusal when the symbol fallback is unavailable in tests/boundary/mcp/nativeDispatchAvailability.test.ts

I only have the test names for Node 24.22.1.

CI on the head, read live with gh:

  • CI, CodeQL production and two PR title runs are completed/action_required.
  • PR readiness has one run completed/cancelled and one completed/success.
  • Check runs: Greptile Review is success. Validate author declaration has one success and one cancelled run.
  • The commit status PR readiness is success.
  • GitHub says the PR is mergeable; its merge state is blocked.
  • No Source tests, Portable tests or Test shard jobs appear in the check runs of the CI run.

The head is 6 commits behind main 88cf498.

Not run

  • A run of tests/acceptance/nativeDispatchFallbackFailure.test.ts on a Mac with another list_names provider or an existing config set
  • A probe that calls close_binary and then session.close() in tests/boundary/mcp/nativeDispatchAvailability.test.ts to check for a double close
  • A merge with current main, 88cf498
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 7ae095c / 72d5e72 (merge base with main)
  • Red run: 7ae095c with the changed source files from 72d5e72
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/application/native/NativeDispatchMetadataInspection.fallback.test.ts tests/acceptance/nativeDispatchFallbackFailure.test.ts tests/boundary/mcp/nativeDispatchAvailability.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

The darwin-only acceptance test passes the caller's environment to the CLI
and points only Hopper, Ghidra and Java at missing paths. On macOS the
list_names fallback has four candidates (ghidra, hopper, ida, kuna), so a
REA_IDA_MCP_CONFIG or REA_KUNA_COMMAND set in the developer's shell still
reaches it: with REA_KUNA_COMMAND set, kuna is no longer rejected as
not_configured. Point both at missing paths, as
tests/acceptance/nativeDispatchSnapshot.test.ts does, so the test always
exercises the unavailable fallback.

Signed-off-by: Zhaowei Gu <[email protected]>
@zw-g

zw-g commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the independent run on three Node versions.

On the three items under "Not run" (everything below ran on macOS 26.7, Intel x86_64, Node 24.22.1, after npm ci):

  • The macOS-only acceptance test. At 7ae095c the 3 changed test files pass on macOS: Test Files 3 passed (3), Tests 12 passed (12). With NativeDispatchMetadataInspection.ts from 72d5e72, 4 tests fail: your 3, plus retains the 32-bit reader refusal when symbol fallback is unavailable.
    On macOS the CLI lists four list_names candidates: ghidra, hopper, ida and kuna. The test pointed only Hopper, Ghidra and Java at missing paths, so REA_IDA_MCP_CONFIG and REA_KUNA_COMMAND still came from the caller's shell. With REA_KUNA_COMMAND set to a stub executable in the shell, the CLI run with the test's environment no longer rejected kuna as not_configured on the ARM image. 2cba185 points both at missing paths, as tests/acceptance/nativeDispatchSnapshot.test.ts already does. With it, the 3 files still pass (12/12), the same 4 tests fail with the old source file, and the shell's REA_KUNA_COMMAND no longer reaches the CLI.
  • Double close. In a scratch copy of the MCP case, I counted closes on the native provider's client. close_binary closed it once. session.close(), called twice after that, returned ok both times, and the count stayed at 1: once close_binary has run, the session has no active target left to close. The unconfigured list_names fixture was never called.
  • Current main. The branch merges cleanly with main 25d3c72. On the merged tree with 2cba185, npm run check:fast passes (2/2 tasks) and the 3 test files pass (12/12); npm run docs:check also passes on the merge. The only file both sides touch is docs/guides/native/native-investigation.md, in different sections, so I didn't add a merge commit.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On head 2cba185, the PR's 3 changed test files gave 11 passed and 1 skipped on Node 22.23.4, 24.22.1 and 26.12.1. The skipped file is tests/acceptance/nativeDispatchFallbackFailure.test.ts (1 test). The CI workflow run is completed/action_required, and I ran nothing on macOS.

Thanks, zw-g, for the reply and for commit 2cba185, test(native): pin IDA and Kuna in the dispatch fallback acceptance test.

Check (Linux VM) Node 22.23.4 Node 24.22.1 Node 26.12.1
Test files 2 passed, 1 skipped (3) 2 passed, 1 skipped (3) 2 passed, 1 skipped (3)
Tests 11 passed, 1 skipped (12) 11 passed, 1 skipped (12) 11 passed, 1 skipped (12)

The 3 files are src/application/native/NativeDispatchMetadataInspection.fallback.test.ts, tests/acceptance/nativeDispatchFallbackFailure.test.ts and tests/boundary/mcp/nativeDispatchAvailability.test.ts. The logs for all three Node versions show tests/acceptance/nativeDispatchFallbackFailure.test.ts skipped (1 test). It runs only on macOS. The other two files ran 2 and 9 tests.

CI on the head, read live with gh:

  • Workflow runs: CI, CodeQL production and PR title are completed/action_required. PR readiness is completed/success.
  • Check runs: Greptile Review and Validate author declaration are success. The commit status PR readiness is success.
  • The CI run has no Source tests, Portable tests or Test shard jobs in its check runs.
  • gh shows mergeable true and state blocked. The head is 32 commits behind main b46f4fc.

Not run

  • A run of tests/acceptance/nativeDispatchFallbackFailure.test.ts on macOS at 2cba185, with REA_KUNA_COMMAND and REA_IDA_MCP_CONFIG exported in the shell to real stubs, expecting a pass.
  • A probe on macOS at 2cba185 that restores NativeDispatchMetadataInspection.ts from 72d5e72 and expects tests/acceptance/nativeDispatchFallbackFailure.test.ts to fail.
  • A merge with current main, b46f4fc.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 2cba185 / 72d5e72 (merge base with main)
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/application/native/NativeDispatchMetadataInspection.fallback.test.ts tests/acceptance/nativeDispatchFallbackFailure.test.ts tests/boundary/mcp/nativeDispatchAvailability.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@zw-g

zw-g commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for running the new head.

On the three "Not run" items, all run on macOS 26.7 (Intel x86_64, Node 24.22.1, npm ci) at 2cba185:

  • Acceptance test with IDA and Kuna stubs in the shell. I exported REA_KUNA_COMMAND (an executable stub) and REA_IDA_MCP_CONFIG (a valid stdio registration whose command is a stub). The 3 test files pass: Test Files 3 passed (3), Tests 12 passed (12). Neither stub was invoked.
    To check that the CLI sees the stubs at all, I ran the built CLI on the test's two images. With the test's environment minus the new pins, ida and kuna are no longer rejected as not_configured. With the pins, they are rejected for the test's missing paths (open_options_invalid, executable_missing), the same as in a clean shell. The test file from before the pin (7ae095c) also passed with the stubs. So the pin keeps the developer's shell out of the test; it does not fix a failure I saw.
  • Red run. With NativeDispatchMetadataInspection.ts from 72d5e72, the acceptance test fails at its details.diagnostics.binary_metadata_failure check, both in a clean shell and with the stubs exported. Across the 3 files, 4 tests fail: your 3 plus the acceptance test.
  • Current main. The branch merges cleanly with b46f4fc and with current main, 99d00d1. On the merged tree (99d00d1 plus 2cba185), npm run check:fast passes (2/2 tasks), the 3 files pass 12/12 with and without the stubs, and npm run docs:check passes. With main's own NativeDispatchMetadataInspection.ts put back into the merged tree, the same 4 tests fail, so the bug is still on main. Of our files, main changed only docs/guides/native/native-investigation.md, so I didn't add a merge commit.

gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
…ack fails

When the byte reader for inspect_native_dispatch_metadata refuses a target
(for example a 32-bit Mach-O) and the list_names symbol fallback then fails
or returns an invalid inventory, only the fallback's error reached the
caller. Retain the reader failure under diagnostics.binary_metadata_failure.

Fixes #7651.

Carries forward e7884a7 (by @morluto, on @dreinst's #7701).

Signed-off-by: Zhaowei Gu <[email protected]>

Supersedes #8036

Co-authored-by: morluto <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
…ack fails

When the byte reader for inspect_native_dispatch_metadata refuses a target
(for example a 32-bit Mach-O) and the list_names symbol fallback then fails
or returns an invalid inventory, only the fallback's error reached the
caller. Retain the reader failure under diagnostics.binary_metadata_failure.

Fixes #7651.

Carries forward e7884a7 (by @morluto, on @dreinst's #7701).

Signed-off-by: Zhaowei Gu <[email protected]>

Supersedes #8036

Co-authored-by: morluto <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
N0zoM1z0 pushed a commit that referenced this pull request Nov 14, 2026
…ack fails

When the byte reader for inspect_native_dispatch_metadata refuses a target
(for example a 32-bit Mach-O) and the list_names symbol fallback then fails
or returns an invalid inventory, only the fallback's error reached the
caller. Retain the reader failure under diagnostics.binary_metadata_failure.

Fixes #7651.

Carries forward e7884a7 (by @morluto, on @dreinst's #7701).

Signed-off-by: Zhaowei Gu <[email protected]>

Supersedes #8036

Co-authored-by: morluto <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thank you for this fix. It landed in #10499 with your authorship kept on the commit (adapted where noted in the PR), so I'm closing this PR as superseded.

@N0zoM1z0 N0zoM1z0 closed this Nov 14, 2026
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Dispatch metadata loses the unsupported-width reason when its symbol fallback fails

4 participants