Repository navigation
fix: channel turns recover safely after gateway restart - #108283
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5108eab23a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sourceReplyFinal: | ||
| action === "send" && sourceReplySinkDeliveryMode === "message_tool_only" | ||
| ? (requestedSourceReplyFinal ?? true) | ||
| : undefined, |
There was a problem hiding this comment.
Preserve final markers in delivery evidence
When a message_tool_only turn sends a progress update with final:false and then produces a private final answer or terminal failure, this marker is only passed into runMessageActionForTool; it is stripped from the model-facing params and never added to the tool result or the messagingToolSentTargets/messagingToolSourceReplyPayloads evidence that hasCompletedSourceReplyDeliveryEvidence reads. Real runs therefore fall back to the legacy “any committed source reply completes the turn” path and treat a progress send as terminal, so the final answer can be kept private/dropped instead of warning or enqueueing the retry that the new tests only cover by manually seeding sourceReplyFinal: false in fake run results.
Useful? React with 👍 / 👎.
7dbaa3a to
0e712c3
Compare
0e712c3 to
2a88121
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a88121165
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (params.toolCallId && (!sourceTurnId || sourceTurnRange === undefined)) { | ||
| return false; |
There was a problem hiding this comment.
Scan beyond the recent tail for delivered receipts
When a delivered-terminal receipt is recovered after a long turn, recoverStore has only loaded the recent 20 transcript messages, so the original user message with restartRecoveryDeliverySourceRunId can easily be outside messages. In that case this check returns false before the durable receipt can mark the session done, leaving the aborted session skipped on every startup even though delivery was already confirmed. The receipt path should either load/scan the source turn by id or complete without requiring the source user message to be present in the tail.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 648624968a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sourceReplyFinal: params.input.sourceReplyFinal, | ||
| sourceReplyToolCallId: params.input.sourceReplyToolCallId, |
There was a problem hiding this comment.
Route terminal receipts through direct sends
When a message_tool_only turn uses a direct-outbound channel (for example Slack declares deliveryMode: "direct" in extensions/slack/src/channel.ts:468), these new terminal-source fields only reach the gateway-plugin branch here; the local executeSendAction path at src/infra/outbound/message-action-runner.ts:1312 still sends and mirrors without arming beginTerminalSourceReplyDelivery or writing the message-tool-source-reply marker. If the gateway/process restarts after such a direct send succeeds, restart recovery cannot see a delivered-terminal receipt and treats the mirrored assistant message as an unresumable tail, so users can get a failure notice or duplicate/drop recovery behavior despite the final reply already being sent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2a3e69b29
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (params.sourceTurnRange.endIndex !== params.messages.length) { | ||
| return false; | ||
| } | ||
| return params.messages.slice(params.toolCallIndex + 1).every((message) => |
There was a problem hiding this comment.
Ignore abort tails when reconciling delivered replies
When a terminal message-tool send has already been recorded as delivered but the aborted run also persisted the standard empty assistant abort artifact, this check rejects completion because the abort artifact is not an exact delivery mirror. The rest of this recovery code explicitly strips those restart-abort tail artifacts before deciding resumability, so this delivered-receipt path can still mark the session failed and send the retry notice even though the terminal reply reached the user; allow the known abort artifact after the mirror when deciding whether the recovered tool result can be appended.
Useful? React with 👍 / 👎.
…tart-recovery # Conflicts: # src/agents/main-session-restart-dispatch.ts # src/agents/main-session-restart-recovery.test.ts # src/agents/main-session-restart-recovery.ts
|
Merged via squash.
|
) * fix(gateway): recover channel turns safely after restart * refactor(gateway): keep recovery identity internal * refactor(gateway): keep recovery metadata private * fix(gateway): preserve recovery action authority * fix(gateway): close recovery lifecycle gaps * fix(gateway): fail closed on missing delivery receipts * fix(gateway): fail closed on unmirrorable replies * fix(gateway): persist terminal delivery intent * fix(gateway): align recovery lifecycle types * fix(gateway): require exact terminal thread receipt * fix(gateway): close recovered terminal tool calls * test(gateway): type terminal tool correlation * fix(gateway): satisfy restart recovery CI contracts * fix(gateway): require terminal tool correlation * fix(agents): scope recovery receipts to source turns * fix(gateway): fail closed without restart correlation * fix(gateway): dedupe terminal source redelivery * fix(agents): keep recovery tool results causal * test(auto-reply): clean recovery fixture directories * fix(gateway): allow live terminal sends without recovery claims * fix(agents): reconcile delivered sends through restart aborts * fix(agents): keep recovery continuations in source turns * fix(agents): keep source-less sends non-terminal * fix(auto-reply): dedupe active source redelivery * fix(agents): harden recovery receipt contracts * fix(agents): admit terminal recovery successors * docs(recovery): document canonical receipt ownership * fix(agents): fail closed on stale turn authority * test(auto-reply): assert rebound session state * fix(plugins): keep restart recovery hook list internal
…igin turns (#109201) PR #108283 started deriving a durable channel source-turn id for gateway chat.send turns carrying originatingChannel/originatingTo overrides, while the gateway's pre-created user-turn recorder keys the persisted turn by run id. The same PR's admission guard then throws 'channel restart recovery requires source-keyed user-turn admission' for every such turn — breaking qa-lab suite runs, ACP-bridge flows, and relay integrations (reproduced live on the codex harness chat-image probe; text-only fails identically). Internal-origin turns (gateway chat.send stamps the internal channel as the ingress provider) carry run ids, not provider message ids; gateway turns already own restart via fingerprint admission and client-side idempotent retries. Skip the mint for internal ingress at both derivation sites so admission takes the source-less persist path, while real channel ingress keeps the new source-keyed recovery. Also surface the full agent.wait result in the codex harness live test error (how this was found). Live proof: gateway-codex-harness.live.test.ts chat-image probe on a Blacksmith Testbox with a real OpenAI key failed with the admission error twice on main and passes admission with this fix.
…igin turns (openclaw#109201) PR openclaw#108283 started deriving a durable channel source-turn id for gateway chat.send turns carrying originatingChannel/originatingTo overrides, while the gateway's pre-created user-turn recorder keys the persisted turn by run id. The same PR's admission guard then throws 'channel restart recovery requires source-keyed user-turn admission' for every such turn — breaking qa-lab suite runs, ACP-bridge flows, and relay integrations (reproduced live on the codex harness chat-image probe; text-only fails identically). Internal-origin turns (gateway chat.send stamps the internal channel as the ingress provider) carry run ids, not provider message ids; gateway turns already own restart via fingerprint admission and client-side idempotent retries. Skip the mint for internal ingress at both derivation sites so admission takes the source-less persist path, while real channel ingress keeps the new source-keyed recovery. Also surface the full agent.wait result in the codex harness live test error (how this was found). Live proof: gateway-codex-harness.live.test.ts chat-image probe on a Blacksmith Testbox with a real OpenAI key failed with the admission error twice on main and passes admission with this fix.
) * fix(gateway): recover channel turns safely after restart * refactor(gateway): keep recovery identity internal * refactor(gateway): keep recovery metadata private * fix(gateway): preserve recovery action authority * fix(gateway): close recovery lifecycle gaps * fix(gateway): fail closed on missing delivery receipts * fix(gateway): fail closed on unmirrorable replies * fix(gateway): persist terminal delivery intent * fix(gateway): align recovery lifecycle types * fix(gateway): require exact terminal thread receipt * fix(gateway): close recovered terminal tool calls * test(gateway): type terminal tool correlation * fix(gateway): satisfy restart recovery CI contracts * fix(gateway): require terminal tool correlation * fix(agents): scope recovery receipts to source turns * fix(gateway): fail closed without restart correlation * fix(gateway): dedupe terminal source redelivery * fix(agents): keep recovery tool results causal * test(auto-reply): clean recovery fixture directories * fix(gateway): allow live terminal sends without recovery claims * fix(agents): reconcile delivered sends through restart aborts * fix(agents): keep recovery continuations in source turns * fix(agents): keep source-less sends non-terminal * fix(auto-reply): dedupe active source redelivery * fix(agents): harden recovery receipt contracts * fix(agents): admit terminal recovery successors * docs(recovery): document canonical receipt ownership * fix(agents): fail closed on stale turn authority * test(auto-reply): assert rebound session state * fix(plugins): keep restart recovery hook list internal
…igin turns (openclaw#109201) PR openclaw#108283 started deriving a durable channel source-turn id for gateway chat.send turns carrying originatingChannel/originatingTo overrides, while the gateway's pre-created user-turn recorder keys the persisted turn by run id. The same PR's admission guard then throws 'channel restart recovery requires source-keyed user-turn admission' for every such turn — breaking qa-lab suite runs, ACP-bridge flows, and relay integrations (reproduced live on the codex harness chat-image probe; text-only fails identically). Internal-origin turns (gateway chat.send stamps the internal channel as the ingress provider) carry run ids, not provider message ids; gateway turns already own restart via fingerprint admission and client-side idempotent retries. Skip the mint for internal ingress at both derivation sites so admission takes the source-less persist path, while real channel ingress keeps the new source-keyed recovery. Also surface the full agent.wait result in the codex harness live test error (how this was found). Live proof: gateway-codex-harness.live.test.ts chat-image probe on a Blacksmith Testbox with a real OpenAI key failed with the admission error twice on main and passes admission with this fix.
Related: #95609
What Problem This Solves
Fixes an issue where users could receive a resend-request notice after a gateway restart even though OpenClaw had enough durable evidence to finish or safely resume the interrupted channel turn. A restart could also lose a newly accepted channel request before its user turn reached the transcript.
Why This Change Was Made
Channel ingress now records the user turn and its restart-recovery claim atomically before hooks or model execution. Same-conversation terminal message-tool sends receive an exact source-turn receipt, and recovery reconciles that receipt instead of replaying the turn. Recovered message authority remains bound to the original session, account, sender, channel, target, and thread.
Ambiguous side effects still fail closed. Before a terminal source send reaches the provider, the exact session records a pending delivery intent. Confirmed success resolves it to delivered; confirmed non-delivery clears it. A crash or timeout with an unknown outcome keeps the pending marker, so recovery asks for a clean retry instead of replaying remaining effects. No Gateway protocol, public plugin SDK, or configuration surface changes.
User Impact
After a gateway restart, safely resumable Discord and other channel turns continue automatically. Already delivered terminal replies are not duplicated, and turns accepted before hooks or model work no longer disappear from recovery state. Truly ambiguous tool effects retain the existing one-time resend notice.
Release-note context: channel turns recover more reliably after gateway restarts, without duplicate terminal replies or unnecessary resend prompts when durable evidence proves the safe outcome.
Evidence
Live source-blind Discord validation was not run against the unmerged branch because it would require replacing a production gateway or provisioning a separate disposable bot/channel. The integration matrix exercises the exact restart boundaries without mutating a live deployment.