Skip to content

refactor(delivery): prevent duplicate and lost scheduled deliveries - #114479

Merged
steipete merged 12 commits into
mainfrom
codex/big-canonical-delivery-lifecycle
Jul 27, 2026
Merged

steipete merged 12 commits into
mainfrom
codex/big-canonical-delivery-lifecycle

Conversation

@steipete

@steipete steipete commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves a problem where scheduled announcements could be duplicated, silently lost, or falsely reported as delivered when a gateway restarted, two producers raced, a provider returned no message identity, or a temporary attachment disappeared.

Why This Change Was Made

Makes the existing SQLite outbound queue the sole owner of a bounded scheduled-delivery intent and its recipient-visible completion receipt. Synchronous producer and platform-attempt fences protect initial ownership, retries, reconciliation, terminal transitions, and queued attachments without changing SQLite schemas, schema versions, configuration, environment, dependencies, or gateway protocols. Explicitly reusable permanent intents carry a JSON-only producer-ownership fact; shipped ordinary and permanent restart-sentinel retry contracts remain unchanged. Cron policy, awareness, and dispatch remain in their current separate owner modules.

Transcript and awareness mirrors intentionally remain best-effort projections: a recipient delivery receipt must not fabricate conversation-state custody.

User Impact

Scheduled messages and attachments are sent at most once across live-producer races and gateway restarts. Ambiguous, partial, cancelled, rejected, and identityless provider sends cannot create a false success receipt or erase another producer’s queued attachment. Existing restart recovery, permanent sentinels, channels, and plugin contracts continue to work.

Evidence

  • Exact reviewed, autoreviewed, and hosted-CI-validated head: ab0eacb85b448f980ca835e8cf2fab9037c159ec.
  • The complete exact-head hosted CI workflow 30256895054 succeeded, including the protected openclaw/ci-gate, packaged build, all Node test shards, Windows tests, all four QA smoke profiles, production and test typechecking, import/topology architecture, max-lines, security, boundary, dependency, lint, and database guards.
  • On that exact final head, 108 focused tests passed across SQLite producer ownership, queue recovery, actual registered Matrix outbound-provider integration, durable attachment replay, same-millisecond and cross-process fencing, partial/identityless provider outcomes, permanent retries, and immutable media custody.
  • The immediately preceding behavior-equivalent head separately passed 846/846 affected tests across 26 files and seven shards: 394 infrastructure/recovery, 159 cron, 93 gateway, 131 agent, 59 Matrix, and 10 unit/plugin-SDK tests. These full-suite results are attributed to their actual earlier head, not misrepresented as a standalone local rerun on the final commit.
  • Both production and test native TypeScript lanes, all changed-file type-aware lint, zero runtime and Madge import cycles, max-lines, formatting, database-first guard, and git diff --check passed on the final head.
  • Fresh official high-reasoning autoreview --mode commit --commit HEAD on the final head: clean; no accepted or actionable findings. TruffleHog clean.
  • Direct regressions cover same-millisecond UUID fences; stale acknowledgement, failure, dead-letter and spool deletion; pristine and active reusable permanent owners; exhausted live producers; disabled-account admission; real registered Matrix-adapter single and mixed identityless sends; partial abort and permanent rejection; exactly one retry; missing regenerated attachment with original durable bytes; bounded receipt expiry/count; and the existing 45-attempt restart sentinel contract.
  • External credentialed production-provider smoke was not available: approved Blacksmith scheduling returned HTTP 429 and direct AWS lease acquisition returned HTTP 401. The registered real Matrix transport-path integration and successful hosted CI are the available proof; no test double is represented as an external live provider run.
  • Maintainer decision: accept the existing SQLite queue as the canonical delivery owner, the reviewed producer-fencing boundary, shipped permanent-retry compatibility, and exact-head transport/build/CI evidence in lieu of unavailable external credentialed smoke.
  • AI-assisted implementation with independent full-diff and final-commit autoreview.

@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 6:13 AM ET / 10:13 UTC.

ClawSweeper review

What this changes

This PR moves scheduled cron delivery ownership, retries, provider-attempt fencing, attachment custody, and completion receipts into the existing SQLite outbound queue to prevent duplicate, lost, and falsely acknowledged sends.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 5 items remain

Keep this PR open. The durable scheduled-delivery work remains necessary, but the supplied validation is tied to reviewed head 626d4c62872f0bd3ec8042d59ea2fd1d4393c6a5, while the current PR head is ab0eacb85b448f980ca835e8cf2fab9037c159ec; it also still lacks inspectable after-fix real-provider proof. The maintainer label requires explicit human handling rather than cleanup closure.

Priority: P1
Reviewed head: ab0eacb85b448f980ca835e8cf2fab9037c159ec
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The PR has substantial focused test claims and completed CI lanes, but its final head lacks inspectable real behavior proof and the stated evidence predates the last ownership-lease changes.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR reports extensive test and static validation, but it provides no inspectable redacted after-fix scheduled delivery through a real provider for the current head. Please attach a terminal capture, live output, recording, or redacted runtime/provider log and redact identifiers, endpoints, and credentials; updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR reports extensive test and static validation, but it provides no inspectable redacted after-fix scheduled delivery through a real provider for the current head. Please attach a terminal capture, live output, recording, or redacted runtime/provider log and redact identifiers, endpoints, and credentials; updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current head outgrew supplied validation: The PR body identifies 626d4c62872f0bd3ec8042d59ea2fd1d4393c6a5 as the exact reviewed head, but the current head is ab0eacb85b448f980ca835e8cf2fab9037c159ec after three additional delivery-fencing commits. The reported test and autoreview evidence therefore does not establish the final proposed behavior.
Delivery boundary changed: The supplied diff moves queue admission into src/infra/outbound/deliver-queue-admission.ts, introduces SQLite claim operations in src/infra/delivery-queue-sqlite-claim.ts, and changes cron delivery dispatch to use durable completion retention rather than process-local completed-delivery state.
Real-behavior proof remains absent: The prior completed ClawSweeper cycle requested a redacted live scheduled-delivery run through a real provider. The supplied PR body reports tests, static checks, and pending CI, but no inspectable runtime transcript, terminal capture, recording, live output, or redacted provider log showing the final-head behavior.
Findings None None.
Security None None.

How this fits together

Scheduled cron runs produce outbound messages and attachments that are routed through OpenClaw’s durable outbound queue before a channel provider sends them. The queue’s persisted intent and recovery state feed retry/restart handling, while cron awareness and transcript mirrors remain downstream projections.

flowchart LR
  Cron[Scheduled cron run] --> Intent[Durable delivery intent]
  Intent --> Queue[SQLite outbound queue]
  Queue --> Fence[Producer and provider fence]
  Fence --> Provider[Channel provider send]
  Provider --> Receipt[Durable completion receipt]
  Queue --> Recovery[Restart and retry recovery]
  Receipt --> Mirrors[Cron awareness and transcript mirrors]
Loading

Decision needed

Question Recommendation
After final-head real-provider proof and merge-result validation are supplied, should the maintainer accept the SQLite ownership refactor as the canonical scheduled-delivery reliability model? Require final-head runtime proof: Request a redacted real scheduled-delivery run that demonstrates the final head’s behavior across the claimed restart or competing-owner boundary, then review the refreshed merge result.

Why: The change intentionally redefines recovery and ownership behavior across cron, outbound delivery, and persisted queue rows; the protected maintainer label and absent final-head runtime proof make this an explicit risk-acceptance decision rather than an automated cleanup decision.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR reports extensive test and static validation, but it provides no inspectable redacted after-fix scheduled delivery through a real provider for the current head. Please attach a terminal capture, live output, recording, or redacted runtime/provider log and redact identifiers, endpoints, and credentials; updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The final three commits changed producer and recovery lease behavior after the head named in the PR evidence, so the reported test results and autoreview do not yet prove the exact merge candidate.
  • Resolve merge risk (P1) - This is a compatibility-, session-state-, and message-delivery-sensitive queue refactor: a missed ownership transition could duplicate a scheduled send, suppress a legitimate retry, or falsely retain/erase delivery state.
  • Resolve merge risk (P1) - The branch is behind its base; refresh the final proof against the current merge result rather than treating base drift alone as a patch defect.
Agent review details

Security

None.

PR surface

Source +837, Tests +1970. Total +2807 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 15 1650 813 +837
Tests 7 2018 48 +1970
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 3668 861 +2807

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/infra/outbound/delivery-queue.storage.test.ts, serialized state: src/infra/session-delivery-queue-recovery.ts, unknown-data-model-change: src/infra/session-delivery-queue-recovery.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove the final ownership boundary before merge (recommended)
    Rebase or otherwise refresh the actual merge result, then attach redacted real-provider evidence that a scheduled delivery is sent once and recovers safely across the relevant restart or contention path.
  2. Pause pending owner review
    Do not merge until a maintainer explicitly accepts the durable queue as the permanent owner for cron delivery receipts and recovery semantics.

Technical review

Best possible solution:

Retain the existing SQLite-only ownership design, rebase or refresh against current main, and provide redacted final-head proof of one scheduled delivery across a restart or concurrent-owner scenario through a real provider before a maintainer decides whether to merge.

Do we have a high-confidence way to reproduce the issue?

No high-confidence live reproduction was established in this review. The supplied diff and tests make the race/restart paths source-reproducible, but the environment could not run read-only inspection or a real provider scenario and the PR has not attached such evidence for its current head.

Is this the best way to solve the issue?

Unclear. Making the existing SQLite queue the single owner is consistent with the repository’s durable-state policy, but the final head needs refreshed runtime and merge-result proof before this can be judged the best safe repair.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 847906373e97.

Labels

Label justifications:

  • P1: The PR addresses scheduled outbound delivery, where a regression can duplicate or silently lose real user messages across restarts.
  • merge-risk: 🚨 compatibility: The refactor changes persisted queue ownership, retry, and completion behavior while preserving prior restart contracts for existing installations.
  • merge-risk: 🚨 message-delivery: Producer and platform-attempt fencing directly controls whether scheduled messages and attachments are sent, retried, or suppressed.
  • merge-risk: 🚨 session-state: The change alters persisted completion receipts and the boundary between durable delivery state and cron/transcript projections.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports extensive test and static validation, but it provides no inspectable redacted after-fix scheduled delivery through a real provider for the current head. Please attach a terminal capture, live output, recording, or redacted runtime/provider log and redact identifiers, endpoints, and credentials; updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current head outgrew supplied validation: The PR body identifies 626d4c62872f0bd3ec8042d59ea2fd1d4393c6a5 as the exact reviewed head, but the current head is ab0eacb85b448f980ca835e8cf2fab9037c159ec after three additional delivery-fencing commits. The reported test and autoreview evidence therefore does not establish the final proposed behavior. (ab0eacb85b44)
  • Delivery boundary changed: The supplied diff moves queue admission into src/infra/outbound/deliver-queue-admission.ts, introduces SQLite claim operations in src/infra/delivery-queue-sqlite-claim.ts, and changes cron delivery dispatch to use durable completion retention rather than process-local completed-delivery state. (src/infra/outbound/deliver-queue-admission.ts:1, ab0eacb85b44)
  • Real-behavior proof remains absent: The prior completed ClawSweeper cycle requested a redacted live scheduled-delivery run through a real provider. The supplied PR body reports tests, static checks, and pending CI, but no inspectable runtime transcript, terminal capture, recording, live output, or redacted provider log showing the final-head behavior. (ab0eacb85b44)
  • Repository policy applied: The supplied full repository AGENTS.md requires durability and SQLite changes to protect canonical state, avoid runtime compatibility shims, preserve shipped retry contracts, and obtain clear proof for user-visible behavior. Those constraints make final-head upgrade and runtime proof material before merge. (AGENTS.md:1, 847906373e97)
  • Read-only inspection limitation: The review environment rejected every attempted read-only shell command before execution with a sandbox network-namespace failure, so this decision relies on the supplied complete policy and GitHub context rather than claiming an independent checkout/history inspection.

Likely related people:

  • steipete: All 12 commits in the supplied PR history, including the latest three ownership-lease fixes, are authored by this account; broader current-main ownership could not be independently established because read-only shell inspection was unavailable. (role: current implementation author; confidence: low; commits: ed801559a911, 626d4c62872f, ab0eacb85b44; files: src/infra/outbound/deliver-queue.ts, src/infra/outbound/delivery-queue-recovery.ts, src/cron/isolated-agent/delivery-dispatch.ts)

Rank-up moves

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

  • Attach redacted final-head proof of a real scheduled delivery through a provider, including the relevant restart or contention outcome.
  • Refresh validation against the actual merge result after bringing the branch current.
  • Have a maintainer review the queue-ownership and persisted-receipt compatibility boundary once the proof is attached.

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-07-27T09:30:32.399Z sha 626d4c6 :: needs real behavior proof before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer decision for reviewed head ab0eacb: the existing SQLite delivery queue is the canonical lifecycle owner; this change does not add a SQLite schema/version, configuration surface, provider contract, or gateway protocol. The previous ClawSweeper review covered a superseded head; its runtime import cycle, Madge cycle, three max-lines failures, and type-aware lint findings were fixed and rechecked on this exact head. Proof includes the actual registered Matrix outbound/recovery adapter, original staged attachment bytes, explicit UUID-fenced producer ownership, same-millisecond and cross-process claims, disabled-account admission, ambiguous provider outcomes, permanent receipt compatibility, and restart/retry regressions; 108 focused corrected-head tests, both native TypeScript lanes, formatting and database guards, and a fresh clean high-reasoning commit autoreview. A credentialed external production-provider smoke could not be run: the approved Blacksmith Testbox returned HTTP 429 and the direct AWS coordinator returned HTTP 401. I accept the real adapter-path regression coverage in lieu of that optional external smoke. The exact-head hosted architecture, guards, build, dead-code, and CI gate still must succeed before protected landing.

@steipete
steipete merged commit 50dee05 into main Jul 27, 2026
123 checks passed
@steipete
steipete deleted the codex/big-canonical-delivery-lifecycle branch July 27, 2026 10:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 28, 2026
…penclaw#114479)

* refactor(delivery): make cron delivery durable and recoverable

* fix(delivery): preserve immutable staged media during stable reuse

* fix(delivery): fence platform attempt settlement and ambiguous batches

* fix(delivery): preserve legacy queues and fence bounded terminal states

* fix(delivery): retain ambiguous partial abort and rejection evidence

* fix(delivery): never impersonate active bounded delivery owners

* fix(delivery): narrow optional durable queue custody

* fix(delivery): enforce admission and stable-owner recovery fences

* fix(delivery): fence explicitly reusable permanent producer intents

* refactor(delivery): split durable queue owners and remove cycle

* fix(delivery): fence permanent recovery and in-flight producer leases

* fix(delivery): limit active recovery leases to explicit producers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant