Skip to content

fix: canceling a queued WebChat turn makes the next queued turn fail and retry - #165168

Merged
steipete merged 1 commit into
mainfrom
fix/followup-drain-sibling-abort
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/followup-drain-sibling-abort

Conversation

@steipete

@steipete steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: canceling one queued WebChat turn with chat.abort makes 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 in followup/collect mode 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 collect mode, 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. createFollowupRunner captures that turn's reply options as session defaults, and scheduleFollowupDrain keeps the active drain's callback; newer callbacks only apply to later drains. For WebChat chat.send, those options include the turn's own per-run abort signal. executeFollowupTurn spreads 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-bind abortSignal. 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 in agent-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 own chat.abort, restart, or supersession, and a sibling's cancellation no longer reaches it.

Causal chain
  1. src/gateway/server-methods/chat-send-agent-dispatch.ts passes abortSignal: activeRunAbort.controller.signal (per chat.send) in reply options; chat.abort aborts it with createQueuedChatAbortSignalReason (src/gateway/chat-queued-turns.ts).
  2. src/auto-reply/reply/agent-runner-execute.ts creates createFollowupRunner({ opts, ... }); src/auto-reply/reply/followup-runner.ts retains them as defaults.
  3. src/auto-reply/reply/queue/drain.ts scheduleFollowupDrain: an active drain keeps its callback (rememberFollowupDrainCallback only affects deferred retries).
  4. src/auto-reply/reply/followup-turn-admission.ts admits with upstreamAbortSignal: resolveFollowupAbortSignal(queued); admission is owned.
  5. src/auto-reply/reply/followup-turn-execution.ts built progressOpts from ...defaults.opts without replacing abortSignal.
  6. src/auto-reply/reply/agent-runner-execution.ts params.opts?.abortSignal?.throwIfAborted() throws the sibling's reason; drainNextQueueItem restores the item and the drain logs and reschedules.

Evidence

  • Regression test in src/auto-reply/reply/followup-turn-execution.lifecycle.test.ts: a queued turn executed with runner defaults carrying an already-aborted sibling signal (rpc and restart reasons) 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 no followup queue drain failed / queued turn aborted lines. Before the fix, it printed followup queue drain failed for agent:main:main: Error: queued turn aborted: rpc.
  • That gateway test also raises one load-sensitive vi.waitFor from 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.
  • Also ran: 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, and git diff --check.

…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.
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 6:40 PM ET / 22:40 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: fe4c095836954a11c2dc58467fc0d6db42a17d50

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful cancellation regressions and reported Gateway-boundary validation.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-admin author is exempt from the external-contributor proof gate. Supplemental evidence exercises the changed queued execution owner through real Gateway RPC cancellation and observes survivor completion after the fix; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-admin author is exempt from the external-contributor proof gate. Supplemental evidence exercises the changed queued execution owner through real Gateway RPC cancellation and observes survivor completion after the fix; no stored-data contract changes.
Evidence reviewed 9 items Introduced production repair: The pinned introduction adds only the admitted operation’s abort signal to execution options; the remaining introduced changes are regression coverage and an existing test timeout.
Current main still contains the defect: Current main spreads retained runner options and rebinds operator authority, tool policy, and run identity without replacing abortSignal. The active drain retains its original callback, allowing a canceled sibling’s signal to reach a surviving turn’s execution guard.
Cancellation ownership remains intact: Admission supplies resolveFollowupAbortSignal(queued) to the reply operation. That resolver combines the item’s abort, queue abort, and operator-authority signals; the operation propagates upstream cancellation. Execution already checks the operation signal and retains the existing authority checks.
Findings None None.
Security None None.

How this fits together

WebChat 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +76. Total +77 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 2 82 6 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 83 6 +77

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This repairs a bounded queued-chat cancellation defect that causes spurious retries and delays.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-admin author is exempt from the external-contributor proof gate. Supplemental evidence exercises the changed queued execution owner through real Gateway RPC cancellation and observes survivor completion after the fix; no stored-data contract changes.

Label justifications:

  • P2: This repairs a bounded queued-chat cancellation defect that causes spurious retries and delays.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-admin author is exempt from the external-contributor proof gate. Supplemental evidence exercises the changed queued execution owner through real Gateway RPC cancellation and observes survivor completion after the fix; no stored-data contract changes.

Evidence

What I checked:

  • Introduced production repair: The pinned introduction adds only the admitted operation’s abort signal to execution options; the remaining introduced changes are regression coverage and an existing test timeout. (src/auto-reply/reply/followup-turn-execution.ts:223, fe4c09583695)
  • Current main still contains the defect: Current main spreads retained runner options and rebinds operator authority, tool policy, and run identity without replacing abortSignal. The active drain retains its original callback, allowing a canceled sibling’s signal to reach a surviving turn’s execution guard. (src/auto-reply/reply/followup-turn-execution.ts:218, 228ff5759f6f)
  • Cancellation ownership remains intact: Admission supplies resolveFollowupAbortSignal(queued) to the reply operation. That resolver combines the item’s abort, queue abort, and operator-authority signals; the operation propagates upstream cancellation. Execution already checks the operation signal and retains the existing authority checks. (src/auto-reply/reply/followup-turn-admission.ts:159, fe4c09583695)
  • Regression coverage: Three added cases exercise canceled sibling defaults with RPC and restart reasons, plus cancellation of the surviving turn itself. Deferred gates avoid added timers or polling. The captured PR body reports all three failing with the production line reverted and passing after the fix; these tests were inspected, not executed by this review. (src/auto-reply/reply/followup-turn-execution.lifecycle.test.ts:28, fe4c09583695)
  • Production-boundary validation context: The existing recovery scenario starts an isolated production Gateway, uses WebSocket chat.send/chat.abort requests, and observes the survivor reaching a loopback HTTP provider and completing. The captured body reports a passing after-fix run without the prior queue-drain error. The provider is synthetic; this is Gateway-boundary evidence, not live-provider or browser evidence. (src/gateway/server.startup-recovery-webchat.test.ts:320, fe4c09583695)
  • Verified three-way merge: The raw test-merge record has the exact pinned main parent followed by the exact PR head. Its production delta against main is the same cancellation-signal binding, preserving unrelated main changes. (src/auto-reply/reply/followup-turn-execution.ts:223, 03d8bab6be75)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 8d0f8e8 into main Oct 4, 2026
121 checks passed
@steipete
steipete deleted the fix/followup-drain-sibling-abort branch October 4, 2026 23:11
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant