Skip to content

fix(root): keep POSIX read admission off the event loop - #1055

Merged
steipete merged 2 commits into
mainfrom
fix/async-root-read-admission
Nov 5, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/async-root-read-admission

Conversation

@steipete

@steipete steipete commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: POSIX root acquisition and guarded reads can block the JavaScript event loop while synchronous filesystem metadata or open calls wait on storage, even when the caller awaits the API.

User Impact

Built-in POSIX root(), openRootFile(), and Root.open()/read admission now await filesystem work. The same descriptor remains pinned through the ordered root/path identity checks, and no Root read consumes bytes or transfers the handle before final admission succeeds.

Windows keeps its existing synchronous admission and native namespace/delete-sharing behavior. Explicit synchronous APIs and custom ioFs adapters keep their contracts. Stat/list/walk observation guards and other mutation/durability paths remain outside this change; the native addon may still load synchronously on first use. No version or dependency changes, release, or publication.

Why This Change Was Made

The existing async traversal stopped at synchronous root acquisition and final admission. Shared procedures now drive the same validation through async POSIX or retained sync owners. Numeric descriptors use callback filesystem operations so a temporary FileHandle cannot later close a transferred descriptor. Bun's native canonicalization moves to the existing native task executor without replacing its physical-path, permissions, socket, or record-lock semantics. Home expansion and bounded-read size observations use async filesystem calls too.

The final fence remains an ordered, best-effort detection fence, not an atomic namespace primitive. Tests preserve exact bigint comparisons, same-FD custody, rejection of replacements during awaited observations, no data reads before admission, and cleanup after failure. A Windows control retains the no-yield final fence.

There is an idle overhead tradeoff. On a synthetic eight-component, 8.8 KB skill file using Node 24.22.1/macOS, serial A/A and interleaved A/B runs (250 operations/sample, three samples per revision) gave these medians:

Operation Wall µs, base → candidate CPU µs, base → candidate Sampled allocation KB/op, base → candidate
root acquisition 13.60 → 49.66 20.99 → 62.83 4.58 → 6.91
root-file open/close 401.72 → 580.25 475.31 → 685.41 77.72 → 106.69
Root readText 384.24 → 589.89 458.64 → 688.24 90.82 → 116.97

Allocation sampling ran separately from timing. The first two identical-base controls differed by -8.6%, -6.9%, and -10.0% in wall time respectively. Candidate wall samples ranged 37–83 µs, 520–908 µs, and 457–815 µs; host variability prevents treating the medians as a precise effect-size estimate. These are owner-level warm measurements, not a production-shaped end-to-end performance claim. The benefit is avoiding event-loop stalls under slow storage, not improving unloaded latency.

Production source changes are +267/-139 lines (net +128); tests/config are +464/-92 (net +372). The growth retains shipped synchronous and Windows contracts while sharing admission logic rather than introducing a second validation owner. No cache or configuration option is added.

Evidence

  • Delayed-filesystem regression: all four cases fail on exact base ea225ba262cf4ab86edc12abe374dfc9068833ff and pass on the candidate. Root acquisition, root-file descriptor open, Root read, and first home expansion observe zero tracked sync filesystem calls while a 500 ms metadata delay permits the event-loop heartbeat to progress.

  • Focused ordered-admission, await-swap, replacement-root, pinned-open/close, bounded-read, exact-identity, raw-path/root-spelling, failure-receipt, and realpath consumer tests pass. Updated the Bun native CI selection to include the new root/read regressions.

  • File-size and filesystem-boundary checks, TypeScript build, and git diff --check pass.

  • pnpm check stops at the mandatory WASM build because local Cargo is unavailable. The initial-head CI compiled the native implementation on Linux/macOS and passed the new Bun 1.4.4 responsiveness/custody tests and Windows runtime/native/package matrix. It found two repaired defects (missing retained identity must fail closed; the FreeBSD subset has no task executor) and stale sync-only test injections/resource classifications. The complete exact-head CI run passes at 27bc0a7f5e482317ef9fff339ea04061363fb3e0, including Linux, macOS, Windows, FreeBSD, native/Bun, and bundled-package checks.

  • The CI-produced portable WASM and macOS native artifact enabled focused local archive/resource proof without installing toolchains. All 54 native-mode resource rows pass. Exact-base archive comparisons retain identical syscall totals (for example TAR nondurable 3,908 → 3,908; ZIP durable 4,713 → 4,713). Aggregate syscall ceilings remain unchanged; explicit resource formulas account for offloading existing observations (+11 promises/+1 request per root guard, +9/+1 per portable directory guard).

  • Independent Codex autoreview: no actionable P0–P2 findings.

  • Tests added or updated when behavior changed

  • Security and compatibility impact considered

  • CHANGELOG.md updated when release-relevant

  • No credentials, private paths, private hosts, or sensitive contents included

@steipete
steipete requested a review from a team as a code owner November 2, 2026 12:42
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-11-02T13:12:53.173255Z 27bc0a7 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR moves built-in POSIX root acquisition and read admission to asynchronous filesystem operations while retaining synchronous and Windows paths.

Example: A POSIX application awaits Root.readText("value") while metadata lookup takes 500 ms.

  • Before: Synchronous admission metadata can block the JavaScript event loop during the lookup.
  • After: Admission awaits filesystem work so timers can progress before the admitted descriptor supplies the file contents.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The useful, owner-directed implementation retains the principal safety checks, but affected test consumers fail and final-effect authority proof remains outstanding.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: An application can stop processing timers and other requests while an awaited filesystem API performs synchronous admission work on slow storage.
Reason: The maintainer-authored direction explicitly trades unloaded latency and allocation for event-loop responsiveness while preserving Windows and synchronous contracts.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep open: this PR addresses blocking filesystem work that remains on main, but change-related test failures need repair before merge.

Priority: P2
Reviewed head: 1bef8eab1f3ea5de82a58432421a06f6cc44f6c3

Before merge

  • Add real behavior proof - Authority-chain proof required: the changed Root and root-file admission owners are exercised by delayed-I/O and real-filesystem swap tests, but no supplied installed-package trace shows an allowed read and replacement-root or escaped-path rejection before bytes are read or a descriptor is transferred; provide terminal output or logs with sensitive paths and endpoints redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Move identity-test instrumentation to the asynchronous observers (P2) - POSIX admission now obtains pathname identities asynchronously and descriptor identities through handle.stat, but test/root-copy-read-identity.test.ts still fabricates identities through lstatSync/statSync/fstatSync. Later synchronous copy checks therefore compare the fabricated inode with an unmodified opening identity and reject before the intended after-copy swap. Exact-head macOS CI confirms the swap assertion at line 71 fails. The archive source observer likewise counts only synchronous fstat and now reports three observations instead of four. Update these fixtures to observe both platform routes and retain the intended swap and same-descriptor assertions.
  • Update exact scheduling budgets for the offloaded observations (P2) - The new asynchronous shared root checks also run in mutation and archive consumers, but their deterministic scheduling oracles remain unchanged. Exact-head CI reports Root.open at 130 Promises against 47, move at 15 asynchronous lstats against 9, archive asynchronous-budget overruns, and mkdir/append/writable-open resource mismatches. These are attributable to the changed observers rather than an unrelated CI outage. Update the affected call-budget tests and scripts/native-call-budget-proof.mjs with source-verified deltas, preserving total filesystem-work and durability checks instead of broadly raising ceilings.
  • Resolve security concern: Verify replacement rejection across awaited admission - Exact bigint comparisons, ordered checks, and descriptor custody remain in source, and the added tests exercise replacements; independently inspectable final-effect evidence is still needed for allowed reads and the nearest forbidden root or pathname replacement.
  • Resolve merge risk - Before merge, the PR owner should establish that the new awaited admission boundaries reject a replaced root or escaped pathname before reading bytes or transferring a descriptor.
  • Improve patch quality - Add final-effect proof for allowed reads and the nearest forbidden root or pathname replacement, showing rejection before data reads or descriptor handoff.

Findings

  • [P2] Move identity-test instrumentation to the asynchronous observers — src/local-file-descriptor.ts:97-99
  • [P2] Update exact scheduling budgets for the offloaded observations — src/root-context.ts:178-180
  • [medium] Verify replacement rejection across awaited admission — src/root-read-admission.ts:106

Tests

  • Missing end-to-end proof: Supply a redacted installed-package trace of responsive POSIX admission plus allowed and forbidden filesystem cases, including rejection before data reads or descriptor handoff.
Agent review details

How this fits together

Root and root-file helpers turn untrusted paths into confined reads or pinned descriptors after canonicalization, exact identity checks, and hardlink and symlink policy checks.

flowchart TD
  A[Caller path] --> B[Root acquisition and traversal]
  B --> C[Pinned descriptor open]
  C --> D[Exact descriptor identity]
  D --> E[Final root and pathname admission]
  E --> F[Read bytes or transfer descriptor]
Loading

Technical review

Best possible solution:

Retain the shared admission procedures, repair their affected test consumers and exact budget oracles, and verify confined reads and rejected replacements through the installed package.

Do we have a high-confidence way to reproduce the issue?

Main directly invokes synchronous filesystem operations during awaited root acquisition and final read admission; the PR also reports exact-base failures of its delayed-filesystem regressions, which were not rerun in this read-only review.

Is this the best way to solve the issue?

Reusing the existing procedures and identity verifiers is a sound approach, but the affected identity fixtures and scheduling budgets must follow the new I/O owners without weakening their assertions.

Full review comments:

  • [P2] Move identity-test instrumentation to the asynchronous observers — src/local-file-descriptor.ts:97-99
    POSIX admission now obtains pathname identities asynchronously and descriptor identities through handle.stat, but test/root-copy-read-identity.test.ts still fabricates identities through lstatSync/statSync/fstatSync. Later synchronous copy checks therefore compare the fabricated inode with an unmodified opening identity and reject before the intended after-copy swap. Exact-head macOS CI confirms the swap assertion at line 71 fails. The archive source observer likewise counts only synchronous fstat and now reports three observations instead of four. Update these fixtures to observe both platform routes and retain the intended swap and same-descriptor assertions.
    Confidence: 0.99
  • [P2] Update exact scheduling budgets for the offloaded observations — src/root-context.ts:178-180
    The new asynchronous shared root checks also run in mutation and archive consumers, but their deterministic scheduling oracles remain unchanged. Exact-head CI reports Root.open at 130 Promises against 47, move at 15 asynchronous lstats against 9, archive asynchronous-budget overruns, and mkdir/append/writable-open resource mismatches. These are attributable to the changed observers rather than an unrelated CI outage. Update the affected call-budget tests and scripts/native-call-budget-proof.mjs with source-verified deltas, preserving total filesystem-work and durability checks instead of broadly raising ceilings.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ea225ba262cf.

Merge-risk options

Maintainer options:

  1. Verify the awaited confinement boundary (recommended)
    The PR owner supplies an installed-package trace showing an allowed read and root/path replacement rejection with no bytes read or descriptor transferred on rejection.

Provenance checked

Testing

Proof path: in-process harness.

Security

Needs attention: No concrete confinement bypass was found, but the new awaited authorization boundaries need final-effect verification.

Evidence

Security concerns:

  • [medium] Verify replacement rejection across awaited admission — src/root-read-admission.ts:106
    Exact bigint comparisons, ordered checks, and descriptor custody remain in source, and the added tests exercise replacements; independently inspectable final-effect evidence is still needed for allowed reads and the nearest forbidden root or pathname replacement.
    Confidence: 0.85

What I checked:

  • Policy and introduced change: Read the complete root AGENTS.md and the pinned introduced diff. No nested AGENTS.md, maintainer notes, or pr-simplify skill were present. The checkout remained clean; no target code or tests were executed. (AGENTS.md:1, 1bef8eab1f3e)
  • Main still performs blocking admission: The base uses synchronous root canonicalization and metadata, and a synchronous final root/path/root read fence; the PR replaces these POSIX observations with awaited operations. (src/root-read-admission.ts:65, ea225ba262cf)
  • Confirmed identity-test failure: Exact-head native macOS CI reports test/root-copy-read-identity.test.ts:71 failing because the expected swap never occurs. Its synthetic identities still intercept synchronous metadata and fstat, whereas POSIX opening now uses asynchronous metadata and handle.stat. (src/local-file-descriptor.ts:99, 1bef8eab1f3e)
  • Confirmed budget and observation failures: Exact-head Node 22 Linux CI reports Root.open Promise count 130 against a ceiling of 47, move metadata counts [15,7,1] against [9,7,1], archive asynchronous-budget failures, and an archive descriptor observer counting three synchronous stats instead of four. (test/fs-call-budget.test.ts:180, 1bef8eab1f3e)
  • Mutation resource oracles also need adjustment: Rust coverage annotations report deterministic resource mismatches in mkdir, append, and writable-open proofs, including mkdir changing from 37 to 48 Promise resources and two to three filesystem requests. (scripts/native-call-budget-proof.mjs:233, 1bef8eab1f3e)
  • Direction and supplied proof: The maintainer-authored PR explicitly accepts higher idle admission costs to avoid slow-storage stalls and supplies delayed-I/O and filesystem-swap test results. The complete body and comments contain no installed-package trace exercising the changed admission boundaries. (1bef8eab1f3e)

Labels

Label changes:

  • add P2: Avoiding slow-storage event-loop stalls is useful, but the evidence establishes no current emergency or widespread outage.
  • add merge-risk: 🚨 security-boundary: The patch introduces suspension points in the root and pathname checks that authorize reads and descriptor handoff.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Avoiding slow-storage event-loop stalls is useful, but the evidence establishes no current emergency or widespread outage.
  • merge-risk: 🚨 security-boundary: The patch introduces suspension points in the root and pathname checks that authorize reads and descriptor handoff.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 2, 2026, 7:56 AM ET / 12:56 UTC.

@steipete
steipete merged commit 939eeb5 into main Nov 5, 2026
57 of 58 checks passed
@steipete
steipete deleted the fix/async-root-read-admission branch November 5, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant