Skip to content

feat(root): check caller authority before filesystem mutations - #296

Merged
steipete merged 4 commits into
mainfrom
codex/fs-safe-audit-api
Sep 13, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/fs-safe-audit-api

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Filesystem writes, moves, and removals can outlive a caller's lease or permission check while waiting for asynchronous preparation.

Why This Change Was Made

Adds an optional synchronous assertBeforeMutation callback to Root defaults and mutation options. Root and per-call assertions compose, and checks run immediately before each library-owned mutation dispatch across native and JavaScript paths. Refusals preserve the caller's error; already-admitted work, descriptor disposal, and identity-owned cleanup still settle.

User Impact

Consumers can carry revocable authority through Root operations, including configuration publication and workspace file changes. The callback cannot revoke an already-dispatched syscall or guard later writes through a returned raw FileHandle. Existing defaults remain unchanged.

Closes #251.

Evidence

  • Revoked-authority regression fails on the original implementation and preserves the target after the fix.

  • 259 focused tests passed, including Root behavior and error normalization; native, JavaScript, and simulated Windows cases are covered.

  • All 32 authority and dispatch tests pass against the rebuilt native binding and current package.

  • Build, documentation, package, boundary, and file-size checks passed; independent review found no actionable P0-P2 findings.

  • The broad local run was not completed. Focused mutation, error-contract, and native suites pass; exact-head cross-platform CI supplies the full-suite landing gate.

  • 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

Actual filesystem dispatch proof

Root removal now submits unlink directly, and buffered writes share a bounded writer that checks authority before every write submission, including short writes. This avoids the internal async preparation in Node's rm and the later chunks in writeFile/appendFile. The Node write loop and removal preparation explain the boundary.

A standalone built-package consumer used real filesystem operations and async-hooks observation, with no filesystem-operation mocks:

{
  "observations": [
    {
      "case": "allowed-write",
      "bytes": 1048576,
      "exactBytes": true
    },
    {
      "case": "reassigned-owner-removal",
      "rejected": true,
      "targetPreserved": true
    },
    {
      "case": "allowed-removal-dispatch",
      "deferredPreparation": false,
      "targetRemoved": true
    },
    {
      "case": "append-owner-reassigned-after-first-write",
      "requestedBytes": 1048576,
      "appendedBytes": 524288,
      "rejected": true,
      "originalPrefixPreserved": true,
      "noLaterChunkWritten": true
    }
  ],
  "syntheticFixtureRemoved": true
}

The regressions fail on the previous PR head. Owned cleanup also rechecks the final file identity after awaited parent guards, preserving a replacement file.

Removal semantics and Windows validation

The maintainer decision is to retain one direct unlink path for Root file removals. Missing targets still report not-found; a target disappearing after admission can now report not-found instead of being silently absorbed by Node's rm recovery. This intentionally avoids a second asynchronous pathname traversal. Ordinary Windows read-only files remain removable through libuv's handle-based unlink implementation, without adding pathname-based chmod recovery.

The exact-head Node 22 Windows job had one 5,000 ms store-overlap timeout. That path exercises Root.write, but identical production and test bytes passed it in 2,330 ms on the earlier run; its private-mode sibling also slowed from 1,518 to 3,041 ms. Node 24 Windows, native Windows, and Node 22 Windows coverage passed. One exact failed-job rerun was requested without changing source, assertions, or timeouts.

The targeted rerun passed. Final head cd3a12d232f6c8a8c854a9d85726840942f2c032 is green in CI (15 jobs), cross-platform coverage, and CodeQL.

@clawsweeper

clawsweeper Bot commented Sep 13, 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.

@clawsweeper clawsweeper Bot added 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 10:19 PM ET / September 13, 2026, 02:19 UTC (Revision 5).

ClawSweeper review

What this changes

Adds composed caller-authority checks before Root filesystem mutations, bounded write submissions, direct file removal, documentation, and regression coverage.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: the capability remains absent from main, both prior findings are fixed, and real-filesystem proof supports the authority fence. The remaining blocker is the unresolved removal-compatibility contract.

Priority: P2
Reviewed head: cd3a12d232f6c8a8c854a9d85726840942f2c032
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent patch with useful real-filesystem proof and repaired regressions; compatibility acceptance remains a separate landing decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured built-package consumer transcript exercises Root writes, removal, and append against real files: allowed operations succeed, reassigned-owner removal preserves its target, and revoked append authority prevents later chunks. The latest commit changes only tests, preserving that production evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured built-package consumer transcript exercises Root writes, removal, and append against real files: allowed operations succeed, reassigned-owner removal preserves its target, and revoked append authority prevents later chunks. The latest commit changes only tests, preserving that production evidence.
Evidence reviewed 9 items Applicable repository policy: Read the full root AGENTS.md and CONTRIBUTING.md; no nested AGENTS.md or maintainer-notes directory was found. Compatibility surfaces and filesystem boundaries informed the review. No target-bundled reviewer, build, or artifact-producing tests were run.
Still needed on main and in the latest release: Pinned main lacks the Root assertion option and still removes files through fs.rm. The v0.9.0 Root option declarations also lack the callback. Existing standalone move assertions and atomic-write callbacks do not supply the complete Root contract.
Prior findings resolved: The delta from the previously reviewed head retargets write failure/visibility observations to FileHandle.write or fs.write and moves the post-removal race injection to unlink. Production source is unchanged since that review. The supplied current-head Linux/macOS checks pass; Windows checks were pending in the captured context.
Findings None None.
Security None None.

How this fits together

Root confines application filesystem operations to a checked directory. The new callbacks carry caller-defined authority through asynchronous preparation and can refuse subsequent mutation submissions.

flowchart TD
  A[Application mutation request] --> B[Root and per-call assertions]
  B --> C[Path and identity preparation]
  C --> D{Live authority allows mutation?}
  D -->|Yes| E[Native or JavaScript filesystem submission]
  E --> D
  D -->|No| F[Refusal and owned cleanup]
  E --> G[Verification and completion]
Loading

Decision needed

Question Recommendation
Should the broader Root authority contract replace file removal for every caller, or preserve the existing removal path when no callback is configured? Preserve omitted-callback compatibility: Approve the broader callback scope while retaining existing removal behavior for callers without an assertion and validating both paths.

Why: The linked contract discussion explicitly leaves this scope and compatibility choice pending; successful authority proof does not authorize changing existing callers’ recovery behavior.

Before merge

  • Resolve merge risk (P1) - Existing callers now bypass Node rm recovery even without opting into authority checks; concurrent-disappearance error behavior and Windows EPERM recovery parity remain unverified.
  • Complete next step (P2) - Approve the broader Root authority scope and resolve omitted-callback removal compatibility by preserving the existing path or explicitly accepting the change with targeted Windows and error-parity evidence.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth Production +286/-153 (net +133); tests +408/-34 (net +374) Production growth supports the stated cross-backend authority fence and shared bounded writer, with larger regression coverage.
Prior findings resolved 2 of 2 Current fault injections now intercept the filesystem APIs used by the implementation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #251
Summary: This PR is an implementation candidate for the linked publication-assertion request and extends the proposed contract to additional Root mutations.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Keep legacy removal for existing callers (recommended)
    Retain the existing no-callback path and validate permitted and refused operations through the opt-in dispatch fence.
  2. Accept the new removal semantics
    Approve unconditional unlink only with focused Windows and removal-error evidence supporting the intended compatibility contract.

Technical review

Best possible solution:

Provide the documented Root dispatch fence while preserving omitted-callback removal behavior, unless owners explicitly accept a compatibility change backed by targeted Windows and error-parity evidence.

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

Not applicable as an existing-contract bug: this adds a new authority guarantee. The supplied real-filesystem transcript demonstrates allowed operations and refusal after owner reassignment.

Is this the best way to solve the issue?

Mostly yes: composed synchronous checks at actual submissions preserve Root’s existing safety machinery. Unconditionally changing omitted-callback removal remains broader than necessary.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded new filesystem capability with demonstrated utility, rather than an established emergency regression.
  • merge-risk: 🚨 compatibility: The unconditional rm-to-unlink change affects existing callers’ removal recovery and error behavior without an explicit compatibility decision.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured built-package consumer transcript exercises Root writes, removal, and append against real files: allowed operations succeed, reassigned-owner removal preserves its target, and revoked append authority prevents later chunks. The latest commit changes only tests, preserving that production evidence.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured built-package consumer transcript exercises Root writes, removal, and append against real files: allowed operations succeed, reassigned-owner removal preserves its target, and revoked append authority prevents later chunks. The latest commit changes only tests, preserving that production evidence.

Evidence

What I checked:

  • Applicable repository policy: Read the full root AGENTS.md and CONTRIBUTING.md; no nested AGENTS.md or maintainer-notes directory was found. Compatibility surfaces and filesystem boundaries informed the review. No target-bundled reviewer, build, or artifact-producing tests were run. (AGENTS.md:1, cd3a12d232f6)
  • Still needed on main and in the latest release: Pinned main lacks the Root assertion option and still removes files through fs.rm. The v0.9.0 Root option declarations also lack the callback. Existing standalone move assertions and atomic-write callbacks do not supply the complete Root contract. (src/root-impl.ts:100, 0fc5776a510d)
  • Prior findings resolved: The delta from the previously reviewed head retargets write failure/visibility observations to FileHandle.write or fs.write and moves the post-removal race injection to unlink. Production source is unchanged since that review. The supplied current-head Linux/macOS checks pass; Windows checks were pending in the captured context. (test/root-post-mutation-guard.test.ts:33, cd3a12d232f6)
  • Authority dispatch and real behavior proof: The captured PR body reports a standalone built-package consumer using real filesystem operations and async-hooks observation: an exact 1 MiB write succeeds, reassigned-owner removal preserves its target, permitted removal completes without deferred preparation, and reassignment after the first append submission stops later chunks at 524288 bytes. These observations exercise the Root removal and shared bounded-write owners; the latest commit changes tests only. (src/write-file-handle.ts:14, cd3a12d232f6)
  • Removal changes existing callers too: File removal unconditionally uses unlink, including when assertBeforeMutation is omitted. This is an introduced production change, rather than base drift, and the added dispatch tests do not establish full Windows recovery/error parity. (src/root-impl.ts:1360, cd3a12d232f6)
  • Affirmative runtime dependency and removal semantics: The patch directly invokes Node filesystem APIs and the PR explicitly relies on their dispatch behavior. Node v22.0.0 rimraf absorbs ENOENT during removal and includes Windows EPERM chmod/stat/unlink recovery, which direct unlink bypasses. (lib/internal/fs/rimraf.js, 12fb157f79da)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Establish Windows removal recovery and concurrent-disappearance behavior for omitted callbacks and the approved authority-enabled path.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-13T00:58:34.462Z sha e3240f4 :: needs real behavior proof before merge. :: [P1] [P1] Fence removal after Node's asynchronous preparation | [P1] [P1] Recheck authority before each buffered content-write submission
  • reviewed 2026-09-13T01:03:13.193Z sha e3240f4 :: needs real behavior proof before merge. :: [P1] [P1] Fence removal after Node's asynchronous preparation | [P1] [P1] Recheck authority before each buffered content-write submission
  • reviewed 2026-09-13T01:41:44.982Z sha 3f8bf55 :: needs real behavior proof before merge. :: [P2] [P2] Retarget write fault injections to the new submission APIs | [P2] [P2] Move the post-removal race injection to unlink
  • reviewed 2026-09-13T01:50:26.032Z sha 7a670a5 :: blocked before merge. :: [P2] [P2] Retarget write fault injections to the new submission APIs | [P2] [P2] Move the post-removal race injection to unlink

@steipete
steipete marked this pull request as ready for review September 13, 2026 01:00
@steipete
steipete requested a review from a team as a code owner September 13, 2026 01:00
@steipete
steipete force-pushed the codex/fs-safe-audit-api branch from e3240f4 to 3f8bf55 Compare September 13, 2026 01:37
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. label Sep 13, 2026
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Sep 13, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
@steipete
steipete merged commit 7274d7e into main Sep 13, 2026
44 of 45 checks passed
@steipete
steipete deleted the codex/fs-safe-audit-api branch September 13, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add a synchronous pre-publication assertion to Root writes

1 participant