Skip to content

refactor(atomic): share sync and async resource ownership - #772

Merged
steipete merged 9 commits into
mainfrom
codex/atomic-io-owner-954
Oct 1, 2026
Merged

steipete merged 9 commits into
mainfrom
codex/atomic-io-owner-954

Conversation

@steipete

@steipete steipete commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Synchronous and asynchronous atomic writes maintained separate staging, retry, copy, restoration, and cleanup procedures. This change gives them a shared internal I/O adapter and temporary-file owner while preserving the public entry points and filesystem guards. FileStore writes, JSON directory synchronization, sibling temporary files, and temporary case probing reuse those procedures.

The complete candidate removes 501 production lines under the unchanged whole-project counter: 56,952 → 56,451. All adapters and callers are counted. Cleanup registration now receives removal authority from an admitted identity or retained-owner callback, avoiding a lookup of the not-yet-created temporary path. Public APIs and migration requirements are unchanged.

Candidate 9d1a45da removes forwarding generators around metadata inspection and chunk I/O. Synchronous calls consume ordinary values; asynchronous calls retain their await boundaries. Exact identity checks, forced-synchronous builtin admission, mutation authority, restoration, and cleanup/error precedence remain in place. Three public adapter regressions exercise real FileHandles and preserve short-write offsets, the two positive write-result observations, zero-progress rejection after one observation, and one read-result observation per bounded snapshot chunk.

Performance hold: lifted by the coordinator. The independent adversarial review found no demonstrated runtime defect and no meaningful hot-path slowdown. The approximately 4–5% measured costs are confined to opt-in copy/restore fallback after rename fails with EPERM/EEXIST, with small absolute costs on synchronization-bound operations. The coordinator accepts this tradeoff for the 501-line production consolidation; the old fixed 5% fallback criterion no longer blocks landing. Historical measurements follow unchanged.

The preceding 1979deb2 candidate passed its fixed 128-workload Linux Node 24/native-off exploratory screen's correctness checks, but did not establish the final 5% non-regression requirement. Guarded no-restore sync fallback was +5.342% (+14.801 µs), sync short-write fallback +3.946%, and async short-write fallback +5.350% (+114.312 µs), with upward control drift in the last case. Several ordinary sync paths improved, but those results do not offset slower endpoints. All samples and earlier experiments are retained separately, without pooling.

Validation for 9d1a45da:

  • Managed P2 reviews of the production change and test split are scoped-clean. The first F revision passed its build and focused tests, then hit the repository's 500-line test-file limit. Moving the three new cases into a 195-line file fixed that gate without changing production code or assertions; the failed attempt remains preserved.
  • The dedicated Linux Node 24 runner fetched the published commit and built it afresh. All 44 focused files passed: 1,100 tests passed and four skips. The uninterrupted full pnpm check, including its package tail, passed 16,785 tests with 691 skips.
  • Package smoke and all 35 installed public scenarios passed with zero skips, including strict public types, actual required-native loading, and fixture cleanup. All 577 compiled package files match the fresh build; all 640 installed package files match the qualified tarball. The native binary was reused after 96 source inputs matched; WASM was freshly rebuilt.
  • Current-head CI, coverage, mutation, and Node 22 benchmarks passed on attempt 1. All nine full checks, nine native lanes, and six consumer-package jobs passed. Every full check and Windows coverage ran the three new getter cases and the retained 5/4/3/12/8 void/receipt/metadata/process/boundary cases, with zero skips in those files. CodeQL and method audits were skipped. Full checks used integration tree d1549ea9, which adds only main's separate watch fix; target atomic files are unchanged. The dedicated proof above and head-pinned package receipts separately attest frozen F2/tree e55b6e10.

Historical status before the coordinator decision: the new A/F performance comparison was being prepared with the same fixed 128-workload design on a replacement 16-CPU runner. No F performance result is claimed yet.

A separate six-call A/D syscall diagnostic confirmed that the earlier cleanup change removes one missing-temp lookup while preserving the remaining observed filesystem sequence, including file fsync → rename → directory fsync. It is diagnostic evidence, not latency qualification for the latest candidate.

The landing gates are final rebased-head cross-platform correctness/package qualification, coverage, mutation, independent P0–P2 review, and CodeQL; their completed results are recorded below. The coordinator has lifted the additional performance hold as explained above.

Intentional reviewed differences: internal registerTempPathForExit now requires an admitted identity or retained-owner callback rather than adopting an entry by name; all production callers already supply one. Injected sync fchmodSync is invoked unbound instead of receiving undocumented internal parameter objects as this. Microtask scheduling differs, but the final authority assertion still directly precedes every mutation without yielding. Public API signatures remain unchanged.

First rebased candidate be3e9ab3 (onto main 851bd85a): all eight commits retained. Range comparison confirms source and test patches are unchanged; the only integration edit moves the cleanup note to Unreleased → Performance and adds the PR link. Released 0.21.3 and 0.22.0 sections are untouched.

Local qualification: frozen install passed. Build passed with the installed Rust compiler explicitly selected after the default compiler lacked its WASM target. Focused atomic/FileStore/JSON/copy/sibling/case/cleanup/settlement tests passed: 79 files, 1,744 tests, 57 platform skips. Full pnpm check passed lint, boundary, build, allocator-artifact build and documentation checks, then finished with 13,145 passing tests and one five-second ZIP extraction timeout under heavy host contention. The complete archive file passed all 17 tests at its unchanged timeout on isolated retry. The package-check tail passed separately. git diff --check and the 500-line test-file gate pass (largest changed test: 474 lines).

Independent managed Codex review of the complete rebased diff and supplied adversarial context is scoped-clean at P0–P2, with no findings. The first rebased head completed CI, coverage, mutation, and an explicitly dispatched CodeQL run successfully. The first automatic CodeQL event was cancelled/skipped during the ready transition.

Latest landing candidate: acc540cd, rebased onto main fce1668b after #770, #769, #760, #765, #782, #781, #783, and #784 landed. All eight original commits are retained, plus the bounded benchmark fixture fix below. The rebases preserve all source/test patches; conflicts were confined to changelog placement. The final UNC-admission integration applied without conflict and retains the new guard before filesystem access. Current Unreleased contains this PR's atomic cleanup note under Performance, alongside #760; released sections remain untouched. Previous heads completed all required hosted gates before subsequent main changes required another rebase.

CI on intermediate head 58c1e9f4 found a pre-existing clock-dependent ZIP benchmark fixture failure in the Windows native lane (run 36793426311). At UTC 00:02:02, the DOS timestamp value 65 completed a false end-of-central-directory record in the dense payload; the parser correctly rejected the resulting ambiguous archive. The fixture and parser were unchanged by the atomic refactor. The benchmark now uses a fixed timestamp, and a regression using the triggering clock fails before the fix and passes afterward. The fixture helper is shared with that regression. No archive admission behavior changed.

The complete latest diff is independently scoped-clean at P0–P2. A fresh Linux runner fetched and verified acc540cd, installed frozen dependencies, built the native binding and WASM from source, and passed uninterrupted pnpm check: 700 files and 17,017 tests passed, with 729 platform skips, including the package-check tail. The same runner passed 1,930 focused tests with 30 platform skips. Final local build, file-size and whitespace gates pass, and the final local focused run passed 1,886 tests with 63 platform skips without retries. Earlier local full-check and focused timeout attempts on superseded heads passed unchanged-file retries; those attempts are not described as uninterrupted passes.

Final-head hosted qualification: CI, coverage, mutation, and CodeQL. All required jobs passed on this exact head: nine Node checks, all nine native lanes, both GNU ABI-floor lanes, six package smoke jobs, workflow lint and Cargo checks, five coverage jobs including merged thresholds, three mutation proof jobs, and both CodeQL analyses. The final head passed on attempt 1. The separate benchmark workflow also passed. Manual-only secure-file jobs were skipped by workflow design. No admin bypass has been used. The superseded c6c06df5 coverage run completed its macOS tests/upload but cancelled Windows with no reported assertion failure (exit 130), then remained stuck in the running state. Normal cancel and force-cancel returned HTTP 409 while rerun returned HTTP 403/already running. A fresh coverage dispatch on that identical head was the first executed retry: run 36805912548; it passed all platform coverage jobs and merged thresholds before #783 required the latest rebase.

@clawsweeper

clawsweeper Bot commented Sep 29, 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: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 11:14 PM ET / October 1, 2026, 03:14 UTC (Revision 28).

ClawSweeper review

What this changes

The branch shares synchronous and asynchronous atomic-write staging, restoration, and cleanup procedures, updates their callers and regression coverage, and fixes clock-dependent ZIP benchmark fixtures.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still has separate atomic-write owners, and the related merged work does not replace this contribution. No actionable introduced defect was found; the recorded performance acceptance still covers this patch.

Likely related people: steipete — recent atomic-area contributor, high confidence.

Priority: P2
Reviewed head: acc540cdc8968f6f27b2afcc92ac0647bbeda8ae

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong real-filesystem qualification and focused adversarial coverage support a clean consolidation with an explicitly accepted performance tradeoff.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The captured installed-package qualification exercises the atomic writer and retained-file ownership on real files, including fallback/restoration and process-exit settlement; its executable blobs match this head. Hosted package results corroborate qualification, though raw job logs were inaccessible. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The captured installed-package qualification exercises the atomic writer and retained-file ownership on real files, including fallback/restoration and process-exit settlement; its executable blobs match this head. Hosted package results corroborate qualification, though raw job logs were inaccessible. No stored-data contract changes.
Evidence reviewed 10 items Repository policy: Read the complete root AGENTS.md. Its filesystem identity, fail-closed cleanup, public-contract, and regression-coverage guidance informed the review. No nested AGENTS.md or maintainer-notes directory was found.
Pinned introduction and continuing usefulness: Inspected the introduced main-to-head hunks and original implementation. Main retains separate synchronous and asynchronous owners; this branch's shared adapter and procedures remain distinct work. The supplied test merge records the exact main and head parents.
Cleanup authority and final effects: Registration no longer obtains removal authority from an arbitrary existing pathname. All production callers supply an identity, later admitted descriptor receipt, or retained-owner cleanup callback. Exit cleanup still checks current identity; publication unregisters the temporary name. Destination writes retain the final authority assertion after asynchronous identity observations.
Findings None None.
Security None None.

How this fits together

fs-safe’s atomic writer receives file content, destination paths, and optional authority checks from applications and higher-level storage helpers. It stages and verifies files before publication, then settles descriptor ownership and temporary-file cleanup.

flowchart TD
  A[Content and destination] --> B[Path and option admission]
  B --> C[Shared atomic writer]
  D[Caller authority checks] --> C
  C --> E[Owned temporary file]
  E --> F[Rename or copy fallback]
  F --> G[Publication verification]
  G --> H[Cleanup and result]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test line delta production +712 −1215 (net −503); tests +1054 −194 (net +860) The introduced diff reduces production duplication while expanding ownership and adapter regression coverage.

Technical review

Best possible solution:

Keep one internal atomic owner for both modes while preserving identity-gated cleanup and the existing public durability, restoration, and authority contracts.

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

Not applicable to the internal consolidation; no introduced bug was established. The ZIP fixture regression supplies a concrete triggering timestamp.

Is this the best way to solve the issue?

Yes: the shared procedures remove parallel ownership implementations without adding public API or configuration surface, and the fixture repair leaves archive admission unchanged.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded improvement to security-sensitive atomic I/O, with no demonstrated urgent regression.
  • merge-risk: 🚨 other: The coordinator explicitly accepted the measured opt-in fallback latency cost; this remains performance context rather than unresolved merge work.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The captured installed-package qualification exercises the atomic writer and retained-file ownership on real files, including fallback/restoration and process-exit settlement; its executable blobs match this head. Hosted package results corroborate qualification, though raw job logs were inaccessible. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured installed-package qualification exercises the atomic writer and retained-file ownership on real files, including fallback/restoration and process-exit settlement; its executable blobs match this head. Hosted package results corroborate qualification, though raw job logs were inaccessible. No stored-data contract changes.

Evidence

What I checked:

  • Repository policy: Read the complete root AGENTS.md. Its filesystem identity, fail-closed cleanup, public-contract, and regression-coverage guidance informed the review. No nested AGENTS.md or maintainer-notes directory was found. (AGENTS.md:1, acc540cdc896)
  • Pinned introduction and continuing usefulness: Inspected the introduced main-to-head hunks and original implementation. Main retains separate synchronous and asynchronous owners; this branch's shared adapter and procedures remain distinct work. The supplied test merge records the exact main and head parents. (src/replace-file-temp-owner.ts:90, acc540cdc896)
  • Cleanup authority and final effects: Registration no longer obtains removal authority from an arbitrary existing pathname. All production callers supply an identity, later admitted descriptor receipt, or retained-owner cleanup callback. Exit cleanup still checks current identity; publication unregisters the temporary name. Destination writes retain the final authority assertion after asynchronous identity observations. (src/temp-cleanup.ts:76, acc540cdc896)
  • Existing public contract: Atomic documentation defines revocable mutation checks, descriptor ownership, restoration, and cleanup/error precedence. Public atomic exports, option types, and package.json have no introduced changes; no serialized format or migration contract changes. (docs/atomic.md:115, acc540cdc896)
  • Re-review continuity: Compared the GitHub tree for the previous reviewed head d5d507a against the checkout's blob identities. All 36 changed non-changelog files are identical; only CHANGELOG.md differs. The previous completed review has no retained findings or published rank-up moves. Direct local comparison was unavailable, so the GitHub tree comparison established continuity. (acc540cdc896)
  • Accepted performance tradeoff: The captured body and refactor(atomic): share sync and async resource ownership #772 (comment) record the coordinator's acceptance of approximately 4–5% costs on opt-in copy/restore fallback after EPERM/EEXIST. The unchanged production blobs preserve that decision's scope; it does not waive independent correctness or security review. (src/replace-file-copy-fallback.ts:189, acc540cdc896)

Likely related people:

  • Peter Steinberger: Raw commit 96239bd adds src/replace-file-mutation.ts:15 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 96239bd478cf; files: src/replace-file-mutation.ts)

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 (27 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-01T00:27:52.450Z sha 5663e8d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T01:08:09.402Z sha 77fb74d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T01:35:13.830Z sha 55986d5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T01:46:59.959Z sha 55986d5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T01:56:58.422Z sha c6c06df :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T02:40:54.310Z sha c6c06df :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T02:50:17.738Z sha d5d507a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T03:04:53.982Z sha d5d507a :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The coordinator has lifted the performance hold for this refactor after the independent adversarial review found no P0/P1 and no demonstrated P2 runtime defect. The measured costs were approximately 4–5% on the opt-in copy/restore fallback paths, reached only after rename fails with EPERM/EEXIST; these are small absolute costs on filesystem synchronization-bound operations. Hot native-on and native-off paths showed no meaningful slowdown. Those fallback costs do not justify blocking the 501-line production consolidation. The historical measurements remain in the PR body; this decision changes the landing criterion, not the data.

Three intentional behavior differences were reviewed:

  1. Internal registerTempPathForExit no longer adopts the identity of whichever entry occupies a pathname. A bare name grants zero removal authority. This is fail-closed hardening of an internal API; every production caller already supplies an admitted identity or retained-owner cleanup callback.
  2. Injected synchronous fchmodSync is called unbound. Previously it received internal parameter objects as this; no documented receiver contract exists.
  3. Microtask scheduling differs. The final authority assertion still directly precedes every mutation without yielding.

All eight commits have been rebased onto main at 851bd85a. The only conflict was CHANGELOG.md; the atomic cleanup note now appears under current Unreleased → Performance, with released 0.21.3 and 0.22.0 sections unchanged. Independent full-diff review and exact-head platform, coverage, mutation, and CodeQL qualification will gate the merge.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 30, 2026
@steipete
steipete force-pushed the codex/atomic-io-owner-954 branch from 9d1a45d to be3e9ab Compare September 30, 2026 23:35
@steipete
steipete marked this pull request as ready for review September 30, 2026 23:35
@steipete
steipete requested a review from a team as a code owner September 30, 2026 23:35
@steipete
steipete force-pushed the codex/atomic-io-owner-954 branch 6 times, most recently from c6c06df to d5d507a Compare October 1, 2026 02:45
@steipete
steipete force-pushed the codex/atomic-io-owner-954 branch from d5d507a to acc540c Compare October 1, 2026 03:08
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: refactor(atomic): share sync and async resource ownership This is item 1/1 in the current shard. Shard 0/1.

This temporary status tracks the active review worker. The completed review will appear in the durable ClawSweeper review comment.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete
steipete merged commit 5d96c7e into main Oct 1, 2026
47 checks passed
@steipete
steipete deleted the codex/atomic-io-owner-954 branch October 1, 2026 03:30
steipete added a commit that referenced this pull request Oct 1, 2026
Drop internal switches, an injected filesystem, and a type re-export that lost their last real use in #772's atomic consolidation; reuse errorCauseOptions and hasNodeErrorCode for exactly equivalent hand-written checks; correct two comments that misdescribed publication visibility and staging cleanup. Branch selection, sync/async boundaries, errors and causes are unchanged; net -12 production lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

1 participant