Skip to content

fix(artifacts): preserve iNES shutdown ownership and I/O failures - #11748

Merged
morluto merged 32 commits into
morluto:mainfrom
ShuaixinHuang:repair/ines-review-11739
Nov 19, 2026
Merged

morluto merged 32 commits into
morluto:mainfrom
ShuaixinHuang:repair/ines-review-11739

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem and fix

Opening an iNES region and then cancelling without consuming the returned stream can terminate the Node process, even when the caller handles errors on that public stream. The reader eagerly creates an internal descriptor stream but attaches its consumer inside a lazy generator. Cancellation reaches that hidden source before an error listener exists. Closing the reader also fails to retire buffered producers or join pending reads and final source validation.

Use the existing artifact resource scope to own producer completion and readable retirement, pipe through an immediately connected transform, and admit asynchronous final identity validation independently. Close cancels and joins admitted work before releasing an owned descriptor; borrowed descriptors stay with their owner, and failed closes retain retry ownership. The shared positional reader also preserves a physical I/O rejection when cancellation races its asynchronous delivery.

Scope and review follow-up

This is the existing replacement for #11739, requested by the human owner; earlier reproduction and review history remain in #11154. No replacement PR or new source push was made during the November 18 qualification.

The valid final-progress finding is addressed: successful capture_process_scenario must retain cleanup facts in the last notification. Only preceding progress is bounded; the timeout path retains its separate cleanup lookup because error delivery can append a failure notification.

The published branch includes main 8ffea11ee, the explicitly declared #11732 missing-installation JVM-probe prerequisite, and the doctor fixture's SIGTERM-readiness ordering. These additions still require review and are not represented as merged upstream. Open #10674 adds NES 2.0 support and overlaps the iNES reader, documentation and regressions; this fix retains classic iNES scope and does not integrate that capability.

Reproduction and executed validation

Linux, Node 24.22.1 / npm 11.16.0. Latest main fetched and checked: d72dfb8c69376c14a0fcc386dc3f7d639b4abc97.

Fresh production-boundary reproduction uses a real 16,400-byte classic iNES file (one PRG bank; SHA-256 dc0d9711c5cbfa24c5fb8091cbbe4df8aeb732ecb57229999c9207fa2637f485), a native file descriptor, and the source loader. Enumerate entries, open the header region with an AbortSignal, attach an error listener to the returned stream, leave it unread, then abort and allow two event-loop turns. Untouched main exits 1 with an unhandled internal stream error. Calling reader.close() before the abort also exits 1. Both cases exit 0 with the public stream destroyed after applying the published core fix; explicit public-stream destruction followed by abort also exits 0. These probes were run independently of Vitest.

For the test pair, an isolated main checkout received only this PR's two regression test files, leaving production code unchanged:

  • npm run test:focused -- tests/boundary/filesystem/inesCancellation.test.ts tests/boundary/filesystem/fileHandleChunks.test.ts — 17 failed / 42 passed, plus 1 uncaught cancellation error.
  • In a separate latest-main checkout, applied the five core files from published head af98ad728d0af726e934d18ef2a1c896bbc64e43: iNES reader, positional chunk reader, their two regression files, and iNES documentation. Verified all five tested files byte-for-byte against that published head.
  • npm run test:focused -- tests/boundary/filesystem/inesCancellation.test.ts tests/boundary/filesystem/inesArtifact.test.ts tests/boundary/filesystem/fileHandleChunks.test.ts tests/acceptance/artifactExtractionCoverage.test.ts — 100 passed / 4 files, including all 59 tests in the failing pair; required runtime build passed.
  • npm run check:fast — typecheck/lint and architecture guards passed (2,871 source files).
  • npm run docs:check — six tasks and eight consistency tests passed.
  • node scripts/ci/static-check-report.mjs typed-lint src/artifacts/InesArtifactReader.ts src/filesystem/readFileHandleChunks.ts tests/boundary/filesystem/inesCancellation.test.ts tests/boundary/filesystem/fileHandleChunks.test.ts — four files, 0 errors / 7 advisory warnings.
  • Staged and unstaged git diff --check — passed.

Coverage includes pending reads, I/O/cancellation precedence, final source validation, unread and buffered stream retirement, paused inventory closure, borrowed descriptors and failed-close retries. Extraction coverage also passed against the latest-main composition.

Earlier qualification of the full published branch at af98ad728 ran the doctor-cancellation, file-handle, iNES-cancellation and process-progress suites: 72 passed / 4 suites, plus required runtime build, fast checks, docs checks and diff checks. This is separate from the fresh five-file core composition above.

Hosted checks and limitations

CI run 43890844606 completed successfully for the exact published head af98ad728d0af726e934d18ef2a1c896bbc64e43, including the required CI gate, static/source/build/docs checks, 12 selected shards and the selected platform baseline lanes. This qualifies the published branch, not a newly pushed merge with d72dfb8c. Greptile reported 5/5 with no actionable findings; there are no inline review threads. Codex's current-head attempt failed with an explicit quota limitation and is not counted as a completed review.

The fresh latest-main run covers the five core files, not a fresh integration of all nine published files, including the JVM prerequisite and doctor/process-test changes. No fresh full monolithic local gate/suite, full-repository typed lint, or local native Windows/macOS run is claimed. The shared environment has an 8 GiB limit; full-repository typed lint previously exhausted it during other qualification and was not repeated here. No public schema, provider, execution authority or installation policy is added.

Stream interruption order

At 33c24cc1ab, iNES uses one recorded interruption across reading, transform delivery, and final source validation. With close requested first, a later caller abort preserves the shutdown result even when source validation was already pending. The inverse order retains typed caller cancellation. Tests also cover admitted physical errors and the join of late validation before descriptor retirement. The exact revision passed 136 focused tests with two existing skips, 836 incrementally selected tests with 16 existing skips, and check:fast.

Author readiness

Human owner: @ShuaixinHuang

@ShuaixinHuang explicitly confirmed review of this replacement’s current final diff, evidence and limitations, accepted responsibility, and declared it ready for initial maintainer review.

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

Summary

Opening an iNES region and cancelling before the returned stream is consumed can terminate the process. Closing the reader can also release an extraction-owned descriptor while a read or final source check is still admitted. Producer completion and readable retirement stay on the artifact resource scope, and a physical descriptor rejection stays primary when cancellation races its delivery.

Change and scope

Merged current origin/main (6a5d77bf2). The missing-installation JVM probe already landed in #11732 (f46b97d1e). The merge duplicated that Ghidra test; the duplicate is removed. This diff does not touch GhidraInstallation.

doctorCancellation.test.ts and processCaptureProgress.test.ts are restored to main. Neither edit is required by iNES shutdown ownership or I/O failure precedence. Main already requires successful capture cleanup facts on the last notification.

NES 2.0 (#10674) is not integrated. Classic iNES remains the supported boundary.

The header-admission regression ages its fixture before a same-size overwrite. Identity is observed through mtime, so a rewrite inside one clock tick was reported as a format error instead of source integrity. The same race fails on main's reader.

The Go provider test for an unstored oversized Mach-O command table asserts the typed parse failure (kind: "truncated", format: "macho", field: "Mach-O load commands") and the projected invalid_format issue. It no longer locks the retired sentence about the load-command range.

The paused-inventory close case now lives only in the existing close/cancel pair. That pair already refuses the next entries() step after close or cancel. The close arm also checks that the borrowed descriptor stays open. A second FileHandle.close() resolves on this runtime, so the removed test's descriptor check was not implied by cleanup.

Contribution scope: ordinary fix inside the existing read-only artifact reader. No new provider, execution, injection, or mutation authority. Not applicable for a separate maintainer scope decision.

Contract and boundary impact

  • Semantic owner and earliest changed stage: InesArtifactReader owns region-stream retirement and joins admitted reads and final source checks before close releases an extraction-owned descriptor. Inventory readers still borrow the admitting scope's descriptor. readFileHandleChunks owns the physical read outcome when cancellation races error forwarding.
  • Contribution scope fit and linked maintainer decision: existing read-only container inspection. Not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: classic iNES only. NES 2.0 and UNIF stay unsupported.
  • Evidence, artifact, provenance, or reconstruction contract: shutdown and I/O failure reasons stay structured (unavailable, cancelled, io, integrity). Reconstruction bytes are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: no target execution. A failed owned-descriptor close keeps the same owner for retry.
  • Generated metadata, package, or installation impact: 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: iNES close/cancel/I/O regressions, chunk-reader rejection forwarding, an aged same-size header rewrite, and the Go provider's truncated Mach-O command-table refusal. Doctor and process-capture tests are unchanged from main. The standalone paused-inventory close test is folded into the existing close/cancel case.
  • Base reproduction: the published PR recorded an unhandled internal stream error on untouched main when an opened region was aborted unread. This update revalidated the focused suites on the merged head; it did not repeat that standalone process-exit probe.
  • User-visible CLI/MCP output: none.
  • Remaining proof gaps: no fresh full check:pr, full-repository typed lint beyond check:fast, or native Windows/macOS run.

Lifecycle coverage in inesCancellation.test.ts includes pending reads, final source validation, unread and buffered retirement, paused inventory closure, borrowed descriptors, and failed-close retry. The chunk reader covers a rejected descriptor read that stays primary while cancellation is delivered.

  • 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, Node 24.22.1. Head 86de59dcb7e3c9aa763d598880cc53a693fa4d69.

  • npx oxfmt on the touched tests — formatted.
  • npm run check:fast — typecheck, lint, and architecture guards passed (2898 source files).
  • npm run test:focused -- tests/boundary/filesystem/inesCancellation.test.ts — 49 passed.
  • On the parent head, npm run test:focused for the iNES, chunk-reader, doctor, and domain iNES suites passed 109 tests, and tests/boundary/go/goBinaryProvider.test.ts passed 17 tests. Those files are unchanged by this fold except inesCancellation.test.ts, which was re-run above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not run. This path uses portable file reads.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: local descriptor ownership only. No new process or network authority.

Author readiness

Human owner: @ShuaixinHuang

@ShuaixinHuang explicitly confirmed review of the prior published diff, evidence, and limitations, accepted responsibility, and declared this PR ready for initial maintainer review. Later pushes do not require a new sign-off. The validation section above is the evidence for the narrowed head.

  • 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.
Open in Web Open in Cursor 

ShuaixinHuang and others added 25 commits November 14, 2026 14:39
…repair-11154-20261116

# Conflicts:
#	src/artifacts/InesArtifactReader.ts
#	tests/boundary/filesystem/fileHandleChunks.test.ts
#	tests/boundary/filesystem/inesCancellation.test.ts
…file

The Windows-only case at `clientConfigurationEnvironment.test.ts:226` wrote
`rea_mcp_input_schema_profile: "full"`. That profile was retired: the reader
now refuses it ("REA_MCP_INPUT_SCHEMA_PROFILE accepts only \"compact\" …"),
so `configureClientConfiguration` returned `failed/readback` before writing
and the case failed on every Windows run, including main's own
`Windows capability and package lane`.

The case has no Windows dependency — it passes an explicit `configPath` and
the Kimi write dialect is the same everywhere — so it now runs on every
platform, which is what let the stale value rot unnoticed. The fixture keeps
the lowercase explicit key the case is about, with the supported value.

Verified on `main` `d6bcfc10`: the same fixture driven through
`configureClientConfiguration(..., "win32")` on this host reproduced
`{"status":"failed","reason":"readback"}` with the retired value and now
returns `{"status":"configured"}` with `compact`. The file's 75 cases pass
here (66 run, 9 platform-conditioned skips) and `check:fast` passes.
…alue-11154

# Conflicts:
#	tests/boundary/mcp/decompileAllCaveats.test.ts
#	tests/boundary/mcp/environmentServeMcp.test.ts
@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-16T14:55:12.666459Z
We couldn’t complete this review. Comment @codex review to try again.
af98ad7 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 Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

The PR makes InesArtifactReader stop region streams and wait for admitted work before closing its owned descriptor. The latest change preserves the first interruption across byte delivery and final source checks.

  • Closing an iNES reader retires its streams before releasing its owned file.
  • A rejected positional read keeps its error when cancellation races delivery.
  • Go provider tests identify truncated Mach-O tables by their structured error.

Diagram

sequenceDiagram
  participant Caller
  participant Reader as InesArtifactReader
  participant Stream as Region stream
  participant Scope as ArtifactResourceScope
  participant File as Owned descriptor
  Caller->>Reader: close()
  Reader->>Stream: Abort with recorded shutdown reason
  Reader->>Scope: close()
  Scope->>Scope: Wait for admitted reads and source checks
  Scope-->>Reader: Work settled
  Reader->>File: close()
  Reader-->>Caller: Closed, or close failure retained for retry
Loading

Reviews (7) · Last reviewed commit: "fix(artifacts): preserve first iNES stre..." · Reviewed by Greptile

Copy link
Copy Markdown
Contributor Author

@morluto Could you please review this PR when you have time? As the author, I am finding the ongoing work of keeping these pending branches synchronized and revalidated a substantial maintenance burden. The current head's CI has passed, there are no unresolved inline review threads, and the PR description records the evidence and remaining validation limits. If this change is outside the project's priorities or scope, a clear direction would also help me avoid further unnecessary maintenance. Thank you.

cursoragent and others added 3 commits November 19, 2026 15:39
The doctor readiness fixture and process-capture progress assertions
are not required by descriptor retirement or I/O failure precedence.
Restoring them, and the Ghidra installation test already merged in
morluto#11732, leaves this change on the iNES reader, chunk reader, and
their regressions. The unused artifact chunk helper import is removed.

Co-authored-by: morluto <[email protected]>
Identity checks observe mtime, and a same-size overwrite inside one
clock tick is indistinguishable from the original file. The admission
test then reports a format error instead of source integrity. Age the
fixture the same way the prefix race already does.
An unstored oversized command table is a truncated Mach-O load-command
parse, projected as invalid_format. The old message lock named a
sentence the parser no longer produces.

Co-authored-by: morluto <[email protected]>
cursoragent and others added 2 commits November 19, 2026 16:42
…ng case

The standalone close test repeated the paused entries() refusal already
covered by the close/cancel pair. The borrowed-descriptor stat stays on
that close case.

Co-authored-by: morluto <[email protected]>
The only content conflict was the Go provider's invalid_format issue.
Both sides already omit the retired Mach-O prose lock; the typed
truncation failure stays. Architecture layer counts still match the
baseline.

Co-authored-by: morluto <[email protected]>
@morluto
morluto enabled auto-merge (squash) November 19, 2026 19:02
@morluto
morluto merged commit a836c89 into morluto:main Nov 19, 2026
50 of 51 checks passed
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction 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: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants