Skip to content

fix: queued follow-up goes unanswered after a delayed /stop or /status - #195358

Closed
arcabotai wants to merge 9 commits into
openclaw:mainfrom
arcabotai:cursor/fix-stop-command-exchange-replay-e241
Closed

arcabotai wants to merge 9 commits into
openclaw:mainfrom
arcabotai:cursor/fix-stop-command-exchange-replay-e241

Conversation

@arcabotai

@arcabotai arcabotai commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #194303

What Problem This Solves

Fixes: a follow-up that is already the next persisted user turn is never answered when a delayed /stop or /status command exchange lands before that turn is replayed.

User Impact

User impact: after /stop (and /status in the same window), the queued follow-up is answered once instead of being dropped. Ordinary commands such as /model, and newer user messages, still supersede that older turn. The command exchange stays in the transcript.

Why This Change Was Made

A delayed command exchange can become the current turn even though a later user message was already persisted. The walk that selects the current turn now crosses context-free commands (including /status) and /stop exchanges, so the already-persisted follow-up stays the admitted turn.

Reparenting that follow-up would rewrite its admission anchor. Holding the next persist across abort settlement can deadlock Stop. This change keeps those producer-side options out of the path and does not let replay cross ordinary context-bearing commands.

The /stop marker (preservesInFlightTurn) is set by the command recorder when the command text is an abort. It is stored message metadata, not a caller-selectable parameter on the public command-exchange APIs.

Evidence

Focused regression (attempt-session-replay.command-exchange.test.ts): a delayed /stop or /status exchange is injected after replay preparation on both reader paths. Without the change, admission throws Persisted user turn changed before replay admission. With it, the follow-up is answered exactly once; the model prompt contains that follow-up once and does not treat /stop or /status as the user question. A later /model exchange or a newer plain user message still fails admission of the older follow-up. GitHub CI on e418fb5221cd was green (88 successful checks). A follow-up commit (08e8a771e04e) keeps preservesInFlightTurn internal to the recorder and does not change that runtime behavior.

Live isolated Gateway on Linux, using a local holding model, against current main (7726572226387e4f6c0400a6d0667a5fd153a677) and this branch at e418fb5221cd3e99c5d9502986236ca41688d631 (the later type-only follow-up does not change these receipts). The command abort or status reply is produced immediately, delivery is held, a follow-up user row is persisted, then the held exchange is released so those rows land immediately after the follow-up:

  • Delayed /stop: current main left the follow-up unanswered in 3 of 3 runs (0 model requests; No answer was returned. Ask again if you still need one.). This branch answered that follow-up exactly once in 3 of 3 runs (ANSWER_FOR FOLLOWUP_BRANCH_STOP_N). The /stop rows on this branch carry preservesInFlightTurn: true.
  • Delayed /status: current main left the follow-up unanswered in 3 of 3 runs (same silent drop). This branch answered that follow-up exactly once in 3 of 3 runs (ANSWER_FOR FOLLOWUP_BRANCH_STATUS_N). The /status rows carry contextFreeCommand: true and were not treated as the user question.

The named admission-error text was not printed on these live runs. On current main the follow-up run exits without a model request after the delayed command rows land; the focused regression remains the inspectable source of Persisted user turn changed before replay admission.

Upgrade and stored-data compatibility from v2026.11.1 (4ffdd2047d192dd65554de3c8c46c0e0197c6e2a): a session created on that release (13 rows, including answered follow-ups, /fast on, a /stop without the new flag, and /status) was opened with this branch after the normal session-database schema upgrade. All 13 pre-upgrade rows loaded unchanged, and session settings including fastMode: true were preserved. A new follow-up on that upgraded session was answered (FOLLOWUP_UPG_NEW_1 still there? → ANSWER_FOR FOLLOWUP_UPG_NEW_1). A new /stop written after the upgrade received preservesInFlightTurn: true without rewriting the v2026.11.1 /stop (preservesInFlightTurn stayed unset/false on that older row).

Redacted live receipts (persistence, delayed command recording, admission, one answer)

Current main, delayed /stop (1 of 3; the other two matched)

follow-up user row observed in transcript  seenRow=true  followupModelRequestsSoFar=0
released held command reply  released=1
{"modelRequestsForFollowup":0,"modelRequestsWhoseTurnIsCommand":0,"answers":0}

user       LONG_TURN please write a very long essay
user       FOLLOWUP_MAIN_STOP_1 what is two plus two?
user       /stop
assistant  Agent was aborted.
custom     run-failed-before-reply

gateway error: No answer was returned. Ask again if you still need one.

This branch, delayed /stop (1 of 3; the other two matched)

follow-up user row observed in transcript  seenRow=true  followupModelRequestsSoFar=0
released held command reply  released=1
{"modelRequestsForFollowup":1,"answers":1}

user       LONG_TURN please write a very long essay
user       FOLLOWUP_BRANCH_STOP_1 what is two plus two?
user       /stop                         preservesInFlightTurn=true
assistant  Agent was aborted.            preservesInFlightTurn=true
assistant  ANSWER_FOR FOLLOWUP_BRANCH_STOP_1

model request for the follow-up:
  prompt includes FOLLOWUP_BRANCH_STOP_1 what is two plus two?
  reply: ANSWER_FOR FOLLOWUP_BRANCH_STOP_1

Current main, delayed /status (1 of 3; the other two matched)

/status does not abort the long turn. The long turn completed, the follow-up was persisted, then the held /status exchange landed after it.

follow-up user row observed in transcript  seenRow=true  followupModelRequestsSoFar=0
released held command reply  released=1
{"modelRequestsForFollowup":0,"modelRequestsWhoseTurnIsCommand":0,"answers":0}

user       LONG_TURN please write a very long essay
assistant  long turn finished
user       FOLLOWUP_MAIN_STATUS_1 what is two plus two?
user       /status     excludeFromContext=true  contextFreeCommand=true
assistant  Session: agent:main:main • duration 5s • Queue: followup

gateway error: No answer was returned. Ask again if you still need one.

This branch, delayed /status (1 of 3; the other two matched)

follow-up user row observed in transcript  seenRow=true  followupModelRequestsSoFar=0
released held command reply  released=1
{"modelRequestsForFollowup":1,"modelRequestsWhoseTurnIsCommand":0,"answers":1}

user       LONG_TURN please write a very long essay
assistant  long turn finished
user       FOLLOWUP_BRANCH_STATUS_1 what is two plus two?
user       /status     excludeFromContext=true  contextFreeCommand=true
assistant  Session: agent:main:main • duration 6s • Queue: followup
assistant  ANSWER_FOR FOLLOWUP_BRANCH_STATUS_1

model request for the follow-up:
  prompt includes FOLLOWUP_BRANCH_STATUS_1 what is two plus two?
  reply: ANSWER_FOR FOLLOWUP_BRANCH_STATUS_1

Upgrade from v2026.11.1

On v2026.11.1 the session had 13 rows, including ANSWER_FOR FOLLOWUP_UPG_OLD_1, /fast on, a /stop without preservesInFlightTurn, ANSWER_FOR FOLLOWUP_UPG_OLD_2, and /status. After opening that same store with this branch:

pre-upgrade rows unchanged after upgrade+restart  same=true  oldRows=13  rowsNow=13
session after upgrade: key=agent:main:main  fastMode=true  thinkingDefault=off
                       thinkingOptions=["off","ultra"]

post-upgrade follow-up: FOLLOWUP_UPG_NEW_1 still there? -> ANSWER_FOR FOLLOWUP_UPG_NEW_1

stored /stop rows:
  seq 8  preservesInFlightTurn=false   (created on v2026.11.1)
  seq 19 preservesInFlightTurn=true    (created after upgrade)

pre-upgrade rows still unchanged after new /stop  same=true

— Opened by an AI agent from Arca. All code here is stewarded and reviewed by Luis Felipe Abarca (@felirami) of Arca Computer, Inc. (https://arca.computer). All Arca OSS contributions: https://oss.arcabot.ai

A follow-up that was already persisted was rejected when a late /stop or
/status exchange became the current turn. Context-free commands and
fast-abort exchanges stay in the transcript without replacing that turn.
Ordinary commands and newer user messages still supersede it.

Co-authored-by: felirami <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 8, 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 agents Agent runtime and tooling size: M labels Nov 8, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Allow replay admission to cross delayed Stop and context-free command exchanges without losing the already-persisted follow-up.

Example: A delayed /stop exchange lands after FOLLOWUP_BRANCH_STOP_1 is persisted.

  • Before: The follow-up produces no model request and receives no answer.
  • After: The follow-up receives ANSWER_FOR FOLLOWUP_BRANCH_STOP_1 exactly once.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused repair with direct Gateway behavior evidence and no concrete introduced defect; latest-stable upgrade validation remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A follow-up can remain unanswered when delayed Stop or status history lands before replay admission.
Reason: Restores answers for demonstrated failures while retaining command history and genuine newer-turn barriers.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR addresses a current unanswered-message bug, preserves ordinary-command barriers, and is not fully superseded by the related Stop-only repair.

Priority: P1
Reviewed head: dffb68ab5740946e8b52ddbc78067346fd003df4

Before merge

  • Add real behavior proof - The supplied isolated Linux Gateway receipts exercise delayed Stop and status delivery and show one answer after the fix; runtime behavior is preserved at the reviewed head. Stored metadata compatibility is demonstrated from v2026.11.1, but the required latest-stable v2026.11.2 upgrade scenario is missing; the contributor should provide redacted logs or live output with credentials and private endpoints removed. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply an upgrade run from v2026.11.2 showing existing transcript rows and settings remain intact and a new follow-up is answered.
Agent review details

How this fits together

The command recorder persists delivered exchanges; session replay walks that history to select the user turn admitted to the model.

flowchart LR
A[Command delivery] --> B[Command recorder]
B --> C[Transcript storage]
D[Persisted follow-up] --> C
C --> E[Current-turn traversal]
E --> F[Replay admission]
F --> G[Model response]
Loading

Technical review

Best possible solution:

Keep command classification in the recorder and replay selection in the existing traversal owner while preserving ordinary-command and newer-user barriers.

Do we have a high-confidence way to reproduce the issue?

Current source establishes the replay barrier, the canonical report supplies failing regressions, and the contributor supplies matching Gateway receipts; this read-only review executed no target code.

Is this the best way to solve the issue?

The change narrowly classifies the two demonstrated command cases through existing owners, preserves delivered history, and tests genuine superseding input without skipping arbitrary commands.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against bdce9c84ea55.

Provenance checked

  • Delivered command history keeps the original intent (289d859: Retain successfully delivered commands and replies as conversation history.)
  • Context-free status recording keeps the original intent (c2cb56c: Keep status visible without interrupting an active reply or entering model context.)
  • Current-turn replay traversal changes intended behavior with a stated reason (40cdfd0: Prepare exact interrupted-turn replay asynchronously while preserving final admission and stale-writer checks.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 40cdfd0 adds src/agents/sessions/session-manager-current-turn.ts:29 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 40cdfd038332; files: src/agents/sessions/session-manager-current-turn.ts)
  • Ayaan Zaidi: Raw commit 289d859 adds src/config/sessions/command-transcript.ts:87 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 289d859c2bab; files: src/config/sessions/command-transcript.ts)

PR surface

Source +52, Tests +188, Other +2. Total +242 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 66 14 +52
Tests 2 188 0 +188
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 7 256 14 +242

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #194303
Summary: Delayed command recording replaces the apparent current turn before replay admission.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Delayed command recording can leave an accepted channel message persisted but unanswered.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-08T19:22:53.528Z sha e418fb5 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-08T20:42:39.935Z sha e418fb5 :: ready, awaiting a maintainer decision. :: none

Reviewed November 9, 2026, 5:52 PM ET / 22:52 UTC (Revision 3).

@arcabotai

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

— Opened by an AI agent from Arca. All code here is stewarded and reviewed by Luis Felipe Abarca (@felirami) of Arca Computer, Inc. (https://arca.computer). All Arca OSS contributions: https://oss.arcabot.ai

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
preservesInFlightTurn is still set by the command recorder when the
command text is an abort. Public command-exchange functions no longer
accept it as a caller parameter.

Co-authored-by: felirami <[email protected]>
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 9, 2026
cursoragent and others added 4 commits November 9, 2026 19:47
Upstream main is 352 test lines over its ceiling. This grant is the
187-line regression plus that inherited overage, with no extra slack.

Co-authored-by: felirami <[email protected]>
Main is 356 test lines over its ceiling. This grant is the 187-line
regression plus that overage, with no extra slack.

Co-authored-by: felirami <[email protected]>
cursoragent and others added 3 commits November 9, 2026 21:19
Upstream main is back within its test-line ceiling, so this grant covers
only the delayed /stop and /status replay regression.

Co-authored-by: felirami <[email protected]>
@arcabotai

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The branch was refreshed onto upstream main (d7f88abf, including the lint fix). CI is green on the new head dffb68ab5740946e8b52ddbc78067346fd003df4. Behavior is unchanged from the previously reviewed head.

— Opened by an AI agent from Arca. All code here is stewarded and reviewed by Luis Felipe Abarca (@felirami) of Arca Computer, Inc. (https://arca.computer). All Arca OSS contributions: https://oss.arcabot.ai

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
obviyus added a commit that referenced this pull request Nov 18, 2026
…Stop reply is delivered late (#195612)

Root cause: src/auto-reply/reply/dispatch-from-config.prepare-operation.ts:217 (on main 1680f54) the fast-abort path lets Stop cancel and release its own message source at once, while a direct Stop reply records its `/stop` exchange only later, at dispatcher settlement after delivery. A turn accepted while that reply is still being sent persists its user row first, so the Stop exchange lands after it and the follow-up can fail replay admission ("Persisted user turn changed before replay admission") and go unanswered.

Fixes #194303

Thanks @amittell for the report, the root-cause analysis and this fix. Thanks @arcabotai for #195358, which reported the same unanswered follow-up; this PR fixes the Stop path at the producer instead of relaxing replay admission.

## What Problem This Solves

Fixes: a message sent right after `/stop` is recorded ahead of the Stop exchange in session history, and can go unanswered, when the Stop reply reaches the channel late.

## User Impact

User impact: after `/stop`, the next message waits until the Stop reply is delivered and recorded, then runs and is answered once, with the Stop exchange first in history. Input already waiting when Stop arrived is still cancelled, as before.

## Why This Change Was Made

Once a stop request is recognized, before Stop selects anything, dispatch retains the Stop message's own source until the Stop reply settles (dispatcher settlement, bounded by the existing follow-up admission barrier timeout). The mailbox does not select past a source with unsettled work, so the next turn starts after the Stop rows. If the abort resolver throws or the message is not handled as a stop, the retention is released immediately.

Unchanged: what Stop cancels, command classification, the command history format, and replay admission (a command row written before a turn still refuses a stale replay). #194336, #194396 and #195358 instead make command exchanges traversable for replay admission, which reverses the `c2cb56c665e` boundary; this PR touches neither replay predicate.

Maintainer edits on top of @amittell's commits: merged current main, rewrote the retention without re-indenting the fast-abort branch (`.catch`/`.finally` instead of `try/finally`), and kept one red-on-base regression (dispatch order) in place of the two test files and the test-lines allocation.

## Evidence

Observed proof lines (base and head): #195612 (comment)

- Regression `dispatch-from-config.command-transcript.test.ts` > "records a late-delivered /stop before the next turn's row" (active run false/true): main 1680f54 fails 2/2 with `expected [ 'next-turn', 'command-input', …(1) ] to deeply equal [ 'command-input', …(2) ]`; this head passes 4/4.
- Real Gateway (`ocx src --node`) with the Telegram plugin, a local Bot API that holds the Stop reply, and a local chat-completions model: on main the follow-up's user row and answer are written before `/stop` / `Agent was aborted.`; here the Stop exchange is recorded first, then the follow-up row and one answer. `/stop` alone behaves the same on both.
- Replay admission still refuses a genuinely out-of-order replay: `attempt-session-replay-cohort.test.ts` (including `completed-after-preparation`), the steering replay test and `abort.test.ts` pass, 48/48.

## Merge danger

Two-way door: no stored data, config or contract change; a revert restores the old ordering. Blast radius: channels that send `/stop` as a message; a hung Stop delivery delays the next turn by at most the existing follow-up admission barrier timeout.

Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Thank you @arcabotai for working on this. The /stop case is fixed in #195612 (b42a8ff) at the source: /stop now holds its place until its reply is delivered and recorded, so the next message is written after it and answered, without changing replay admission. The delayed /status case from this PR is not covered there; if you can still reproduce a /status follow-up going unanswered on main, please open an issue with the steps.

@obviyus obviyus closed this Nov 18, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
…Stop reply is delivered late (openclaw#195612)

Root cause: src/auto-reply/reply/dispatch-from-config.prepare-operation.ts:217 (on main 5cd28bd) the fast-abort path lets Stop cancel and release its own message source at once, while a direct Stop reply records its `/stop` exchange only later, at dispatcher settlement after delivery. A turn accepted while that reply is still being sent persists its user row first, so the Stop exchange lands after it and the follow-up can fail replay admission ("Persisted user turn changed before replay admission") and go unanswered.

Fixes openclaw#194303

Thanks @amittell for the report, the root-cause analysis and this fix. Thanks @arcabotai for openclaw#195358, which reported the same unanswered follow-up; this PR fixes the Stop path at the producer instead of relaxing replay admission.

## What Problem This Solves

Fixes: a message sent right after `/stop` is recorded ahead of the Stop exchange in session history, and can go unanswered, when the Stop reply reaches the channel late.

## User Impact

User impact: after `/stop`, the next message waits until the Stop reply is delivered and recorded, then runs and is answered once, with the Stop exchange first in history. Input already waiting when Stop arrived is still cancelled, as before.

## Why This Change Was Made

Once a stop request is recognized, before Stop selects anything, dispatch retains the Stop message's own source until the Stop reply settles (dispatcher settlement, bounded by the existing follow-up admission barrier timeout). The mailbox does not select past a source with unsettled work, so the next turn starts after the Stop rows. If the abort resolver throws or the message is not handled as a stop, the retention is released immediately.

Unchanged: what Stop cancels, command classification, the command history format, and replay admission (a command row written before a turn still refuses a stale replay). openclaw#194336, openclaw#194396 and openclaw#195358 instead make command exchanges traversable for replay admission, which reverses the `1bcf6c36036` boundary; this PR touches neither replay predicate.

Maintainer edits on top of @amittell's commits: merged current main, rewrote the retention without re-indenting the fast-abort branch (`.catch`/`.finally` instead of `try/finally`), and kept one red-on-base regression (dispatch order) in place of the two test files and the test-lines allocation.

## Evidence

Observed proof lines (base and head): openclaw#195612 (comment)

- Regression `dispatch-from-config.command-transcript.test.ts` > "records a late-delivered /stop before the next turn's row" (active run false/true): main 5cd28bd fails 2/2 with `expected [ 'next-turn', 'command-input', …(1) ] to deeply equal [ 'command-input', …(2) ]`; this head passes 4/4.
- Real Gateway (`ocx src --node`) with the Telegram plugin, a local Bot API that holds the Stop reply, and a local chat-completions model: on main the follow-up's user row and answer are written before `/stop` / `Agent was aborted.`; here the Stop exchange is recorded first, then the follow-up row and one answer. `/stop` alone behaves the same on both.
- Replay admission still refuses a genuinely out-of-order replay: `attempt-session-replay-cohort.test.ts` (including `completed-after-preparation`), the steering replay test and `abort.test.ts` pass, 48/48.

## Merge danger

Two-way door: no stored data, config or contract change; a revert restores the old ordering. Blast radius: channels that send `/stop` as a message; a hung Stop delivery delays the next turn by at most the existing follow-up admission barrier timeout.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…Stop reply is delivered late (#195612)

Root cause: src/auto-reply/reply/dispatch-from-config.prepare-operation.ts:217 (on main 1680f54) the fast-abort path lets Stop cancel and release its own message source at once, while a direct Stop reply records its `/stop` exchange only later, at dispatcher settlement after delivery. A turn accepted while that reply is still being sent persists its user row first, so the Stop exchange lands after it and the follow-up can fail replay admission ("Persisted user turn changed before replay admission") and go unanswered.

Fixes #194303

Thanks @amittell for the report, the root-cause analysis and this fix. Thanks @arcabotai for #195358, which reported the same unanswered follow-up; this PR fixes the Stop path at the producer instead of relaxing replay admission.

## What Problem This Solves

Fixes: a message sent right after `/stop` is recorded ahead of the Stop exchange in session history, and can go unanswered, when the Stop reply reaches the channel late.

## User Impact

User impact: after `/stop`, the next message waits until the Stop reply is delivered and recorded, then runs and is answered once, with the Stop exchange first in history. Input already waiting when Stop arrived is still cancelled, as before.

## Why This Change Was Made

Once a stop request is recognized, before Stop selects anything, dispatch retains the Stop message's own source until the Stop reply settles (dispatcher settlement, bounded by the existing follow-up admission barrier timeout). The mailbox does not select past a source with unsettled work, so the next turn starts after the Stop rows. If the abort resolver throws or the message is not handled as a stop, the retention is released immediately.

Unchanged: what Stop cancels, command classification, the command history format, and replay admission (a command row written before a turn still refuses a stale replay). #194336, #194396 and #195358 instead make command exchanges traversable for replay admission, which reverses the `c2cb56c665e` boundary; this PR touches neither replay predicate.

Maintainer edits on top of @amittell's commits: merged current main, rewrote the retention without re-indenting the fast-abort branch (`.catch`/`.finally` instead of `try/finally`), and kept one red-on-base regression (dispatch order) in place of the two test files and the test-lines allocation.

## Evidence

Observed proof lines (base and head): #195612 (comment)

- Regression `dispatch-from-config.command-transcript.test.ts` > "records a late-delivered /stop before the next turn's row" (active run false/true): main 1680f54 fails 2/2 with `expected [ 'next-turn', 'command-input', …(1) ] to deeply equal [ 'command-input', …(2) ]`; this head passes 4/4.
- Real Gateway (`ocx src --node`) with the Telegram plugin, a local Bot API that holds the Stop reply, and a local chat-completions model: on main the follow-up's user row and answer are written before `/stop` / `Agent was aborted.`; here the Stop exchange is recorded first, then the follow-up row and one answer. `/stop` alone behaves the same on both.
- Replay admission still refuses a genuinely out-of-order replay: `attempt-session-replay-cohort.test.ts` (including `completed-after-preparation`), the steering replay test and `abort.test.ts` pass, 48/48.

## Merge danger

Two-way door: no stored data, config or contract change; a revert restores the old ordering. Blast radius: channels that send `/stop` as a message; a hung Stop delivery delays the next turn by at most the existing follow-up admission barrier timeout.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit b42a8ff)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…Stop reply is delivered late (openclaw#195612)

Root cause: src/auto-reply/reply/dispatch-from-config.prepare-operation.ts:217 (on main 1680f54) the fast-abort path lets Stop cancel and release its own message source at once, while a direct Stop reply records its `/stop` exchange only later, at dispatcher settlement after delivery. A turn accepted while that reply is still being sent persists its user row first, so the Stop exchange lands after it and the follow-up can fail replay admission ("Persisted user turn changed before replay admission") and go unanswered.

Fixes openclaw#194303

Thanks @amittell for the report, the root-cause analysis and this fix. Thanks @arcabotai for openclaw#195358, which reported the same unanswered follow-up; this PR fixes the Stop path at the producer instead of relaxing replay admission.

## What Problem This Solves

Fixes: a message sent right after `/stop` is recorded ahead of the Stop exchange in session history, and can go unanswered, when the Stop reply reaches the channel late.

## User Impact

User impact: after `/stop`, the next message waits until the Stop reply is delivered and recorded, then runs and is answered once, with the Stop exchange first in history. Input already waiting when Stop arrived is still cancelled, as before.

## Why This Change Was Made

Once a stop request is recognized, before Stop selects anything, dispatch retains the Stop message's own source until the Stop reply settles (dispatcher settlement, bounded by the existing follow-up admission barrier timeout). The mailbox does not select past a source with unsettled work, so the next turn starts after the Stop rows. If the abort resolver throws or the message is not handled as a stop, the retention is released immediately.

Unchanged: what Stop cancels, command classification, the command history format, and replay admission (a command row written before a turn still refuses a stale replay). openclaw#194336, openclaw#194396 and openclaw#195358 instead make command exchanges traversable for replay admission, which reverses the `c2cb56c665e` boundary; this PR touches neither replay predicate.

Maintainer edits on top of @amittell's commits: merged current main, rewrote the retention without re-indenting the fast-abort branch (`.catch`/`.finally` instead of `try/finally`), and kept one red-on-base regression (dispatch order) in place of the two test files and the test-lines allocation.

## Evidence

Observed proof lines (base and head): openclaw#195612 (comment)

- Regression `dispatch-from-config.command-transcript.test.ts` > "records a late-delivered /stop before the next turn's row" (active run false/true): main 1680f54 fails 2/2 with `expected [ 'next-turn', 'command-input', …(1) ] to deeply equal [ 'command-input', …(2) ]`; this head passes 4/4.
- Real Gateway (`ocx src --node`) with the Telegram plugin, a local Bot API that holds the Stop reply, and a local chat-completions model: on main the follow-up's user row and answer are written before `/stop` / `Agent was aborted.`; here the Stop exchange is recorded first, then the follow-up row and one answer. `/stop` alone behaves the same on both.
- Replay admission still refuses a genuinely out-of-order replay: `attempt-session-replay-cohort.test.ts` (including `completed-after-preparation`), the steering replay test and `abort.test.ts` pass, 48/48.

## Merge danger

Two-way door: no stored data, config or contract change; a revert restores the old ordering. Blast radius: channels that send `/stop` as a message; a hung Stop delivery delays the next turn by at most the existing follow-up admission barrier timeout.

Co-authored-by: Ayaan Zaidi <[email protected]>

Release adaptation: Add callback to existing abort parameter type; defer Stop transcript through existing dispatcher lifecycle barrier.

(cherry picked from commit b42a8ff)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

3 participants