Repository navigation
fix(gateway): prevent duplicate final replay after restart - #121507
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
fffe8f3 to
8af9ffd
Compare
8af9ffd to
4e26e2b
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 10, 2026, 6:54 AM ET / 10:54 UTC. ClawSweeper reviewWhat this changesThe PR records per-final-delivery state across direct and queued channel sends so restart recovery can avoid replaying an already accepted reply. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessKeep open. The source change addresses the prior legacy-marker replay path, but its fail-closed upgrade behavior for existing identity-less session markers needs maintainer confirmation before merge. Priority: P1 Review scores
Verification
How this fits togetherChannel turns create agent reply payloads and send them through direct adapters or the durable outbound queue. Persisted session state is later used by restart recovery to retry, complete, or interrupt a final delivery. flowchart LR
A[Inbound channel turn] --> B[Agent final payload]
B --> C[Persisted delivery identity]
C --> D{Direct or queued delivery}
D --> E[Channel platform request]
E --> F[Delivery state settlement]
F --> G[Restart recovery]
G --> H[Retry, complete, or interruption]
Decision needed
Why: This intentionally changes upgrade behavior to prevent duplicate user-visible replies at the cost of not automatically recovering an ambiguous final; source inspection cannot choose that product tradeoff. Before merge
Agent review detailsSecurityNone. PR surfaceSource +502, Tests +979, Generated 0. Total +1481 across 74 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt one canonical delivery-owner state machine, retain the legacy fail-closed interruption, resolve the branch conflict, and revalidate the resulting head across restart recovery plus direct and queued delivery. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main replays replayable markers without an identity, while the PR's focused recovery test covers that same legacy state and prevents the replay. Is this the best way to solve the issue? Unclear pending product direction: recording delivery custody at the send owner is the right architectural layer, but maintainers must approve the fail-closed behavior for older persisted markers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e37614c83f97. 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 (2 earlier review cycles)
|
4e26e2b to
a710ab3
Compare
a710ab3 to
9fe5320
Compare
14c6b7b to
1224fe4
Compare
1224fe4 to
f1fb713
Compare
|
Reverted commit 1f75018 in #121491 because main CI runs 31382622463 and 31383087703 fail five substantive jobs: The two state-machine regressions are:
The same runs also report four Discord/Telegram harness type errors against the new provider-owned delivery custody contract. Please re-land the restart-replay repair once the cross-lane delivery suites and test-type gate are green together. |
Re-lands the reverted #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]>
…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]>
Context: #96242
What Problem This Solves
A final reply could be delivered twice when the gateway stopped after the channel accepted it but before later session cleanup removed its replay marker.
Root Cause and Fix
Delivery custody had divergent owners. Reply dispatch could mark a final as admitted before a durable queue row existed; direct channel adapters could cross platform I/O before core recorded ambiguity; restart recovery then had to infer whether the reply was sent.
Pending-final delivery now records one serialized logical identity. One boundary owns each transition:
preparedtoqueued; the durable executor records the batch terminal resultdeliveredorsuppressedThe shared durable lifecycle consumes the callback once and removes it from the adapter context, so channel leaf/chunk paths cannot repeat custody writes. Generic reply-dispatcher transitions and three caller-specific completion derivations were deleted.
Identity-less markers from older builds cannot prove whether the platform accepted the final. Restart uses the visible interruption path instead of replaying it; no fabricated identity, duplicate sender, cache, schema, sidecar, or config was added.
Product Contract
Accepted final replies are delivered at most once across restart. Proven pre-send work remains retryable. Ambiguous or partial delivery fails closed with one visible interruption notice; OpenClaw does not rerun the previous model/tool request.
Local Proof
Exact head
f1fb7130227:tsgo:core,tsgo:test:src,tsgo:extensions:test: cleanA broader earlier ownership-boundary group covered shared send/queue/lifecycle, Telegram draft/native/durable, and Discord durable/component paths: 285/285. A local mock-gateway restart trace also proved one accepted final, one provider request, and zero recovery model dispatch; a seeded shipped identity-less marker produced one visible interruption and zero replay/model dispatch.
Discord
Command shape (broker secrets omitted):
The real Discord recorder observed the progress/tool draft, its final edit, the persistent final, then draft cleanup.
{"status":"pass","head":"f1fb7130227","discord":{"messages":2,"edits":1,"deletions":1,"timeline":[{"elapsedMs":1535,"kind":"message","textLen":60},{"elapsedMs":7554,"kind":"edit","textLen":23},{"elapsedMs":7971,"kind":"message","textLen":23},{"elapsedMs":8272,"kind":"delete"}],"expectedFinal":"OPENCLAW_E2E_DRAFTPROOF"}}Telegram
The real-user Telegram doctor check passed. An external inspector paused the exact candidate after Telegram accepted the final and before pending-final cleanup, then sent
SIGKILL; the same config and state restarted while the recorder stayed active. The user saw exactly one final and no duplicate, edit, or deletion. The provider received one request, restart issued zero recovery model dispatches, and the gateway reached ready twice.{"status":"pass","head":"f1fb7130227","telegram":{"sutFinals":1,"duplicates":0,"edits":0,"deletions":0,"providerRequests":1,"recoveryModelDispatches":0,"gatewayReadyEvents":2}}Diff
Maintainer Decision
Accepted: identity-less pending-final markers fail closed with one visible interruption instead of blind replay. Historic state cannot prove whether a channel already accepted the final; at-most-once delivery takes priority over silently duplicating it. This is the named shipped-state bridge. No fabricated identity, migration sender, or compatibility replay path is permitted. Blind replay can duplicate recipient-visible effects and model/tool side effects.
Decision owner: Ayaan Zaidi — APPROVED. For shipped pending-final markers without delivery identities, fail closed with the existing visible interruption. Do not fabricate identities or blind replay; either can duplicate recipient-visible output and re-run model/tool side effects.