Repository navigation
refactor(sessions): move conversation reads into workers - #163208
Conversation
Read conversation lists, standalone send/turn addresses, and manual-compaction primary bindings through the existing history worker. Retain source custody through discovery and cleanup, current route checks, and native incognito reads. Keep getConversationSession synchronous for the public plugin SDK. Transaction and delivery authority guards remain native pending the S10 entry-patch cutover. No schema, stored data, migration, retention, or permission 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. |
|
Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 4:57 AM ET / 08:57 UTC (Revision 9). ClawSweeper reviewWhat this changesMoves conversation listing, address lookup, and manual-compaction binding reads into the existing session history worker so SQLite work yields off the Gateway thread. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main still performs these conversation reads synchronously. The pinned diff preserves the query kernel, SDK compatibility, and delivery authority checks; no actionable introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe conversation registry maps channel addresses to current session bindings. Gateway listing, sending, turns, and compaction consume those records while channel routing and delivery owners enforce current authority. flowchart TD
A[Gateway conversation requests] --> B[Resolve logical and physical store]
B --> C{Durable or incognito}
C --> D[Session history worker]
C --> E[Process-held incognito reader]
D --> F[Shared conversation query]
E --> F
F --> G[Current source and route checks]
G --> H[Listing delivery or compaction]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +126, Tests +241. Total +367 across 23 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep independent durable reads on the existing history worker, with transaction-local authority checks and shipped synchronous SDK callbacks retaining their current owners. Do we have a high-confidence way to reproduce the issue? Not applicable as a specific bug reproduction: current-main source establishes the synchronous reads being migrated, and recorded production-boundary execution verifies the cutover. Is this the best way to solve the issue? Yes. Reusing the existing worker and unchanged query kernel is a narrow solution that preserves synchronous SDK and transaction-local contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a9442b7a6da4. 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 (8 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Resolve overlap with the conversation delivery worker cutover while retaining both worker operations and async read callers. Focused composed proof: 72 tests across five files passed in 185.34 seconds wall; production types, targeted lint, database worker ratchet, import cycles and isolated autoreview passed.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Integrate main dbb580a. All 76 focused S14 and category-projection cases passed; the prior WAL SQL-budget failure no longer reproduces. Independent review is scoped-clean through P2. The inherited duplicate logger trace property is corrected by main d81a2d8 and will be integrated before publication.
Integrate main 0f470ae, including d81a2d8 which removes the inherited duplicate logger trace. Production typechecking and the database-worker ratchet pass. The S14 patch is byte-identical to the independently reviewed and focused-tested composition; incoming changes are the logger correction and disjoint type-only custody refactoring.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Integrate main 18ad182 including 0a188c4. Preserve both inventory and conversation worker interfaces. The declaration case independently failed on CI main parent 0fc181d and passes after this integration. Worker/registry proof: 23 tests passed; exact declaration regression passed; production types and isolated review through P2 passed.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…3208) * refactor(sessions): move conversation reads into workers Read conversation lists, standalone send/turn addresses, and manual-compaction primary bindings through the existing history worker. Retain source custody through discovery and cleanup, current route checks, and native incognito reads. Keep getConversationSession synchronous for the public plugin SDK. Transaction and delivery authority guards remain native pending the S10 entry-patch cutover. No schema, stored data, migration, retention, or permission changes. * test(sessions): await conversation reads in account history proof
Landed
Merged as
745421393a55e5617e2c4d5f5e0dc085560228c2on October 2, 2026. The final reviewed head was016947ff4574d4050819ce73afd0d0638347dd4b.Final CI run 36986417642 succeeded on its first attempt: all 77 jobs were terminal with no failures. Exact-head ClawSweeper review completed at 08:57 UTC with no findings. Native review, GitHub-pending preparation, merge admission, and the exact-head merge receipt completed successfully. No admin exception or CI rerun was needed for the final head.
The earlier failures, their bounded investigations, main-owned repairs, scoped proof and source identities are retained below as historical landing evidence.
Updated landing head
Current head:
016947ff4574d4050819ce73afd0d0638347dd4b. This merge incorporates main18ad182a8e6f, including0a188c4f038f(include required normalization exports in declaration fixtures). The sole merge conflict was in the history-worker types; both main's inventory interfaces and S14's conversation operation remain present. No rebase or admin merge was used.The prior-head CI run 36983182194 failed
test/scripts/write-unified-entry-dts.test.ts, case “reuses unaffected canonical groups while rebuilding runtime after input edits,” because the synthetic normalization package omitted./record-coerce. This was independently reproduced on its exact main parent0fc181d08277a2d1034235a85ca6a181a4de605fin a separate worktree, with the same Node 24.21.0 subprocess error. The sole test failure caused five fail-fast cancellations and the aggregate-gate failure. Main's correction landed before exception submission, so it was integrated instead.On the new composition, 23 tests across the worker boundary, registry, and worker-reader suites passed in 244.68 seconds wall. The exact formerly failing declaration case passed in 70.99 seconds wall (the other ten file cases were intentionally excluded by the name filter). Production types and whitespace checks passed, and fresh isolated Codex autoreview against the incorporated main was scoped-clean through P2. The earlier 76-case S14/category proof below retains its stated source context. The S14 diff remains 23 files, +478/-111.
A fresh CI run and exact-head ClawSweeper review are required for this published head. All earlier landing candidates and CI failures below are historical evidence.
Current landing candidate
Head
24a9f58fcf52d0e1e87e406af5f008996b7f1b5eintegrates main through0f470aecdc12via merge commits, without rebasing. It includesdbb580aed3e7, which repairs the unrelated WAL tick fixture by controlling GatewayScheduler timeouts without changing the SQL observer. It also includes main'sd81a2d8b7294correction for an inherited duplicate loggertraceproperty found by local typechecking.All 76 tests in six focused suites passed: conversation worker-boundary, send, turn, delivery-store, registry, and category projection. Command:
node scripts/run-vitest.mjs src/gateway/conversation-list.worker-read.test.ts src/gateway/conversation-send.test.ts src/gateway/conversation-turn.test.ts src/config/sessions/conversation-delivery-store.test.ts src/config/sessions/conversation-registry.test.ts src/gateway/session-row-projection.category.test.ts --maxWorkers=1; wall 531.30 seconds on the loaded macOS host. The formerly failing category case passed in 35.145 seconds, beyond the WAL tick interval.Production typechecking, the database-worker ratchet, and whitespace checks passed after integrating the main-owned type correction. Fresh isolated Codex autoreview against the incorporated WAL-fix main was scoped-clean through P2. The subsequent nine incoming files were inspected (one-line harness correction and disjoint type-only custody refactoring); the entire S14 diff against main is byte-identical before and after that integration, so the scoped review and behavioral proof remain applicable. S14 remains 23 changed files, +478/-111; its production change is unchanged.
This new head starts a fresh CI run. Prior-head failures and their investigations below remain historical evidence. The coordinator authorizes one REST job rerun per known Bun UI GC, Windows skills-watcher, or Windows ACP-initialization flake, with its cause/known uncertainty recorded. Main's WAL-fixture repair supersedes the prior identical-repeat stop.
What Problem This Solves
Maintainer-requested S14 database-worker cutover. Conversation listing, standalone send/turn lookups, and manual-compaction primary-address reads execute SQLite on the Gateway thread. Resolving custom/shared store ownership also performs synchronous reads before the address query.
User Impact
This is an internal database-access change with no intentional user-visible behavior change. Conversation ordering, routing and binding contracts are preserved.
Why This Change Was Made
Solution: Use the existing session history worker for list, exact-address, and primary-binding selections, preserving the connection-bound query kernel. Async callers prepare physical store ownership through the existing worker discovery path, retain the logical agent and captured physical source, and recheck authority after awaited work. The Gateway list filters using current route configuration after the read; send and compaction recheck cancellation.
Impact
Only independent reads move in this slice. Address registration, delivery writes, and transaction-local authority remain with their current owners. Incognito databases retain their process-held native reader.
The migrated durable reads execute in the existing history worker; the calling thread awaits records. The real Gateway list/primary/exact-read boundary test observes zero caller-thread SQLite calls.
conversation-registry.tssession-accessor.sqlite-conversation-read.tssession-accessor.sqlite-conversation.ts(registration, unchanged)session-transcript.worker.tsThe two shared T1 read sites remain for the explicitly retained SDK/authority paths. No inventory classifications changed. Production delta: +190 / -64 / net +126 LOC across 12 production files, plus 10 test files. The two synchronous list/primary signatures are replaced by awaited reads; the shared SQL kernel is reused.
ConversationRecordmoves from the SQL module to a leaf type module and remains exported by the registry.Original pinned base:
786a6b56e8c8b7f2b9b0bf154db179c3e833efd2. Main was merged without conflicts atd4b98b3a5101349febc02ae14b828f689f7b8538; none of the lane's paths overlapped incoming main changes. LOC is measured both on the original lane commit against the pinned base and on the final lane diff against merged main, excluding incoming main work.Evidence
110 tests across all 10 changed test files pass on the merged head. Each row ran
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test <file> --maxWorkers=1with the exact path below; Testbox also setCI=1.src/gateway/conversation-list.worker-read.test.tssrc/config/sessions/conversation-registry.test.tssrc/gateway/conversation-send.test.tssrc/gateway/conversation-turn.test.tssrc/gateway/conversation-list.admission.test.tssrc/gateway/conversation-list.account-removal.test.tssrc/commands/doctor-telegram-general-topic-conversations.test.tssrc/infra/outbound/outbound-session.integration.test.tssrc/auto-reply/reply/session.conversation-kind.test.tssrc/config/sessions/session-accessor.sqlite-reclamation-reuse.test.tsWall times include CLI, compilation and fixture setup. The new boundary file exercises real worker routing and source retirement. Existing registry/reclamation files exercise durable store, generation and FIFO contracts that a mock cannot prove; this change awaits the new read port in their existing cases. The registry file's test-body time exceeds 30 seconds on the loaded Mac. Normal PR CI timings are not yet available.
The real Gateway boundary proof covers shared logical/physical owners, list/exact/primary results, missing stores, delayed route revocation, rejection without a native fallback, source replacement during both discovery and row reads, and native incognito ownership. Caller suites retain reset/rollover/peer-context and admission ordering coverage.
Additional pre-merge sibling proof passed in the focused
pnpm test ... --maxWorkers=1batches:src/gateway/conversation-list.test.ts(7 cases) andsrc/gateway/server.sessions.compaction.test.ts(20 RPC cases). No incoming main paths overlapped this lane.Post-merge gates:
node scripts/check-changed.mjs— exit 0; formatting, production types, all 27 test type graphs, lint, dead-export scans and all selected guards passed.pnpm check:database-worker-ratchet --base 786a6b56e8c8b7f2b9b0bf154db179c3e833efd2— passed, no T1 growth.pnpm check:madge-import-cycles— passed, 0 cycles.node scripts/database-worker-inventory.mjs --json— filtered measurements in Impact; run on the original base and final head.git diff --numstat d4b98b3a5101349febc02ae14b828f689f7b8538...HEAD— production +190/-64/net +126;git diff --checkpassed.Testbox evidence: provider
blacksmith-testbox, leasetbx_01m3x913nw927qc36tszdmx4bp, workflow run. Native command exit 0. The runner verified sourcea243035125e8692f8283106d82e81258f625da12and tree84011796072f7b3ce472e77eac963e89f77afc59; its synthetic carrier had that same tree. The lease was stopped after proof, so lifecycle cancellation of the workflow is separate from the successful test command.Observed validation limitations: on the loaded Mac, the account-removal suite exceeded its existing 180-second
beforeAlldeadline while importing bundled plugins; neither test ran. The same tree passed on Testbox, with no timeout or assertion changes. The first Testbox lease expired after waiting over ten minutes for a runner (setup failure); no source tests ran there, and the expired lease is stopped. An initial unrelated compatibility-expiration gate was resolved by merging main's #163127. No loaded-host timeout fix is claimed.Compatibility retained / S10 dependency
resolveCurrentConversationSessionremains synchronous for the publicgetConversationSessioncontract inopenclaw/plugin-sdk/session-store-runtime, documented indocs/plugins/sdk-runtime/agent.md.resolveConversationremains synchronous for current-authority checks, includingconversation-turn'sassertCommitAllowedcallback. The callback reachesapplySessionEntryPatchInDatabaseand must see its executing transaction's rows. Moving that check requires a typed, worker-local conversation precondition in S10's entry-patch contract/kernel; an earlier read snapshot is insufficient.registerConversationAddressesandrunConversationDatabaseWriteretain the existing address-persistence and delivery-write FIFO.resolveConversationRegistryScoperemains with native inbound reply capture. These write-side paths are outside the coordinator-authorized independent read cut; durable read failures propagate.Update behavior
No schema, state format, configuration, permission, retention, durability, or migration changes. Doctor behavior is unchanged; its tests await the same conversation-read semantics.
Overlapping open PRs
runGatewaySessionCompaction; separate workspace/cwd behavior. This change only awaits the primary-conversation read and checks cancellation afterward.Landing repair and focused proof
Exact-head CI run
36959894630(attempt 1) exposed one missed async caller intest/gateway-account-history.e2e.test.ts: both compaction cases called.find()on the Promise returned bylistConversations. This is caused by this PR, not a pre-existing or flaky failure. The fixture now awaits the read; its assertions and timeouts are unchanged. No extra test was added.The repaired source passed both existing client and server-endpoint compaction cases on Blacksmith Testbox lease
tbx_01m3xarbfxxdpz5anmdt6jbt1c, run 36960665529.pnpm test test/gateway-account-history.e2e.test.ts --maxWorkers=1took 697.73 seconds wall including isolated build preparation; test bodies took 50.63 seconds. The complete selected changed-file checks passed, including all four root-test type graphs, formatting, lint, guards, and dead-export scans. The wrapper verified repaired treef2daeccf21f71e99a6375fad6d4054386eb38f8b, returned exit 0, and stopped the lease. Fresh isolated Codex autoreview of the repair was scoped-clean through P2.The local attempt stopped before tests at the managed-Gateway artifact isolation fence; no runtime artifacts were rebuilt there. The original CI run cancelled sibling jobs after the real failure, so those cancellations are unrun coverage rather than passing checks.
Main conflict resolution
GitHub reported a real conflict after main landed the conversation-delivery worker cutover. Merge commit
327854fbf2a52efaafd0705f4f9564ff8da526a7merges main1edb1f76d221640f338a882b44ea7bccf8c488c0without rebasing. The five conflicts retain both conversation-row and conversation-delivery worker request variants and handlers, main's exported physical-store pinning helper, and S14's awaited read callers. Main's removed delivery write wrappers stay removed. The S14 production diff against the incorporated main is unchanged.Composed proof on this merge candidate passed 72 tests across five files: conversation worker-boundary, send, turn, delivery-store, and registry suites. Command:
node scripts/run-vitest.mjs src/gateway/conversation-list.worker-read.test.ts src/gateway/conversation-send.test.ts src/gateway/conversation-turn.test.ts src/config/sessions/conversation-delivery-store.test.ts src/config/sessions/conversation-registry.test.ts --maxWorkers=1; wall time 185.34 seconds. Production types, targeted lint of the five conflict files, database-worker ratchet, import-cycle analysis (zero cycles), andgit diff --checkpassed. Fresh isolated Codex autoreview of the full candidate against the incorporated main was scoped-clean through P2.Unrelated CI flake (cause identified)
The Windows failure in run 36963211906, job 110701453851 is a fixture race in
src/skills/runtime/refresh.missing-root.integration.test.ts, case “replans a directory replaced between source planning and the first scan.” The watcher concurrently plans a source root and itsskillscompanion (refresh-watch-targets.ts). The fixture replaces the source directory with a junction as soon as that root's plan resolves, without joining the companion's in-flight prefix enumeration. fs-safe correctly rejects the stale directory observation; the test'sready()helper directly awaits the rejected planning promise, ahead of the runtime's guarded recovery.A bounded local controlled-schedule probe used the real
skillsObservationScope, fs-safe 0.22.0 Roots, directory streams, and filesystem replacement. Holding the companion's already-open stream across the fixture replacement reproducedFsSafeError: directory changed during operation; joining the companion plan before replacement completed without error. This is macOS mechanism proof, not a replay of the historical Windows scheduler. An initial 30-round unforced macOS probe did not reproduce the race.Independent corroboration: the workflow-only PR #163177 failed the exact Windows test with the same
path-mismatcherror and stack throughobservationPrefixKindandskillsObservationScopein run 36956693232, job 110681408510. Its test, refresh owner, target planner, scope planner, and filesystem probe blobs are byte-identical to this PR; both use fs-safe 0.22.0. S14 changes none of these files or dependency inputs. The fixture predates S14 (introduced by #159226); the recent polling-policy change does not change scope planning. Three scheduled main Windows shards passed, consistent with timing-dependent failure rather than independently demonstrated red main.Under explicit maintainer direction, rerun only the failed Windows job via the REST job-rerun endpoint. No fixture assertions, timeouts, dependency versions, or production behavior are changed. The earlier unclassified status is superseded by this investigation; no main-failure admin exception is claimed.
The authorized single-job rerun completed successfully: Windows job 110705315899, run 36963211906 attempt 2, unchanged head
327854fbf2a52efaafd0705f4f9564ff8da526a7. The dependent CI gate 110708345932 remains red solely because 22 selected sibling jobs were cancelled by the first attempt's fail-fast. Its log identifies incomplete UI, Node, types, lint, architecture and other Windows lanes; it reports no new test failure. Cancelled coverage remains unrun. No cancelled-job rerun or admin bypass was requested.Resumed cancelled coverage: attempt 3
The coordinator explicitly authorized resuming the failed/cancelled jobs of run 36963211906 via REST. Attempt 3 is complete with 77 terminal jobs and no remaining running jobs. The original Windows watcher job stays passed. Two previously cancelled jobs failed, and the aggregate CI gate failed downstream:
src/gateway/session-row-projection.category.test.ts, “reconciles more category rows than exact admission permits and survives archive eviction.” The zero-host-SQL observer captured exactly two periodic WAL-maintenance sequences (busy_timeout,wal_checkpoint(PASSIVE), timeout restoration), not conversation row queries. The fixture freezes onlysetInterval/clearInterval, while the unchanged WAL owner usesGatewaySchedulerandsetTimeoutfor its 10-second checkpoint ticks. This is an unrelated timer-control fixture failure with an identified cause. S14 changes none of the fixture, SQL observer, WAL owner or scheduler; the scheduler migration is main commit70ca83470faae(fix(storage): join WAL maintenance before database retirement #162166). No assertion, timeout or fixture was changed here.extensions/acpx/src/runtime-argv.process.test.ts, “preserves ACP argv through real processes and reconnect (leased=true, command=path).” The real ACP fixture missed its configured 5,000 ms initialization deadline;acpx0.19.1 raisedACP_SESSION_INIT_FAILEDfromstartRuntimeClient. An unrelated earlier report in ci: bound hourly iOS proof and accept coalesced jobs #158413 records the same fixture timeout but explicitly leaves its cause unresolved. S14 does not modify this fixture, lease wrapper or ACPX runtime. The available log does not establish why the handshake exceeded the deadline, so this is not claimed as a known flake with an identified cause.Landing stopped under the coordinator's explicit unclassified-failure rule. No new rerun, timeout increase, speculative fix, admin exception, or merge request followed attempt 3. The separate task retains ownership of the earlier Windows skills-watcher race fix.
Explicit single-job retry: identical repeat
The coordinator accepted the recorded classifications and authorized one rerun of each of the two failed jobs, with an explicit stop if either repeated identically. The job reruns were serialized. REST rerun of compact-small-20 job 110711496702 produced job 110718797509, attempt 4, which failed the same
session-row-projection.category.test.tscase with the same 12-statement WAL-checkpoint/busy-timeout assertion payload. The retained logs were compared directly and the payloads match exactly.Stopped at that condition: the Windows ACP job's newly authorized rerun was not submitted, no third Node execution was requested, and no merge request followed. The coordinator's separate task owns the WAL timer-fixture fix on main; the recorded Windows uncertainty is accepted under the repository's test-failure policy and is not the reason for this stop. The PR head remains
327854fbf2a52efaafd0705f4f9564ff8da526a7.