Repository navigation
refactor(sessions): move cold maintenance selection into workers - #163200
Conversation
Keep live work admissions and cooldowns on the host while selecting and rechecking stored protection in the archive worker. Retain logical admission scopes and lexical artifact paths, and use the existing execution owner for ordinary cold maintenance opening. No schema, retention, configuration, or update behavior changes.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 11:34 PM ET / October 2, 2026, 03:34 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch moves cold-transcript discovery, candidate selection, and protection reads into existing database workers while retaining host scheduling and live commit checks. Merge readiness✅ Ready for maintainer review This remains a useful landing candidate: current main still performs cold-maintenance selection on the Gateway thread. No introduced correctness or security defect was found, and the production-boundary evidence covers selection, revocation, rollback, and archive preservation. Priority: P2 Review scores
Verification
How this fits togetherCold storage moves inactive session transcripts from SQLite into compressed archives. Gateway timers and storage requests initiate maintenance; database workers prepare archives and commit changes while the host checks current admissions and configuration. flowchart TD
A[Timer or storage request] --> B[Host maintenance scheduler]
B --> C[Worker store discovery]
C --> D[Worker candidate selection]
D --> E[Archive preparation]
E --> F[Stored ownership and live authority checks]
F --> G[Commit archive or retain transcript]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +201, Tests +261, Other +1. Total +463 across 6 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep cold-maintenance SQL behind the existing worker owners while preserving host admissions, archive compatibility, and transaction-time protection. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the current-main host-side SQLite path, and the supplied baseline control exercises the real maintenance boundary; this reviewer did not execute it. Is this the best way to solve the issue? Yes, extending the existing archive and discovery workers removes the synchronous work without adding a competing scheduler, storage format, or public API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f2b72224a65f. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…nclaw#163200) * refactor(sessions): move cold selection and protection to workers Keep live work admissions and cooldowns on the host while selecting and rechecking stored protection in the archive worker. Retain logical admission scopes and lexical artifact paths, and use the existing execution owner for ordinary cold maintenance opening. No schema, retention, configuration, or update behavior changes. * fix(sessions): retain freelist pragma guard annotation
What Problem This Solves
Enabled cold-storage maintenance runs every 60 seconds and through
sessions.storage.run. Candidate selection, protection scans, target discovery, and cold mutation opening could execute SQLite on the Gateway thread.Related: #163041.
Why This Change Was Made
Extend the existing
cold-preparearchive-worker operation to select candidates from captured admission identities and cooldowns. The host keeps live admissions and single-flight scheduling; the worker owns stored references and deletion snapshots. Mutation rechecks both stored ownership and the host's current authority before committing.Prepare configured targets through the existing inventory/registry readers. Preserve logical admission scopes and lexical SQLite locators for archive files and restore cooldowns. Ordinary maintenance opens its database through the existing agent execution owner. Registry snapshots guard discovery; physical source and execution claims guard writes, including integrity-triggered re-registration.
User Impact
Cold-storage maintenance moves SQLite selection off the Gateway thread while retaining existing archive ordering, budgets, and admission protections.
Evidence
Coordinator-reviewed head:
19c648991c6e0e54d3f88fff51815cf42667504d, after mergingd4b98b3a5101349febc02ae14b828f689f7b8538from main without conflicts.All 72 focused tests passed on that head. Serial local invocations used
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000and/usr/bin/time -p; wall times include the pnpm wrapper and compiled-worker preparation:pnpm test src/config/sessions/session-cold-storage.test.ts --maxWorkers=1pnpm test src/config/sessions/session-cold-storage.selection.test.ts --maxWorkers=1pnpm test src/config/sessions/session-cold-storage.admission.test.ts src/config/sessions/session-cold-storage-eligibility.test.ts src/config/sessions/session-cold-storage.preflight.test.ts src/config/sessions/session-cold-storage.publication.test.ts src/gateway/session-cold-storage-maintenance.test.ts --maxWorkers=1The selection tests exercise real worker boundaries and use deferred gates for ordering; no sleeps or timer polling were added. The original tests exposed the defects described below and were repaired before this final run.
Testbox did not execute the test commands: its assigned job was canceled before any steps while the provider kept reporting the lease as queued. The lease is confirmed completed; the final proof above comes from the supported local fallback.
node scripts/worktree-setup.mjs gateway: passed on the merged head (build 8m28.9s; dependency setup 23.7s).node scripts/check-changed.mjs -- scripts/database-worker-inventory.mjs src/config/sessions/session-cold-storage.ts src/config/sessions/session-cold-storage-worker.ts src/config/sessions/session-cold-storage-selection.ts src/config/sessions/session-cold-storage.selection.test.ts src/config/sessions/session-cold-storage.test.ts: passed, exit 0. This includes core and all core-test type-check shards, touched-file lint/formatting, dead-export scans, runtime cycle checks, and selected repository guards.pnpm check:database-worker-ratchet --base 786a6b56e8c8b7f2b9b0bf154db179c3e833efd2: passed.pnpm check:madge-import-cycles: passed, zero cycles.node scripts/database-worker-inventory.mjs --json: measured the original base and candidate; owner T1 6→1. The new selection kernel contributes 3 worker-tier calls; cold worker calls 18→19.PR CI on
19c648991c6e0e54d3f88fff51815cf42667504dran and passed the cold-storage suites: core 23 tests (48.65 s), selection 5 (8.11 s), admission 1 (5.26 s), eligibility 16 (0.73 s), preflight 13 (2.51 s), publication 7 (2.69 s), lifecycle 18 (14.36 s), and backup 6 (18.10 s). See CI run 36958544766.Landing correction
37738d8e09fee92acc612e13eb272d04ed7cd2ebmoves the existing raw-SQLite allowance comment directly above its freelist PRAGMA call. The extraction had separated them, causinglint:kyselyto fail; executable code is unchanged. The failure reproduced locally, and the corrected Kysely guard passed. The five selection tests passed again (99.48 s wall, including worker preparation); independent Codex review of the correction found no actionable P0–P2 issues. Exact-head CI run 36959614441 passed, including the previously failing architecture guard. Its logs confirm all 65 focused cold-storage tests: core 23 (50.34 s), selection 5 (9.16 s), admission 1 (4.81 s), eligibility 16 (0.658 s), preflight 13 (2.60 s), and publication 7 (2.52 s). Additional lifecycle, inventory, read, synchronous-write, transcript-turn, and backup suites also passed. The unchanged seven Gateway timer tests retain the prior local proof; this CI run did not select that file. The initial PR context check also rejected the problem heading; the body now uses the required template headings.The baseline control ran the new logical-admission boundary test with the two original cold-storage implementation files from
786a6b56e8c8b7f2b9b0bf154db179c3e833efd2; it failed only the zero-SQLite assertion (29 prepares, 20 gets, 7 iterates, 4 alls, 2 opens, 1 exec, 1 close). The final tests additionally cover delayed admissions, unrelated work, configuration revocation, worker rejection, lexical file aliases, and embedded-archive ownership changes.The broader local run exposed a real discovery/writer lifetime error during forced integrity verification: re-registration invalidated the discovery memo. The fix limits that witness to discovery and retains live source/execution guards for writes. Tests still prove rollback and exact archive-worker exit, while permitting the separately owned shared actor to remain idle.
Worker classification trace:
session-accessor.sqlite-archive.worker.tsdispatchescold-preparetoprepareSessionColdBatchInWorker, which calls the new selection kernel and admission-key reader.cold-mutatereachesmutateSessionColdTranscriptInWorkerthrough the existing mutation-worker port and calls the same admission-key reader inside its transaction. These are the only production callers of the new module's SQL functions; no existing mixed kernel was reclassified.Compatibility retained
No public SDK contract changed. The private
SessionColdBatchInputtype moved from the archive-worker module to the selection kernel; no runtime function export was deleted. The synchronous host selection, existence probe, and protection closures were removed. The shared snapshot/reference kernels still serve their other callers. Existing incognito, restore, and explicit Doctor/maintenance native ownership is retained.Update behavior
No schema, stored-byte format, retention, durability, configuration, or permission changes. Existing installations and updater/Doctor behavior are unchanged.
Overlapping open PRs
#157922 replaces the archive-size constant in
prepareSessionColdBatchInWorkeranddecodeSessionColdRecordsfor usage date filtering. Its goal is independent; this change leaves those constants intact.