Repository navigation
fix: keep session delivery persistence from blocking the Gateway - #147887
Conversation
Run standalone queue persistence on the existing shared-state worker. Carry captured database context through producers, recovery, generated media, and retry scheduling, and join admitted scheduler work before closure. Preserve queue JSON, deduplication, retry, and settlement contracts. Retain compound task/subagent transactions and current main Health, diagnostics, and task/flow behavior. Route real-worker fixtures through their canonical fork owners and remove obsolete test-only queue facades. Validation: fresh P2 review, full 36-command changed gate, 19 selected routing tests, and five ordinary queue/Health/media/settlement cases passed.
|
🦞👀 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 September 14, 2026, 1:13 AM ET / 05:13 UTC (Revision 2). ClawSweeper reviewWhat this changesMoves session-delivery persistence into the existing shared-state worker, carries database context through recovery and settlement, and updates test routing for worker-backed execution. Merge readiness✅ Ready for maintainer review This remains useful: current main and the latest release still execute session-delivery persistence synchronously. No introduced correctness or security defect was identified, and the follow-up test correction preserves the routing assertions. Priority: P2 Review scores
Verification
How this fits togetherThe session-delivery queue retains restart continuations and agent completion messages until delivery and settlement finish. Gateway producers and recovery feed this queue; its scheduler retries pending work and records durable completion. flowchart LR
A[Restart and agent messages] --> B[Captured database context]
B --> C[Shared-state worker]
C --> D[SQLite delivery queue]
D --> E[Recovery and retry scheduler]
E --> F[Session delivery]
F --> G[Durable settlement]
G --> C
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +244, Tests +816, Docs +9, Other +11. Total +1080 across 61 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep standalone queue persistence on the shared-state worker while preserving the existing record format, compound transaction ownership, and shutdown settlement ordering. Do we have a high-confidence way to reproduce the issue? Yes, from source: current-main queue APIs directly execute synchronous SQLite helpers despite returning Promises. No runtime reproduction was executed in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing shared-state worker and queue kernels addresses the blocking operations without introducing another persistence owner or changing stored records. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e9a1e2fce8ca. LabelsLabel 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)
|
Normalize the dedicated Gateway worker config when comparing singleton file selection with a mixed Gateway aggregate. Keep importer completeness, exact-once membership, includes, forwarded arguments, and watch-mode assertions unchanged. The original case reproduced the hosted Large 15 failure. The corrected case, fresh P2 review, and all 16 selected changed checks pass. Runtime sources and compiled artifacts remain identical to the qualified parent.
|
Merged via squash.
|
…nclaw#147887) * fix(state): move session delivery queue operations to shared worker Run standalone queue persistence on the existing shared-state worker. Carry captured database context through producers, recovery, generated media, and retry scheduling, and join admitted scheduler work before closure. Preserve queue JSON, deduplication, retry, and settlement contracts. Retain compound task/subagent transactions and current main Health, diagnostics, and task/flow behavior. Route real-worker fixtures through their canonical fork owners and remove obsolete test-only queue facades. Validation: fresh P2 review, full 36-command changed gate, 19 selected routing tests, and five ordinary queue/Health/media/settlement cases passed. * test: preserve leaf ownership in helper routing checks Normalize the dedicated Gateway worker config when comparing singleton file selection with a mixed Gateway aggregate. Keep importer completeness, exact-once membership, includes, forwarded arguments, and watch-mode assertions unchanged. The original case reproduced the hosted Large 15 failure. The corrected case, fresh P2 review, and all 16 selected changed checks pass. Runtime sources and compiled artifacts remain identical to the qualified parent.
Refs #147887 ## What Problem This Solves The startup queue retry test can stop its runtime after the SQLite scan but before the scheduled delivery starts. ## Why This Change Was Made A zero-delay timer created during a fake-clock tick is due at the next millisecond. Drain the pending timer before stop joins delivery. The test alone advances its clock; this state has one writer. ## User Impact Test-only repair of a false failure; production delivery and shutdown stay unchanged. ## Evidence The [original CI failure](https://github.com/openclaw/openclaw/actions/runs/35180792378/job/105072674481) expects one delivery but gets zero. Real-SQLite controls reproduce both reply orders: the old wait fails during a tick; the corrected wait passes both. Disabling the drain still fails delivery and persistence checks. All 56 runtime, recovery, storage and real-Gateway clock-jump cases pass. `node scripts/run-vitest.mjs src/infra/session-delivery-queue-runtime.test.ts` ## Compatibility One test line changes. No runtime, schema, configuration, dependency or public interface changes. ## Consumers Only the existing startup pending-scan retry test changes. ## Invalidation Each case stops its runtime before closing its database and restores real timers. ## Tests The 999+1 ms retry boundary, no early delivery, exactly one delivery, and empty pending rows remain asserted. ## Contention Stop still cancels unadmitted timers and joins only admitted work. Co-authored-by: Ayaan Zaidi <[email protected]>
…w#150631) Refs openclaw#147887 ## What Problem This Solves The startup queue retry test can stop its runtime after the SQLite scan but before the scheduled delivery starts. ## Why This Change Was Made A zero-delay timer created during a fake-clock tick is due at the next millisecond. Drain the pending timer before stop joins delivery. The test alone advances its clock; this state has one writer. ## User Impact Test-only repair of a false failure; production delivery and shutdown stay unchanged. ## Evidence The [original CI failure](https://github.com/openclaw/openclaw/actions/runs/35180792378/job/105072674481) expects one delivery but gets zero. Real-SQLite controls reproduce both reply orders: the old wait fails during a tick; the corrected wait passes both. Disabling the drain still fails delivery and persistence checks. All 56 runtime, recovery, storage and real-Gateway clock-jump cases pass. `node scripts/run-vitest.mjs src/infra/session-delivery-queue-runtime.test.ts` ## Compatibility One test line changes. No runtime, schema, configuration, dependency or public interface changes. ## Consumers Only the existing startup pending-scan retry test changes. ## Invalidation Each case stops its runtime before closing its database and restores real timers. ## Tests The 999+1 ms retry boundary, no early delivery, exactly one delivery, and empty pending rows remain asserted. ## Contention Stop still cancels unadmitted timers and joins only admitted work. Co-authored-by: Ayaan Zaidi <[email protected]>
Put back upstream b1c68b9 content that the continuation line had silently reverted in shared files. Every row has a keep/restore disposition recorded in the round journal. Feature hunks are preserved. Production: - announce deps: use callSubagentLifecycleGateway for the wake and cleanup deps (openclaw#146369 inherited Gateway binding). - reply-delivery: clear blockSourceText on superseded deferred replies (openclaw#143722). - stream-rendering: record a block reply as delivered only when it has text (openclaw#135751). - gateway runtime handles: carry hotReloadStatus through the managed reload. - sweep-kill and sweeper: honor retired cancellations (reconcileRetiredSubagentCancellation), and pass the run's Gateway context resolver into sweep session deletes. - registry read: per-child snapshot reads (openclaw#154727), so the Gateway event loop is not blocked. - session delivery queue: read the post-enqueue status inside the SQLite worker instead of on the main thread, restoring the openclaw#147887 invariant. Tests restored to upstream's coverage: - task-registry kernel test: back to upstream's kernel functions. - double-announce: real outbound adapter retry outcomes (openclaw#131419). - side-question: listener-failure hooks case (openclaw#144828). - session-delivery storage: main-thread-SQL idle assertion (openclaw#157458). - media-only: the re-resolved auth selection assertion. - resume persistence: activation uses the real recovery-runtime shape. The resume "steered requester turn" test was adapted for upstream's async task lookup (openclaw#157634). Its stub now settles like the real waker, and the test waits for settle before an exact count, with a no-pending-wake assertion added. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fq5EX9ESA3CG9cuZxVoKAK
…rage API The continuation merge re-widened every session-delivery storage operation to OpenClawStateWorkerContext | stateDir | undefined and resolved the state dir inside the storage owner. Restore upstream's required OpenClawStateWorkerContext parameter and its plain moveSessionDeliveryToFailed (upstream removed the status-probing catch in openclaw#147887). Continuation events persist only a delivery-queue state dir, so their callers bind it once through captureContinuationQueueContext. The post-compaction delivery dep now requires a context; its single call site supplies the fallback. Tests pass the context they already hold. Refs #1418 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Block: cosmetic drift in session-delivery-queue.records.ts. Restores upstream b51feb9's systemEvent agentId doc comment ("Preserves ownership when a durable event targets the literal global session.") over the older openclaw#147887 (d20490a) wording, and moves SESSION_DELIVERY_QUEUE_NAME back above the type declarations where upstream keeps it. Stayed: the codec type move (QueuedSessionDelivery and payload types derived from session-delivery-queue-codec.ts) is unchanged. Home: restored to upstream (drift residue). Refs #1418 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Session-delivery queue APIs returned Promises while executing SQLite on the Gateway thread, including during retry scheduling and restart recovery.
User Impact
Queue persistence moves to the existing shared-state worker while preserving deduplication, retry bookkeeping, settlement, and restart recovery. No configuration, schema, or retained-data migration is required.
Why This Change Was Made
Producers, recovery, generated-media preparation, and the scheduler carry one captured database context through the operation. Scheduler shutdown joins admitted reads and drains before database closure. Queue records retain their existing JSON serialization boundary; compound task/subagent transactions remain on their existing native owner.
Real-worker fixtures use the canonical fork owners across focused, watch, full-suite, and CI selection. The composition retains current main's noncreating Health reads, Health writes, diagnostics, and task/flow behavior.
Evidence
The runtime change passed fresh independent P2 review, all 36 changed-gate commands, 19 selected routing tests, five ordinary behavior cases, and the normal package build.
A plain-Node child using that exact compiled build passed a synthetic enqueue/read/reopen/recovery/settlement/reopen flow: exactly one delivery and settlement, no replay, and zero parent SQLite calls across six observed methods through final close. All 60 source files and 9,422 runtime files were verified before and after execution; fixture and process cleanup completed.
CI exposed an aggregate-versus-singleton expectation in the helper-routing test. The original focused control failed and the corrected control passed, along with fresh P2 review and all 16 follow-up checks. Only that test changed afterward; the 60 previously qualified files and all compiled runtime files remain byte-identical.