Repository navigation
fix(sandbox): avoid snapshot overhead for fast checkpoints - #196727
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. |
Transfer accepted captures to unique retired paths under the projection lease, then use the existing independent run-end lifetime for deletion. Join pending deletion before another capture, retaining bounded failure recovery while allowing the next command to run. Preserve canonical read-after-command ordering. Remove the privileged deletion shortcut and qualify native proof with unprivileged filesystem work and separate kernel settlement accounting.
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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR selects direct capture for fast checkpoints, defers disposable snapshot cleanup, and reduces snapshot-worker metadata overhead. Example: A command edits a file in a 100-file btrfs workspace and its probe finishes below 500 ms.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses measured checkpoint overhead, and source review found no actionable introduced defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSandbox command finalization sends workspace changes through the projection owner, which captures files, reconciles them into the canonical checkout, and resumes the runtime. flowchart TD
A[Sandbox command] --> B[Checkpoint owner]
B --> C[Existing manifest probe]
C --> D[Direct or snapshot capture]
D --> E[Canonical acceptance]
E --> F[Command completion]
E --> G[Retired capture cleanup]
Technical reviewBest possible solution: Keep adaptive capture and retired cleanup in the existing checkpoint owner while preserving canonical acceptance, cancellation, and bounded artifact cleanup. Do we have a high-confidence way to reproduce the issue? Current main selects snapshot capture for changed btrfs checkpoints and awaits deletion; the preceding merged PR records the resulting latency and CPU cost, but this review ran no target code. Is this the best way to solve the issue? Selecting capture from existing probe facts removes unnecessary snapshots, while the existing lifecycle owner can delete uniquely retired artifacts without delaying canonical acceptance; the worker change preserves metadata and cancellation contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ecbad2efa1d7. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +125, Tests +205, Docs +70, Other +308. Total +708 across 16 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 HistoryReviewed November 10, 2026, 11:59 AM ET / 16:59 UTC (Revision 3). |
Allocate the exact 137 new regression lines for adaptive capture, next-command overlap, caller disposal and bounded cleanup recovery. Keep the shared baseline unchanged and do not allocate inherited main debt. The exact test-line guard passes against the branch parent; independent Codex review is clean.
|
Addressed the latest review's one open item on head
The earlier CI main parent The formal native performance campaign is still running. The budget-only commit changes no runtime or benchmark bytes, so the pinned @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Read snapshot metadata directly in the capture worker with a shared bounded yield for cancellation. Preserve asynchronous metadata reads on the main thread and non-snapshot scans. Extend native allocation proof to account for workers and cover scan equivalence and cancellation.
|
The final source candidate is
All 45 scanner/worker tests, focused type/lint checks, the runtime build and fresh full-candidate Codex autoreview pass. The PR body records the unchanged acceptance criteria and pending final native proof. Please review the new worker path and allocation instrumentation at this head. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…196727) * fix(sandbox): avoid snapshot overhead for fast checkpoints * fix(sandbox): retire checkpoint captures outside the command lease Transfer accepted captures to unique retired paths under the projection lease, then use the existing independent run-end lifetime for deletion. Join pending deletion before another capture, retaining bounded failure recovery while allowing the next command to run. Preserve canonical read-after-command ordering. Remove the privileged deletion shortcut and qualify native proof with unprivileged filesystem work and separate kernel settlement accounting. * test(sandbox): budget checkpoint retirement regressions Allocate the exact 137 new regression lines for adaptive capture, next-command overlap, caller disposal and bounded cleanup recovery. Keep the shared baseline unchanged and do not allocate inherited main debt. The exact test-line guard passes against the branch parent; independent Codex review is clean. * perf(sandbox): reduce snapshot worker metadata overhead Read snapshot metadata directly in the capture worker with a shared bounded yield for cancellation. Preserve asynchronous metadata reads on the main thread and non-snapshot scans. Extend native allocation proof to account for workers and cover scan equivalence and cancellation.
Related: #196662
Maintainer decision: land on the counterbalanced pilot evidence. Final measurement acceptance remains pending because shared-host contention and unstable A/A controls prevented a qualified full campaign.
What Problem This Solves
Taking and recursively removing a full btrfs snapshot on every changed command reduced container pauses but added 28% command latency and CPU in the original 62,000-file benchmark. Small workspaces should not pay that snapshot cost.
User Impact
Small, fast checkpoints keep direct paused capture. Expensive checkpoints retain atomic capture and resume before scanning. Commands still wait for canonical acceptance; after runtime resume, the workspace lease renames the disposable capture to a unique retired path and hands cleanup to the existing run-end lifetime. The next command can execute during deletion; the next snapshot waits for pending cleanup and retries interrupted removals before creating another artifact.
Cleanup keeps the existing native recursive remover and needs no new utility, privilege or mount option. Snapshot creation can still wait for dirty writeback, and nested subvolumes retain the complete paused fallback.
Why This Change Was Made
The manifest worker already knows the accepted entry count. It now carries that fact on an early-aborting probe, so a large tree is recognized even when the changed pathname sorts first. A 20,000-entry inventory or a probe lasting 500 ms selects snapshots. No additional scan, persistent cache, schema, or configuration is introduced. Recovery and initial layout capture without probe facts remain on the direct path.
Canonical writes retain session authority. The lease transfers only an immutable, disposable artifact to independent cleanup. Unique retired names prevent delayed deletion from touching a later capture. Pending promises track active work, not cached scan results; persistent removal failures prevent another snapshot from growing the backlog. A rolling snapshot cannot be refreshed by the current immutable-copy primitive, and an early probe is not a complete changed-path set for safe selective reflinks.
The snapshot manifest scan also avoids one asynchronous filesystem dispatch per metadata read inside the existing capture worker. A shared 32-read yield services cancellation; the main thread and non-snapshot scans retain asynchronous reads. File hashing, identity and containment checks are unchanged.
Evidence
Two regressions fail on the parent: small btrfs checkpoints unnecessarily invoke snapshots, and completed commands remain blocked behind capture deletion. On the candidate all 9 checkpoint scenarios pass, including interrupted acceptance, nested fallback, later guest writes, canonical read-after-command, bounded cleanup custody and caller disposal. Native filesystem owner tests: 10/10. The broader projection owner run passed 83 tests with 2 platform skips; its one obsolete always-snapshot recovery expectation was corrected and replayed green.
The next-command overlap regressions additionally fail on preliminary head a04f5a3 with
OPENCLAW_STATE_LEASE_HELD, then pass on the retired-path handoff. Final staged candidate Codex autoreview is scoped-clean through P2. Production delta: +125 LOC: 103 for adaptive capture and bounded lifetime transfer/recovery, plus 22 for worker metadata reads. Tests: +205 LOC, including real-worker scan equivalence and cooperative cancellation; the two scanner/worker test files pass all 45 tests. The checkpoint test registrations move to their existing fixture module to stay within the file limit without dropping coverage.pnpm check:changed --base 4ec97ef5e73e0780cb0d9a70d096a1bba5600027completed on the final candidate: all categories pass except the inherited unused-export scans. Both reproduce on the exact parent with identical 28/8 symbol sets and attributed introducing commits. These are existing main regressions. The runtime build also passes. The nine checkpoint cases take 57.24 s including cold compilation (54.17 s Vitest duration, 63% transform and 35% tests); they exercise the actual SQLite lease and lifecycle boundary. The maintainer explicitly accepted the pilot for landing; the incomplete final native campaign remains a measurement limitation, not completed proof.The exact 205 regression lines have a justified allocation record, and the test-line guard passes against the branch parent. Final-head CI run
42859153410passes every job except baseline-ratchets and its dependent CI gate. The exact CI main parentecbad2efa1d7e89d041965612b2237760a024c50independently reproduces 18 lines of debt: 6,632,310 test lines against a 6,632,292 ceiling. #196680 (3686da563c54738b11fac5c9a103ee8b3943b5e6) introduced 21 lines of debt; #196636 and #196742 paid down three. This PR adds 205 test lines and 205 credit, leaving the inherited debt unchanged. This remains a named main regression.Final-head CodeQL and OpenGrep initially completed analysis but failed while uploading SARIF because of GitHub installation API rate limits. Only those failed jobs were rerun after diagnosis; both workflows succeeded on attempt 2. No security exception or alert dismissal was used. ClawSweeper reviewed the final source head and reports zero findings.
Native measurement acceptance, recorded before the campaign
Final performance results are pending. The first complete adaptive/cleanup campaign passed small-workspace latency and large pause goals, but did not establish a CPU improvement over the snapshot-every-command implementation, so it was held. A counterbalanced 20-command metadata pilot reduced command median from 2623 to 2088 ms and cgroup CPU from 4694 to 3346 ms/command; snapshot scan time fell from 1517 to 999 ms. All read checks passed. These are pilot results, not the final acceptance campaign.
The first final-head small campaign was affected by another benchmark becoming active in the shared Docker VM. All consistency checks passed, but the whole attempt is retained as contended evidence, not performance acceptance. Subsequent quiet 10/10 controls still differed by 24.7% in command median, despite only 4.6% CPU variation. Recorded phases place most variation in command/engine control and staging waits; manifest scan stayed at 23 ms. Those controls are retained. One explicitly recorded small-workspace protocol revision uses the unchanged driver with 10 warmup and 50 measured commands per arm (
--requests 5), improving sample resolution without assuming a warmup cause. The large protocol stays 10/10; outcome targets are unchanged. The revised first control passed correctness but failed its independent resource gate: another workload consumed 34.43 CPU-seconds and 563.85 MB reads during 60.22 seconds. No second control or paired campaign followed. All native timing is now idle pending a reserved quiet interval; no favorable subset or repeated-until-green controls will be selected.The selected runtime and extended worker-allocation driver are pinned to
12227a56a740261516bb036efcad77fa8078837f. Fresh full-candidate Codex autoreview is scoped-clean through P2; runtime build, targeted checks and the 205-line test allocation pass. The maintainer accepted the pilot for landing at this exact head under the review/security gates and the documented inherited-CI exception. Pilot command median 2.09 s is below the earlier pre-#196662 baseline of 2.37 s, but that comparison is across campaigns, not a qualified final paired comparison. Pilot pause p95 is 223 ms, cgroup CPU improves 28.7%, and all consistency checks pass. Shared-host noise leaves final two-regime acceptance, worker allocation and writeback diagnostics pending. The committed driver isscripts/perf/local-workspace-checkpoint-measure.ts; writeback diagnostics usescripts/perf/local-workspace-snapshot-writeback.py.Use real Podman+btrfs, 62,000 files/1.1 GB and 100 files/400 KiB, with the same approximately 35 GiB synthetic agent database and 10,000 sessions. Compare pre-#196662 source 3f17d92, shipped 10d6744, and this pinned candidate. Each large formal arm has 10 warm-up and 10 measured mutating commands; the revised small arms have 10 warm-up and 50 measured commands, with canonical and next-guest read checks throughout. Run A/A controls and five counterbalanced baseline/candidate pairs per regime; retain slow and failed arms.
Small-workspace command median must match or improve the pre-change baseline within measured A/A spread, with zero snapshots. Large-workspace pause p95 must be at most 300 ms, with command latency and total CPU materially below the snapshot-every-command implementation. Report remaining differences from the pre-change baseline explicitly. No 20% latency/CPU regression is accepted implicitly.
Include the final cleanup tail outside per-command latency but inside burst CPU/wall accounting. Wait for btrfs kernel deletion work and report whole-VM CPU as well as cgroup CPU, since kernel cleaner work can escape container accounting. Measure allocation separately and keep instrumented profiles out of plain latency results. Dirty-writeback tests compare source churn at 1.7 GB/hour, explicit pre-syncfs, and separately labeled 1.1 GB bursts; they cannot retrospectively attribute an untraced historical pause.
ClawSweeper gate: address every open item by number and obtain zero open items on the final head before merge.