Skip to content

fix(apple): preserve Interface Builder read failures instead of invalid archives - #6074

Closed
XiaoBinGan wants to merge 4 commits into
morluto:mainfrom
XiaoBinGan:fix/interface-builder-read-failure
Closed

XiaoBinGan wants to merge 4 commits into
morluto:mainfrom
XiaoBinGan:fix/interface-builder-read-failure

Conversation

@XiaoBinGan

@XiaoBinGan XiaoBinGan commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

decode_interface_builder reports a selected document that was never read as a successful partial graph. When a readable-format nib cannot be opened (EACCES), or the selected name is replaced by byte-identical content on a new inode, the tool exits 0 with documents: [], graph.truncated: true and archive coverage reason one_or_more_archives_invalid. The typed read outcome survives only as a human-readable limitation, so an automated caller cannot branch on unavailable access versus malformed content.

Fixes #6066.

Problem and expected behavior

The per-document catch in analyzeInterfaceBuilderBundle only separates an aborted caller signal and InterfaceBuilderDecodeBudgetExceeded; every remaining exception is pushed onto invalid, which the coverage projection turns into one_or_more_archives_invalid. A read failure occurs before any decode, so calling those bytes "invalid archives" misstates what was established.

Expected: preserve the typed reader outcome (integrity for a changed entry, io for a refused open) for the artifact boundary, and keep describing only bytes that were actually read and rejected as invalid archives. Genuine decode failures, budget omissions and cancellation reporting stay as they are.

Change and scope

The catch rethrows an ArtifactReaderFailure before the decode-failure classification. The existing shared translation (ArtifactOperationFailure.ts) already maps a reader reason onto ArtifactOperationError with matching recovery, so no new schema or consumer is needed. This mirrors the existing convention for other artifact producers, which rethrow reader failures rather than reinterpreting them.

Intentionally not included: permission classification inside the shared directory reader, which is independently needed and cannot repair this catch by itself.

Contract and boundary impact

  • Semantic owner and earliest changed stage: analyzeInterfaceBuilderBundle per-document classification; earliest stage is the artifact read boundary.
  • Contribution scope fit and linked maintainer decision: ordinary bug fix within existing boundaries; not applicable.
  • CLI and MCP/tool-catalog contract: unchanged schemas; failures now surface as typed ArtifactOperationError instead of successful partial Evidence. No tool was added or renamed.
  • Provider, bridge, target-format, or platform compatibility: no provider change; the behavior is platform-independent, but the reported case was reproduced on macOS.
  • Evidence, artifact, provenance, or reconstruction contract: partial Evidence no longer claims malformed archive content for a document that was never read.
  • Target selection, authority, upstream behavior, and cleanup details: no target execution; reader cleanup already owns descriptors on the failure path.
  • Generated metadata: none.

Expected effects:

  • 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/artifacts/apple/InterfaceBuilderReadFailure.test.ts — four cases: a readable document control, a changed-inode document, a refused open, and a genuinely malformed document.
  • Base reproduction or other evidence: the two failure cases fail on the affected base revision and pass with the change; the malformed and readable controls pass on both. On base they returned success with documents: [] and reason: one_or_more_archives_invalid.
  • User-visible CLI/MCP output (if applicable): the refused-open case previously returned success plus a limitation naming EACCES; the changed-entry case previously returned success plus a limitation naming the changed entry. Both now surface the typed failure.
  • Remaining proof gaps: this was exercised through the production DirectoryArtifactReader and the analysis entry point, not through an end-to-end MCP session. Natural incidence and other platforms were not measured. No repaired software or known-good revision is established.

Evidence-bearing checks:

  • 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

  • node node_modules/vitest/vitest.mjs run src/artifacts/apple/InterfaceBuilderReadFailure.test.ts src/artifacts/apple/InterfaceBuilderDecodeBudget.test.ts --maxWorkers=1 — 19 passed (4 new, 15 existing).
  • npx tsc --noEmit -p . — no errors.
  • npx oxfmt --check <changed files> — formatted.
  • npm run verify:module-boundaries — 2481 source files checked, no violations.
  • node node_modules/vitest/vitest.mjs run src/artifacts/apple --maxWorkers=1 — 6 pre-existing failures on macOS-only/symlink fixtures reproduce identically on the unmodified base revision; the new file adds 4 passing tests and changes none of them.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Callers that previously received successful partial Evidence for an unread document now receive a typed failure; that is the reported defect, not a supported contract.
  • Real Hopper/Ghidra, browser, or OS coverage: none required; no analysis engine is involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no target interaction, no new data exposure. A failed read now stops the operation instead of continuing with partial output.

Author readiness

Human owner: @XiaoBinGan

  • 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.

…id archives

decode_interface_builder reported a selected document that could not be read, or whose identity changed before open, as a successful partial graph with archive coverage reason one_or_more_archives_invalid. The per-document catch only separated aborted signals and decode-budget exceptions, so every remaining reader failure was consumed as malformed content.

Keep an ArtifactReaderFailure out of the malformed-content classification so the artifact boundary preserves its typed reason. Genuine decode failures, decode-budget omissions and cancellation reporting are unchanged.

Adds a regression covering a changed inode and a real io refusal through the production reader, plus readable, malformed and restored controls.
@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

The PR preserves typed Interface Builder read failures instead of labeling unread documents as invalid archives.

  • Interface Builder reads now stop with the original access or identity failure.

Reviews (2) · Last reviewed commit: "chore: integrate Interface Builder read-..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc2eb7c08f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// established, so it is not evidence of malformed archive content:
// preserve its typed reason for the artifact boundary instead of
// reporting the document as invalid.
if (cause instanceof ArtifactReaderFailure) throw cause;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Retain earlier decoded documents with the read failure

When a bundle has a readable lexically earlier archive and a later archive whose open/read fails, documents already contains a completed decode here, but the unconditional rethrow carries no partialObservation; ArtifactProvider consequently returns only the ArtifactOperationError, discarding the earlier graph and its source hashes. Keep the typed reader failure but attach the accumulated analysis as partial evidence so one unreadable .nib does not erase already established facts.

AGENTS.md reference: AGENTS.md:L31-L31

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this in this PR — the report that scopes the fix explicitly excludes it. #6066 states: "A read or identity-validation failure should preserve its typed failure... It is sufficient to propagate the typed read failure; this report does not require a new partial-result schema."

Surfacing the already-decoded graph beside a typed read failure needs a new member of AnalysisPartialObservation (there is no Interface Builder variant today) plus a producer/consumer contract for it. That is a public contract change, and the report says it is not required. If you want it, I am glad to do it as a separate change with its own contract review rather than adding a schema member inside a misclassification fix.

The earlier-decoded documents are still built and passed to buildInterfaceBuilderAnalysis; they are discarded only at the throw boundary, exactly as the report accepted.

// established, so it is not evidence of malformed archive content:
// preserve its typed reason for the artifact boundary instead of
// reporting the document as invalid.
if (cause instanceof ArtifactReaderFailure) throw cause;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the primary read failure through final cleanup

When an identity/read failure is accompanied by a descriptor close failure, this rethrow is followed by the outer finally's await reader.close(), and a rejection there replaces the original error under JavaScript finally semantics. The provider then sees only cleanup io instead of the original integrity/io reason, so compose the close outcome with the primary and retain retry ownership rather than allowing final cleanup to overwrite the reason this change is intended to preserve.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6119bc5. The finally now composes rather than replaces: the catch records the typed primary, the close attempt gets its own try, and on failure it becomes ArtifactReaderFailure.withCleanup(primary, cleanupObservation(closeCause, ...)) — the same pattern src/artifacts/inventory/scanReader.ts and src/artifacts/javascript/JavaScriptArtifactFiles.ts already use for owned-reader cleanup. The provider therefore still sees integrity/io with the close failure attached as cleanup ownership.

Covered by a new case, keeps the read failure when final cleanup also fails, asserting the reason and message survive and cleanup is set. Verified red → green: restoring the bare finally { await reader.close(); } makes it fail.

One remaining cleanup is unchanged and pre-existing: a close-only failure with no document failure was never surfaced as its own result, and this change does not alter that.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

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 ✅ Completed 2026-10-23T07:49:37.724376Z 82be61f New commits
ℹ️ 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.

Addresses the two review findings on this change:

- Final cleanup no longer replaces the typed primary: a close failure after a read/identity failure is composed as cleanup ownership through ArtifactReaderFailure.withCleanup, so the provider still sees integrity/io rather than cleanup io.
- The unreadable-document control forwards the real reader instance instead of its prototype, so the continuation branch works for any document rather than relying on a single-document fixture.

@CassieFox23 CassieFox23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, XiaoBinGan, for the fix and the tests.

Main fixed the core of this in 78f8eca. It rethrows ArtifactReaderFailure in the same place, with a test. So this PR now conflicts with main.

The PR still adds the close-failure wrapping and its test. Main still does a plain reader.close(). Issue #6066 is still open.

Static read only. I ran nothing.

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

@XiaoBinGan XiaoBinGan closed this Oct 24, 2026
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Closing as superseded — main now covers both parts of this change, with tests.

  • 78f8eca53 rethrows ArtifactReaderFailure in the same per-document catch, so a read or identity failure is no longer reported as invalid archive content.
  • 59a00d77f replaced the bare finally { await reader.close(); } with resources.release / resources.cleanupFailure, which composes a close failure as cleanup ownership instead of replacing the typed primary.

Verified rather than assumed: I applied this PR's five test cases to a clean upstream/main checkout and they all pass there, including keeps the read failure when final cleanup also fails. So there is no behaviour left for this branch to add.

Thanks for the review, @CassieFox23 — the body-template findings were valid and I have kept them in mind for the follow-up.

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 23, 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] Interface Builder decoding treats read and identity failures as invalid archives

3 participants