Skip to content

refactor(sessions): move cold inventory and restore keys to workers - #163041

Merged
steipete merged 3 commits into
mainfrom
dbasync/cold
Oct 1, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/cold

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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.

Measured owner Tier Pinned base This branch
session-cold-storage.ts T1 11 6
session-cold-storage-inventory.ts T1 0 3
session-cold-storage-worker.ts W 15 18
session-transcript.worker.ts W 10 9

Owner 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=1800000 and --maxWorkers=1.

Test file Result Command wall time
session-cold-storage.inventory.test.ts 5 passed 435.57 s
session-cold-storage.publication.test.ts 7 passed 12.98 s
session-cold-storage-maintenance.test.ts 7 passed 223.79 s
session-cold-storage.test.ts 5 passed 253.60 s
session-accessor.sqlite-cold-read.test.ts 1 passed 176.87 s
session-activity-summaries.test.ts 1 passed 358.82 s
session-transcript-runtime.catalog.test.ts 1 passed 272.99 s
session-cold-storage.preflight.test.ts 13 passed 209.81 s

Wall 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
pnpm test src/config/sessions/session-cold-storage.inventory.test.ts --maxWorkers=1
pnpm test src/config/sessions/session-cold-storage.publication.test.ts --maxWorkers=1
pnpm test src/gateway/session-cold-storage-maintenance.test.ts --maxWorkers=1
pnpm test src/config/sessions/session-cold-storage.test.ts --maxWorkers=1 -t 'restores exact history and projections|reader is revoked|rejects unmigrated or damaged'
pnpm test src/config/sessions/session-accessor.sqlite-cold-read.test.ts --maxWorkers=1 -t 'counts hot and cold transcripts in one snapshot'
pnpm test src/gateway/session-activity-summaries.test.ts --maxWorkers=1 -t 'backfills a cold archived transcript'
pnpm test src/plugin-sdk/session-transcript-runtime.catalog.test.ts --maxWorkers=1 -t 'keeps cold transcript listings available'
pnpm test src/config/sessions/session-cold-storage.preflight.test.ts --maxWorkers=1

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.
  • Codex autoreview, branch mode against the same merge base, high reasoning, P0–P2: scoped-clean, no accepted/actionable findings.

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 INCOGNITO locators 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

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.

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
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL labels Oct 1, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 6:44 PM ET / 22:44 UTC (Revision 2).

ClawSweeper review

What this changes

Moves 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
Reviewed head: 3ede7481eefeb2c0e08923482f47ebea5c9751d2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent worker cutover with useful focused validation and no concrete blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified repository-admin authorship exempts ordinary contributor proof. The body reports focused production-worker inventory tests and restore regressions; publication receipt tests use mocks and are supplemental. No schema or stored-data representation changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository-admin authorship exempts ordinary contributor proof. The body reports focused production-worker inventory tests and restore regressions; publication receipt tests use mocks and are supplemental. No schema or stored-data representation changes require migration proof.
Evidence reviewed 9 items Pinned introduction: Reviewed the merge-base-to-head production and test changes using the host-pinned identities, rather than treating base-branch drift as PR edits.
Still necessary on current main: The fetched main implementation still queries session_windows on the host after a successful restore and performs cold-storage inventory synchronously through its read-only database helper.
Latest-release comparison: v2026.9.7 also retains the host-side restored-key lookup and synchronous inventory implementation; this is not already-shipped cleanup.
Findings None None.
Security None None.

How this fits together

Session 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +212, Tests +425. Total +637 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 9 353 141 +212
Tests 7 468 43 +425
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 821 184 +637

Review metrics

Metric Value Why it matters
Production versus test growth production net +212 lines; tests net +425 lines Production growth has a stated purpose: separating status ownership and retaining source and lifecycle checks across worker reads.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded improvement to Gateway database execution with no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-admin authorship exempts ordinary contributor proof. The body reports focused production-worker inventory tests and restore regressions; publication receipt tests use mocks and are supplemental. No schema or stored-data representation changes require migration proof.

Evidence

What I checked:

  • Pinned introduction: Reviewed the merge-base-to-head production and test changes using the host-pinned identities, rather than treating base-branch drift as PR edits. (3ede7481eefe)
  • Still necessary on current main: The fetched main implementation still queries session_windows on the host after a successful restore and performs cold-storage inventory synchronously through its read-only database helper. (src/config/sessions/session-cold-storage.ts, 6d5bb1bd3bd4)
  • Latest-release comparison: v2026.9.7 also retains the host-side restored-key lookup and synchronous inventory implementation; this is not already-shipped cleanup. (src/config/sessions/session-cold-storage.ts:511, c074824a27c9)
  • Inventory ownership and settlement: Durable stores use retained history-worker readers. Incognito stores borrow only existing native handles. All filesystem sizing settles before current-source and retained-owner checks, and claims release in finally. (src/config/sessions/session-cold-storage-status.ts:96, 3ede7481eefe)
  • Committed restore facts: The existing restore transaction now selects its session key before the commit checkpoint. The host rejects incomplete cleanup and rechecks database, request, and caller authority immediately before emitting the notification. The key is notification data, not a new authorization capability. (src/config/sessions/session-cold-storage-worker.ts:582, 3ede7481eefe)
  • Focused validation context: The captured PR body reports 40 focused passing cases, a failing baseline publication control, measured command costs, and passing changed-file, worker-ratchet, and cycle checks. Inspected tests cover actual durable worker routing, missing stores, incognito lifetime, foreign commits, source replacement, and mocked publication settlement. No tests were executed during this read-only review. (src/config/sessions/session-cold-storage.inventory.test.ts:63, 3ede7481eefe)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-01T22:28:15.913Z sha 3ede748 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit c3f2837 into main Oct 1, 2026
142 of 143 checks passed
@steipete
steipete deleted the dbasync/cold branch October 1, 2026 23:47
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant