Skip to content

perf: observe metadata synchronously in archive, copy, publish, and move paths - #248

Merged
steipete merged 2 commits into
mainfrom
perf/sync-observations-2
Sep 9, 2026
Merged

steipete merged 2 commits into
mainfrom
perf/sync-observations-2

Conversation

@steipete

@steipete steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Complete the synchronous-observation rule introduced in PR #238. Archive extraction, copy, publication, move, and directory-mode paths now use synchronous Node metadata observations, preserving native realpath spelling. This removes metadata work from the libuv queue while retaining asynchronous data and structural I/O.

Every existing containment, identity, hardlink, symlink, permission, ownership, deadline, and publication check remains in order. Error codes and application error messages are unchanged. Awaited production test hooks remain in place; no fsync, open, read, write, rename, mkdir, unlink, or close operation was converted or removed.

Scope and exceptions

The source-wide audit also covers sibling staging, temporary workspace cleanup, hashing, secret and secure reads, install paths, walking, lock acquisition/reclamation, queue ownership, and guarded move receipts. Custom filesystem adapters retain their asynchronous metadata contract; the real Node branch uses synchronous observations. Root capability stat calls retain their public async signatures and already use synchronous metadata internally. Linux procfs statfs authentication retains its existing awaited authority-lifetime checks. The default branch in replace-file-descriptor was already synchronous on the baseline and needed no edit.

CHANGELOG.md has one Unreleased entry, and docs/reading.md documents the expanded rule. No generated dist artifacts are committed.

20-file extraction budgets

The fixture contains 20 files in three directories. Counters include all fs/promises functions, async FileHandle methods, and FileHandle.close own properties. Both native auto and off run against the prepared native binding. The tests require zero async lstat, stat, realpath, and FileHandle.stat observations, and pin total async calls to the measured value plus 10 percent. Total filesystem calls are unchanged between baseline and this branch with the same instrumentation.

Backend / format / durability: async calls before to after; reduction

  • auto / TAR / default: 619 to 268; 56.7 percent
  • auto / TAR / false: 507 to 196; 61.3 percent
  • auto / ZIP / default: 619 to 268; 56.7 percent
  • auto / ZIP / false: 507 to 196; 61.3 percent
  • off / TAR / default: 873 to 455; 47.9 percent
  • off / TAR / false: 761 to 383; 49.7 percent
  • off / ZIP / default: 1308 to 530; 59.5 percent
  • off / ZIP / false: 1196 to 458; 61.7 percent

The 80 percent total-async-call reduction target was not reached. All targeted async metadata calls are gone; the remaining calls perform data or structural I/O. For default durable TAR, auto retains 73 opens, 93 close calls, 42 reads, 24 syncs, 23 mkdirs, and 13 other async calls. Off retains 94 opens, 114 close calls, 44 reads, 41 writes, 24 syncs, 66 mkdirs, 43 handle chmods, 20 renames, and nine other async calls.

Supplied 500-file benchmarks

Baseline: origin/main at 651df2e, built in a detached scratch worktree with the same dependencies, prepared WASM, and native artifact. Node 26.8.1, pnpm 11.25.0, macOS arm64. The supplied awaittime and arch harnesses were run in both native modes. The TAR fixture includes AppleDouble entries; the default durability pass still makes 1,023 sync calls. These are single paired runs, not statistical confidence estimates. The final branch measurements ran after the test and packaging jobs finished.

awaittime TAR wall time, milliseconds before to after:

  • auto / default: 3109 to 2374; 23.6 percent faster
  • auto / durable:false: 2517 to 1916; 23.9 percent faster
  • off / default: 4050 to 2458; 39.3 percent faster
  • off / durable:false: 3436 to 1953; 43.2 percent faster

arch warmed extraction, milliseconds per operation before to after:

  • auto / TAR: 2733 to 1871; 31.5 percent faster
  • auto / TGZ: 2776 to 1712; 38.3 percent faster
  • auto / ZIP: 1586 to 921; 41.9 percent faster
  • off / TAR: 3204 to 2308; 28.0 percent faster
  • off / TGZ: 3063 to 2529; 17.4 percent faster
  • off / ZIP: 1979 to 1416; 28.4 percent faster

The 30 percent wall-time target was met for the profiled off-mode default and durable:false runs and the warmed auto runs. It was missed for the profiled auto runs and warmed off runs. Remaining default-TAR costs include 53,136 native realpath observations in auto and 86,546 in off, taking 578 and 826 ms respectively; opens take 271 and 515 ms. The 1,023 sync calls accumulate 729 and 1462 ms of wait time respectively. Attribution overlaps during the bounded durability batches and must not be summed as exclusive wall time. No checks or durability calls were removed to chase the target.

Validation

  • pnpm exec tsc --pretty false: passed.
  • pnpm lint:file-size, pnpm lint:fs-boundary, pnpm docs:check, node scripts/check-pack.mjs, git diff --check: passed.
  • pnpm test:security: 226 passed across five files.
  • pnpm test --maxWorkers=1: 8449 passed, 87 skipped, three known local failures; 237 files passed, five skipped, two failed. All re-pointed tests and all eight archive budget cases passed.
  • Two failures are in consumer-pnpm-lifecycle.test.ts because the local pnpm executable does not expose the required lifecycle JavaScript CLI.
  • The third is the known private-store overlapping-read race in store-stress.test.ts, rejecting with path-mismatch. Its first isolated rerun also reported seven passed and that one failure. Baseline isolation passed all eight. No store-stress assertion or identity check was changed.
  • pnpm check reached the known missing wasm32-unknown-unknown Rust target failure. The prepared WASM was restored and the remaining component proofs were run separately. An earlier file-size check caught the added import taking move-path-regression.test.ts one line over budget; formatting the existing assertion fixed it without changing its meaning.
  • Independent Codex autoreview: scoped-clean through P2; no accepted or actionable findings.
  • Final isolated store-stress rerun: all eight tests passed. The initial full-run and first-isolation failures remain reported above; no tests were weakened.

Security-suite coordinator exception

The only security-suite edit is test/additional-boundary-bypass.test.ts, "captures exact directory identities for temp file cleanup": change the spy from fsp.lstat to fs.lstatSync. Both toHaveBeenCalledWith(target.dir, { bigint: true }) assertions and the intervening mockClear are byte-for-byte unchanged. The initial security run stopped on that mechanism-spy failure; the coordinator explicitly authorized this one-line change, after which all 226 security tests passed. No other security-suite test needed an exception.

Re-pointed tests and shared fixtures

All scenarios and parameterized cases are retained. Synthetic filesystem swaps inside synchronous spies use synchronous fixture operations at the same observation point.

  • test/archive-adjacent-errors.test.ts: archive identity changes after open.
  • test/archive.test.ts: archive input pinning before extraction, and the realpath rebind fixture used by the out-of-destination clobber regression.
  • test/atomic-publication-stress.test.ts: failed sibling output remains registered when immediate cleanup fails; the fstat assertion additionally identifies the descriptor argument.
  • test/clawpatch-regression.test.ts: destination swapped before realpath settles, and destination swapped only during realpath.
  • test/directory-mode-proc.test.ts: the shared simulated proc-fd stat route and exact followed-fd identity rejection. Existing timeout and descriptor-lifetime barriers remain on statfs/chmod.
  • test/file-hash.test.ts: caller-owned handle remains open with its offset unchanged on failure; real retained replacements before and after open, including high-bigint identities.
  • test/helpers/file-hash-identity.ts: the complete file-hash-identity.test.ts preview, descriptor, current-path, retry, failure, and native-dispatch matrices.
  • test/helpers/queue-read-identity.ts: the complete json-durable-queue-identity.test.ts preview, descriptor, current-path, retry, symlink, and size-admission matrices.
  • test/json-durable-queue-batch-durability.test.ts: post-link path-mismatch propagation; unverifiable initial pending identity; post-claim read-identity failure preserves owned state.
  • test/json-durable-queue-failure.test.ts: inspection errors are not missing files; stale-temp inspection errors propagate.
  • test/move-path-mutation-receipt.test.ts: exact bigint rename-source receipt; source cleanup stops after authority revocation during the metadata observation. The scenario label now says stat observation.
  • test/move-path-regression.test.ts: late hardlink with and without caller-option mutation; source swapped after validation cannot commit bytes.
  • test/opened-file-change.test.ts: distinct pre-open generation receipts; all non-authorizing evidence cases; receipts do not carry into a later observation.
  • test/permission-secret-stress.test.ts: concurrent size increase remains too-large in both readers.
  • test/secret-directory-admission.test.ts: both writers reject changed descriptor ownership before initialization.
  • test/secret-file-failure.test.ts: secret path retargeted after preview in sync and async readers.
  • test/secret-read-identity.test.ts: ordered preview/descriptor/target/input observations for both symlink policies; replacement between preview and realpath resolution.
  • test/secure-file-failure.test.ts: permission inspection failure; non-file descriptor; mismatched realpath identity; unexpected descriptor uid.
  • test/secure-file-identity.test.ts: realpath replacement; numeric public Stats receipt; rounded identity collisions; persistent unknown identity; Windows transient-identity retry.
  • test/sibling-temp-durability.test.ts: replacement appears after cleanup starts.
  • test/sibling-temp-platform.test.ts: known, transient-unknown, unknown, and rounded-replacement Windows identity cases.
  • test/sidecar-lock-acquire-failure.test.ts: resolved-target fallback after parent realpath failure.
  • test/sidecar-lock-helpers-failure.test.ts: reclaim-guard inspection failures; non-file opened snapshot with both rejection policies.
  • test/sidecar-lock-ownership-token.test.ts: release when descriptor/pathname identity drifts.
  • test/sidecar-lock-root-admission.test.ts: creator cleanup retains its token when a later stat fails over a replacement. The injection is armed after payload admission so bounded-read size hints do not consume the fault; all original assertions remain.
  • test/sidecar-lock-root-resolver.test.ts: Windows resolver failures with numeric, unknown, and changed descriptor evidence.
  • test/archive-fsync-budget.test.ts and test/helpers/archive-fs-counts.ts: the existing TAR/ZIP, auto/off, default/false matrix now pins async and total calls and rejects async metadata observations.

The read-admission helper already intercepted both synchronous and asynchronous observations from PR #238; its read and archive-input identity matrices pass without changing the helper or dropping any cases.

@steipete
steipete requested a review from a team as a code owner September 9, 2026 14:44
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. 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. labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 11:04 AM ET / 15:04 UTC (Revision 2).

ClawSweeper review

What this changes

Moves metadata checks to synchronous Node calls across archive, copy, publication, move, and supporting filesystem operations, and updates their tests and hash diagnostic.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful and is not implemented on current main. The new commit resolves the earlier hash-proof finding; no additional actionable defects were found.

Priority: P2
Reviewed head: a3fb53d9cfdcd9687bc80c497204c7539a32025f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent optimization with real extraction measurements, preserved safety coverage, and the previous diagnostic blocker resolved.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured macOS benchmark output exercises real archive extraction through the changed production paths in native auto/off modes and records improved after-change timings. The repaired Windows hash diagnostic retains stable-file and pre-read replacement rejection checks, with both pinned-head jobs successful; raw job receipts could not be independently opened.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured macOS benchmark output exercises real archive extraction through the changed production paths in native auto/off modes and records improved after-change timings. The repaired Windows hash diagnostic retains stable-file and pre-read replacement rejection checks, with both pinned-head jobs successful; raw job receipts could not be independently opened.
Evidence reviewed 10 items Repository policy: Read the complete root AGENTS.md and contribution guide. No nested AGENTS.md files or maintainer-notes directory were found. Applied filesystem-boundary, compatibility, and changelog guidance; no builds, tests, or bundled review helpers were executed.
Current main still needs this optimization: GitHub still reports main at the supplied base SHA. Its archive input staging uses asynchronous pathname and descriptor metadata observations, so the central change is not already present.
Release and related implementation boundary: The supplied latest release, v0.8.6, also retains asynchronous hash metadata checks. GitHub confirms #238 merged; that earlier optimization covers adjacent hot paths rather than replacing this remaining work.
Findings None None.
Security None None.

How this fits together

fs-safe validates untrusted paths and retained file identities before applications read, publish, move, or remove files. This change alters how metadata is observed while preserving the surrounding asynchronous data transfers and filesystem mutations.

flowchart TD
  A[Paths and archive inputs] --> B[Metadata observations]
  B --> C{Identity and containment valid?}
  C -->|No| D[Reject operation]
  C -->|Yes| E[Asynchronous data and mutation operations]
  E --> F[Post-operation verification]
  F --> G[Result or safety error]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta Production +235/-187 (net +48); tests +250/-228 (net +22) Growth primarily supports synchronous observations and preserved adapter/error handling, with corresponding observer updates.
Extraction coverage 8 format/backend/durability cases The retained matrix checks output bytes, durability counts, total calls, and absence of asynchronous metadata observations.

Technical review

Best possible solution:

Keep the established synchronous-observation pattern consistent across Node paths while retaining adapter compatibility, asynchronous mutations, and independent safety checks.

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

Not applicable as a bug reproduction: this is an optimization supported by paired real extraction measurements; the earlier diagnostic defect is corrected in source.

Is this the best way to solve the issue?

Yes. The patch extends the already-merged observation pattern without removing safety checks or introducing a competing API, and preserves custom adapters' asynchronous contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured macOS benchmark output exercises real archive extraction through the changed production paths in native auto/off modes and records improved after-change timings. The repaired Windows hash diagnostic retains stable-file and pre-read replacement rejection checks, with both pinned-head jobs successful; raw job receipts could not be independently opened.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This is a measured filesystem performance improvement without an established urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured macOS benchmark output exercises real archive extraction through the changed production paths in native auto/off modes and records improved after-change timings. The repaired Windows hash diagnostic retains stable-file and pre-read replacement rejection checks, with both pinned-head jobs successful; raw job receipts could not be independently opened.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured macOS benchmark output exercises real archive extraction through the changed production paths in native auto/off modes and records improved after-change timings. The repaired Windows hash diagnostic retains stable-file and pre-read replacement rejection checks, with both pinned-head jobs successful; raw job receipts could not be independently opened.

Evidence

What I checked:

  • Repository policy: Read the complete root AGENTS.md and contribution guide. No nested AGENTS.md files or maintainer-notes directory were found. Applied filesystem-boundary, compatibility, and changelog guidance; no builds, tests, or bundled review helpers were executed. (AGENTS.md:1, a3fb53d9cfdc)
  • Current main still needs this optimization: GitHub still reports main at the supplied base SHA. Its archive input staging uses asynchronous pathname and descriptor metadata observations, so the central change is not already present. (src/archive-input.ts:51, 651df2e7b4fa)
  • Release and related implementation boundary: The supplied latest release, v0.8.6, also retains asynchronous hash metadata checks. GitHub confirms perf: make metadata observations synchronous inside async hot paths #238 merged; that earlier optimization covers adjacent hot paths rather than replacing this remaining work. (src/file-hash.ts:20, 733bc50c81b9)
  • Earlier finding resolved: The new commit changes only the diagnostic and changelog. Candidate observations now intercept lstatSync and fstatSync, retain asynchronous baseline observers, record preview completion, and preserve rejection-before-read and stable-digest assertions. (scripts/hash-identity-proof.mjs:290, a3fb53d9cfdc)
  • Windows diagnostic validation: Both Windows Node 22.23.2 and 24.20.0 hash-proof checks succeeded on the pinned head. The inspected driver runs real stable and replacement scenarios against the compiled package. Raw log inspection was blocked by the artifact storage domain allowlist; no claim of independently reading those receipts is made. (.github/workflows/hash-identity-proof.yml, a3fb53d9cfdc)
  • Captured real extraction measurements: The supplied PR-body snapshot, sourceRevision bd537404c762cb812c728fac1b46db48a0a9e73f16bd81985b5a357d9a58bfd9, reports paired 500-file extraction runs on macOS arm64 with Node 26.8.1, matching dependencies and prepared native/WASM artifacts. TAR profiling improved 23.6–43.2%; warmed TAR/TGZ/ZIP runs improved 17.4–41.9%. These exercise the changed archive production path in native auto/off modes; the author explicitly limits them to single paired measurements. (e308ab260d8f)

Likely related people:

  • Peter Steinberger: Raw commit 1811443 adds src/archive-durability.ts:48 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 18114434aced; files: src/archive-durability.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 (1 earlier review cycle)
  • reviewed 2026-09-09T14:49:28.664Z sha e308ab2 :: blocked before merge. :: [P2] [P2] Update the Windows hash-proof observers with the production calls

@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. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. labels Sep 9, 2026
@steipete
steipete merged commit 686c193 into main Sep 9, 2026
30 checks passed
@steipete
steipete deleted the perf/sync-observations-2 branch September 9, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant