Repository navigation
perf(copy): reduce plugin capture root-resolution overhead - #878
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 2:34 PM ET / 18:34 UTC (Revision 3). ClawSweeper reviewWhat this changesReuse freshly checked canonical POSIX roots during guarded file-copy admission to reduce repeated path resolution. Review scores
ProductKind: Performance · Worth it: Yes 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. Added test files: 1. SecurityNone. EvidenceWhat I checked:
Likely related people:
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment History |
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-pathassertCurrentwork; adjacent full-flow proof went from 119.383 seconds passing to 252.762 seconds exceeding the unchanged 180-second limit.User Impact
The existing
copyRootFileSyncAPI 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:71e0d67988c5Candidate 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
lstatself time falls 5.515 → 2.487 seconds and copy-pathassertCurrentinclusive time falls 9.046 → 4.204 seconds versus 0.24.2. These are instrumented diagnostic samples.Separate instrumentation confirms the mechanism: ordinary
realpathSynccalls per file fall 25 → 5 versus 0.24.2 and 13 → 5 versus the original main baseline. Against main, directlstatSynccalls 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 checkpasses: 713 files / 17,420 tests passed, 30 files / 738 platform-specific tests skipped; build, docs, archive allocator, package/declaration/import checks pass.pnpm test:securitypasses all 226 tests. SHA-256 hashes of all six changed files matched implementation commitd9333cf0c037; 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 --checkpasses.Tests added or updated when behavior changed
Security and compatibility impact considered
CHANGELOG.mdupdated under UnreleasedNo 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 autowith 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 head4682b5bf859aadds 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.