Repository navigation
perf(worktrees): reuse templates for source-only sessions - #169239
Conversation
Use the existing isolated Git policy for template population, validation, and index refresh. Preserve inherited Git path vetoes and distinguish the checkout policy in the template key. Add bounded preparation diagnostics for filesystem, policy, template lifecycle, and disk-admission outcomes.
|
🦞👀 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. What this changesThis PR enables filesystem-template reuse for source-only managed worktrees and adds diagnostics explaining template selection and fallback. Example: Create 20 concurrent source-only worktrees from a 54,000-file repository on compressed Btrfs.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: current main still excludes source-only sessions from template acceleration, and this focused optimization preserves filter isolation without introducing a competing owner; no actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe managed-worktree service turns an admitted repository revision into an independently editable checkout; Git owns registration and indexes, while the existing template registry and filesystem backend own reusable source materialization. flowchart TD
A[Session preparation] --> B[Managed worktree service]
B --> C[Git registration]
C --> D[Isolated checkout policy]
D --> E[Existing template cache]
E --> F[Native filesystem clone]
D --> G[Ordinary Git fallback]
F --> H[Published checkout]
G --> H
Technical reviewBest possible solution: Reuse the existing source-template owner under isolated Git policy, preserving ordinary checkout fallback and reader custody. Do we have a high-confidence way to reproduce the issue? Current-main source directly establishes the excluded source-only path, and the author reports a baseline-failing regression; this review did not execute it. Is this the best way to solve the issue? The patch addresses eligibility through the existing template and Git-policy owners, with focused regressions and an explicitly recorded cold-build tradeoff. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against af288ea70b81. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +105, Tests +52, Docs +4. Total +161 across 10 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel 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 Reviewed October 11, 2026, 1:37 PM ET / 17:37 UTC. |
…69239) Use the existing isolated Git policy for template population, validation, and index refresh. Preserve inherited Git path vetoes and distinguish the checkout policy in the template key. Add bounded preparation diagnostics for filesystem, policy, template lifecycle, and disk-admission outcomes.
What Problem This Solves
Sandboxed sessions always performed a full Git checkout, even when their worktree root supported native Btrfs snapshots. The source-only eligibility check skipped template preparation before the filesystem probe ran, so preparation logs only reported
template=unavailable.User Impact
Source-only sessions now reuse and refresh native filesystem templates while preserving the existing no-host-filter policy. Preparation diagnostics identify eligibility, probe, ACL, checkout-policy, cache, build, and disk-admission outcomes, including backend and clone-byte estimates.
Why This Change Was Made
Template population, validation, and cloned-index refresh now use the existing source-only Git policy. Git still owns registration, refs, and indexes; native helpers own directory materialization. The cache key includes the effective checkout configuration and source-only policy. Inherited Git path overrides still select ordinary checkout; a new regression preserves an external index and the new worktree’s real index. External attributes retain their existing fallback; cancellation, authority checks, reader custody, and disk admission remain in place.
Removed the blanket source-only exclusion and redundant commit resolution: registration already supplies the pinned commit. Production LOC delta: +105 (
git diff --numstatexcluding tests and docs). Production LOC grows because the requested failure diagnostics and extending the existing filter-isolation contract to template creation/validation/index refresh require additional paths; there is no parallel clone implementation, new cache owner, config option, or schema change.Evidence
Native Btrfs proof: Linux, loop-mounted Btrfs with compression, fs-safe 0.26.0, UID 65534. An ordinary parent successfully creates a subvolume template and snapshots it. Clone edits preserve source contents and symlinks; an ordinary non-subvolume source correctly fails.
Regression fails on unchanged base: no source-only template is created. Candidate proves reuse, independent contents, commit and effective-config invalidation, and no host-filter execution.
Blacksmith Testbox
tbx_01m4nvxg2kn6ctr5ba1b0jse4d: baseline regression rejected as expected; focused 43 tests passed in 68.61 s (test orchestration), including template custody and acceleration fallback.The initial changed gate found a three-line checkout-module cap regression; removed redundant commit resolution. Testbox’s final sync then timed out. AWS fallback
cbx_2afdb0487e4fran the changed gate and all worktree siblings: 633 tests passed across 55 files in 714.06 s; platform-specific cases skipped. Structural guards, format, core production types, and agent test-type graphs passed. The full gate stopped on seven inherited UI JSX TS2339 errors in Activity/Usage files; unchanged baselineb11fbcf10138reproduces all seven errors. Its UI unused-export failures were also reproduced unchanged (15 production exports, three repeated in the full-tree scan). The infra test-type graph and remaining non-typecheck gates passed, including typed lint, native schema, database-first policy, import cycles, and webhook/pairing guards.Non-root real-service benchmark on a loaded 8-core Linux rig, compressed loop-mounted Btrfs, synthetic 54,000-file repository:
All 20 candidate creates reused a warm Btrfs template. Checkout improves 11.8× and total preparation 3.4×; the full checkout phase misses the 1.5 s target because template validation, Git index refresh, and waiting remain. The first cold create now pays the template build cost. These synthetic loaded-rig timings are not production latency predictions.
Native service follow-up: warm single checkout 5.44 s / total 7.53 s; changed the source commit, retired/rebuilt the old native subvolume, and verified cloned edits remain independent of the template and subsequent checkouts.
Final AWS run
cbx_2afdb0487e4f: reviewed source hashes verified; 12 focused tests passed, including the external-index regression.service.source-only-filters.test.tstook 22.69 s andpreparation-timing.test.ts1.26 s with--maxWorkers=1(45.80 s total wrapper time including worker preparation).Independent review: no actionable P0–P2 findings after retaining the original Git-environment veto.
Hosted CI run 38159958535 passed on exact head
ada46fb3b04bin 603 s. All required checks passed before squash merge9fec51a05540. The patch-identical rebase changed none of the ten reviewed/tested file blobs.No production state or service was accessed or changed. The Linux rig uses synthetic state; macOS native execution was not run on the saturated development host.