Repository navigation
fix(sandbox): reuse prepared commits without template rebuilds - #195883
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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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. |
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.
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 --stagedretains the unrelated 20-entry changelog-attribution failure, reproduced on the exact parent and introduced by policy commit266a7aa0fe69e2b5fe6445c4ceb1e15b5360c957/ #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.