Repository navigation
fix(sessions): keep acknowledged inputs queued across a graceful restart - #204848
Merged
Merged
Conversation
Co-authored-by: obviyus <[email protected]>
An accepted input that its transcript append has not consumed has not started. A restart now hands its queued row to boot replay instead of ending it as restart-unrecoverable. A consumed input resumes from the transcript and is not replayed. Co-authored-by: obviyus <[email protected]>
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Collaborator
Author
|
Landed as d40e839. Bug: a graceful restart ended an acknowledged chat message as restart-unrecoverable when its turn had not written its user entry yet. Fix: settleUserTurnPendingInput hands an accepted, unconsumed input to restart replay; a consumed one still resumes from the transcript. Proof: owner unit test red on base and green on head; real Gateway E2E 'admitted as its own turn' passed 6 of 6 on head (lost 10 of 10 on main); the new mid-tool-call case keeps the tool at one run and the input unreplayed. |
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 25, 2026
…art (openclaw#204848) ## Problem A graceful restart can drop a chat message that the Gateway already acknowledged. When the follow-up becomes its own turn (no other run is active) and SIGTERM arrives before that turn writes its user entry, `settleUserTurnPendingInput` finishes the accepted row with `restart-unrecoverable`. After restart, the user sees "The Gateway restarted before this message ran. Send it again." The message never runs. A follow-up that queues behind a running turn survives only because the restart marker sets a preserve flag on live queued owners. An input that is already being admitted is not in that set. ## Solution `settleUserTurnPendingInput` now hands an accepted, unconsumed input over to restart replay instead of finishing it. The decision comes from a stored fact, not from timing: - The transcript append that writes a turn's user entry also consumes the pending row in the same SQLite transaction (it deletes the row, or sets `consumed_event_id` for collected inputs). The recorder's `consumed` flag is published by that commit. - Accepted and not consumed: the turn has not started. The row stays queued, and boot replay (`state = 'queued' AND consumed_event_id IS NULL`) runs it once. - Consumed: the turn has started and its user entry is in the transcript. Settlement is unchanged; restart resume continues that turn, and the input is not injected again. - Not accepted (no ack sent): unchanged; the row ends as `restart-unrecoverable` and the client got an error. The restart marker's preserve flag stays. It also protects queued accepted rows that settle at shutdown with a failure that is not classified as a restart. ## Impact - Acknowledged chat messages run after a graceful restart, exactly once. - A turn stopped mid-tool-call resumes from the transcript. Its tool does not run again and its input is not replayed. - Production: one condition in the existing owner. No schema, state, hook or export change. ## Evidence Each result below has a red base run (production change reverted, tests kept) and a green head run. - Owner unit test, `src/sessions/user-turn-transcript.test.ts` "hands an unconsumed input to restart replay only once accepted": `accepted=true` fails on base (the row is `cancelled`) and passes on head. `accepted=false` passes on both: a pre-ack input still ends. - Real Gateway E2E (`test/gateway-restart-resume.e2e.test.ts`, isolated state and port): - "keeps an acknowledged follow-up admitted as its own turn": base fails with the production shape (row `<key>:user` cancelled, `end_cause = restart-unrecoverable`, `consumed_event_id` NULL, no model request after restart). Head passes. Head passed 6 of 6 runs; the same case lost the input in 10 of 10 runs on main before this change. - "keeps an acknowledged follow-up queued behind a running turn": passes on head (regression guard). - New "continues a turn stopped mid-tool-call without replaying its input": SIGTERM while `exec` runs. After restart the turn resumes from the transcript, the `exec` callback count stays 1, the transcript holds one user entry for the input, no replayed turn is answered, and no pending row remains. Passes on base and head: it guards exactly-once against this change. - `oxlint` and `oxfmt --check` on the changed files: clean. Test cost: +228 test lines (under the 400-line record threshold). Each added E2E case takes about 15-20 s; it needs a real Gateway restart, which no cheaper layer can prove. Co-authored-by: Ayaan Zaidi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A graceful restart can drop a chat message that the Gateway already acknowledged. When the follow-up becomes its own turn (no other run is active) and SIGTERM arrives before that turn writes its user entry,
settleUserTurnPendingInputfinishes the accepted row withrestart-unrecoverable. After restart, the user sees "The Gateway restarted before this message ran. Send it again." The message never runs.A follow-up that queues behind a running turn survives only because the restart marker sets a preserve flag on live queued owners. An input that is already being admitted is not in that set.
Solution
settleUserTurnPendingInputnow hands an accepted, unconsumed input over to restart replay instead of finishing it. The decision comes from a stored fact, not from timing:consumed_event_idfor collected inputs). The recorder'sconsumedflag is published by that commit.state = 'queued' AND consumed_event_id IS NULL) runs it once.restart-unrecoverableand the client got an error.The restart marker's preserve flag stays. It also protects queued accepted rows that settle at shutdown with a failure that is not classified as a restart.
Impact
Evidence
Each result below has a red base run (production change reverted, tests kept) and a green head run.
src/sessions/user-turn-transcript.test.ts"hands an unconsumed input to restart replay only once accepted":accepted=truefails on base (the row iscancelled) and passes on head.accepted=falsepasses on both: a pre-ack input still ends.test/gateway-restart-resume.e2e.test.ts, isolated state and port):<key>:usercancelled,end_cause = restart-unrecoverable,consumed_event_idNULL, no model request after restart). Head passes. Head passed 6 of 6 runs; the same case lost the input in 10 of 10 runs on main before this change.execruns. After restart the turn resumes from the transcript, theexeccallback count stays 1, the transcript holds one user entry for the input, no replayed turn is answered, and no pending row remains. Passes on base and head: it guards exactly-once against this change.oxlintandoxfmt --checkon the changed files: clean.Test cost: +228 test lines (under the 400-line record threshold). Each added E2E case takes about 15-20 s; it needs a real Gateway restart, which no cheaper layer can prove.