Repository navigation
fix(gateway): prevent restart replay after final delivery - #121908
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
e6776cf to
931c3ec
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 3:01 AM ET / 07:01 UTC. ClawSweeper reviewWhat this changesThe PR records durable per-delivery ownership for final replies across Gateway recovery, queues, and Telegram/Discord sends so restart recovery does not replay an already accepted final. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep open: current main has a source-proven restart replay window, and the PR targets the correct custody boundary. Its high-risk persisted-state and channel-delivery changes still need exact-head CI diagnosis and maintainer review before landing. Priority: P1 Review scores
Verification
How this fits togetherAn agent final is marked recoverable before delivery, then routed through a channel or outbound queue to the recipient platform. Restart recovery reads that session state to decide whether to retry or stop the interrupted run. flowchart LR
A[Agent final reply] --> B[Pending final marker]
B --> C[Reply dispatcher]
C --> D[Channel or outbound queue]
D --> E[Platform send]
E --> F[Durable delivery settlement]
B --> G[Restart recovery]
F --> G
G --> H[Retry or visible interruption]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +525, Tests +1338, Generated 0. Total +1863 across 77 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one canonical per-delivery custody record, transition it before platform I/O, and prove on the exact head that accepted finals are never replayed while proven-unsent finals remain retryable. Do we have a high-confidence way to reproduce the issue? Yes, from current source: persist a replayable final, let the platform accept it before settlement returns, then restart; recovery unconditionally resubmits that marker. Is this the best way to solve the issue? Yes in approach: a durable fact at the send boundary is the only way to close the crash window; a cleanup-only change remains too late. Full exact-head branch inspection was limited by unavailable promisor blobs and GitHub DNS. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2ae316e2f33d. 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
|
825f8d8 to
e16a790
Compare
Record channel delivery custody before recipient-visible sends so restart recovery cannot duplicate accepted finals. Ambiguous legacy markers now fail closed with a visible interruption instead of blind replay. Co-authored-by: Ayaan Zaidi <[email protected]>
e16a790 to
f9bbdec
Compare
|
Landed via 210aca6 with all five originally failing jobs green on the exact head. Final-head proof (
|
…ptions #121908 (210aca6) added the onPlatformSendDispatch options bag to final draft-stream updates and updated draft-failures-progress.test.ts, but missed 19 sibling assertion sites across 6 dispatch test files. Those files do not currently execute in any CI lane, so main's local dispatch suite has been red since. Two remaining failures (context-recovery session-target prefix, draft-failures-progress preview shape) predate #121908 and are tracked separately. Co-Authored-By: Claude Fable 5 <[email protected]>
…21908) Re-lands the reverted openclaw#121507 on the current custody contracts. The reply dispatcher now owns direct-send pending-final custody: claim before provider I/O, terminal settlement for delivered/suppressed/failed outcomes, proven no-send stays replayable, ambiguous evidence fails closed — so Gateway restarts can no longer duplicate an already-accepted final reply. Proof: ClawSweeper local review clean, exact-head ci-gate green, live Telegram E2E (one turn, one final, no duplicates). Co-authored-by: Ayaan Zaidi <[email protected]>
…ptions openclaw#121908 (d5a4097) added the onPlatformSendDispatch options bag to final draft-stream updates and updated draft-failures-progress.test.ts, but missed 19 sibling assertion sites across 6 dispatch test files. Those files do not currently execute in any CI lane, so main's local dispatch suite has been red since. Two remaining failures (context-recovery session-target prefix, draft-failures-progress preview shape) predate openclaw#121908 and are tracked separately. Co-Authored-By: Claude Fable 5 <[email protected]>
What Problem This Solves
Re-lands #121507 (reverted in #121491, commit 0d4e9f3): a Gateway restart between preparing a final reply and confirming its delivery could replay a final the recipient already received. This PR records per-delivery custody for pending finals so restart recovery replays only proven-unsent finals and fails closed (visible interruption, no blind replay) on ambiguous evidence.
Why This Change Was Made
The original merge broke main (5 CI jobs) and was reverted. Root causes, fixed here:
preparedforever after successful, failed, or suppressed dispatch. The dispatcher now claims custody before provider I/O (prepared→queued; a terminal or replaced marker cancels the send instead of duplicating it), settlesdeliveredon success, restorespreparedon proven no-send failures, and fails closed tounknownon ambiguous ones. Suppression is recorded before cancellation observers run.onPlatformSendDispatchin core and stripped it from channel send params; main (via the re-landed seam) passes it through so transports claim custody immediately before wire I/O. This re-land keeps main's contract;markDeliveryPlatformSendDispatched'sunknown_after_sendpreserve-guard (landed post-revert) stays authoritative, fixing the partial-send custody regression from the first attempt.bot.test-helpers.tsbut missed at four sites.Custody transitions accept
["prepared", "queued"]where the durable queue or turn lifecycle may run after a dispatcher claim, so each boundary keeps exactly one authoritative writer.User Impact
After a Gateway restart mid-reply, users no longer receive the same final answer twice. If delivery evidence is ambiguous, recovery shows a visible interruption instead of silently replaying. No configuration changes.
Evidence
check-test-types: green, including the four harness errors from the revert rationale.dispatch-from-config.reply-dispatch.test.ts(10 failures): green, with the original write-count expectations intact.before-deliver.test.ts(5 custody failures): green — dispatcher custody state machine implemented.deliver.queue-integration.test.ts(2unknown_after_sendfailures): green under main's preserve-guard.heartbeat-runner.ack-token-heartbeat-acks.test.ts: green — provider-owned callback pass-through preserved.src/auto-reply/reply,src/infra/outbound,src/channels/turn,src/agents/main-session-recovery,extensions/telegram,extensions/discord: green.pnpm tsgo:core,pnpm check:test-types,pnpm plugin-sdk:api:gen+ surface check: green.Production LOC +978/−473 (net +505, the custody state machine and fail-closed recovery paths); tests +1719/−361.