Skip to content

perf(worktrees): reuse templates for source-only sessions - #169239

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-btrfs-template-clone-20260919
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-btrfs-template-clone-20260919

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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 --numstat excluding 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_2afdb0487e4f ran 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 baseline b11fbcf10138 reproduces 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:

    Measurement Before After
    First cold create, total 33.20 s 38.85 s
    First cold create, checkout 6.64 s 11.08 s
    20 concurrent creates, total p50 120.35 s 35.31 s
    20 concurrent creates, checkout p50 95.15 s 8.03 s
    Native snapshot, p50 unused 1.05 s

    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.ts took 22.69 s and preparation-timing.test.ts 1.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 ada46fb3b04b in 603 s. All required checks passed before squash merge 9fec51a05540. 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 11, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Oct 11, 2026
@steipete
steipete marked this pull request as ready for review October 11, 2026 17:30
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The reported benchmark performs full Git checkouts, with median total preparation of 120.35 seconds.
  • After: All 20 creations reuse a warm template, with median total preparation of 35.31 seconds; the first cold creation becomes slower.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Source review found no actionable defect; recorded native service measurements support the optimization, but shipped-entry-point proof is not supplied and hosted checks remain pending.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; its body reports non-root native Btrfs service measurements and independent-edit/rebuild results, while inspected regression tests use a substituted filesystem backend.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Sandboxed source-only sessions repeatedly wait for full Git materialization even when their destination supports filesystem snapshots.
Reason: The feature-history owner authored the change, and reported native measurements support its value while explicitly accepting the slower first cold creation.

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
Reviewed head: ada46fb3b04bae4b9495ee31553b2b3383316bd1

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied native benchmark exercises the worktree service directly; no shipped CLI or Gateway session run is shown.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Source-only template exclusion changes intended behavior with a stated reason (28d8ee4: Sandboxed managed projects must materialize source without executing host Git filters or repository programs.)
  • Template materialization and checkout identity keeps the original intent (25dcf15: Git owns registration and indexes while filesystem templates share source storage, with checkout-policy invalidation and ordinary Git fallback.)
  • Shared template custody keeps the original intent (7283a5c: Source and sandbox templates share the existing registry, allocation lifecycle, and retirement owner.)
  • Preparation diagnostics keeps the original intent (404d388: Attribute preparation latency through bounded logs and diagnostic events without changing preparation outcomes.)
  • Native filesystem worker configuration keeps the original intent (a174813: Native filesystem helpers retain explicit operator configuration, cancellation settlement, and guarded mutation ownership.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main still excludes source-only templates: The eligibility condition explicitly includes !options.sourceOnly, so this PR supplies behavior absent from fetched main. (src/agents/worktrees/checkout.ts:398, af288ea70b81)
  • Pinned introduced change: Template population and validation use the existing isolated Git policy; cloned-index refresh uses that same policy, and inherited Git-path overrides still veto acceleration. (src/agents/worktrees/checkout.ts:214, ada46fb3b04b)
  • Original isolation intent: fix: sandboxed sessions cannot edit managed projects #152641 introduced the source-only exclusion alongside filter-safe materialization; its stated contract forbids running repository programs on the host. (src/agents/worktrees/checkout.ts:435, 28d8ee4f096b)
  • Existing cache lifecycle retained: The source-v2 content identity separates checkout policies; the existing registry rejects mismatched generations, preserves active readers, and rebuilds unused templates without changing stored record shapes. (src/agents/worktrees/template-cache.ts:200, ada46fb3b04b)
  • Behavioral regressions: The added service tests exercise real Git, independent checkout contents, commit and configuration invalidation, external-index preservation, and absence of host-filter execution; native directory operations are replaced by a copy backend. (src/agents/worktrees/service.source-only-filters.test.ts:103, ada46fb3b04b)
  • Reported native performance and accepted cold-build cost: The complete PR body records non-root real-service Btrfs measurements, warm reuse, commit-triggered retirement and rebuild, independent edits, and the slower cold creation; these are synthetic service measurements rather than production latency guarantees. (ada46fb3b04b)

Likely related people:

  • Peter Steinberger: Raw commit 25dcf15 adds src/agents/worktrees/checkout.ts:99 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 25dcf15b0aef; files: src/agents/worktrees/checkout.ts)

PR surface

Source +105, Tests +52, Docs +4. Total +161 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 188 83 +105
Tests 2 55 3 +52
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 247 86 +161

Review metrics

Metric Value Why it matters
Production versus test growth Production +188/-83, net +105; tests +55/-3, net +52. Growth extends the existing isolation policy into template operations and adds bounded diagnostics; service regressions protect independent contents and filter isolation.

Labels

Label changes:

  • add P2: This improves managed-session preparation on supported filesystems while retaining a working Git fallback.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This improves managed-session preparation on supported filesystems while retaining a working Git fallback.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 execution lanes are retired.

Reviewed October 11, 2026, 1:37 PM ET / 17:37 UTC.

@steipete
steipete merged commit 9fec51a into main Oct 11, 2026
201 of 203 checks passed
@steipete
steipete deleted the steipete/perf-micro-btrfs-template-clone-20260919 branch October 11, 2026 17:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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