Repository navigation
Conversation
Commit and publish archive state before waking the existing background maintenance owner after the response. Preserve early and in-flight unarchive, source custody, and snapshot finalization after deletion. Separate registered removal from creation with per-checkout leases and worker-backed disk admission. Keep byte debt until native work settles, retry failed releases, and retain borrowed Git sources through creation and restoration. Refresh queued restore facts under its held leases. Compiled-Gateway measurements use 5,000 sessions, 50 real worktrees, and 150 archive calls per variant. Archive p99 meets the 100 ms target, and all 150 dirty worktrees restore after automatic cleanup. Full before/after measurements and revision-bound proof are in the PR.
|
🦞👀 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. Reviewed October 4, 2026, 10:56 AM ET / 14:56 UTC (Revision 2). ClawSweeper reviewWhat this changesSession archiving responds after committing and publishing its state, then schedules background checkout cleanup while preserving restoration and concurrent disk admission. Merge readiness✅ Ready for maintainer review The prior CLI finding is fixed, and no remaining actionable correctness defect was found. Current main still performs inline archive cleanup, so this PR remains useful. Recorded runtime proof supports the improvement; pending CI remains an ordinary landing gate. Likely related people: steipete (high confidence, verified prior worktree and cleanup contributions). Priority: P2 Review scores
Verification
How this fits togetherThe Gateway stores session archive requests and publishes their results to clients. Managed-worktree maintenance then snapshots and removes retired Git checkouts, retaining the information needed to restore saved work. flowchart TD
A[Archive request] --> B[Authorize and commit session state]
B --> C[Publish state and respond]
C --> D[Background maintenance]
D --> E[Check session and checkout custody]
E --> F[Snapshot and remove checkout]
F --> G[Retained restore snapshot]
G --> H[Unarchive and restore]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +886, Tests +1199, Docs +2, Other -2. Total +2085 across 72 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one background maintenance owner for retired checkouts, with durable archive state, lossless snapshots, and session-scoped restore fencing. Do we have a high-confidence way to reproduce the issue? Yes—the supplied compiled-Gateway workload measures the archive delay, and current-main source confirms the inline cleanup path. This read-only review did not rerun it. Is this the best way to solve the issue? Yes—the change uses the existing maintenance owner and removes synchronous archive cleanup while retaining checkout, source, and restore custody. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e785c56d8207. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Remove upward type-only capacity imports without changing emitted runtime JavaScript. Preserve CLI cleanup assertions while allowing the owning maintenance callback, and adapt project authority fixtures to worker-backed lease storage while retaining their real lifecycle and admission checks. Supply prepared placement observations in the existing dispatch fixture. Preserve real module exports in authority mocks and remove four obsolete baseline entries without adding isolation exceptions.
Merge current main to incorporate the independently diagnosed prepareRuntimeRefresh fixture repair from #164938. Preserve the compound 3b worker lifecycle, native deletion, and exact transcript rewrite cutover. The merge is conflict-free and retains the previous candidate's stable patch ID. Refresh focused integration, SDK, and published-driver update proof for the new surrounding worktree and placement owners.
Follow up #164938 (339c4da), which moved managed-worktree allocation to worker-backed leases. The shared-state codec admitted lock errors but dropped unmarked non-lock SQLite errors. Losing errcode prevented lease acquisition from reporting the original storage failure. Admit the existing validated numeric result code in both codec directions. Keep acquisition classification and outcome-unknown handling unchanged. Cover NOTADB and extended IOERR in the existing transport table, retain ordinary-error opt-in coverage, and document admission diagnostics. No schema, persistence, or update migration changes are required. The original native provisioning case reproduced its missing outcome on main. All 58 transport tests pass. The unchanged native provisioning file passes all 15 tests in 76.48s wall when run alone; an earlier concurrent run exceeded its unchanged 120s deadline. Changed-file checks pass, including core production and all 27 test type graphs. Independent Codex review through P2 found no actionable findings.
…w#164938) * perf(sessions): return archive responses before worktree cleanup Commit and publish archive state before waking the existing background maintenance owner after the response. Preserve early and in-flight unarchive, source custody, and snapshot finalization after deletion. Separate registered removal from creation with per-checkout leases and worker-backed disk admission. Keep byte debt until native work settles, retry failed releases, and retain borrowed Git sources through creation and restoration. Refresh queued restore facts under its held leases. Compiled-Gateway measurements use 5,000 sessions, 50 real worktrees, and 150 archive calls per variant. Archive p99 meets the 100 ms target, and all 150 dirty worktrees restore after automatic cleanup. Full before/after measurements and revision-bound proof are in the PR. * fix(worktrees): repair archive cleanup CI contracts Remove upward type-only capacity imports without changing emitted runtime JavaScript. Preserve CLI cleanup assertions while allowing the owning maintenance callback, and adapt project authority fixtures to worker-backed lease storage while retaining their real lifecycle and admission checks. Supply prepared placement observations in the existing dispatch fixture. Preserve real module exports in authority mocks and remove four obsolete baseline entries without adding isolation exceptions.
Follow up openclaw#164938 (c6b10b3), which moved managed-worktree allocation to worker-backed leases. The shared-state codec admitted lock errors but dropped unmarked non-lock SQLite errors. Losing errcode prevented lease acquisition from reporting the original storage failure. Admit the existing validated numeric result code in both codec directions. Keep acquisition classification and outcome-unknown handling unchanged. Cover NOTADB and extended IOERR in the existing transport table, retain ordinary-error opt-in coverage, and document admission diagnostics. No schema, persistence, or update migration changes are required. The original native provisioning case reproduced its missing outcome on main. All 58 transport tests pass. The unchanged native provisioning file passes all 15 tests in 76.48s wall when run alone; an earlier concurrent run exceeded its unchanged 120s deadline. Changed-file checks pass, including core production and all 27 test type graphs. Independent Codex review through P2 found no actionable findings.
What Problem This Solves
Archiving a session waits for snapshotting, Git removal, and contention on the worktree creation lease before returning to the user.
User Impact
Archive commits and publishes session state, responds, then wakes background cleanup. Unarchive before cleanup keeps the checkout; unarchive during cleanup waits for its finalized snapshot and restores it. Conversation state, dirty files, worktree bindings, and snapshot retention remain intact. No configuration or schema migration is required.
Why This Change Was Made
Existing
archivedAtmetadata marks retirement. The maintenance owner from #164758 handles immediate notification, coalesced follow-up sweeps, periodic cleanup, and shutdown. The synchronous archive cleanup path is removed. Worker settlement follows #164824: structured registry predicates, live lease admission at transaction and commit, native receipts, and retention of uncertain outcomes.Registered removal holds its session and per-checkout custody. Worker-backed disk reservations account for concurrent writes across processes, so unrelated creation can proceed when space permits. Creation and restore retain borrowed Git sources, and nested restore retains both creation and mutation leases. Once deletion is admitted, terminal snapshot settlement survives caller cancellation. Failed reservation releases retry at later admission or maintenance.
Production source is +1,670/-784, net +886 lines. Growth preserves three contracts when cleanup and creation overlap: cross-process disk admission, borrowed Git-source lifetime, and lossless finalization after deletion. Superseded inline cleanup and duplicate temporary source leases are removed. The requested filter (
git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*') is +1,718/-802, net +916, including tooling and the shared test fixture.Evidence
Compiled-Gateway proof on an isolated Linux rig (8 CPUs, Node 26.8.1), with 5,000 durable sessions, 50 real Git worktrees, and 150 archive calls per variant. One persistent
GatewayClientWebSocket connection, three rounds, no archive warmup or excluded samples. Timing ends at the actual response.Base:
33bf4664a0e9d4d84dfa797296e6b6c5b464d6e2. Measured candidate tree:423dae8ff688da54d8fed4cfb0d9ebd581be9926.P99 fell 93.2% (14.61×). Every candidate response was below 100 ms. All 150 automatic removals and dirty-file restores passed. Both isolated Gateways stopped. An earlier baseline run measured 1,200.674 ms p99; the table uses the faster baseline rerun, which corrected the memory sampler to follow the Gateway runtime instead of the CLI launcher. RSS is the Gateway process's kernel high-water mark, including worker threads and excluding child processes; the observed difference is -16.0 MiB (-1.1%). These are synthetic measurements on a shared host, not live deployment evidence.
Runtime builds passed for baseline and candidate using
nice -n 10 ionice -c3 node --import ./scripts/tsx.mjs scripts/build-all.mts sourcePerformance(1m10.0s and 1m23.3s). The driver wasnode --import ./scripts/tsx.mjs .rig/final-archive-real-gateway.mjs, with task-localTMPDIRand loopback port 19542.Initial validation used
blacksmith-testbox/openclaw-check, leasetbx_01m43fzfnrbwczs25fhb45q4kk(run). The source capsule verifies the exact candidate tree and 69 paths. Initial passing coverage totals 552 tests across 43 files, with one platform skip, after three test-only corrections: scope the worker-admission SQL observer to the checkout's mutation lease, supply the independent disk-admission callback in the upstream snapshot-receipt fixture, and await the asynchronous claim/release in a capacity regression. The focused corrected archive case passed in 36.20s; the 29-file worktree/core run passed 462 tests in 477.69s. The negative control restores a native registry guard inside worker grants and fails the corrected assertion as intended.Independent P0–P2 review is complete. Its one fixture-caller finding is fixed, and follow-up review of all three test corrections is clean. Initial published head:
36217d714a7d5910a0d5e234e6696f2748d2bac7(treeb6fa1c3f46df83725a37fd3e2e26f931aa419c4b); only those three test files differ from the measured candidate. All required changed-file checks completed: production types, all core test-type groups, script types, three export scans, core/script lint, formatting, and repository guards. The final exact-source run exited 0 in 309.846 runner seconds. The canonical plan resumed at the failed test-type and lint boundaries after the fixture corrections; preceding checks remained valid. The lease is stopped. No local tests, types, builds, or lane classification ran on the constrained Mac. Native macOS/Windows performance measurements and production deployment are outside this Linux rig proof. Final current-head CI results are recorded below.pnpm test src/agents/worktrees/capacity.worker.test.ts --maxWorkers=1pnpm test src/gateway/server.sessions.archive-worktree-lifecycle.test.ts --maxWorkers=1pnpm test src/agents/worktrees/service.capacity.test.ts -t "reconciles a missing owned checkout" --maxWorkers=1pnpm test test/scripts/eager-import-closure.test.ts -t "PR wrapper inventory" --maxWorkers=1These timings describe selected coverage counted above. Testbox results refer to wrapper command exits; stopping the lease can mark its linked Actions run cancelled.
CI repair
The first PR CI run (37207389554) found a type-import cycle and three stale test fixtures. The capacity helper now uses its own disk-admission type, CLI tests retain required behavior without enumerating every internal callback, and project-authority tests use the real async lease lifecycle over synthetic storage. The dispatch fixture now supplies prepared placement observations required by a pre-existing runtime contract. Four obsolete mock-export baseline entries were removed; no exceptions were added.
Repair validation uses
blacksmith-testbox/openclaw-check, leasetbx_01m43kndgd96s06v4v8s9e7eye(run).pnpm check:architecturepassed with zero runtime or Madge cycles. Focused runs passed CLI 14, capacity/owner 24, project authority 15, and dispatch demand 2 tests. CLI, authority, and dispatch add 31 tests across 3 files beyond the initial coverage. Independent review of the final five-file repair is clean at P0–P2.pnpm test src/cli/worktrees-cli.test.ts --maxWorkers=1pnpm test src/projects/project-registry.authority.test.ts --maxWorkers=1pnpm test src/gateway/server-methods/sessions.dispatch.demand.test.ts --maxWorkers=1The capacity change is type-only: esbuild 0.28.2 emits byte-identical JavaScript before and after (SHA-256
89c3f657c000a9c16f57b36237587e6bf269deaca4e4a00dd096550aa549dc77). These CI repairs preserve the measured runtime. Final head:abb347af656fbc1d2cf8a0ea5950c76367f322d8; repair tree:bcd5dd399220aa22477ca513ad14288b26f49f71(72 intended PR paths). The canonical commandnode scripts/check-changed.mjs --timed -- src/agents/worktrees/capacity.ts src/cli/worktrees-cli.test.ts src/projects/project-registry.authority.test.ts src/gateway/server-methods/sessions.dispatch.demand.test.ts config/test-mock-exports-baseline.txtpassed every selected check, including production types, all 27 core test-type groups, three export scans, lint, formatting, and repository guards. The final command (including the authority test rerun) exited 0 in 1,450.981 command seconds / 1,454.976 runner seconds. Across the initial and repair proof, 583 focused tests in 46 files passed, with one platform skip.The repair lease is stopped. Current-head CI run 37210713549 completed successfully on
abb347af656fbc1d2cf8a0ea5950c76367f322d8: 80 successful jobs, 21 skipped, 14,784 summed job-execution seconds. The final PR check rollup is 104 passed, 48 skipped, zero failures or pending checks;openclaw/ci-gateis successful. A transient dependency-review status resolved on the same head to “No dependency changes require review,” without a workflow rerun. No merge or auto-merge command was issued.