Repository navigation
fix(worktrees): avoid slow APFS worktree cloning - #146401
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 September 12, 2026, 5:14 PM ET / 21:14 UTC (Revision 3). ClawSweeper reviewWhat this changesAccelerates macOS managed worktree creation with native APFS directory cloning and verified Git-index metadata updates, and includes the TLS cleanup registration prerequisite. Merge readiness✅ Ready for maintainer review The performance fix remains useful, and no actionable correctness blocker was found. The added, explicitly scoped RSS comparison satisfies the previous review’s outstanding request. Priority: P2 Review scores
Verification
How this fits togetherManaged worktrees turn repository revisions into isolated agent checkouts. The filesystem backend materializes source files, while the existing worktree service and Git retain allocation, registration, validation, and recovery ownership. flowchart TD
A[Repository revision] --> B[Managed worktree service]
B --> C[Validated source template]
C --> D[Native APFS directory clone]
D --> E[Verify shared file identities]
E --> F[Git index validation]
B --> G[Normal Git fallback]
G --> H[Independent agent checkout]
F --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +248, Tests +184, Docs +2. Total +434 across 9 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep acceleration within the existing worktree lifecycle, using clone-proven metadata while preserving Git validation, independent checkouts, and normal fallback. Do we have a high-confidence way to reproduce the issue? Yes: repeated managed-worktree creation on a large APFS repository exercises main’s per-file clone and index-refresh costs, corroborated by the supplied before/after measurements. This read-only review did not execute the runtime. Is this the best way to solve the issue? Yes: the patch removes the measured overhead within the existing backend, conservatively translates proven file identities, and retains Git fallback without adding configuration or another lifecycle owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d093d651f71d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
394adf4 to
30f1f01
Compare
|
@clawsweeper re-review Added the requested comparative peak RSS evidence to the PR body: 422 MiB before and 424 MiB after for the matched native/cold/warm/native benchmark process, using process.resourceUsage().maxRSS. The measurement scope is explicit: Node startup, fixture preparation and all creates; excludes Git children and is not an aggregate process-tree peak. The existing architecture and conservative validation remain unchanged. The refreshed main integration also passed 24 focused tests, a full build, and the supported CLI proof. Its cached creates took 4.14 and 6.68 seconds; the one-time template rebuild after the configuration fingerprint changed is reported separately as cold. Native controls and follow-up status times remain in the body to make the shared-host variability visible. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* fix(gateway): register TLS renewal with its sidecar owner Pass the renewal handle directly to the variadic gateway lifetime owner. This completes the integration between TLS renewal (openclaw#146267) and the sidecar ownership refactor (openclaw#146275), repairing TS2741 and retaining working TLS watcher cleanup. * perf(worktrees): accelerate APFS directory cloning
Related: #146288. Follow-up to #146338. During validation, the TLS integration blocker was repaired independently by #146412; duplicate #146411 was closed. The final merged commit contains only the eight APFS-related files.
What Problem This Solves
Fixes managed APFS worktree creation taking longer than normal Git checkout, particularly in repositories with many small files.
User Impact
Warm worktrees retain copy-on-write storage savings and become faster to prepare. On a 41,655-path OpenClaw checkout, the first host comparison improved from 40.7 seconds to 3.52 seconds; normal Git controls took 8.13–13.69 seconds in the candidate run. A final three-run repeat took 3.90–5.49 seconds (median 4.16 s), with native controls of 9.64 s and 34.79 s on the variable shared host. Subsequent
git statustook 0.21–0.23 seconds, so validation was not deferred to the next command. Cold creation still pays for the initial Git template checkout.Apple discourages general directory cloning through
clonefile. This change uses that documented atomic API for managed source-only templates. Cancellation waits for an admitted native clone to settle before recovery touches its destination. Unsupported filesystems and clone failures retain Git fallback; unsupported index representations retain full Git validation. No configuration or dependency changes are required.Why This Change Was Made
Replace the per-file JavaScript loop with one asynchronous native directory clone. Then translate only the copied Git index's file identity metadata where APFS proves the data stream is unchanged and the source's cached metadata still matches. Keep blob IDs, paths, modes, modification times and sizes; leave racy, unsupported or changed entries for Git's normal refresh. Preserve normal edit detection, including same-size edits with restored modification times on Git builds that compare timestamps at whole-second resolution.
The existing worktree service owns allocation, template validation, setup, registration and recovery. Git remains responsible for final index validation and branch state.
Evidence
clonefile0.675 s; existing JavaScript traversal without lease checks 6.77 s; recursive nativecopyfile13.99 s. Rust would call the same native operation and is not needed.process.resourceUsage().maxRSS) across the native/cold/warm/native sequence was 422 MiB before and 424 MiB after. This includes Node startup, fixture preparation and all creates in that process; it excludes Git child processes and is not a per-checkout or aggregate process-tree peak.update-index --refreshfell from 24.94 s to 0.082 s. Only 26 symlinks and one empty file required content verification.EXDEV. Warm clones allocated about 16–17 MiB versus about 654 MiB for native checkout on the isolated proof volume.pnpm build, and three supportedpnpm openclaw worktrees createCLI runs passed, including index-v4 fallback.server-startup-finish.ts:416: the TLS sidecar is passed as an array to a newly variadic registration API. The separate repair is fix(gateway): stop TLS renewal through its lifetime owner #146411. This branch has been rebased onto that prerequisite and newer main; fresh independent P0–P2 review, 24 focused tests, full build, and supported CLI proof of the integrated APFS delta all pass. CI is rerunning on the updated head.These are measurements on one shared host, not universal speed guarantees. The first host comparison uses native APFS storage without disk images; disposable-volume proof measures physical sharing separately.
Kernel-source inspection used Apple-published XNU
f6217f891ac0bb64f3d375211650a4c1ff8ca1ea:clonefile_internalenforces absent destination, same mount and filesystem permissions, then callsVNOP_CLONEFILEonce.VNOP_CLONEFILEsupplies the directory authorization callback, which operates on prefilled attributes without per-child vnodes.getattrlist_internalobtains the requested file metadata and clone identity through one filesystem attribute operation. The documented clone ID uniquely identifies a data stream.APFS's internal tree transaction and locking implementation is not public. The published XNU source predates the tested Darwin 27 kernel; full native proof validates behavior on the actual host.
The final combined-head CI is green: run34717840913, head
30f1f01dfc2ef29b040a7e752a7040767fcf05bf. The included TLS prerequisite also passed an isolated supported-CLI HTTPS startup/shutdown proof: verified health200, both actual renewal watchers stopped on SIGTERM, clean54ms Gateway shutdown, exit0, reusable port, and complete synthetic-state cleanup.Merged as
9b59fe4ef7da6444059d4fe4651b14097f13ab59. Verified on current main. The final merge excludes the already-landed TLS repair (b405e7f644106306d2d3965ecf22335fdbe15716, #146412).