[PR #4438] [CLOSED] fix(filesystem): reject regular file reads cancelled during final checks #6243

Closed
opened 2026-10-31 01:12:58 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4438
Author: @jiwonsudo
Created: 10/16/2026
Status: ❌ Closed

Base: main ← Head: fix/regular-file-read-late-cancellation


📝 Commits (1)

  • e846aa8 fix(filesystem): reject regular file reads cancelled during final checks

📊 Changes

2 files changed (+111 additions, -1 deletions)

View changed files

📝 src/application/RegularFileRead.ts (+5 -1)
➕ tests/boundary/filesystem/regularFileReadCancellation.test.ts (+106 -0)

📄 Description

Summary

Fixes #4379. withRegularFile checks the abort signal before its final metadata check, but not after it or after closing the file. If cancellation arrives in that window, the read still resolves with the file contents even though signal.aborted is true.

Problem and expected behavior

The helper runs a final handle.stat() and path stat() to make sure the file did not change during the read. If the caller aborts while those calls are running (or while the file is being closed), the read returns the value as if nothing happened. The pre-aborted case already rejects correctly.

Expected: after the final checks and cleanup are done, the read should reject with the caller's abort reason. The descriptor should still be closed.

Change and scope

In withRegularFileOwned I added a signal?.throwIfAborted() check in two places:

  • after withOwnedRegularFile returns, so the check runs after the final metadata checks and after the file is closed
  • after the resource scope recovers a failed close, before returning the recovered value

This follows docs/tool-design.md ("Before returning success, check the signal after the last awaited finalization step"). Only the success path changes. Existing primary failures and cleanup failures are thrown the same way as before.

Follow the contribution scope. This is a small bug fix inside existing code, so a maintainer scope decision is not needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/application/RegularFileRead.ts, shared regular file read helper
  • Contribution scope fit and linked maintainer decision: bug fix, not applicable
  • CLI and MCP/tool-catalog contract: none
  • Provider, bridge, target-format, or platform compatibility: none
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): cleanup order is unchanged. The new check runs only after cleanup has finished.
  • Generated metadata (docs/public/product-catalog.json), 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: new tests/boundary/filesystem/regularFileReadCancellation.test.ts with a real temp file:
    • abort during the final handle.stat(): rejects with the abort reason, and the handle is closed (fd === -1)
    • abort during a successful close: rejects with the abort reason
    • abort during a failed close that the resource scope then recovers: rejects with the abort reason, close was retried, and the scope has nothing pending
    • control with no abort: still returns the value
  • Base reproduction or other evidence: without the fix, the first three tests fail and the control passes.
  • User-visible CLI/MCP output (if applicable): not applicable. As the issue says, no end-to-end CLI/MCP effect has been observed.
  • Remaining proof gaps: I did not run the full npm run check:pr locally.

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

Node v22.22.0, Linux:

  • npx vitest run tests/boundary/filesystem/regularFileReadCancellation.test.ts: 4 passed (3 failed without the fix)
  • npx vitest run tests/boundary/filesystem plus all other test files that use RegularFileRead or JsonFiles: the same set of tests failed with and without this change. My environment cannot run the JavaScript static analysis adapter. Apart from the new test file, the results are identical.
  • npx tsc --noEmit: passed
  • npx oxlint on the changed files: no issues
  • npx oxfmt --check on the changed files: passed
  • npm run verify:test-discovery: passed, all 1416 test files found once
  • npm run verify:module-boundaries: passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Reads that are cancelled late now reject instead of returning a value, which matches the existing pre-abort behavior.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. Tested on Linux only.
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: none

Author readiness

Human owner: @jiwonsudo

  • 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. (N/A, no CLI or MCP change)
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4438 **Author:** [@jiwonsudo](https://github.com/jiwonsudo) **Created:** 10/16/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/regular-file-read-late-cancellation` --- ### 📝 Commits (1) - [`e846aa8`](https://github.com/morluto/rea/commit/e846aa8a6a0575905cbf8c995e569195e2761567) fix(filesystem): reject regular file reads cancelled during final checks ### 📊 Changes **2 files changed** (+111 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/application/RegularFileRead.ts` (+5 -1) ➕ `tests/boundary/filesystem/regularFileReadCancellation.test.ts` (+106 -0) </details> ### 📄 Description ## Summary Fixes #4379. `withRegularFile` checks the abort signal before its final metadata check, but not after it or after closing the file. If cancellation arrives in that window, the read still resolves with the file contents even though `signal.aborted` is `true`. ## Problem and expected behavior The helper runs a final `handle.stat()` and path `stat()` to make sure the file did not change during the read. If the caller aborts while those calls are running (or while the file is being closed), the read returns the value as if nothing happened. The pre-aborted case already rejects correctly. Expected: after the final checks and cleanup are done, the read should reject with the caller's abort reason. The descriptor should still be closed. ## Change and scope In `withRegularFileOwned` I added a `signal?.throwIfAborted()` check in two places: - after `withOwnedRegularFile` returns, so the check runs after the final metadata checks and after the file is closed - after the resource scope recovers a failed close, before returning the recovered value This follows `docs/tool-design.md` ("Before returning success, check the signal after the last awaited finalization step"). Only the success path changes. Existing primary failures and cleanup failures are thrown the same way as before. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). This is a small bug fix inside existing code, so a maintainer scope decision is not needed. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/application/RegularFileRead.ts`, shared regular file read helper - Contribution scope fit and linked maintainer decision: bug fix, not applicable - CLI and MCP/tool-catalog contract: none - Provider, bridge, target-format, or platform compatibility: none - Evidence, artifact, provenance, or reconstruction contract: none - Target selection, authority, upstream behavior, and cleanup details (if applicable): cleanup order is unchanged. The new check runs only after cleanup has finished. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none Expected effects: - [x] 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: new `tests/boundary/filesystem/regularFileReadCancellation.test.ts` with a real temp file: - abort during the final `handle.stat()`: rejects with the abort reason, and the handle is closed (`fd === -1`) - abort during a successful close: rejects with the abort reason - abort during a failed close that the resource scope then recovers: rejects with the abort reason, close was retried, and the scope has nothing pending - control with no abort: still returns the value - Base reproduction or other evidence: without the fix, the first three tests fail and the control passes. - User-visible CLI/MCP output (if applicable): not applicable. As the issue says, no end-to-end CLI/MCP effect has been observed. - Remaining proof gaps: I did not run the full `npm run check:pr` locally. 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 Node v22.22.0, Linux: - `npx vitest run tests/boundary/filesystem/regularFileReadCancellation.test.ts`: 4 passed (3 failed without the fix) - `npx vitest run tests/boundary/filesystem` plus all other test files that use `RegularFileRead` or `JsonFiles`: the same set of tests failed with and without this change. My environment cannot run the JavaScript static analysis adapter. Apart from the new test file, the results are identical. - `npx tsc --noEmit`: passed - `npx oxlint` on the changed files: no issues - `npx oxfmt --check` on the changed files: passed - `npm run verify:test-discovery`: passed, all 1416 test files found once - `npm run verify:module-boundaries`: passed ## Compatibility, safety, and release - Breaking changes or migration steps: none. Reads that are cancelled late now reject instead of returning a value, which matches the existing pre-abort behavior. - Real Hopper/Ghidra, browser, or OS coverage: not applicable. Tested on Linux only. - Package or release metadata impact: none - Security, privacy, process, or containment review: none ## Author readiness Human owner: @jiwonsudo - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. (N/A, no CLI or MCP change) - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:12:58 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6243
No description provided.