Skip to content

fix(agents): mid-turn messages no longer drop message-tool replies - #176084

Open
coletebou wants to merge 2 commits into
openclaw:mainfrom
coletebou:fix/steer-skipped-outbound-reply
Open

coletebou wants to merge 2 commits into
openclaw:mainfrom
coletebou:fix/steer-skipped-outbound-reply

Conversation

@coletebou

@coletebou coletebou commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #176028

What Problem This Solves

Fixes: on turns whose visible reply must go through the message tool (message_tool_only), a message that arrives while the agent is working can make steering skip the message(action=send) that carries the finished answer, so the earlier message never gets its reply.

User Impact

User impact: a reply the agent already wrote is delivered even when the user sends another message mid-turn. The newer message is still handled right after, in order, as the steering docs promise. Users who type follow-ups while the agent works no longer see answers silently disappear.

Why This Change Was Made

Since #163852, steering skips the unstarted tail of a sequential tool batch once one call has started. That is the right call for work the model may want to replan, but on message_tool_only turns the final text is private and the answer is itself a tool call. Any sequential sibling (bundled MCP tools are sequential by default) made the answer skippable.

The steering checkpoint in agent-core now asks an internal, OpenClaw-owned classifier whether the call about to launch delivers the turn's visible reply, and does not skip it when it does. The steer stays queued and is applied after that call's result. The classification lives with the existing message-tool terminal hook, which already owns "a current-source send is this turn's reply" after delivery; it now answers the same question before launch, reusing the same route helpers:

  • only message send actions, only on message_tool_only turns;
  • sends with no explicit route, or whose explicit route resolves to the current conversation;
  • sends to other conversations, non-send actions, other tools, and automatically delivered turns are unchanged.

Running tools, parallel batches, and later calls in the batch keep their current behavior. If steering already skipped an earlier call in the same batch, the send is skipped with the rest of the batch: that answer was composed assuming the skipped call would run, so the model replans with both skips visible. Docs updated in concepts/queue-steering, concepts/queue, and concepts/agent.

Accepted edge case: classification reads the call's arguments as the model sent them, before before_tool_call hooks or preparers can rewrite them, and a dryRun or final: false progress send to the current conversation also counts. In either case the only effect is that the call launches one step before the steer applies.

Evidence

Gateway proof (real Gateway process from the built runtime, real plugin loading, chat.send over the Gateway protocol, session transcript read back with chat.history; only the model is scripted). New case in test/gateway-steer-fifo.e2e.test.ts: a message_tool_only webchat turn answers input A with [steering_gate (sequential, held), message(send A), steering_tail]; input B steers in while the gate is held; the model then answers B with message(send B). The case asserts:

  • the first request's system prompt is the message-tool-only one (final text private, so the send is the only visible answer);
  • the send's tool result reaching the model is "Sent visible reply to the current source conversation", not the steering skip;
  • the ordinary steering_tail call is still skipped, the steer follows the tool results, and the tail tool never executes;
  • chat.history shows answer A, then answer B.

Captured from one run of that case with this change: the scripted provider's second request (what the Gateway sent back after the first batch), the fixture plugin's execution trace, and chat.history for the session as the WebChat user sees it. The capture was a temporary local dump in the test, not committed. Redaction: user entries are trimmed to the message text (sender metadata and timestamps removed); nothing else was edited.

{
  "modelRequestCount": 2,
  "secondModelRequestInput": [
    {
      "role": "user",
      "text": "INITIAL_HELD_TURN"
    },
    {
      "call": "steering_gate",
      "call_id": "call_steering_gate",
      "arguments": "{}"
    },
    {
      "call": "message",
      "call_id": "call_reply_a",
      "arguments": "{\"action\":\"send\",\"message\":\"ANSWER_FOR_HELD_TURN\"}"
    },
    {
      "call": "steering_tail",
      "call_id": "call_steering_tail",
      "arguments": "{}"
    },
    {
      "result_for": "call_steering_gate",
      "output": "steering gate completed"
    },
    {
      "result_for": "call_reply_a",
      "output": "Sent visible reply to the current source conversation via internal-ui."
    },
    {
      "result_for": "call_steering_tail",
      "output": "Skipped to process an incoming message."
    },
    {
      "role": "user",
      "text": "STEER_BEHIND_MESSAGE_TOOL_REPLY"
    }
  ],
  "pluginToolTrace": [
    "gate-execute-start",
    "gate-execute-end"
  ],
  "chatHistory": [
    {
      "role": "user",
      "parts": [
        "INITIAL_HELD_TURN"
      ]
    },
    {
      "role": "assistant",
      "parts": [
        "[toolCall steering_gate {}]",
        "[toolCall message {\"action\":\"send\",\"message\":\"ANSWER_FOR_HELD_TURN\"}]",
        "[toolCall steering_tail {}]"
      ]
    },
    {
      "role": "toolResult",
      "parts": [
        "steering gate completed"
      ]
    },
    {
      "role": "assistant",
      "parts": [
        "ANSWER_FOR_HELD_TURN"
      ]
    },
    {
      "role": "toolResult",
      "parts": [
        "Sent visible reply to the current source conversation via internal-ui."
      ]
    },
    {
      "role": "toolResult",
      "parts": [
        "Skipped to process an incoming message."
      ]
    },
    {
      "role": "user",
      "parts": [
        "STEER_BEHIND_MESSAGE_TOOL_REPLY"
      ]
    },
    {
      "role": "assistant",
      "parts": [
        "[toolCall message {\"action\":\"send\",\"message\":\"ANSWER_FOR_STEER\"}]"
      ]
    },
    {
      "role": "assistant",
      "parts": [
        "ANSWER_FOR_STEER"
      ]
    },
    {
      "role": "toolResult",
      "parts": [
        "Sent visible reply to the current source conversation via internal-ui."
      ]
    }
  ]
}

Reading it: the send launched while the steer waited (Sent visible reply ...), the ordinary steering_tail was still skipped and never executed (trace has no tail-executed), the steer follows the tool results, and the transcript shows ANSWER_FOR_HELD_TURN before ANSWER_FOR_STEER. The case passes (pnpm test:e2e:gateway test/gateway-steer-fifo.e2e.test.ts -t "message-tool-only answer").

Same command with the new agent-core check neutralized (equivalent to main for this path):

 × test/gateway-steer-fifo.e2e.test.ts > Gateway steer FIFO > delivers a message-tool-only answer launched behind a running sequential tool 8910ms
AssertionError: expected 'Skipped to process an incoming messag…' to contain 'Sent visible reply to the current sou…'
Expected: "Sent visible reply to the current source conversation"
Received: "Skipped to process an incoming message."

The case takes about 10 s; the wall time is dominated by the one-time runtime build of the e2e setup (about 13 min cold on the 16 GB macOS machine used). Not covered: a live Telegram run (needs Telegram Test Server userbot credentials).

  • New regression through the real composition (real Agent, real message tool on the WebChat internal sink, terminal hook in message_tool_only mode): the model answers input A with [sequential lookup, message(send)] while input B arrives. Fails on main with sent: [answer B], deliveries: 1; passes with this change with both answers delivered in order and the steer after the first answer's result.
  • agent-core contract: a classified call launches when steering arrives during the previous call or during the reply's own preparation, the remaining tail is still skipped, and the steer is injected once after the results. Reverting either checkpoint call site fails the matching case. Once steering already skipped an earlier call, the classified send is skipped with the tail.
  • Classifier cases: explicit send to the source route (classified), explicit send to another target (not classified), read action, another tool, and automatic delivery (no classifier installed).
  • pnpm test on touched suites, --maxWorkers=1 (warm): packages/agent-core/src/agent-loop.steering.test.ts 2.1 s wall (0.7 s Vitest), src/agents/embedded-agent-runner/run/message-tool-terminal.loop.test.ts 15.2 s wall (11.2 s Vitest, mostly transforming the message-tool runtime the file already imported; the new case runs in under 10 ms), src/agents/embedded-agent-runner/run/message-tool-terminal.test.ts 11.2 s wall (9.1 s Vitest). Also green: agent-loop.test.ts, stream-steering.test.ts, agent-loop.async-tools.test.ts, message-tool-terminal.tool-authored.test.ts.
  • pnpm tsgo:core; tsgo on the agents-other, packages and test-root-other test graphs; type-aware oxlint on touched files; oxfmt check; pnpm check:line-cap-ratchet (no growth in the grandfathered agent-loop.ts); pnpm format:docs:check; git diff --check.
  • Extensive multi-model review: the steering semantics, transcript pairing, and route matching held up. A stale-classifier concern for a reused agent does not apply (every attempt creates a fresh Agent and the installer has one call site), and a line-growth concern for agent-loop.ts was a false positive (the ratchet skips comments and passes). One gap was closed: a test now pins that the send is skipped with the tail once steering already skipped an earlier call.
  • PR CI on the first head: checks-node-changed-extensions-bundle-1 failed in extensions/codex/src/app-server/compact.test.ts ("keeps later compactions behind an active request after a queued waiter cancels", Bun shard: got the generic "The operation was aborted." instead of the waiting-to-start abort reason), and the two ci-gate checks aggregate it. That test does not reach the steering checkpoint; it ran only because agent-core changes select the changed-extension lanes. It passed 3/3 locally, pnpm test:ci-failed 176084 classifies it [unknown] (no matching job on main), and no existing report was found. Treated as an inherited flake; not rerun just for green. On the current head every check passes, including that test.
  • Inherited, not touched by this change: pnpm check:max-lines-ratchet reports three ui/src/pages files whose suppressions are missing from config/max-lines-baseline.txt at the fork point, and pnpm docs:check-links:anchors reports five broken fragments in unrelated pages.

Production +92/-15, tests +350/-8 (including the Gateway e2e case), docs +8/-5 against the merge base. No new state, config, or public SDK surface; the duplicated pending-send extraction in the terminal hook became one helper shared by the pre-launch and post-delivery checks.

On message_tool_only turns the final text is private and the visible
answer is a message(action=send) call. Once a call of a sequential batch
had started, a waiting steer skipped that unstarted send, so the earlier
message never got its reply.

The sequential launch checkpoint now asks an internal, OpenClaw-owned
classifier whether the call about to launch delivers the turn's visible
reply. If it does, steering stays queued and applies after that call's
result. The message-tool terminal hook installs the classifier on
message_tool_only turns for sends that address the current conversation.
Parallel batches, running tools, and later calls keep their behavior.

Fixes openclaw#176028
@clawsweeper

clawsweeper Bot commented Oct 18, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T03:13:17.160670Z
We couldn’t complete this review. Comment @codex review to try again.
c43d575 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Oct 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves current-conversation message-tool replies when a follow-up arrives during sequential tool execution.

Example: Input B arrives while input A runs [lookup, message(send A), tail] in message_tool_only mode.

  • Before: Steering skips A's send, so only B receives an answer.
  • After: A's answer is delivered before B's answer, while the ordinary tail remains skipped.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, source-supported repair with captured Gateway behavior, complementary boundary regressions, successful exact-head CI, and no blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The updated body supplies captured output from a built Gateway on macOS using real plugin loading, chat.send, the real message tool, and chat.history with a scripted provider: answer A precedes answer B, the ordinary tail remains skipped, and the provider receives steering after the tool results; this resolves the prior review's requested delivery trace.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Typing a follow-up while the agent works can silently discard the earlier message's already-composed answer.
Reason: The change restores the documented per-input answer ordering through existing owners without adding configuration or changing public plugin contracts.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current reply-loss bug, has sufficient Gateway behavior evidence, and has no blocking findings.

Priority: P1
Reviewed head: c43d5756cb77d371198d1088ef7a16f045d9a9e2

Before merge

None.

Findings

None.

Agent review details

How this fits together

The built-in agent loop schedules model-requested tools and queued steering; the message-tool terminal owner identifies current-conversation replies that must launch before steering is consumed.

flowchart TD
  A[Model tool calls] --> B[Sequential launch checkpoint]
  C[Queued follow-up] --> B
  D[Current-source reply classifier] --> B
  B --> E[Message tool delivery]
  E --> F[Tool results and reply history]
  F --> G[Apply follow-up]
Loading

Technical review

Best possible solution:

Use the existing steering checkpoint and message-delivery owner to preserve current-source answers while retaining ordinary tail replanning.

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

Current-main source establishes the skipped-send path, and the author supplies a matching Gateway capture and failing neutralized-check control; no target code was executed during this review.

Is this the best way to solve the issue?

The patch fixes the owning scheduling decision with a private classifier, reuses routing helpers, and preserves cancellation, admission, and the existing skipped-prefix contract.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Sequential steering checkpoints and steering documentation changes intended behavior with a stated reason (8c6ace2: Protect freshly requested plans while allowing queued steering to skip an unstarted sequential tail after execution begins.)
  • Message-tool route extraction and delivery completion keeps the original intent (fix(agents): prevent duplicate recovery after explicit source replies #113554: Use canonical current-source route matching to recognize delivered explicit replies and avoid duplicate recovery.)
  • Input-scoped final reply completion keeps the original intent (09dece0: Keep completion attached to the originating accepted input and wait for owned sibling work to settle.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still exposes the failure: The current-main steering checkpoint drains queued messages without a visible-reply exception; the messaging prompt states that message_tool_only final text is private and skipping the message tool leaves the user without a reply. (packages/agent-core/src/agent-loop-steering.ts:8, 066c207b69e8)
  • Both sequential checkpoints use the exception: The introduced diff passes the pending call at both launch checkpoints, retaining ordinary preparation, cancellation, admission, result settlement, and tail skipping. (packages/agent-core/src/agent-loop.ts:601, c43d5756cb77)
  • Classification stays with the existing delivery owner: Only message_tool_only attempts install the classifier; explicit routes reuse existing send extraction and current-source matching instead of introducing another routing policy. (src/agents/embedded-agent-runner/run/message-tool-terminal.ts:148, c43d5756cb77)
  • New Gateway capture resolves the earlier proof request: The author's current PR body captures the real Gateway's second provider request, plugin execution trace, and chat.history: ANSWER_FOR_HELD_TURN is delivered before ANSWER_FOR_STEER, and steering_tail returns a steering skip without executing. The reported neutralized-check control fails on the expected skipped-send result. (test/gateway-steer-fifo.e2e.test.ts:859, c43d5756cb77)
  • Earlier steering intent is preserved with a documented exception: fix(agent): mid-turn messages no longer skip freshly requested tools #163852 intentionally preserved sequential-tail replanning; this PR explains why the already-composed visible answer needs a narrow exception and still skips it when an earlier call has already been skipped. (packages/agent-core/src/agent-loop-steering.ts:4, 8c6ace2d7d97)
  • Exact-head checks and mergeability: Paginated REST reads found no failing or unfinished check runs; openclaw/ci-gate and the combined commit status are successful for the reviewed head. GitHub reports the PR mergeable and clean. (c43d5756cb77)

Likely related people:

  • Peter Steinberger: Raw commit 8c6ace2 adds packages/agent-core/src/agent-loop-steering.ts:17 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8c6ace2d7d97; files: packages/agent-core/src/agent-loop-steering.ts)
  • Vincent Koc: Raw commit 09dece0 adds src/agents/embedded-agent-runner/run/message-tool-terminal.ts:162 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 09dece092c6c; files: src/agents/embedded-agent-runner/run/message-tool-terminal.ts)

PR surface

Source +77, Tests +342, Docs +3. Total +422 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 92 15 +77
Tests 5 350 8 +342
Docs 3 8 5 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 450 28 +422

Review metrics

Metric Value Why it matters
Production versus test changes Production +92/-15; tests and support +350/-8 Production growth connects the existing scheduling and delivery owners; tests cover routing, both preparation checkpoints, skipped-prefix behavior, and Gateway delivery.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #176028
Summary: This PR and two alternative open PRs address the same sequential-steering loss of the current-source message-tool answer.

Members:

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Follow-up messages can silently suppress an earlier completed answer in an active messaging workflow.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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-10-18T05:28:55.315Z sha 5c4ada1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-18T09:40:52.566Z sha c43d575 :: needs real behavior proof before merge. :: none

Reviewed October 18, 2026, 5:58 AM ET / 09:58 UTC (Revision 3).

Adds a Gateway e2e case for openclaw#176028: a message_tool_only webchat turn
answers with [held sequential tool, message(send), ordinary tail] while
a second message steers in. The send launches and its answer reaches
chat history before the steered answer, and the ordinary tail is still
skipped. With the agent-core check neutralized, the case fails on the
send's "Skipped to process an incoming message." result.
@coletebou

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 18, 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 18, 2026
@coletebou

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 18, 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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. labels Oct 18, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 18, 2026
@coletebou

Copy link
Copy Markdown
Contributor Author

@claude is this still needed

@coletebou

coletebou commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@codex is this still needed

@coletebou

Copy link
Copy Markdown
Contributor Author

@clawsweeper

@coletebou

Copy link
Copy Markdown
Contributor Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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.

[Bug]: Steering skips the message-tool answer on message-tool-only turns, so the earlier message never gets its reply

1 participant