Repository navigation
perf(worktrees): reuse sandbox dependency templates - #164517
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 3, 2026, 4:50 PM ET / 20:50 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR prepares pnpm dependencies in a disposable sandbox and reuses filesystem templates for new private managed-worktree checkouts, with source-only fallback and worker-backed registry access. Merge readiness✅ Ready for maintainer review Keep open: current main lacks this optimization, and the reviewed patch has useful production-path evidence with no concrete blocking defect found. Maintainer-authored work also remains outside automatic closure. Likely related people: steipete — recent worktree and projection contributor, medium confidence. Priority: P2 Review scores
Verification
How this fits togetherManaged worktrees give agent sessions independent repository checkouts. Sandbox projection preparation turns a selected repository commit and sandbox policy into a private execution workspace whose accepted changes reconcile with the canonical worktree. flowchart TD
A[Repository commit and sandbox policy] --> B[Private workspace preparation]
B --> C{Reusable template available}
C -->|No| D[Disposable sandbox installation]
D --> E[Validate output and retire builder]
E --> F[Prepared or source-only template]
C -->|Yes| F
F --> G[Independent session checkout]
G --> H[Agent execution and reconciliation]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +793, Tests +484, Docs +29, Other +2. Total +1308 across 17 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep dependency preparation under the existing template lifecycle, preserve private-session isolation, and retain clean source-only fallback when acceleration cannot safely apply. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a performance optimization, and the captured body provides before/after measurements through the real sandbox checkout flow. Is this the best way to solve the issue? Yes: sharing the existing template registry and cleanup owner while installing inside an isolated guest preserves the host boundary and avoids a competing package-cache lifecycle. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 930bd387bbaa. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
* perf(worktrees): reuse sandbox dependency templates * fix(worktrees): avoid shadowing template records
What Problem This Solves
Fresh sandboxed managed worktrees repeatedly install the same pnpm dependencies before an agent can run repository code. The sandbox executes a private Git checkout, so warming only the canonical host worktree does not reach it.
User Impact
New Docker/Podman private checkouts on supported copy-on-write filesystems arrive with dependencies after the first checkout prepares their generation. Existing sessions retain their files and do not wait behind a cold template installation.
worktreeAcceleration: falsealso disables dependency preparation; no new configuration is added.Why This Change Was Made
Prepare the independent Git checkout and frozen pnpm install once in a disposable sandbox, then clone that template into each private session checkout. The generation includes the selected commit, lockfile hash, immutable sandbox image (guest Node/package-manager versions), guest workdir, and installation policy. The existing template registry, allocation lease, and seven-day GC own preparation and retirement; the old inline projection Git preparation and separate source-template lifecycle implementation are replaced by shared owners. Template registry access now runs through the existing SQLite worker broker.
The builder receives no configured environment credentials, custom binds, or setup command, and its Git metadata is mounted read-only. Host ignored-file provisioning and unsandboxed
operator.adminsetup authority remain unchanged. Only realnode_modulesdirectories, independent of Git ignore spelling, are retained as additional template output; all tracked source, including the frozen lockfile and ignore rules, must remain unchanged. Failed installation or source mutation records a warning and caches a clean source-only fallback for the generation. Cleanup must retire the builder before publication or deletion. Sandboxes configured withnetwork: noneuse offline installation: a real cold probe failed promptly in 0.22 s, while ordinary installation was still retrying after 30 s.Installation and consumption use the same guest
/workspacepath. pnpm absolute shims therefore need no relocation. Native-protocol stamps also remained valid in the whole-tree experiment, but production deliberately removes those generated outputs outsidenode_modules; native work regenerates them normally. A plain read-only host-store trial did not satisfy this workload's offline metadata/store contract.Production LOC grows because preserving the source-only host boundary requires a separate credential-free guest installer with durable cancellation/cleanup custody, a precise dependency-output invariant, and worker-backed registry access. Unsupported external pnpm virtual stores fall back instead of publishing broken links, and missing cache directories rebuild through the same owner. The change does not add a second setup owner or a writable shared package cache. Production delta under the requested exclusions: +1009/-213, net +796 lines.
Evidence
Linux Btrfs/Podman rig, Node 24.21.0, pnpm 12.5.1, OpenClaw's common sandbox image (irrelevant Brew/Bun installation omitted), isolated synthetic state. Rootful Podman used guest
0:0for root-owned rig fixtures; no host credentials or package store were mounted. Real flow:ManagedWorktreeService.create→ persisted sandbox-required session →resolveSandboxContext→ sandbox exec →node --import ./scripts/tsx.mjs -e "import('./src/agents/worktrees/checkout-policy.ts')".The full-flow numbers include source-worker startup and private checkout preparation, not model or full RPC latency. The second before case briefly overlapped another check process; the narrower boundary measurements were uncontended. The first generation still pays the installation cost. A subsequent frozen install reused all dependencies without relinking in 3.74 s. Cold install peak RSS was about 1 GiB; prepared imports used about 217 MiB.
Ten Btrfs snapshots added zero data bytes and 327,680 physical metadata bytes.
btrfs filesystem du --rawreported zero exclusive bytes for every checkout; ordinarydureported approximately 6.53 GB per checkout because it counts shared extents repeatedly.Live proof passed: lockfile commit creates a new template and retires its predecessor; consumer edits do not alter siblings; forced install failure preserves clean source and excludes partial modules/host credentials; a second failed-generation checkout reuses that fallback; an existing projection resumes while the global allocation lease remains held. No production host was modified.
Testbox provider:
blacksmith-testbox, initial validation leasetbx_01m41fyp8ctey5d3z3fej78rd8; final validation leasetbx_01m41nn12z0g49mnqycyr54dqm. Queued leases that disappeared were replaced; active leases were stopped before base changes. Installed frozen dependencies once in the independently synchronized checkout.pnpm build: passed on the final Testbox lease in 8m32s (full remote command including focused tests: 9m45s). The build reported an unrelated Control UI startup gzip budget warning, 373,687 B versus 373,454 B; build exit was 0.node scripts/check-changed.mjs --stagedat basec3f61d8f591f: 24 checks passed; core lint failed only on the two callback-shadowing errors subsequently corrected in9705e3d53531. The corrected files passed focused Testbox lint, and the current-head CI core-lint job passed. Full original summary below; the historical aggregate exit remains 1.Initial fixture failures (wrong broker test pool and parameterized test context) were fixed. The type gate caught and corrected an optional AbortSignal where Git preparation requires cancellation custody. No test sleeps, timer-driven polling, or per-test Gateway boots were added.
The initial published commit is a patch-identical rebase from validated base
c3f61d8f591fonto28a6f71449aa;git range-diffreports an unchanged patch. Earlier live rig measurements used base52b32becc08d; the final focused regressions and build usedc3f61d8f591f. The first current-head CI run (37151390481) found two lane-ownedno-shadowlint errors, fixed in9705e3d53531by renaming callback-local variables without changing behavior. The correction passed independent Codex review and focused lint onblacksmith-testboxleasetbx_01m41qamm36efs6pzegc7hm8bk:node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json --threads=1 src/agents/worktrees/checkout.ts src/gateway/worker-environments/local-workspace-template.ts, zero warnings/errors in 12.5 s (38.79 s whole remote command including frozen dependency installation). Lease stopped. It also failedchecks-ui-e2e (1/2)inboard-mcp-app.e2e.test.ts:527(602 px iframe gap). Source/history attributes the latter to inherited commit668c06211e6c/ #164493:.mountnow relies on a flex host whileboard.cssforces that host todisplay: block. The fullui/tree and browser fixture inputs are unchanged by this PR; no browser reproduction or upstream fix is claimed.Platform gap: live dependency-template proof is Linux/Btrfs/Podman. APFS/ReFS reuse the existing clone backends; no new native-platform proof was run. Existing sessions are not reinstalled automatically after their own lockfile edits.
Linux rig staged-check summary (original exit 1; lint correction verified separately)
Current-head CI: run 37152085073 completed on
9705e3d535317b92e02befff859daf075547fbcb. All jobs passed or were intentionally skipped exceptchecks-ui-e2e (1/2)and its aggregate gate. The UI job reproduced the same inherited 602 px iframe gap; the core-lint correction and production types passed. This PR remains open pending an upstream UI repair; no merge was requested by this lane. All Testbox leases and live-proof containers have been stopped.