Repository navigation
fix: canceling a queued WebChat turn makes the next queued turn fail and retry - #165168
Conversation
…ollowups A followup queue keeps the runner callback of the turn that started the drain, and executeFollowupTurn spread that runner's retained reply options into every queued turn without re-binding abortSignal. Canceling the first WebChat chat.send therefore made the next queued turn throw the sibling's "queued turn aborted" reason on its first attempt; the drain logged a failure and retried it. Bind execution to the admitted turn's reply operation signal, which already follows the item's own upstream signals. Also give a load-sensitive gateway test wait the same explicit timeout as its neighbours.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 6:40 PM ET / 22:40 UTC. ClawSweeper reviewWhat this changesThe PR binds queued reply execution to each turn’s own cancellation signal, adds cancellation regressions, and extends an existing Gateway test wait. Merge readiness✅ Ready for maintainer review The fix remains necessary on current main and correctly isolates cancellation between queued turns. No actionable introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherWebChat sends enter OpenClaw’s session reply queue while another run is active. Queue admission creates a reply operation whose cancellation signal controls subsequent agent execution. flowchart TD
A[WebChat messages] --> B[Session reply queue]
B --> C[Turn admission]
C --> D[Reply operation]
E[Own cancellation signals] --> D
D --> F[Agent execution]
F --> G[Reply or cancellation outcome]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +1, Tests +76. Total +77 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep cancellation owned by the admitted reply operation throughout queued execution, preserving independent cancellation of every turn. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the path: cancel the turn whose callback owns an active drain, then execute a surviving queued turn under the retained options. The reported regression and Gateway runs were not independently executed during this read-only review. Is this the best way to solve the issue? Yes, using the already-admitted operation’s signal is the narrowest repair and preserves the existing queue, restart, and authority cancellation owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 228ff5759f6f. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…ollowups (openclaw#165168) A followup queue keeps the runner callback of the turn that started the drain, and executeFollowupTurn spread that runner's retained reply options into every queued turn without re-binding abortSignal. Canceling the first WebChat chat.send therefore made the next queued turn throw the sibling's "queued turn aborted" reason on its first attempt; the drain logged a failure and retried it. Bind execution to the admitted turn's reply operation signal, which already follows the item's own upstream signals. Also give a load-sensitive gateway test wait the same explicit timeout as its neighbours.
What Problem This Solves
Fixes: canceling one queued WebChat turn with
chat.abortmakes the next queued turn in the same session fail its first attempt (followup queue drain failed ... Error: queued turn aborted: rpc) and get retried, when both turns were queued infollowup/collectmode behind an active run or startup recovery.User Impact
Canceling a queued turn now only cancels that turn. The surviving queued turns run on their first attempt. They no longer hit a spurious error log, an extra debounce delay, or repeated preparation such as preflight compaction. In
collectmode, a group whose sources were already adopted can no longer be completed and dropped instead of retried. A sibling canceled for restart can also no longer make a surviving turn look restart-aborted.Why This Change Was Made
Root cause: a followup queue keeps using the runner callback created by the turn that started the drain.
createFollowupRunnercaptures that turn's reply options as session defaults, andscheduleFollowupDrainkeeps the active drain's callback; newer callbacks only apply to later drains. For WebChatchat.send, those options include the turn's own per-run abort signal.executeFollowupTurnspreads the defaults into every queued turn's execution options. It already re-binds the per-turn fields (operator authority, tool policy, run id) to the queued turn, but it did not re-bindabortSignal. A later queued turn therefore ran under the first turn's signal. Once that first turn was canceled, the survivor was admitted normally (admission uses its own signal), then threw the sibling's abort reason from the execution guard inagent-runner-execution.ts. The drain restored it, logged the failure, and the retry succeeded only because the rescheduled drain picked up the survivor's own callback.The fix binds the execution signal to the admitted turn's reply operation (
turn.operation.abortSignal). That is the same signal admission and preflight compaction already use, and the same one the visible reply path passes. The operation is created from the queued item's own upstream signals (its abort signal, queue abort signal, and operator-authority signal) and aborts itself from them. So the survivor still stops on its ownchat.abort, restart, or supersession, and a sibling's cancellation no longer reaches it.Causal chain
src/gateway/server-methods/chat-send-agent-dispatch.tspassesabortSignal: activeRunAbort.controller.signal(perchat.send) in reply options;chat.abortaborts it withcreateQueuedChatAbortSignalReason(src/gateway/chat-queued-turns.ts).src/auto-reply/reply/agent-runner-execute.tscreatescreateFollowupRunner({ opts, ... });src/auto-reply/reply/followup-runner.tsretains them asdefaults.src/auto-reply/reply/queue/drain.tsscheduleFollowupDrain: an active drain keeps its callback (rememberFollowupDrainCallbackonly affects deferred retries).src/auto-reply/reply/followup-turn-admission.tsadmits withupstreamAbortSignal: resolveFollowupAbortSignal(queued); admission is owned.src/auto-reply/reply/followup-turn-execution.tsbuiltprogressOptsfrom...defaults.optswithout replacingabortSignal.src/auto-reply/reply/agent-runner-execution.tsparams.opts?.abortSignal?.throwIfAborted()throws the sibling's reason;drainNextQueueItemrestores the item and the drain logs and reschedules.Evidence
src/auto-reply/reply/followup-turn-execution.lifecycle.test.ts: a queued turn executed with runner defaults carrying an already-aborted sibling signal (rpcandrestartreasons) completes, and its own signal still cancels it. With only the production line reverted, all three cases fail (promise rejected "Error: queued turn aborted: rpc" instead of resolving, and the restart equivalent). With the fix, 13/13 pass.pnpm test src/auto-reply/reply/followup-turn-execution.lifecycle.test.ts --maxWorkers=1: ~32s wall, mostly compile/import. The new cases take ~30ms of test time; there are no timers or polling, and they use deferred gates only.pnpm test src/gateway/server.startup-recovery-webchat.test.ts --maxWorkers=1(the original repro) passes in 38.7s wall, and stderr has nofollowup queue drain failed/queued turn abortedlines. Before the fix, it printedfollowup queue drain failed for agent:main:main: Error: queued turn aborted: rpc.vi.waitForfrom the 1s default to the 30s its neighbors use. Under heavy host load (load avg ~50), it failed on main at the initial in-flight assertion before reaching the scenario.src/auto-reply/reply/followup-turn-execution.test.ts(45 passed),src/auto-reply/reply/followup-turn-execution.steering.test.ts(4 passed),pnpm tsgo, andgit diff --check.