Skip to content

perf(copy): reuse guarded directory admission within batches - #849

Merged
steipete merged 3 commits into
mainfrom
perf/batched-root-copy-validation
Oct 8, 2026
Merged

steipete merged 3 commits into
mainfrom
perf/batched-root-copy-validation

Conversation

@steipete

@steipete steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Copying thousands of files repeatedly resolves the same filesystem roots and ancestor paths; this dominates plugin source captures in OpenClaw Doctor (openclaw/openclaw#166526).

User Impact

createRootFileCopyBatchSync() on advanced exposes a disposable batch whose copyFile() accepts the existing guarded-copy options and returns the same owned descriptor. Canonical POSIX copies reuse directory admissions across files; ordinary copyRootFileSync also reuses admission within its operation. Windows and noncanonical spellings retain their existing resolver. No version change or publication is included.

Why This Change Was Made

The cache retains exact directory identities for one explicit operation and checks every retained ancestor before use, including symlink replacements pointing back to the original tree. It binds the initially admitted leaf parent before caching. Each file still goes through the existing no-follow source-open, root/fd/path identity checks, hardlink policy, exclusive destination creation, native dirfd transfer or bounded byte copy, permissions, and identity-checked cleanup. There is no policy-relaxation option, process-wide cache, or file-admission cache. Earlier successful copies remain caller-owned if a later file fails.

Evidence

  • pnpm check: 696 test files / 17,308 tests passed; 36 files / 787 platform-specific tests skipped. Docs, build, archive allocator, package/declaration/import checks passed; git diff --check clean.
  • Existing copy tests now exercise both APIs. Added warm-cache root/ancestor/leaf replacements, symlink-back-to-original races, unchanged leaf-parent identity, hardlinks, byte limits, pinned source expectations, collisions, raw traversal, and native/portable mid-copy races. Removing the initial-parent comparison makes both new parent-swap regression tests fail.
  • Independent Codex review at P2: fixed the initial leaf-parent capture race. A remaining report about real-directory replacement before the first ancestor identity observation was checked against stock 0.24.2: both accept the same confined path with its original leaf parent and file intact. This retains the existing initial-admission contract; subsequent replacement of a recorded ancestor rejects.
  • Callable benchmark audit passed for all four batch methods. The included 3,000-file benchmark checks all output bytes outside its timed loop, rotates order across three rounds, and cleans descriptors and fixtures.
  • macOS arm64 / Node 26.10.0 / native off, 3,000 × 1 KiB: stock 0.24.2 median 5.119 s (1,706 µs/file); candidate single 4.751 s (1,584 µs/file); batch 4.373 s (1,458 µs/file). Shared-host load varied substantially: batch samples 1.928–4.402 s; stock 5.067–6.506 s. These are copy benchmarks, not a Doctor budget pass.

OpenClaw consumption and end-to-end Doctor timing are a separate proof-only worktree, with no OpenClaw commit. A dependency release and caller adoption are needed for the explicit batch API; the Doctor issue should remain open until that result is established.

  • 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

Add explicit operation-scoped batch custody for canonical POSIX directory identities while preserving fresh file admission, exclusive creation, descriptor checks, and cleanup. Recheck every retained ancestor and bind initial leaf-parent receipts before caching. Windows and noncanonical spellings retain their existing resolver.

Related: openclaw/openclaw#166526. Adds source/destination ancestor-swap regressions and a 3000-file comparison benchmark; no release or version change.
@steipete
steipete requested a review from a team as a code owner October 7, 2026 23:20
@clawsweeper

clawsweeper Bot commented Oct 7, 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. 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. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 8:31 PM ET / October 8, 2026, 00:31 UTC (Revision 3).

ClawSweeper review

What this changes

Adds disposable synchronous file-copy batches that reuse checked directory identities while preserving per-file validation, with documentation, regression coverage, and comparison benchmarks.

Merge readiness

✅ Ready for maintainer review

Keep open: current main lacks the batch API, and the branch retains useful, distinct work. This Codex review found no blocking correctness or security defect.

Priority: P2
Reviewed head: ca14aeefb5306b75e182c6952b27d30fb30bf3f2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, compatible implementation with real filesystem measurements, broad regression coverage, and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured macOS filesystem benchmark exercises production single-copy and batch entrypoints on 3,000 files, verifies all resulting bytes, and reports improved batch timing; race tests supplement that evidence. It establishes copy behavior and performance, without claiming downstream Doctor completion. No stored-data contract changes apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured macOS filesystem benchmark exercises production single-copy and batch entrypoints on 3,000 files, verifies all resulting bytes, and reports improved batch timing; race tests supplement that evidence. It establishes copy behavior and performance, without claiming downstream Doctor completion. No stored-data contract changes apply.
Evidence reviewed 7 items Repository policy applied: Read the complete root AGENTS.md and CONTRIBUTING.md. Applied filesystem-boundary, compatibility, focused regression coverage, and public export/documentation guidance. No nested AGENTS.md or maintainer notes were found. Tests and build commands were not executed under the read-only review contract.
Pinned introduction and continued necessity: Inspected all introduced files against the pinned main revision. Main exports only the single-file helper and contains its uncached admission implementation; the batch and cache remain distinct branch work. The verified test-merge commit records main followed by the exact PR head as parents. The latest published release is v0.24.2; no merged fixing PR establishes that this request is already implemented.
Cache custody and fresh validation: The canonical POSIX fast path checks exact root and ancestor identities on every use and compares the first admitted leaf-parent identity before caching. Windows, noncanonical spellings, and raw traversal retain the existing resolver. Copying still opens and validates each source, creates destinations exclusively, verifies descriptor/path identities around transfer, and performs identity-checked cleanup. Retained directory metadata does not bypass these checks.
Findings None None.
Security None None.

How this fits together

fs-safe’s guarded copy helpers accept source and destination paths within filesystem roots and return an owned destination descriptor. Directory admission protects path boundaries before the existing file-opening, transfer, and cleanup checks run.

flowchart TD
  A[Source and destination paths] --> B[Single copy or disposable batch]
  B --> C[Directory admission cache]
  C --> D[Recheck roots and ancestors]
  D --> E[Fresh source and destination checks]
  E --> F[Native transfer or bounded byte copy]
  F --> G[Verify identities and return owned descriptor]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth production +113 net lines; tests +193 net lines Production growth implements explicit batch custody and identity revalidation, supported by expanded copy regression coverage.

Technical review

Best possible solution:

Provide operation-scoped directory reuse while retaining fresh per-file admission, explicit disposal, and the existing platform fallbacks.

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

Not applicable as a bug reproduction: the captured body supplies a concrete filesystem benchmark for the performance improvement, and the benchmark implementation was inspected.

Is this the best way to solve the issue?

Yes. Explicit disposable batches bound cache lifetime, preserve the existing single-file API, and retain fresh identity checks instead of introducing a global cache or weaker policy.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded copy-performance improvement with measured filesystem results and no demonstrated urgent 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 (live_output): The captured macOS filesystem benchmark exercises production single-copy and batch entrypoints on 3,000 files, verifies all resulting bytes, and reports improved batch timing; race tests supplement that evidence. It establishes copy behavior and performance, without claiming downstream Doctor completion. No stored-data contract changes apply.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured macOS filesystem benchmark exercises production single-copy and batch entrypoints on 3,000 files, verifies all resulting bytes, and reports improved batch timing; race tests supplement that evidence. It establishes copy behavior and performance, without claiming downstream Doctor completion. No stored-data contract changes apply.

Evidence

What I checked:

  • Repository policy applied: Read the complete root AGENTS.md and CONTRIBUTING.md. Applied filesystem-boundary, compatibility, focused regression coverage, and public export/documentation guidance. No nested AGENTS.md or maintainer notes were found. Tests and build commands were not executed under the read-only review contract. (AGENTS.md:23, ca14aeefb530)
  • Pinned introduction and continued necessity: Inspected all introduced files against the pinned main revision. Main exports only the single-file helper and contains its uncached admission implementation; the batch and cache remain distinct branch work. The verified test-merge commit records main followed by the exact PR head as parents. The latest published release is v0.24.2; no merged fixing PR establishes that this request is already implemented. (src/advanced.ts:1, ca14aeefb530)
  • Cache custody and fresh validation: The canonical POSIX fast path checks exact root and ancestor identities on every use and compares the first admitted leaf-parent identity before caching. Windows, noncanonical spellings, and raw traversal retain the existing resolver. Copying still opens and validates each source, creates destinations exclusively, verifies descriptor/path identities around transfer, and performs identity-checked cleanup. Retained directory metadata does not bypass these checks. (src/copy-path-admission.ts:55, ca14aeefb530)
  • Regression coverage and review continuity: Read the new batch tests and complete existing synchronous-copy tests, now exercised through both APIs. Coverage includes root/ancestor replacement, symlink-back replacement, initial parent capture, pinned source identity, hardlinks, collisions, limits, native/portable transfer races, and descriptor ownership. Production cache and copy files have no differences from the previous reviewed head; the supplied prior review has no retained findings or published rank-up moves. (test/copy-root-file-batch-sync.test.ts:158, ca14aeefb530)
  • Real filesystem benchmark evidence: The captured PR body reports macOS arm64, Node 26.10.0, native-disabled runs copying 3,000 one-KiB files: stock median 5.119 seconds, candidate single 4.751 seconds, and batch 4.373 seconds. The inspected benchmark calls the production advanced APIs, rotates execution order, checks every output’s bytes outside timing, and closes descriptors. Shared-host variance limits performance precision; the body expressly does not claim an end-to-end Doctor budget pass. No stored-data format, migration, or persisted setting changes are introduced. (benchmarks/root-file-copy-batch.mjs:35, ca14aeefb530)
  • Merged feature-history routing: Git history identifies the synchronous-copy introduction and subsequent expected-source-identity work. GitHub independently verifies steipete as author of both merged PRs: feat(copy): add a synchronous guarded clone-capable file copy #839 and feat(copy): bind copyRootFileSync to an expected source identity #841. Historical local blame/show inspection encountered unavailable promisor objects; GitHub commit patches supplied the relevant history instead. No source-line introduction pointer is asserted. (src/copy-root-file-sync.ts, 3bdcb003d6a1)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-10-07T23:23:27.976Z sha 036be37 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T23:46:43.151Z sha b4d2404 :: needs maintainer review before merge. :: none

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