Repository navigation
refactor(sessions): move cold inventory and restore keys to workers - #163041
Conversation
Read durable cold-storage status through the existing discovery and history workers. Preserve process-held incognito counts with the same snapshot kernel, and retain current source ownership through asynchronous filesystem reads. Publish restored session keys from committed worker receipts and recheck authority before notifications and RPC responses. No schema, retention, configuration, or update changes.
# Conflicts: # src/gateway/session-cold-storage-maintenance.test.ts
|
🦞👀 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 1, 2026, 6:44 PM ET / 22:44 UTC (Revision 2). ClawSweeper reviewWhat this changesMoves durable session archive inventory and restored-session key reads into existing workers while preserving storage status and observer notifications. Merge readiness✅ Ready for maintainer review This PR remains useful: current main and the latest release still perform the targeted reads on the Gateway thread. No actionable introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherSession cold storage archives inactive conversation transcripts and restores them when needed. Gateway storage requests consume its inventory, while successful restores notify session observers. flowchart TD
A[Storage status request] --> B[Configured store discovery]
B --> C{Store lifetime}
C --> D[Durable history worker]
C --> E[Process-held incognito reader]
D --> F[Storage status response]
E --> F
G[Restore worker receipt] --> H[Current-owner notification]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +212, Tests +425. Total +637 across 16 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep durable reads in the existing workers and publish committed restore facts through the current lifecycle owners, retaining native incognito behavior. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main directly performs the targeted inventory and restored-key SQLite reads on the caller thread. Runtime reproduction was not executed during this read-only review. Is this the best way to solve the issue? Yes. The patch extends existing discovery, history, and restore workers rather than adding a competing storage owner, and preserves the inventory snapshot and native incognito contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6d5bb1bd3bd4. LabelsLabel changes: No label 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)
|
|
Merged via squash.
|
…penclaw#163041) * refactor(sessions): move cold inventory and restore receipts to workers Read durable cold-storage status through the existing discovery and history workers. Preserve process-held incognito counts with the same snapshot kernel, and retain current source ownership through asynchronous filesystem reads. Publish restored session keys from committed worker receipts and recheck authority before notifications and RPC responses. No schema, retention, configuration, or update changes. * test(sessions): align cold inventory proofs with worker reads
What Problem This Solves
Cold-storage status resolved stores and queried inventory on the Gateway thread. Successful restores then queried the session key again on that thread before notifying session observers.
Why This Change Was Made
Resolve configured stores and read durable inventory through the existing history worker. Keep the three counters in one SQLite snapshot, preserve missing-store zero values and schema errors, and retain source ownership through asynchronous filesystem sizing. Both storage RPCs recheck request authority before responding or scheduling maintenance.
Return the restored session key from the admitted worker transaction and publish it only after successful settlement and current-owner checks. The status owner is separated from maintenance; its old internal export is removed and every caller moves to the new owner. No compatibility alias remains.
User Impact
Durable status inventory executes zero parent-thread SQLite primitives in the real entry-point test. Restore publication no longer performs its own host-side key lookup. Timer selection/protection is unchanged.
session-cold-storage.tssession-cold-storage-inventory.tssession-cold-storage-worker.tssession-transcript.worker.tsOwner T1 total: 11 → 9. The three shared inventory queries remain T1 because configured incognito stores use their existing process-held database. No inventory classifications were changed. Other touched production files have zero measured primitive calls.
Production delta: +353 / −141 / net +212 lines, against merged main
74a47d542ee3e32ae5f4ffe53d4a45f619a01900. Nine production files and seven test files changed. No schema, retention, durability, configuration, or permission changes.Evidence
40 focused tests passed on the integrated source. Every test invocation used
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000and--maxWorkers=1.session-cold-storage.inventory.test.tssession-cold-storage.publication.test.tssession-cold-storage-maintenance.test.tssession-cold-storage.test.tssession-accessor.sqlite-cold-read.test.tssession-activity-summaries.test.tssession-transcript-runtime.catalog.test.tssession-cold-storage.preflight.test.tsWall times include worker-generation verification, transformation, fixture admission, and cleanup on the loaded macOS host. The unchanged restore cases exercise real archive bytes, projections, commit revocation, and schema failures; mocks cannot prove those storage contracts. Only the relevant cases ran in the larger existing files. CI timings are not yet available.
The new inventory tests cover durable worker routing without parent SQLite, configured shared/missing stores, native incognito absence/presence and retirement during filesystem work, foreign externalization, source replacement, and worker rejection. The shared-kernel race test preserves coherent hot/cold counts across a foreign archive commit. Publication tests cover delayed receipts, exact committed keys, rejection/refusal, incomplete cleanup, and retired caller/request/database authority. The publication regression fails on the pinned host implementation with the intended calling-thread SQLite error (8.93 s negative-control wall time).
Exact focused test commands
Validation gates:
node scripts/check-changed.mjs --base 74a47d542ee3e32ae5f4ffe53d4a45f619a01900: passed (formatting, core/test types, lint, and all selected guards).pnpm check:database-worker-ratchet --base 98e86147b19c120d800dab559897276a582446da: passed after integration.pnpm check:madge-import-cycles: passed, zero cycles.node scripts/database-worker-inventory.mjs --json: captured on the pinned base and final branch, filtered to the owner files above.git diff --numstat 74a47d542ee3e32ae5f4ffe53d4a45f619a01900...HEAD: production sum above; tests/support/docs excluded.Initial validation exposed a dispatcher size limit, an unused heavy test import, and a test-only promise annotation; each was corrected. The inherited stale max-lines entry was fixed by main commit
ccbd3b58f294, included in the integration. Testbox source staging did not dispatch a command and its lease was stopped; all reported test proof is local. No CI reruns or proof-only re-pushes were used.Compatibility retained
Configured
INCOGNITOlocators keep their existing process-held database and return zero counts without creating a missing handle or file. The shared synchronous inventory kernel is retained for this explicit native-lifetime contract; durable stores always use the worker and never fall back after failure. Existing timer/protection and incognito preflight paths remain outside this cutover. No public Plugin SDK export is removed.Update behavior
Stored bytes, schemas, admission/migration behavior, archive layout, and updater/Doctor behavior are unchanged. There is no data migration or new configuration to apply.
Overlapping open PRs
SessionTranscriptWorkerInput/values and the worker dispatch callback, for fork reply selection.These are different operations; the overlapping reader/dispatcher hunks remain narrow. Main's maintenance-test setup changes from #162792 and #162964 were preserved when resolving the integration conflict.