Skip to content

fix(sandbox): reuse prepared commits without template rebuilds - #195883

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-sandbox-template-slots-2324
Nov 9, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-sandbox-template-slots-2324

Conversation

@steipete

@steipete steipete commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated sandbox dependency preparation when concurrent sessions return to different source commits, and retires unused template generations left behind by older runtime identities.

Related: #195713, #195443.

User Impact

Sessions reuse prepared dependencies for up to four recently used commits instead of repeatedly replacing one shared template. Active clone and installer readers keep their generation pinned until they settle. Existing disk admission still applies; no configuration or database migration is required.

This does not establish the full 20-session Gateway recovery target below 60 seconds: the separate full-size lifecycle fixture remains limited by initial projection capture/synchronization before container creation.

Why This Change Was Made

The template owner already publishes staged generations atomically. It now retains previous ready generations under content-addressed keys in the existing registry and admits matching readers without refreshing another commit. Successful reader admission updates the existing last-used timestamp in the same transaction.

The existing collector bounds ready sandbox generations to four per repository/template root across runtime identities. Older observed identities become eligible after six unused hours; the most recently used identity retains normal idle expiry, subject to the shared bound. Live readers can temporarily exceed it. Completed projections own independent COW file references and Git metadata, so deleting their original template does not remove their data.

Maintenance uses its existing deletion-spacing and IO-pressure gate, waiting before taking the template publication lock. Builds opportunistically collect at most one eligible generation; warm admission adds no registry scan. No new cache layer, schema fields, or configuration. Production grows by 145 lines for selection/publication and bounded retirement; tests grow by exactly 182 lines with a scoped allocation. The existing service GC parameter type moved beside its cleanup policy to avoid growing the oversized service module.

Evidence

The regression fails on exact parent 4a42d5bd1ea392d3519f08660c915ae7b02abeca. Focused cache/registry, interleaved 20-reader, LRU/pinning, stale identity, real Git/source-dependent installation, and maintenance tests pass. The maintenance regression admits a warm reader with a zero wait budget while GC is paused at its IO gate.

Native APFS COW and real container dependency preparation used 62,000 synthetic files / 1,100,004,000 bytes per checkout, in serial B/C/C/B controls. After seeding three commits, 20 consumers ran in A×7/B×7/C×6 waves. All 80 outputs had the correct HEAD, clean Git status, and source-dependent installed bytes.

Metric Baseline controls Candidate controls
Repeat preparations after seeding 3 / 3 0 / 0
Sum of wave wall time 47.477 / 46.655 s 21.331 / 18.066 s
Node process CPU 4.060 / 3.698 s 4.327 / 3.539 s
Main-isolate allocation 160.4 / 192.3 MB 113.7 / 116.4 MB
Consumer p50 15.119 / 15.157 s 6.370 / 6.060 s
Consumer max 17.216 / 16.716 s 8.597 / 6.389 s

Median wave time falls 58%; allocation falls 35%. CPU is flat within A/A variability, with no CPU improvement claimed. Candidate wall spread is 18% versus 2% baseline. Seed costs and between-wave output checks are excluded; the wave sum is not full-cohort first-turn latency. CPU excludes subprocesses; allocation excludes workers/native allocations. The installer uses a minimal local dependency, not a production-sized dependency tree; this owner fixture does not include the 35-GiB agent database. The benchmark extension and reproduction protocol are included in this PR.

Both candidates preserve their three original ready IDs throughout all waves. An additional untimed native collection removed all three template rows/directories; all 20 completed projections still passed the same content checks. Waiters shared one baseline build per wave: nested mutationWait/templatePrepare timings do not imply duplicate installs.

Independent Codex autoreview is clean through P2. The exact test-line allocation and line-cap checks pass. Core/test/script types and all dead-export scans pass. The required pnpm check:changed --staged retains the unrelated 20-entry changelog-attribution failure, reproduced on the exact parent and introduced by policy commit 266a7aa0fe69e2b5fe6445c4ceb1e15b5360c957 / #194364. The caused service line-cap and mechanical lint failures were repaired; narrow lint, format, line-cap and the five slot regressions pass after repair. This main regression is recorded, not treated as noise. No changed production module is imported by Control UI.

Exact-head CI 42596689801 passes (47 successful jobs, 28 skipped). OpenGrep 42596689621 passes: 106 rules, 12 files, zero findings and no suppressions. Verified head: afc94df898850d5563e43106f2aa8e3fff68a5e3.

@clawsweeper

clawsweeper Bot commented Nov 9, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T09:54:48.668512Z afc94df PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Nov 9, 2026
@steipete

steipete commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Landing note (maintainer review): template retention is bounded at four ready sandbox generations per repository across runtime identities, superseded identities expire after 6 h, and each new build retires at most one over-capacity template under the owner's mutation lease. Three-commit controls (62k files, 1.1 GB per checkout): repeat preparations 3 → 0, median owner-wave 47.1 s → 19.7 s, allocation −35%, all 80 projections correct. Addresses Team's stale-template-in-use ping-pong (sandbox mutationWait/templatePrepare ~12 s each in slow sends). Production +145 lines for the retention bound and GC; exact-head CI green.

@steipete
steipete merged commit 3a48d6f into main Nov 9, 2026
142 of 146 checks passed
@steipete
steipete deleted the steipete/fix-sandbox-template-slots-2324 branch November 9, 2026 10:06
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
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 gateway Gateway runtime scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant