Skip to content

fix(agent-core): restore drained steer/follow-up to its source queue on abort - #128695

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/steer-abort-requeue-128008
Aug 28, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/steer-abort-requeue-128008

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #128008

What Problem This Solves

An accepted steering or follow-up message could disappear when the Agent drained it from its queue and the run then aborted before transcript injection. The message was no longer queued, never reached the provider, and could remain visible as a ghost pending entry.

Why This Change Was Made

Agent owns both queues, so each queue now keeps drained messages in its own in-flight state until message_end commits them to the transcript. When a run settles with an uncommitted message, the same queue restores it ahead of messages accepted later.

This keeps steering and follow-up scheduling separate by construction. It also replaces the earlier loop-level source flag and optional public callback with one private queue lifecycle. The maintainer rewrite keeps the behavior and credit from @SunnyShu0925's PR and the original reproduction from @yetval.

User Impact

  • Steering accepted during a sequential tool batch survives an abort and reaches the next provider request in order.
  • Follow-ups survive the same pre-injection abort window and remain deferred until the agent would otherwise stop.
  • No configuration or public Agent Loop API changes.

Evidence

The live proof used the real Agent, real steering and follow-up queues, real sequential tool execution, a real awaited turn_end abort, and the built-in OpenAI Responses HTTP transport against a loopback provider that recorded each request.

Revision Steering after abort Follow-up after abort
Main 1dba34be9be1249c0e35badcb5ec887ce5d71c72 Queue empty; neither ordered marker reached request 2 Queue empty; neither ordered marker reached the later request
Head 685501499843f4f6be7d8c66d92f038824091640 Queue retained; both markers reached request 2 in order Queue retained; both markers stayed out of request 2 and reached request 3 in order

The skipped sequential tail tool ran zero times on both revisions.

Focused validation:

  • node scripts/run-vitest.mjs packages/agent-core/src — 206 tests passed.
  • node scripts/run-vitest.mjs src/agents/sessions/agent-session-loop-correctness.test.ts src/agents/sessions/agent-session-loop-next-turn.test.ts — 40 tests passed.
  • Repository formatter — passed for both changed files.
  • Core lint — 0 warnings and 0 errors.
  • Core production type check — passed.
  • git diff --check — passed.
  • Exact-head openclaw/ci-gate — passed.
  • Exact-head local ClawSweeper — patch correct, security clear, no findings, owner decisions, or Rank-up moves.

The two new regressions fail on pre-fix production code at the queue-retention assertion and pass with this repair.

AI Assistance

  • AI-assisted: Yes
  • Confirmed understanding: Yes. Drained messages remain owned by their source queue, transcript commit removes them from in-flight state, and run settlement restores only messages that never committed.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@SunnyShu0925
SunnyShu0925 force-pushed the fix/steer-abort-requeue-128008 branch 3 times, most recently from 7e261cf to a3b351c Compare August 24, 2026 11:48
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: S labels Aug 24, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 6:39 AM ET / 10:39 UTC.

ClawSweeper review

What this changes

This PR restores steering and follow-up messages to their originating Agent queue when an abort occurs after destructive drain but before transcript injection.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

The current main loop still destructively drains messages without restoring them on the abort path, while this PR adds a source-aware restoration at the Agent-owned queue boundary. The patch is a focused repair with no remaining correctness finding; exact-head CI completion remains the merge gate.

Priority: P1
Reviewed head: 848b0f066995e51cf9a8b921919d206a3800e19b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused source-aware repair with meaningful after-fix runtime evidence and targeted regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body contains an after-fix terminal trace using the real Agent, queues, sequential tool execution, and an aborting lifecycle listener; redact any private details in future proof updates.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body contains an after-fix terminal trace using the real Agent, queues, sequential tool execution, and an aborting lifecycle listener; redact any private details in future proof updates.
Evidence reviewed 6 items Current-main defect: Current main drains initial, checkpoint, and follow-up messages into loop-local pendingMessages, while stopIfAborted emits the aborted outcome without returning that state to a queue.
Owner-boundary repair: The branch records whether pending input came from steering or follow-up, restores it before abort events, and Agent wires that callback to the corresponding private queue.
Queue scheduling contract: Agent documents steering as mid-run input and follow-up as input that runs only after the agent would otherwise stop; restoring follow-up into steering would therefore change observable scheduling.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs packages/agent-core/src/agent-loop.test.ts --run

Result: PASS (completed)

[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128695-rYcqcC/target

 ✓  unit  packages/agent-core/src/agent-loop.test.ts (70 tests) 165ms

 Test Files  1 passed (1)
      Tests  70 passed (70)
   Start at  10:40:22
   Duration  2.15s (transform 1.51s, setup 808ms, import 884ms, tests 165ms, environment 0ms)

[test] passed 1 Vitest shard in 10.83s

Assertions:

  • PASS expect_output: Test Files
  • PASS expect_output: passed

How this fits together

Agent Core accepts steering during tool execution and follow-up input after an otherwise completed run, draining both into the loop before injecting them into the transcript. The Agent owns those queues, so an abort in that handoff window must return uncommitted messages to the correct queue for a later prompt.

flowchart LR
  A[User steering or follow-up] --> B[Agent-owned queues]
  B --> C[Agent loop drains input]
  C --> D{Abort before transcript injection}
  D -->|Yes| E[Restore source queue]
  D -->|No| F[Add to transcript]
  E --> G[Next prompt]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The repair adds 34 production lines and a new optional AgentLoopConfig callback; its queue-ordering and abort behavior should remain covered by the exact-head agent-core checks before merge.
  • Complete next step (P2) - This is an active, focused contributor PR with no discrete repair request; finish normal exact-head validation.
Agent review details

Security

None.

PR surface

Source +34, Tests +133. Total +167 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 34 0 +34
Tests 1 133 0 +133
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 167 0 +167

Review metrics

Metric Value Why it matters
Production versus regression coverage production +34, tests +133 The production growth adds source tracking and queue restoration; the tests cover steer recovery, no-abort single delivery, and follow-up routing.

Merge-risk options

Maintainer options:

  1. Validate queue recovery on this head (recommended)
    Require the exact-head agent-core checks to finish successfully before merging the change that preserves queued user input across aborts.

Technical review

Best possible solution:

Merge the source-aware Agent-owned restoration once exact-head CI validates the abort regressions, retaining steering and follow-up as separate scheduling queues.

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

Yes. Current main visibly drains queue state into pendingMessages and its abort closure does not restore it; the PR body also supplies an after-fix Agent runtime trace for that sequence.

Is this the best way to solve the issue?

Yes. Source-aware restoration at the loop's abort choke point and Agent-owned queues preserves the documented distinction between immediate steering and deferred follow-up scheduling.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2abc76d1aebe.

Labels

Label justifications:

  • P1: An abort can silently discard an already accepted user message during an active agent run.
  • merge-risk: 🚨 session-state: The patch changes whether queued user input survives the agent loop's abort boundary.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body contains an after-fix terminal trace using the real Agent, queues, sequential tool execution, and an aborting lifecycle listener; redact any private details in future proof updates.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body contains an after-fix terminal trace using the real Agent, queues, sequential tool execution, and an aborting lifecycle listener; redact any private details in future proof updates.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the recent agent-core caller-context refactor that is immediately adjacent to the current loop lifecycle. (role: recent agent-core contributor; confidence: high; commits: 39535f287efd, b3ab27607746; files: packages/agent-core/src/agent-loop.ts, packages/agent-core/src/agent.ts)
  • juyaohuidt: Current-main blame for the relevant abort block resolves to this repository-history snapshot. (role: current-line history contributor; confidence: medium; commits: 343e554dd4be; files: packages/agent-core/src/agent-loop.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head agent-core CI checks complete successfully before merge.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-24T11:55:00.034Z sha a3b351ca56f4aa144dbba93ba16e435498ac375c :: needs changes before merge. :: [P3] Remove the duplicate embedded cancellation test
  • reviewed 2026-08-24T13:02:57.479Z sha 848b0f066995e51cf9a8b921919d206a3800e19b :: needs maintainer review before merge. :: none

@SunnyShu0925
SunnyShu0925 force-pushed the fix/steer-abort-requeue-128008 branch from a3b351c to bfb7c6f Compare August 24, 2026 12:12
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed agents Agent runtime and tooling size: M labels Aug 24, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/steer-abort-requeue-128008 branch from bfb7c6f to 848b0f0 Compare August 24, 2026 12:56
Keep drained steering and follow-up messages owned by their original queue until message_end commits them. Restore any uncommitted batch when the run settles so aborts cannot silently discard accepted input.

Co-authored-by: SunnyShu0925 <[email protected]>
@obviyus
obviyus force-pushed the fix/steer-abort-requeue-128008 branch from 848b0f0 to 6855014 Compare August 28, 2026 09:01
@obviyus
obviyus merged commit 82343d9 into openclaw:main Aug 28, 2026
182 checks passed
@obviyus

obviyus commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @SunnyShu0925!

Proof: A real Agent run sent two ordered steering messages and two ordered follow-ups through the OpenAI Responses HTTP transport. Main lost both pairs after abort. The merged repair delivered steering in the next provider request, kept follow-ups deferred until the request after that, preserved both orders, and never ran the skipped tail tool.

  • Bug: An abort after queue drain could silently discard accepted steering or follow-up messages.
  • Fix: Each queue now owns drained messages until transcript commit and restores uncommitted messages when the run settles.
Before After
The accepted messages vanished, and the next provider request did not contain them. Steering reaches the next request in order; follow-ups stay deferred and then arrive in order.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks too. It's a pleasure working with you!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 29, 2026
Keep drained steering and follow-up messages owned by their original queue until transcript commit, then restore uncommitted messages after abort. This prevents silent message loss without changing queue scheduling.

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

Labels

merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

agent-core: steer queued during a tool batch is lost when the run aborts before the loop injects it

2 participants