Skip to content

fix: steering misses the next tool boundary after ACK - #120964

Merged
steipete merged 4 commits into
mainfrom
steipete/steering-message-insertion-bug-5203e4
Aug 9, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/steering-message-insertion-bug-5203e4

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where users steering during an active tool call could see duplicate Steering badges and then active run changed; review and retry. Even after the started ACK, the unstarted sequential tail could execute before the message entered runtime ownership.

Why This Change Was Made

The Gateway now waits for queue acceptance—not transcript completion—before ACK. Exact-run anti-ABA remains; stale exact targets fall back FIFO without steering successors; embedded and Codex runtimes report and fence ownership; Codex terminal turns cancel pending bound steering; and the UI renders one badge while preserving replyToId.

User Impact

After started, the steer is owned and appears at the earliest safe boundary after a running tool. The unstarted tail skips, there is no successor misdelivery, and the UI shows one Steering badge.

Release note context: Steering now waits for runtime queue acceptance before acknowledging, preventing messages from missing the next safe tool boundary.

Evidence

  • Rebased onto the exact authoritative base af73dbcc834027e84d8717e17c504020a17e567a. The cumulative PR diff remains 30 files and +1307/-402 total: production +349/-201 (net +148), tests +926/-169 (net +757), and generated +32/-32 (net 0).
  • The explicitly approved red-main repair remains isolated to the generated baseline: PR fix(plugin-sdk): detect private type changes in API baseline #120975 changed private-type hashing without refreshing the manifest, so only docs/.generated/plugin-sdk-api-baseline.sha256 was regenerated with pnpm plugin-sdk:api:gen; the API check passes. The reviewed ten-file P1 repair did not alter that baseline.
  • All three ClawSweeper P1 ownership gaps are addressed: Copilot reports queue acceptance only after session.send succeeds or a pending question is claimed; reply-targeted exact steering hydrates and accepts before the ACK while ordinary replies remain post-ACK; and Codex terminal receipt seals unsent admission while serialized terminal cancellation preserves correlation for an earlier consumed dispatch.
  • Final focused proof passed all 620 tests across 10 files and 8 Vitest shards, including the serialized Codex terminal-ordering regression and five real Gateway FIFO E2Es.
  • The final manifest-only rebase smoke passed all 202 tests, and pnpm plugin-sdk:api:check passed on the final head. The three source commits retain identical stable patch IDs across the rebase (9e5b1cc499db68bb8c29228b61f66018f493f87b, 0ce0dc46168cd931f7b3f753b18df9a4bb037dfa, and 437208cdbf48dbc04afa5ca80efe5acf64060364); only the isolated generated-manifest commit was regenerated for the new base.
  • Targeted formatting (oxfmt --check), oxlint, and git diff --check passed for the ten-file repair; pnpm plugin-sdk:api:check confirmed the existing generated API baseline.
  • Direct sibling Codex source inspection confirmed the exact-turn turn/steer contract, atomic active-turn mailbox admission, clientUserMessageId correlation on user-message notifications, and ordered item/turn notification emission (codex-rs/app-server-protocol/src/protocol/v2/turn.rs:175, codex-rs/app-server/src/request_processors/turn_processor.rs:910, codex-rs/core/src/session/mod.rs:4022, codex-rs/app-server/src/bespoke_event_handling.rs:187, and codex-rs/app-server/src/bespoke_event_handling.rs:1020).
  • Final merge autoreview completed clean with no accepted/actionable findings.
  • Source-blind behavior validation was blocked only because no standalone configured Gateway target was available; it did not report a behavioral failure. Real Gateway E2E remains the boundary proof.
  • Exact-head CI previously exposed four ask_user call-shape assertions; the redundant positional callback was removed, established steer call shapes were restored, and all 30/30 ask_user tests passed without changing their expectations.
  • Remote Testbox/Crabbox was unavailable due to broker authentication, so the trusted-source changed gate ran locally under the repository fallback policy.
  • The positive production delta establishes the queue-acceptance ownership boundary across Gateway, embedded, Copilot, and Codex runtimes.
  • No screenshot artifact is included: the visual duplicate is proven by the component DOM assertion for exactly one Steering badge, and the behavior is proven by the real Gateway E2E.
  • AI-assisted.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling extensions: codex size: XL maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 06:55
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete force-pushed the steipete/steering-message-insertion-bug-5203e4 branch 2 times, most recently from f7256cf to 49d728f Compare August 9, 2026 08:20
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 9, 2026, 5:57 AM ET / 09:57 UTC.

ClawSweeper review

What this changes

The PR makes steering acknowledgements wait for runtime acceptance and adds terminal fencing across Gateway, embedded, Codex, and chat UI paths.

Merge readiness

⛔ Blocked by patch quality or review findings - 8 items remain

Keep open. The prior Copilot and reply-target ownership blockers remain, and terminal Codex cancellation introduces an ordering race that can reject an already-completed steer.

Priority: P1
Reviewed head: 49d728f5f1ca5623c53a00225959a8db9aaa0ce4

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The proposed ownership design is useful, but three P1 runtime races make the current patch unsafe to merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the reported Gateway E2E is useful supplemental evidence but does not cover the remaining races.
Patch quality 🧂 unranked krab (1/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the reported Gateway E2E is useful supplemental evidence but does not cover the remaining races.
Evidence reviewed 5 items Copilot acceptance gap: Copilot awaits transcript persistence after session send but never invokes the new acceptance callback; the PR does not modify this runtime, so pre-ACK waiting remains tied to receipt rather than queue ownership.
Reply-target ownership gap: The handler omits a captured injection attempt when replyToId is present, so the new pre-ACK helper continues without runtime acceptance; reply-context injection happens later during dispatch.
Codex terminal ordering race: The PR cancels the queue immediately when terminal notification receipt arrives, but the router can receive that receipt before an earlier queued item-completed handler confirms a dispatched steer.
Findings 3 actionable findings [P1] Report Copilot queue acceptance after session send
[P1] Gate reply-targeted steers before acknowledging them
[P1] Retain dispatched Codex batches until queued completion runs
Security None None.

How this fits together

A chat steer passes from the UI through Gateway admission into an active runtime queue. The runtime must record ownership before Gateway acknowledges it, while terminal events must not let a successor run inherit or erase that message.

flowchart LR
  A[Chat composer] --> B[Gateway admission]
  B --> C[Active-run registry]
  C --> D[Embedded, Copilot, or Codex runtime]
  D --> E[Runtime ownership]
  E --> F[Gateway acknowledgement]
  F --> G[Steering badge]
Loading

Before merge

  • Report Copilot queue acceptance after session send (P1) - The new pre-ACK promise only settles when a runtime calls onQueueAccepted, but Copilot still waits for transcript persistence after session.send and never calls it. A steer during tool work therefore still receives started only after the boundary this PR is intended to protect; report acceptance immediately after a successful send and add the held-receipt Gateway/Copilot regression.
  • Gate reply-targeted steers before acknowledging them (P1) - When replyToId is present, this path leaves the injection attempt undefined, so the new pre-ACK wait immediately continues. The later reply-context injection can still reject after started; resolve and begin that injection before acknowledging ownership, with a terminal-race regression for queued reply-targeted steering.
  • Retain dispatched Codex batches until queued completion runs (P1) - Terminal notification receipt can overtake an earlier queued item/completed handler. Cancelling here clears the dispatched batch first, causing an already-completed steer to become accepted-unconfirmed; stop unsent admission now, but let serialized completion confirm dispatched work before cancellation.
  • Resolve merge risk (P1) - Direct Codex upstream-source inspection remains unavailable, so this review cannot certify the external app-server protocol assumptions behind the Codex path.
  • Complete next step (P2) - This maintainer-labeled PR needs the three concrete ownership repairs and a source-complete Codex review before another merge decision.
  • Improve patch quality - Add Copilot and reply-target Gateway regressions covering acknowledgement before transcript receipt and terminal rejection.
  • Improve patch quality - Add the delayed Codex completion-versus-terminal receipt ordering regression.
  • Improve patch quality - Re-run source-complete review with sibling Codex source available.

Findings

  • [P1] Report Copilot queue acceptance after session send — src/auto-reply/reply/reply-run-registry.ts:1659-1689
  • [P1] Gate reply-targeted steers before acknowledging them — src/gateway/server-methods/chat-send-handler.ts:266-281
  • [P1] Retain dispatched Codex batches until queued completion runs — extensions/codex/src/app-server/run-attempt-notification-controller.ts:243-246
Agent review details

Security

None.

PR surface

Source +96, Tests +450. Total +546 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 17 202 106 +96
Tests 9 601 151 +450
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 26 803 257 +546

Review metrics

Metric Value Why it matters
Production versus test delta production +202/-107; tests +597/-151 The positive production growth spans three runtime ownership boundaries, so each must demonstrate the same acknowledgement invariant.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/agent-session-prompting.ts, serialized state: src/agents/sessions/sdk.test.ts, serialized state: test/gateway-steer-fifo.e2e.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair all ownership boundaries before merge (recommended)
    Add immediate Copilot acceptance, pre-ACK reply-target injection, and terminal fencing that preserves dispatched Codex batches until their queued completion handlers run.
  2. Pause for runtime-contract review
    Hold the PR until the exact Codex source and protocol behavior can be inspected alongside the repaired ordering regression.

Technical review

Best possible solution:

Make every runtime report acceptance at its actual queue boundary, start reply-target injection before a started acknowledgement, and retain already-dispatched Codex batches until serialized completion handlers can confirm them.

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

Yes, from source: hold Copilot transcript receipt after session.send, send a reply-targeted steer, or delay a Codex item-completed handler before terminal receipt; each exposes a remaining ownership race.

Is this the best way to solve the issue?

No. Waiting for acceptance is the right owner boundary, but the implementation omits Copilot and reply-target paths and cancels dispatched Codex work before serialized confirmation.

Full review comments:

  • [P1] Report Copilot queue acceptance after session send — src/auto-reply/reply/reply-run-registry.ts:1659-1689
    The new pre-ACK promise only settles when a runtime calls onQueueAccepted, but Copilot still waits for transcript persistence after session.send and never calls it. A steer during tool work therefore still receives started only after the boundary this PR is intended to protect; report acceptance immediately after a successful send and add the held-receipt Gateway/Copilot regression.
    Confidence: 0.98
  • [P1] Gate reply-targeted steers before acknowledging them — src/gateway/server-methods/chat-send-handler.ts:266-281
    When replyToId is present, this path leaves the injection attempt undefined, so the new pre-ACK wait immediately continues. The later reply-context injection can still reject after started; resolve and begin that injection before acknowledging ownership, with a terminal-race regression for queued reply-targeted steering.
    Confidence: 0.99
  • [P1] Retain dispatched Codex batches until queued completion runs — extensions/codex/src/app-server/run-attempt-notification-controller.ts:243-246
    Terminal notification receipt can overtake an earlier queued item/completed handler. Cancelling here clears the dispatched batch first, causing an already-completed steer to become accepted-unconfirmed; stop unsent admission now, but let serialized completion confirm dispatched work before cancellation.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 917fd92686c5.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: The remaining races can acknowledge an active steer too late or reject it after delivery during normal agent tool work.
  • merge-risk: 🚨 session-state: The patch changes which terminal run owns a queued steering message and when that ownership is invalidated.
  • merge-risk: 🚨 message-delivery: The patch controls whether a user's steer is acknowledged, delivered, or incorrectly rejected.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the reported Gateway E2E is useful supplemental evidence but does not cover the remaining races.

Evidence

What I checked:

Likely related people:

  • steipete: Current ownership lines trace to the recent steering boundary work, and this PR's acceptance and Codex terminal changes are authored by steipete. (role: recent steering feature contributor; confidence: high; commits: 7a8eee4a363b, 43fbbe8a4d58, 49d728f5f1ca; files: extensions/copilot/src/attempt-active-run.ts, extensions/codex/src/app-server/attempt-steering.ts, src/auto-reply/reply/reply-run-registry.ts)
  • vincentkoc: Recent Gateway reply-admission recovery history is adjacent to the reply-target ownership boundary affected here. (role: adjacent Gateway recovery contributor; confidence: medium; commits: bccf65938e; files: src/gateway/server-methods/chat-send-handler.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-09T08:50:59.686Z sha 49d728f :: found issues before merge. :: [P1] Report Copilot acceptance when it enqueues the steer | [P1] Gate reply-targeted steers on runtime ownership

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 9, 2026
@steipete
steipete force-pushed the steipete/steering-message-insertion-bug-5203e4 branch from 49d728f to 89bad62 Compare August 9, 2026 15:33
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: copilot labels Aug 9, 2026
@steipete

steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready proof for final exact head 7b920107c1765f3d0b8576dd8710266a32959744:

  • Exact-head CI run 31326367280 completed successfully (attempt 1, openclaw/ci-gate included).
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 120964 completed successfully. It validated the zero-finding READY FOR /prepare-pr artifacts, used gate mode hosted_exact_or_recent_parent, reused the exact-head hosted CI, and verified the remote PR tree matches the local prep head. prep_head_sha and pr_head_sha are both 7b920107c1765f3d0b8576dd8710266a32959744; gates passed at 2026-08-09T17:45:00Z. No separate Testbox lease or remote run was created (REMOTE_GATES_PROVIDER, REMOTE_GATES_LEASE_ID, and REMOTE_GATES_RUN_URL are empty).
  • All ClawSweeper Rank-up moves are addressed: Copilot reports queue acceptance after successful send or pending-question ownership; exact reply-target steering hydrates and accepts before ACK; Codex terminal receipt seals unsent admission while serialized completion preserves an earlier dispatched correlation; the three matching regressions were added; direct sibling Codex source was inspected; the source-complete final review is clean; and no move was skipped.
  • The standalone source-blind validator lacked a configured Gateway target, but that environment gap is covered by five real Gateway FIFO E2Es exercising the operator-visible queue-ownership boundary.

Focused proof already run and recorded on this PR:

node scripts/run-vitest.mjs extensions/codex/src/app-server/attempt-steering.test.ts extensions/codex/src/app-server/run-attempt.steering.test.ts
node scripts/run-vitest.mjs extensions/copilot/src/attempt-active-run.test.ts
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt.queue-message.test.ts src/agents/sessions/sdk.test.ts
node scripts/run-vitest.mjs src/auto-reply/reply/reply-run-registry.test.ts
node scripts/run-vitest.mjs src/gateway/server-methods/chat.directive-tags.test.ts
node scripts/run-vitest.mjs test/gateway-steer-fifo.e2e.test.ts
node scripts/run-vitest.mjs ui/src/pages/chat/chat-composer-queue.test.ts
node scripts/run-vitest.mjs ui/src/pages/chat/chat-send.test.ts
pnpm plugin-sdk:api:check
git diff --check

Those eight Vitest shards passed 620/620 tests, including all three P1 regressions and five real Gateway E2Es. The manifest-only patch-equivalence smoke passed 202/202, the Plugin SDK API baseline check passed, targeted formatting/oxlint/diff checks passed, and final autoreview had no accepted or actionable findings.

@steipete
steipete force-pushed the steipete/steering-message-insertion-bug-5203e4 branch from 26b3bdc to 5a96043 Compare August 9, 2026 17:08
@steipete
steipete force-pushed the steipete/steering-message-insertion-bug-5203e4 branch from 5a96043 to 7b92010 Compare August 9, 2026 17:25
@steipete
steipete merged commit 72283e4 into main Aug 9, 2026
128 of 129 checks passed
@steipete
steipete deleted the steipete/steering-message-insertion-bug-5203e4 branch August 9, 2026 17:46
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
* fix(steering): wait for queue acceptance before ack

* fix(steering): preserve session steer call contract

* fix(steering): close runtime ownership gaps

* fix(ci): refresh plugin SDK API baseline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation extensions: codex extensions: copilot gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant