Repository navigation
refactor: move outbound delivery lease SQLite off the Gateway thread - #152736
Conversation
|
🦞👀 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 changes before merge. Reviewed September 20, 2026, 6:25 PM ET / 22:25 UTC (Revision 17). ClawSweeper reviewWhat this changesMoves outbound delivery claims and lease renewals into the shared SQLite worker while preserving message ownership and recovery behavior. Merge readiness⛔ Needs changes before merge - 1 item remains The prior timing defect is resolved, and no remaining actionable code defect was found. This remains useful work: current main still performs claims and renewals on the Gateway thread. Priority: P2 Review scores
Verification
How this fits togetherThe outbound delivery queue holds messages and media until delivery settles. Its leases select the active sender, while a final ownership check guards provider sends and recovery handles interrupted work. flowchart TD
A[Outbound messages] --> B[Durable delivery queue]
B --> C[Shared SQLite worker]
C --> D[Claim or renew exact owner]
D --> E[Final ownership check]
E --> F[Provider send]
F --> G[Acknowledgement and cleanup]
D --> H[Recovery after interruption]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +43, Tests +511, Docs +9. Total +563 across 20 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one worker-backed queue path with unchanged ownership checks, transaction kernels, media custody, and recovery semantics. Do we have a high-confidence way to reproduce the issue? Yes, from source: current-main claim and renewal facades execute synchronous SQLite transactions on the caller thread. The supplied regression evidence covers writer contention; this review did not execute tests. Is this the best way to solve the issue? Yes. Reusing the shared worker and existing transaction kernels removes the blocking work without changing stored formats, lease timing, or the final provider-send fence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7627a337b5ca. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (16 earlier review cycles; latest 8 shown)
|
Preserve canonical Doctor cleanup and all landed worker owners. Current-main behavioral controls pass 68 cases and independent review is clean. The composed shared runtime remains 702 counted lines; the following domain-routing repair addresses the unchanged 700-line guard before publication.
Route the existing eight queue operations through one typed domain adapter while retaining each executor and transaction owner. Remove the obsolete lease-only selector and preserve current-main worker operations and canonical fixtures. Reuse the exact duplicate test-route deletion from 57a0a198ebdec2530afd17b656183f060fb4c4b3.
Carry current main including the canonical formatter callback arity fix from #153921. Preserve the exact Claims feature patch and eight-command domain dispatcher while retaining transcript dispatch and source heartbeat context. Current core types, 75 focused controls, size guards, lint, review, and refreshed compiled worker proof pass.
Carry the verified main Stylelint expectation and task identifier codec import repairs from #153982 and #153988. The complete Claims feature patch is unchanged. Preserve the prior failed CI and migration-fixture controls; current 378 checks, types, size guards, lint, review, build, and compiled ten-request worker proof pass.
Capture the queue row and await real worker renewal before fixing the host recovery clock. Model an expired detached scan without shortening the authoritative lease or sleeping. Fix the clock before startup captures its recovery deadline. Preserve exact owner, renewed expiry, and retry assertions; both modes reject a stale-snapshot guard mutation. Production remains unchanged.
|
Merged via squash.
|
…penclaw#152736) * refactor: move outbound claim and renewal SQLite to worker * test: route outbound queue consumers through database workers * test: expect worker routing for durable Discord delivery * test(ci): retain one owner for Twitch delivery coverage * test(outbound): clean up ACK fixtures with their owner * test: join Doctor database cleanup before snapshots * test(claws): adopt canonical Doctor reader cleanup Carry the exact Doctor fixture from 89e700b (openclaw#146361). Preserve ordered async drain, native reset, and temporary-directory cleanup while closing both metadata readers in finally. Supersedes the local helper-based fixture repair without changing Claims production. * refactor(outbound): centralize delivery queue worker dispatch Route the existing eight queue operations through one typed domain adapter while retaining each executor and transaction owner. Remove the obsolete lease-only selector and preserve current-main worker operations and canonical fixtures. Reuse the exact duplicate test-route deletion from 57a0a198ebdec2530afd17b656183f060fb4c4b3. * test(outbound): control recovery snapshot timing Capture the queue row and await real worker renewal before fixing the host recovery clock. Model an expired detached scan without shortening the authoritative lease or sleeping. Fix the clock before startup captures its recovery deadline. Preserve exact owner, renewed expiry, and retry assertions; both modes reject a stale-snapshot guard mutation. Production remains unchanged.
Related: #153076, #152892, #153296, #152583, #152319, #153216, #153921, #153982, #153988
What Problem This Solves
Outbound delivery claims and lease heartbeats perform SQLite work on the Gateway thread, including time spent waiting for a database writer.
User Impact
Claims and renewals run off the Gateway thread while preserving delivery ownership, retry budgets, media custody, and recovery. No configuration, schema, retention, or lease timing changes are required.
Why This Change Was Made
The existing awaited claim and renewal facades dispatch through the shared-state worker and reuse the existing transaction and ownership kernels. One typed delivery-queue adapter routes all eight queue operations to their existing executors. Direct count, pruning, and media-retention kernels remain direct calls; existing write operations keep their transaction and admission owners. The final provider-send fence remains synchronous and owner-checked. Lease stop joins accepted renewals, and an unavailable claim reply retains custody and media for recovery.
Evidence
The original host-SQL regression fails on the native claim implementation and passes with the worker path. The
28efc78a4f29main integration passed 378 checks: the full 352-case planner suite, 18 migration/backfill controls, and eight Claims/ACK/reply-loss controls. The normal wrapper completed them in 223.85 seconds. Real worker startup, SQLite writer contention, accepted-renewal shutdown, and committed-reply-loss recovery require the actual process and storage boundary. The preceding domain extraction passed 56 behavioral and routing checks. Its complete selected static gate is retained for the unchanged feature patch; this main carry additionally passed fresh core types, both size guards, formatting, scoped lint, zero runtime import cycles, and independent P0–P2 review. The maintainedqaRuntimebuild was refreshed and passed.An ordinary Node run against that completed build exercised ten requests across all eight registered queue operations through the same real worker. It verified one winner from concurrent claims, refused stale renewal, retained failure health counts, retention snapshots, ACK settlement, and exact owner/retry state after reopening. The normalized trace was:
The task-owned diagnostic (
node compiled-queue-proof.mjs) used Node 24.21.0 on macOS arm64, isolated synthetic config/state, actual built exports, and the normal worker entry. Instrumentation forwarded native calls unchanged. Synthetic seed rows, capture of the failure entry, verification reads, and the final drain were outside the measured ten-request phase. All 13,039 build-artifact hashes matched afterward. No provider account or live send was involved.The first expanded diagnostic expected an ordinary transient failure to remain in health counts; the canonical retention contract correctly removed it. The retained-count fixture now explicitly requests the existing completion-retention contract. The expected count and all production code remained unchanged; the original harness failure is preserved separately.
Current main's complete Doctor, ACK, and private-completion fixtures are preserved. The unchanged runtime size guard initially rejected the composed dispatcher at 702 counted lines; the domain extraction passes it without changing a limit or baseline and removes the old lease-only selector. The database-worker routing audit for this candidate is clean across 428 explicit core file routes, 276 explicit extension file routes, and four whole-extension roots. It includes the exact canonical duplicate-registration removal from #153216, retaining the first owner and all test coverage.
The previous
b8090db71b86CI run failed on a newer-main formatter callback arity error in five leaf checks and their aggregates. This successor includes the landed compiler correction from #153921. The old failure logs remain bound to that prior head; the Claims feature patch is unchanged.The later
047f9ea6909cCI run exposed the shared Stylelint target expectation; the next main-input control exposed a stale import in the task-identifier migration fixture before its subject ran. This successor carries the verified main fixes from #153982 and #153988, including the complete canonical fixture postimages. All earlier failed runs and controls remain source-bound. No fixture variant, compatibility export, UI budget, or assertion change was added here.Fresh review of the green
28efc78a4f29head found a scheduling risk in two recovery fixtures: an artificial five-second lease could expire before the real worker renewed it, and the successful cases deliberately waited for expiry. The test-only successor captures the row and awaits real worker renewal, then fixes the host clock before recovery computes its deadline and supplies an expired detached scan view. The authoritative row, real worker, normal lease, and exact owner/expiry/retry assertions remain intact. No timeout, deadline, retry, or production seam was added.The final recovery and worker sibling controls passed all 20 cases in two files (
pnpm test <files> --maxWorkers=1, 60.71 seconds including wrapper/startup). A separate final standalone measurement,pnpm test src/infra/outbound/delivery-queue.producer-recovery.test.ts --maxWorkers=1, passed all 17 cases: 21.47 seconds Vitest run wall time, 24.20 seconds total wrapper elapsed time including preparation and cleanup. Exact-head CI job 106159227977 reports 17 individual case durations summing to 8.959 seconds, with the repaired pair at 389/410 ms. Those CI case durations are not a standalone file wall time; the CI log does not emit one. The affected pair measured 812/650 ms, versus 5956/6145 ms before the repair; the deliberate waits are removed. A causal mutation that made settlement trust the stale snapshot instead of the authoritative row failed both recovery modes at the unchanged owner assertion. Production was restored byte-for-byte. An earlier private fixture attempt incorrectly crossed startup recovery's deadline and produced one false-green mutation case; that result is preserved and the ordering was corrected before publication. This is deterministic guard-sensitivity proof, not a claim to have reproduced a random CI flake. The final selected changed gate and full-context P0–P2 review passed. The prior 378-case, build, and compiled-worker evidence remains bound to unchanged production.Final exact-head CI passed for
1cc90e7fc27017a3ebed0c9be368855c4933ef6e: 150 successful jobs, 14 skipped jobs, and no failures. The fixture-only follow-up preserves every production file from the qualified28efc78a4f29build and runtime proof.