Skip to content

fix(gateway): steering during worktree creation still runs as a follow-up after the task - #165537

Merged
steipete merged 2 commits into
mainfrom
codex/stab-steer-prestart-2
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/stab-steer-prestart-2

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Related: #165462

What Problem This Solves

Fixes: a message sent with Steer right after starting a New Session with a new worktree (while it shows "Creating worktree…") still runs as a separate follow-up turn after the task finishes, instead of reaching the task. #165462 fixed a later point in that window; live, the steer usually arrives while the first turn's reply operation exists but its backend is still preparing.

User Impact

User impact: steering during worktree creation now joins the first turn as soon as its runtime is ready, on both the built-in and the Codex runtime. If that turn ends, is replaced, or its authority changes first, the message still runs once as a follow-up. The queued-follow-up acknowledgement semantics are unchanged.

Why This Change Was Made

runActiveReplySteer resolved the injection target and the steering authority when the steer was admitted. During preparation the active reply operation has no ready backend yet, so there was no target and the steer fell back to the follow-up queue immediately. The steering owner now parks the input in its FIFO custody, waits for that exact reply operation's backend to become ready (new readiness signal on the reply-run registry), then re-verifies the same operation object, resolves tool/pending-input authority at that moment, and injects. Cancellation, retirement, and rekeying release the wait and fall back. Authority is revalidated after the wait and immediately before injection rather than captured beforehand.

Evidence

Live (dev Gateway, OpenAI provider, fresh state): sessions.create {worktree: true, message} then chat.send {queueMode: "steer", message: "…put the word PINEAPPLE<n>…"} ~2 s later, while the worktree was being created.

Build Runs Steer position in transcript Final answer contains the word
main 500c95a (with #165462), built-in runtime 2 (follow-up) after the answer no
main 500c95a, Codex runtime 2 (follow-up) after the answer no
this branch, built-in runtime 1 before the answer yes
this branch, Codex runtime 1 before the answer yes

The regression now drives real sessions.create + chat.send dispatch and reply preparation (only model execution is synthetic):

TMPDIR=… pnpm test src/gateway/server-methods/chat-send-prestart-steer.test.ts --maxWorkers=1
main:   fails (premature terminal; steer not consumed by the initial turn) — 72.5 s wall
branch: passes — 41.4 s wall

Six affected test files: 68 passed (includes reply-run-registry.backend-ready.test.ts, handoff adoption, media carrier/paths). Production and test types, scoped lint, formatting, ratchets pass. Deslop and branch autoreview clean (a rekey concern was ruled out by the existing queued-only guard).

Production +75/−30 (readiness signal + post-wait revalidation; the pre-captured authority parameters are removed); tests +236/−157; docs +4/−3.

CI follow-through

CI run 37300380552, attempt 1, exposed a synchronization race in chat-send-prestart-steer.test.ts: steering admission can park the message before reply preparation enters the runtime fixture, so the test read initialOperation.phase before the fixture assigned that operation. The same three-file Gateway selection reproduced the failure locally (1 failed, 20 passed; 61.74 s).

The test now waits for an explicit runtime-entry signal before the existing phase assertion. No assertion was removed or weakened, and production code is unchanged. The repaired selection passes all 21 tests in 34.76 s; the focused file passes all 3 cases with --maxWorkers=1 in 34.30 s. This public-RPC regression uses real session/worktree creation, reply preparation, and transcript persistence, which accounts for its runtime. The original CI failure took 10.57 s in the failing test; its three-file invocation took 22.60 s. Codex autoreview of the four-line repair is scoped-clean through P2.

Formatting, scoped lint, core test types, and changed-scope contract guards pass. The local changed-file command remains red solely on unrelated dead exports in extensions/google-meet/src/transports/types.ts, extensions/memory-wiki/src/compiled-cache.ts, extensions/workboard/src/gateway-helpers.ts, and src/meeting-bot/runtime-facade-types.ts. The same scan independently fails for all of those exports on main 6b37a39aa10; those four files are identical between the PR and that baseline. This is local baseline evidence, not a claim of passing CI.

The corrected head ceca71960713965814217b9e70e6ac17bad2b46a passed all three prestart-steering cases in CI run 37303089262 (accepted 10.684 s, unavailable 2.741 s, rejected 3.997 s). That run remains failed/cancelled because check-guards job 111740773333 found an inherited Madge import cycle among migration and state-reader files, from src/infra/deferred-plugin-migrations.ts through src/state/openclaw-state-read.types.ts.

Inherited-failure qualification: CI checked merge 0be42ce7d59a188c41429310e0e8db999b6183db, whose ordered parents are main 83b743ac7141882378a821db5beacd14a7222745 and this exact PR head. Its tree matches Git's merge of those parents. Every cycle node and the scanner/config/workflow inputs are identical to the baseline; the same guard independently fails with the identical cycle on current main d4940e8bf63. The PR changes none of those cycle files. This qualifies for the native inherited-failure admin route; it is not a passing-CI claim. security-fast passed. The successful fail-fast monitor cancelled jobs 111740773615, 111740773949, and 111741290757; no additional failed step was found, and cancelled coverage remains incomplete. The native evidence retains the complete checkout, failure, aggregate, and cancellation logs.

Park incoming steering in the existing FIFO owner while its exact reply operation prepares. Publish first-backend readiness from that operation, then revalidate ownership and current tool authority before injection. Settle waits on source cancellation, owner retirement, or rekey without following a replacement.

The Gateway regression now uses real dispatch and reply preparation instead of manufacturing a ready owner. It fails on current main and passes with the repair; unavailable and rejected injection retain existing follow-up acknowledgement and execution behavior. Keep backend readiness internal and retire precomputed steering authority parameters.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 5, 2026 11:02
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 7:42 AM ET / 11:42 UTC (Revision 3).

ClawSweeper review

What this changes

Steering messages wait for the original turn’s runtime to become ready, then join that turn if still authorized or remain queued for a follow-up.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still misses steering during backend preparation. The prior synchronization finding is repaired, and no additional blocking code defect was found.

Priority: P2
Reviewed head: ceca71960713965814217b9e70e6ac17bad2b46a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with meaningful live evidence and the prior test race addressed.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured live comparison exercises the changed reply-steering owner through fresh-worktree sessions.create and chat.send on a dev Gateway: both runtimes consume the steer before the initial answer in one turn. The repaired public-RPC tests supplement this with unavailable and rejected follow-up cases. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured live comparison exercises the changed reply-steering owner through fresh-worktree sessions.create and chat.send on a dev Gateway: both runtimes consume the steer before the initial answer in one turn. The repaired public-RPC tests supplement this with unavailable and rejected follow-up cases. No stored-data contract changes.
Evidence reviewed 8 items Pinned production change: The introduced delta waits for the exact reply operation’s backend, checks operation identity before and after the wait, and resolves steering authority afterward. Existing queue custody and injection finalization remain the owners.
Prior finding resolved: The exact-head commit adds an initial-runtime rendezvous, resolves it after assigning the initial operation, and awaits it before asserting the running phase. Accepted, unavailable, rejected, consumption, transcript, and fallback assertions remain. This addresses the previous review’s finding and rank-up request.
Current main still needs the repair: At fetched main, the steering owner captures the injection target before parking and falls back when no target exists; it does not await backend readiness. The related earlier fix is GitHub-verified as merged at #165462, but addresses targetless Gateway admission rather than this remaining preparation window. No release implementation is established.
Findings None None.
Security None None.

How this fits together

The Gateway passes incoming steering messages to the reply queue and active-turn registry. Those owners decide whether the runtime consumes the message during the current turn or executes it later.

flowchart TD
  A[Incoming steering message] --> B[Ordered reply queue]
  B --> C[Original turn preparing]
  C --> D[Runtime readiness signal]
  D --> E[Check current owner and permissions]
  E --> F[Inject into active turn]
  E --> G[Execute queued follow-up]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +45, Tests +83, Docs +1. Total +129 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 4 75 30 +45
Tests 6 240 157 +83
Docs 1 4 3 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 319 190 +129

Review metrics

Metric Value Why it matters
Production versus regression coverage production net +45 lines; tests net +83 lines Production growth is explained by lifecycle readiness signaling and post-wait revalidation, with regression coverage at the Gateway and readiness boundaries.

Technical review

Best possible solution:

Keep startup steering in the existing FIFO owner until the original runtime can accept it, while preserving current authority checks and once-only follow-up delivery.

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

Yes: current-main source captures an unavailable injection target during backend preparation, and the supplied live comparison exercises that window through sessions.create and chat.send. Reviewer execution was not performed.

Is this the best way to solve the issue?

Yes: extending the existing reply operation’s readiness lifecycle preserves queue ownership and avoids a parallel steering mechanism.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured live comparison exercises the changed reply-steering owner through fresh-worktree sessions.create and chat.send on a dev Gateway: both runtimes consume the steer before the initial answer in one turn. The repaired public-RPC tests supplement this with unavailable and rejected follow-up cases. No stored-data contract changes.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded timing window where steering runs later than requested during worktree and runtime preparation.
  • 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 (live_output): The captured live comparison exercises the changed reply-steering owner through fresh-worktree sessions.create and chat.send on a dev Gateway: both runtimes consume the steer before the initial answer in one turn. The repaired public-RPC tests supplement this with unavailable and rejected follow-up cases. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured live comparison exercises the changed reply-steering owner through fresh-worktree sessions.create and chat.send on a dev Gateway: both runtimes consume the steer before the initial answer in one turn. The repaired public-RPC tests supplement this with unavailable and rejected follow-up cases. No stored-data contract changes.

Evidence

What I checked:

  • Pinned production change: The introduced delta waits for the exact reply operation’s backend, checks operation identity before and after the wait, and resolves steering authority afterward. Existing queue custody and injection finalization remain the owners. (src/auto-reply/reply/agent-runner-steer-adoption.ts:146, ceca71960713)
  • Prior finding resolved: The exact-head commit adds an initial-runtime rendezvous, resolves it after assigning the initial operation, and awaits it before asserting the running phase. Accepted, unavailable, rejected, consumption, transcript, and fallback assertions remain. This addresses the previous review’s finding and rank-up request. (src/gateway/server-methods/chat-send-prestart-steer.test.ts:206, ceca71960713)
  • Current main still needs the repair: At fetched main, the steering owner captures the injection target before parking and falls back when no target exists; it does not await backend readiness. The related earlier fix is GitHub-verified as merged at fix(gateway): steering a session while its worktree is being created is held until the task finishes #165462, but addresses targetless Gateway admission rather than this remaining preparation window. No release implementation is established. (src/auto-reply/reply/agent-runner-steer-adoption.ts, d4940e8bf63e)
  • Captured real behavior evidence: The supplied PR body records sessions.create with a fresh worktree followed by chat.send in steer mode on a dev Gateway using the OpenAI provider. Main produced two turns with the steer after the answer; the branch produced one turn with the steer before the answer and the requested word present, for both built-in and Codex runtimes. The body additionally reports all three repaired Gateway cases passing in 34.30 seconds; these are contributor-reported observations, not reviewer execution. (ceca71960713)
  • Authority and compatibility checks: The changed wait retains exact operation identity and releases on completion, failure, cancellation, supersession, or rekey. Injection still composes live source authority with the current operation and backend; the Codex adapter revalidates each input immediately before physical RPC dispatch. The patch adds process-local readiness promises without changing configuration, public plugin APIs, or persisted formats. (src/auto-reply/reply/reply-run-registry.message-injection.ts:172, ceca71960713)
  • Codex dependency contract inspected: The PR explicitly claims Codex-runtime behavior, and OpenClaw’s steering docs identify native turn/steer as its transport contract. The sibling source requires a nonempty expected turn ID and reports no-active-turn or expected-turn-mismatch rejection. Dependency ownership was verified through the cache repository’s origin URL, https://github.com/openai/codex.git, rather than inferred from its checkout name. (codex-rs/app-server/src/request_processors/turn_processor.rs:1024, a956835d0207)

Likely related people:

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

Rating scale

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

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

Workflow

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

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-05T11:08:10.934Z sha 1aab65f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T11:15:48.062Z sha 1aab65f :: needs changes before merge. :: [P2] Synchronize the regression with initial runtime entry

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 5, 2026
@steipete
steipete merged commit 145a5e5 into main Oct 5, 2026
132 of 138 checks passed
@steipete
steipete deleted the codex/stab-steer-prestart-2 branch October 5, 2026 11:56
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

steipete added a commit that referenced this pull request Oct 5, 2026
…#165788)

Keep source reservations as completion barriers without using them as steering targets. The parked steering change in #165537 retained strict target selection but dropped the separate source-owned drain barrier. Preserve the existing ordering and image-delivery regression assertions, and update the authority-mismatch assertion to the parked fallback owner.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…w-up after the task (openclaw#165537)

* fix(gateway): retain pre-start steering until the reply backend is ready

Park incoming steering in the existing FIFO owner while its exact reply operation prepares. Publish first-backend readiness from that operation, then revalidate ownership and current tool authority before injection. Settle waits on source cancellation, owner retirement, or rekey without following a replacement.

The Gateway regression now uses real dispatch and reply preparation instead of manufacturing a ready owner. It fails on current main and passes with the repair; unavailable and rejected injection retain existing follow-up acknowledgement and execution behavior. Keep backend readiness internal and retire precomputed steering authority parameters.

* test(gateway): wait for runtime entry in prestart steering proof
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…openclaw#165788)

Keep source reservations as completion barriers without using them as steering targets. The parked steering change in openclaw#165537 retained strict target selection but dropped the separate source-owned drain barrier. Preserve the existing ordering and image-delivery regression assertions, and update the authority-mismatch assertion to the parked fallback owner.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant