Skip to content

perf(copy): reduce plugin capture root-resolution overhead - #878

Merged
steipete merged 3 commits into
mainfrom
fix35-copy-canonical-root
Oct 8, 2026
Merged

steipete merged 3 commits into
mainfrom
fix35-copy-canonical-root

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Synchronous plugin captures repeatedly resolve deep absolute roots during each guarded file copy. OpenClaw commit 2c8c66f3fbd switched generation captures to this API. Its retained installed-OTEL trace attributes 20.428 seconds per load to copyRootFileSync, including 14.869 seconds in repeated copy-path assertCurrent work; adjacent full-flow proof went from 119.383 seconds passing to 252.762 seconds exceeding the unchanged 180-second limit.

User Impact

The existing copyRootFileSync API is faster on canonical POSIX paths; consumers need no call-site change for this improvement. The batch API also benefits. This PR builds on the already-merged admission reuse in #849 and separately measures the incremental improvement over the original main baseline.

No version bump, release, OpenClaw dependency change, or OpenClaw E2E result is included. The installed-plugin timeout must be rechecked by the consumer after release; the component benchmark does not establish that its 180-second deadline now passes.

Why This Change Was Made

Initial admission still called the ordinary root resolver repeatedly after capturing and checking the same exact root identity. On deep plugin dependency paths, each ordinary canonicalization walks the absolute prefix again. The copy owner now passes its freshly checked canonical root to the existing lexical resolver, retaining the traversal and before/after root and parent guards. Initial canonicalization is unchanged and uses the ordinary resolver. Aliases, noncanonical spellings, and Windows retain the complete ordinary path. This preserves the ordinary resolver's root-alias semantics, which can differ from native resolution.

No source-file admission is cached or safety option relaxed. Source and destination descriptors, exact identities, symlink/hardlink policy, caller-pinned source identity, exclusive creation, byte bounds, executable mode, clone/offload selection, and identity-checked cleanup remain with their existing owners. No fsync or publication boundary is removed. In particular, ordinary and native resolution of symlink targets containing .. remain distinct: those aliases use the existing resolver.

Evidence

Dedicated Linux x64 AWS Crabbox, Node 24.19.0, four-CPU affinity, one sequential workload at a time. Synthetic installed-plugin tree: 60 packages, 6,000 nested JS/declaration/map/metadata files, 104,688,000 bytes total, file sizes 200 bytes–64 KiB. The harness mirrors the independent source pin, expected inode, per-file destination root, bound, automatic clone policy, mode selection, and hashing through the copied descriptor. Fixture creation and complete byte/hash/mode/independent-inode verification are outside timing.

Every file in the comparable native runs used copy-file-range. Forward/reverse samples:

Comparison Before Candidate single-file API Reduction
Published 0.24.2 13.040 / 13.024 s 8.731 / 8.676 s 33.2%
Pre-change main 71e0d67988c5 10.421 / 10.342 s 8.718 / 8.661 s 16.3%

Candidate batch samples were 5.697 / 5.679 s in the published-version comparison; that API already exists on main and requires consumer adoption. An initial source-checkout run had no native binding and used byte copying, so it is excluded from the comparable native results. Shared-Mac timing is also excluded.

Separate CPU profiles reproduce the original bottleneck: capture-scoped lstat self time falls 5.515 → 2.487 seconds and copy-path assertCurrent inclusive time falls 9.046 → 4.204 seconds versus 0.24.2. These are instrumented diagnostic samples.

Separate instrumentation confirms the mechanism: ordinary realpathSync calls per file fall 25 → 5 versus 0.24.2 and 13 → 5 versus the original main baseline. Against main, direct lstatSync calls fall 113 → 111, native canonicalizations 57 → 55, and all descriptor-stat, open, close, read, and chmod counts stay identical. No fsync is called on this path. These are JavaScript call counts, excluding syscalls inside native helpers and resolvers; instrumented runs are separate from the timing table.

  • Seven new macOS tests pass, covering canonical-root reuse, source/destination replacement during initial identity observation, source-root symlink swapping during lexical admission, ordinary alias semantics, and retargeting an alias after fallback root capture.

  • Existing native/portable adversarial suites cover source/destination swaps, pinned-source replacement, growth, collisions, hardlinks, permissions, and identity-checked cleanup.

  • Independent Codex review at P2: scoped-clean; complete admission-owner and related guard/copy context supplied.

  • Full Linux pnpm check passes: 713 files / 17,420 tests passed, 30 files / 738 platform-specific tests skipped; build, docs, archive allocator, package/declaration/import checks pass. pnpm test:security passes all 226 tests. SHA-256 hashes of all six changed files matched implementation commit d9333cf0c037; the later main merges leave copy production code, tests, benchmark and copy docs byte-identical.

  • The new performance regression test fails on untouched main with the expected repeated-resolution assertion and passes on the candidate.

  • git diff --check passes.

  • Tests added or updated when behavior changed

  • Security and compatibility impact considered

  • CHANGELOG.md updated under Unreleased

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

Hosted CI: the initial Windows Node 22 package-smoke job hit the unchanged 120-second limit in consumer-creation-probe.mjs auto with the native addon omitted. That private-creation probe does not call the changed copy APIs. All other checks passed. The unchanged-head retry was cancelled by a later main update and is not counted as passing proof. Current head 4682b5bf859a adds main's unrelated guest-publication and temporary-directory diagnostic fixes; the copy source, tests, benchmark and copy docs are unchanged. Final hosted checks for this exact head are green: 38 passed, five workflow-conditional skips, including CI, coverage, CodeQL and benchmarks (CI run 37823629733). The Windows Node 22 package-smoke check also passed on this current head. No test deadline or assertion was altered.

@steipete
steipete requested a review from a team as a code owner October 8, 2026 17:39
@clawsweeper

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

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 2:34 PM ET / 18:34 UTC (Revision 3).

ClawSweeper review

What this changes

Reuse freshly checked canonical POSIX roots during guarded file-copy admission to reduce repeated path resolution.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, narrowly implemented optimization with real filesystem proof; one implementation-coupled call-count test limits the patch rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The fully inspected body supplies after-fix measurements through built public copy APIs on a real Linux filesystem with native transfers and complete output verification. The measured implementation remains unchanged at this head; downstream OpenClaw timeout recovery is expressly outside the claim, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Capturing thousands of plugin files spends substantial time repeatedly resolving deep filesystem roots.
Reason: The supplied measurements demonstrate an incremental benefit for existing callers from a small change. Prior merged area ownership supports this direction, and the PR correctly separates component performance from downstream timeout recovery.

Merge readiness

✅ Ready for maintainer review

This PR provides a measured improvement beyond the already-merged batch optimization. The production change preserves the existing safety checks, and no blocking defect was found.

Priority: P2
Reviewed head: 4682b5bf859a07310cf0f068b4736fb58a4f5b6b

Before merge

None.

Findings

None.

Tests

  • Low-value test test/copy-root-canonical-admission.test.ts: reuses the checked source root without the ordinary resolver rediscovering it: The exact mocked realpath call-count assertion pins the implementation rather than the copy contract; remove this test while retaining the real benchmark and adversarial behavior tests.
Agent review details

How this fits together

The guarded copy API copies files between filesystem roots while checking confinement and file identity. It accepts source and destination paths and returns an owned destination descriptor for reading or hashing.

flowchart TD
  A[Source and destination paths] --> B[Copy path admission]
  B --> C{Canonical POSIX paths?}
  C -->|Yes| D[Reuse checked root]
  C -->|No| E[Ordinary root resolution]
  D --> F[Traversal and identity checks]
  E --> F
  F --> G[Guarded copy and final checks]
  G --> H[Owned destination descriptor]
Loading

Technical review

Best possible solution:

Keep the optimization within the shared copy-admission owner while preserving ordinary alias resolution and every existing identity check.

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

Yes: main visibly repeats root discovery during initial copy admission, and the supplied native benchmark reproduces the overhead with comparable before/after measurements. No runtime reproduction was executed by this review.

Is this the best way to solve the issue?

Yes: passing the already-checked root to the existing resolver removes redundant work without adding a competing path owner, public setting, or consumer migration.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • src/copy-path-admission.ts initial root admission keeps the original intent (perf(copy): reuse guarded directory admission within batches #849: Reuse directory admission within explicit operations while rechecking retained identities, preserving fresh file admission, and retaining ordinary resolution for aliases and Windows.)

Testing

Proof path: shipped entry point. Added test files: 1.

Security

None.

Evidence

What I checked:

  • Introduced production change: The pinned introduced delta changes one production file: it supplies the already-checked root to the existing resolver during initial admission. No exported API, option default, dependency, release script, or stored format changes. (src/copy-path-admission.ts:15, 4682b5bf859a)
  • Current main still performs repeated resolution: Main captures the canonical root but calls initial admission without passing it, leaving ordinary root discovery inside repeated resolver calls. The incremental improvement remains absent from the reviewed main revision. (src/copy-path-admission.ts:87, 40f4f3deb9da)
  • Original admission intent and ownership: perf(copy): reuse guarded directory admission within batches #849 introduced operation-scoped directory reuse while retaining fresh per-file checks and alias fallbacks. Its merged commit, raw parent record, and parent-relative patch verify the relevant source introduction. An extended pickaxe search encountered an unavailable historical blob with HTTP 403; the directly verified introduction remains available. (src/copy-path-admission.ts:79, 00c65e098fde)
  • After-fix real filesystem measurements: The fully read PR body reports Linux x64 AWS Crabbox runs on Node 24.19.0 using built public APIs and real native copy-file-range transfers for 6,000 files totaling 104,688,000 bytes. Main samples of 10.421/10.342 seconds become 8.718/8.661 seconds, a reported 16.3% reduction, with complete byte, hash, mode, and independent-inode verification. This establishes component performance, not the downstream 180-second timeout outcome. Captured context sourceRevision: be72446b6abfcb3d32e91d4c40b46fafec115dac68a1bdfcad21f3b3fae85c59. (benchmarks/plugin-source-capture.mjs:54, 4682b5bf859a)
  • Proof remains applicable after main synchronization: The production admission code, new tests, benchmark, and copy documentation are byte-identical between the measured implementation commit and the reviewed head. The central admission, copy, directory-guard, and resolver files are also unchanged between the benchmark's main baseline and fetched main. (src/copy-path-admission.ts:11, 4682b5bf859a)
  • Safety boundary preserved: Canonical-root reuse is gated by POSIX, absolute normalized paths, exact root canonicalization, and a current directory guard. Root and parent checks surround admission; source pinning, descriptor/path verification, exclusive creation, bounded transfer, permissions, and identity-checked cleanup remain in the copy owner. Aliases and Windows retain ordinary resolution. (src/copy-path-admission.ts:68, 4682b5bf859a)

Likely related people:

  • Peter Steinberger: Raw commit 00c65e0 adds src/copy-path-admission.ts:76 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 00c65e098fde; files: src/copy-path-admission.ts)

Review metrics

Metric Value Why it matters
Production and test growth Production +8/-5 lines; tests +126 lines; benchmark +142 lines The small production change has proportionate adversarial coverage and a reproducible performance workload.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Measured synchronous-copy overhead warrants normal-priority improvement without evidence of an emergency caused by this patch.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-08T17:45:08.354Z sha d9333cf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T18:00:01.530Z sha b59e566 :: 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