Skip to content

refactor: move outbound delivery lease SQLite off the Gateway thread - #152736

Merged
steipete merged 18 commits into
mainfrom
codex/outbound-claim-worker-20260919
Sep 20, 2026
Merged

steipete merged 18 commits into
mainfrom
codex/outbound-claim-worker-20260919

Conversation

@steipete

@steipete steipete commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

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 28efc78a4f29 main 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 maintained qaRuntime build 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:

worker thread 2: claim, claim, renew, renew, enqueue, failPending,
                 countFailed, pruneTombstones, mediaRetentionSnapshot, ack
host data [construct, close, prepare, exec, get, all, run, iterate]: [0,0,0,0,0,0,0,0]
coordinator [construct, close, prepare, exec, get, all, run, iterate]: [0,0,0,0,0,0,0,0]
positive sensitivity control: [1,1,4,1,1,1,1,1]
reopened exact owner: true; retry budget preserved: true
synthetic state removed: true; natural process exit: 0

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 b8090db71b86 CI 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 047f9ea6909c CI 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 28efc78a4f29 head 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 qualified 28efc78a4f29 build and runtime proof.

@clawsweeper

clawsweeper Bot commented Sep 19, 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 docs Improvements or additions to documentation size: L maintainer Maintainer-authored PR labels Sep 19, 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 Sep 19, 2026
@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed September 20, 2026, 6:25 PM ET / 22:25 UTC (Revision 17).

ClawSweeper review

What this changes

Moves 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
Reviewed head: 1cc90e7fc27017a3ebed0c9be368855c4933ef6e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation with convincing worker-boundary proof and a resolved timing regression.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The recorded plain-Node run exercises the changed queue facades through the real compiled worker, showing off-thread SQLite execution, competing-claim exclusion, stale-renewal refusal, settlement, and durable reopening. The latest test-only change preserves that production proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The recorded plain-Node run exercises the changed queue facades through the real compiled worker, showing off-thread SQLite execution, competing-claim exclusion, stale-renewal refusal, settlement, and durable reopening. The latest test-only change preserves that production proof.
Evidence reviewed 8 items Introduced production change: The pinned introduced diff routes the existing asynchronous facades through the shared worker, adds two typed operations, and consolidates eight queue commands without replacing their transaction kernels.
Still necessary on main: Fetched main still calls the synchronous claim and renewal implementations from the asynchronous facade. The related merged enqueue and failure-settlement work does not cover these operations.
Latest release comparison: The latest supplied release, v2026.9.5, also retains the synchronous claim and renewal path.
Findings None None.
Security None None.

How this fits together

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

Before merge

  • Complete next step (P2) - Add the measured wall time for pnpm test src/infra/outbound/delivery-queue.producer-recovery.test.ts --maxWorkers=1 to the PR evidence, with CI seconds when available, completing the previous review's cost-reporting request.
Agent review details

Security

None.

PR surface

Source +43, Tests +511, Docs +9. Total +563 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 6 118 75 +43
Tests 13 630 119 +511
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 757 194 +563

Review metrics

Metric Value Why it matters
Production versus test growth Production +43 net lines; tests and test support +510 Production growth is justified by typed worker adapters that reuse existing kernels; most growth covers ownership and failure recovery.

Technical review

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The recorded plain-Node run exercises the changed queue facades through the real compiled worker, showing off-thread SQLite execution, competing-claim exclusion, stale-renewal refusal, settlement, and durable reopening. The latest test-only change preserves that production proof.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This bounded responsiveness improvement removes claim and renewal SQLite waits from the Gateway thread.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The recorded plain-Node run exercises the changed queue facades through the real compiled worker, showing off-thread SQLite execution, competing-claim exclusion, stale-renewal refusal, settlement, and durable reopening. The latest test-only change preserves that production proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The recorded plain-Node run exercises the changed queue facades through the real compiled worker, showing off-thread SQLite execution, competing-claim exclusion, stale-renewal refusal, settlement, and durable reopening. The latest test-only change preserves that production proof.

Evidence

What I checked:

  • Introduced production change: The pinned introduced diff routes the existing asynchronous facades through the shared worker, adds two typed operations, and consolidates eight queue commands without replacing their transaction kernels. (src/infra/outbound/delivery-queue-platform-lease.worker.ts:19, 1cc90e7fc270)
  • Still necessary on main: Fetched main still calls the synchronous claim and renewal implementations from the asynchronous facade. The related merged enqueue and failure-settlement work does not cover these operations. (src/infra/outbound/delivery-queue-platform-lease.ts:17, 7627a337b5ca)
  • Latest release comparison: The latest supplied release, v2026.9.5, also retains the synchronous claim and renewal path. (src/infra/outbound/delivery-queue-platform-lease.ts:17, ec9c1a13db89)
  • Previous finding resolved: The latest commit removes the five-second lease and real sleep. Both recovery modes now await actual worker renewal before fixing the host clock and supplying an expired detached snapshot; exact owner, expiry, and retry assertions remain. (src/infra/outbound/delivery-queue.producer-recovery.test.ts:334, 1cc90e7fc270)
  • Production runtime proof: The supplied body records a plain-Node 24.21.0 run on macOS arm64 using built exports and the normal worker entry. Ten requests exercised all eight queue operations, with zero measured host/coordinator SQLite calls, one competing-claim winner, stale-renewal refusal, ACK settlement, and preserved owner/retry state after reopening. This is storage-boundary proof, not live-provider proof; the latest commit changes only tests.
  • Ownership and recovery safeguards: The worker invokes the existing synchronous transaction kernels, which reread owner and expiry. The provider-dispatch fence remains synchronous. Added coverage exercises expiry during writer contention, joining accepted renewal before ACK, and retaining media after a committed claim loses its reply. (src/infra/outbound/delivery-queue-platform-lease.worker.test.ts:101, 1cc90e7fc270)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the repaired producer-recovery test's measured wall time and CI duration when available.

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 (16 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-20T05:49:24.038Z sha aaadf00 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T07:02:58.899Z sha 5aee21b :: blocked before merge. :: none
  • reviewed 2026-09-20T08:01:07.658Z sha 2739a9c :: blocked before merge. :: none
  • reviewed 2026-09-20T08:35:18.683Z sha 1c73689 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T18:52:42.798Z sha b8090db :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T20:07:21.967Z sha 047f9ea :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T20:40:08.847Z sha 047f9ea :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T21:36:02.369Z sha 28efc78 :: needs changes before merge. :: [P2] [P2] Make the recovery snapshot expiry test deterministic

@steipete
steipete marked this pull request as ready for review September 19, 2026 09:33
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Sep 19, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 20, 2026
Carry the exact Doctor fixture from 8416d71 (#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.
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.
@clawsweeper clawsweeper Bot added the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Sep 20, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Sep 20, 2026
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.
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 20, 2026
@steipete
steipete merged commit 85364ab into main Sep 20, 2026
229 checks passed
@steipete
steipete deleted the codex/outbound-claim-worker-20260919 branch September 20, 2026 23:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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