Skip to content

refactor(steering): gateway-owned atomic start-or-steer - #125808

Merged
steipete merged 3 commits into
mainfrom
steipete/gateway-start-or-steer
Aug 18, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/gateway-start-or-steer

Conversation

@steipete

@steipete steipete commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The browser owned start-vs-steer and exact run targeting, producing failures like #125427 (landed mitigation #125428) and requiring beta-only expectedRunId wire state; three parallel steering state machines (gateway captured-op, channel steer adoption, server /steer) duplicated accepted/rejected/unconfirmed/fallback policy, and two of them addressed runs by session key or raw session id (correlation-only authority; successor-abort class fixed for one path in #125763).

Why This Change Was Made

The Gateway session-work admission is the correct atomic owner of the start-or-steer decision (mirrors the upstream Codex contract: core start_or_steer attempts steering with no expected turn under the active-turn lock and starts on NoActiveTurn — verified in sibling codex-rs at rev 4861236f06d0: core/src/session/turn_input.rs:195-249,478-564; protocol/src/turn_input.rs:115-124). One captured-operation lifecycle (resolveCurrentMessageInjectionTarget / beginReplyMessageInjectionTarget / finalizeReplyMessageInjectionAttempt) now serves all three paths with the #125763 captured-instance abort.

User Impact

Steer-mode sends to an idle session start a run instead of failing with "active leaf changed"; rejected injections visibly queue as follow-ups (fixes the silent CLI-runtime steer drop class, #124731); /steer actually injects into the active run under its command authorization. Deliberate semantics changes: (1) registry-less active embedded runs are no longer steered by raw session id — the message becomes a visible followup (fail-closed captured-authority rule); (2) the transcript-branch CAS (expectedLeafEntryId) now guards only non-steer sends — explicit steer intent targets the session's current state; (3) expectedRunId exact-match behavior is unchanged when supplied (its removal is a follow-up PR).

Evidence

Production LOC +285/−295 (net −10), tests +423/−418; deleted the duplicate policy machine, commands-steer.runtime.ts, leaf-bound injection identity + reject-before-ack, dead toolAuthorityFingerprint on targets, the boolean messageInjectionAttempted; new gateway matrix tests (idle→start incl. active-descendant case, direct-run capture, successor never injected/aborted, non-injectable runtime visible fallback, idempotent retry) — the two targetless-steer regressions fail pre-change with active-leaf-changed; focused suites 298+379+25+7 passed; tsgo core lanes, check-changed, pnpm build (no INEFFECTIVE_DYNAMIC_IMPORT) green; codex autoreview clean on the final tree. Pending-user-input claim/cancel semantics moved verbatim from embedded runs.ts:486-520 into the shared primitive; runs.ts keeps its copy for its four non-steer callers (talk control, TUI backend, sessions-send tool, subagent announce) — consolidation follow-up noted. Known unrelated env-dependent local failure of the heartbeat usage test (CI-green on main; follow-up task filed).

  • ClawSweeper findings addressed: docs/gateway/protocol.md and the ChatSendParams schema comments now document the start-or-steer contract (commit 1b097ca1c5f). Upstream Codex contract independently verifiable at public revision openai/codex@4861236 (codex-rs/core/src/session/turn_input.rs, codex-rs/protocol/src/turn_input.rs). Prior CI failure was a shard timeout in extensions/codex run-attempt.test.ts (passes locally in 42s on this branch); fresh exact-head CI attached below.
  • ClawSweeper P1 addressed: /steer now presents the command turn's tool-authority fingerprint to the unified injection check; mismatch falls back to a normal prompt under the sender's own authority (commit f9a2b20; regression tests included; mismatch test fails pre-fix).

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 18, 2026 12:24
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 18, 2026
@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 10:26 AM ET / 14:26 UTC.

ClawSweeper review

What this changes

Centralizes start-or-steer admission and captured message injection for Gateway, channel, and /steer paths.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

The prior /steer authority finding is addressed on the current head: Gateway and command injection now project caller authority before delivery. Keep this maintainer-owned PR open for direct verification of its asserted Codex contract and completed exact-head CI.

Priority: P1
Reviewed head: f9a2b20d79955187e91aed2cb810272d9e1add2a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The authority repair and focused coverage are coherent, but upstream-contract verification and exact-head CI remain unresolved.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate.
Evidence reviewed 5 items Prior authority finding repaired: Both /steer and Gateway injection project current caller authority into the injection request; the registry rejects mismatched fingerprints.
Focused authority coverage: Tests cover matching-authority injection and mismatched authority falling back without invoking the backend.
Current-main behavior remains unchanged: Current main retains the old targetless-steer active-leaf rejection; this PR is not redundant.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

pnpm openclaw --helprunner@runnervmzvulz:/tmp/clawsweeper-live-proof-125808-dleaeZ/target$ pnpm openclaw --help
$ node scripts/run-node.mjs --help
pnpm openclaw --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.88 kB
[log]
[success] rolldown v1.2.0 Finished in 32.97 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.6s
node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

[tsdown-build] invocation 2/2 finished in 11.6s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4435ms (slowest: built plugin control-plane loads 3396ms)

OpenClaw 2026.8.1 (f9a2b20) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console (silent|fatal|error|warn|info|debug|trace)
  --no-color   
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

Gateway and channel inputs resolve a session’s direct reply operation, then either inject into that exact active run or continue as a normal turn. The shared registry enforces runtime capability and tool-authority checks before delivery.

flowchart LR
A[Chat send or channel input] --> B[Gateway and reply admission]
B --> C{Direct active operation?}
C -->|Yes| D[Captured injection target]
C -->|No| E[Start or queue normal turn]
D --> F{Authority and runtime accept?}
F -->|Yes| G[Active run receives message]
F -->|No| E
G --> H[Transcript and audit finalization]
E --> H
Loading

Decision needed

Question Recommendation
Should this maintainer-authored Gateway refactor wait for direct inspection of the cited Codex contract and completed exact-head CI before merge? Obtain contract and CI proof: Verify the cited Codex implementation and wait for the current head’s required checks before deciding to merge.

Why: Repository policy requires direct Codex-source inspection when the PR explicitly depends on that contract, and the required checkout is unavailable to this review.

Before merge

  • Resolve merge risk (P1) - The PR explicitly relies on upstream Codex start-or-steer semantics, but direct sibling-source inspection is unavailable.
  • Resolve merge risk (P1) - Exact-head CI is still in progress.
  • Resolve merge risk (P1) - Targetless steer and transcript-CAS semantics change for existing Gateway clients and persisted outbound work.
  • Complete next step (P2) - Manual maintainer review is needed for unavailable direct Codex-contract verification and current-head CI; no narrow mechanical repair is identified.
Agent review details

Security

None.

PR surface

Source +47, Tests +55, Docs 0. Total +102 across 25 files.

View PR surface stats
Area Files Added Removed Net
Source 18 404 357 +47
Tests 6 472 417 +55
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 25 877 775 +102

Review metrics

Metric Value Why it matters
Production versus test delta production +285/-295 (net -10); tests +423/-418 The refactor removes duplicated steering policy while materially reshaping regression coverage.

Merge-risk options

Maintainer options:

  1. Verify the external contract before merge (recommended)
    Inspect the cited Codex revision and complete exact-head CI, then reassess the shared injection lifecycle.
  2. Accept the remaining contract risk
    A maintainer may merge based on the OpenClaw implementation and tests while owning the unverified upstream-semantics claim.

Technical review

Best possible solution:

Keep the shared captured-operation lifecycle and verify the cited Codex revision plus exact-head CI before merge.

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

No live reproduction was run in this read-only review; source and focused tests establish the targetless-steer and authority-fallback paths.

Is this the best way to solve the issue?

Unclear: the shared captured-operation owner is coherent and repairs the earlier authority finding, but its asserted Codex equivalence could not be directly checked.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: This changes default follow-up delivery into active agent runs.
  • merge-risk: 🚨 compatibility: Existing targetless-steer and transcript-CAS behavior changes for Gateway clients.
  • merge-risk: 🚨 security-boundary: The refactor controls whether incoming commands can inject into runs carrying retained tool authority.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current authority repair and has substantial history on steering and command routing. (role: feature owner and recent area contributor; confidence: high; commits: f9a2b20d7995, 9d5ca69befdd, ca915228d3a3; files: src/auto-reply/reply/commands-steer.ts, src/auto-reply/reply/reply-tool-authority.ts, src/gateway/server-methods/chat-send-admission.ts)
  • jalehman: Authored the merged direct-run targeting repair that this Gateway-level refactor generalizes. (role: adjacent contributor; confidence: medium; commits: 5b8dcf9d28db; files: ui/src/pages/chat/chat-send.test.ts)

Rank-up moves

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

  • Provide direct inspection evidence for the cited Codex revision.
  • Complete exact-head CI.

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 (3 earlier review cycles)
  • reviewed 2026-08-18T12:29:16.442Z sha 25632037c52f39229a49849b16bf6d5343fa0ab0 :: found issues before merge. :: [P2] Update the targetless-steer API contract
  • reviewed 2026-08-18T13:02:23.344Z sha 5450880b0cd49a6053edadbb4204a2591ac8bcb6 :: found issues before merge. :: [P1] Preserve command-caller authority before injecting
  • reviewed 2026-08-18T13:37:02.020Z sha 0c71b12 :: found issues before merge. :: [P1] Preserve command-caller authority before injecting

@steipete
steipete force-pushed the steipete/gateway-start-or-steer branch from 2563203 to 5450880 Compare August 18, 2026 12:54
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui labels Aug 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 18, 2026
…ration lifecycle

chat.send with queue mode steer now atomically captures the selected
session's current direct reply operation under the writer barrier and
injects into exactly that operation; with no direct owner it starts a
new run instead of failing with active-leaf-changed. Client-supplied
expectedRunId keeps exact-match semantics; the transcript-branch CAS
(expectedLeafEntryId) now guards only non-steer sends.

All three steering paths (gateway chat.send, channel queue steering,
server /steer) share one begin/finalize lifecycle on the reply-run
registry, including the captured-instance abort from 5a15e1a.
Deleted: the duplicate accepted/rejected/unconfirmed policy machine in
steer adoption, the raw embedded /steer runtime path, the leaf-bound
injection identity and reject-before-ack compat, and the dead target
tool-authority fingerprint. messageInjectionAttempted becomes a typed
messageInjectionDisposition (none | accepted | rejected); rejected
injections take one visible followup fallback, so non-injectable
runtimes queue instead of silently dropping.

Deliberate semantics: a registry-less active embedded run is no longer
steered by raw session id (correlation-only authority) - the message
becomes a visible followup; /steer injects under its own command
authorization instead of the inbound tool-authority gate it could
never satisfy.
Targetless steer is no longer a leaf-bound compatibility path that can
reject with active-leaf-changed; it targets the selected session's
current state (inject into the direct run, else start a turn).
expectedRunId stays an exact-run fence; expectedLeafEntryId is the
non-steer transcript-branch CAS.
@steipete
steipete force-pushed the steipete/gateway-start-or-steer branch from 5450880 to 0c71b12 Compare August 18, 2026 13:30
@steipete steipete self-assigned this Aug 18, 2026
The authorized-sender command gate is weaker than tool-authority equality. Make /steer and gateway injection present the same projected evidence as channel steering so mismatches fall back to a normal prompt under the sender’s own authority.
@steipete
steipete merged commit 6515f6a into main Aug 18, 2026
218 checks passed
@steipete
steipete deleted the steipete/gateway-start-or-steer branch August 18, 2026 14:33
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
)

* refactor(steering): gateway-owned start-or-steer via one captured-operation lifecycle

chat.send with queue mode steer now atomically captures the selected
session's current direct reply operation under the writer barrier and
injects into exactly that operation; with no direct owner it starts a
new run instead of failing with active-leaf-changed. Client-supplied
expectedRunId keeps exact-match semantics; the transcript-branch CAS
(expectedLeafEntryId) now guards only non-steer sends.

All three steering paths (gateway chat.send, channel queue steering,
server /steer) share one begin/finalize lifecycle on the reply-run
registry, including the captured-instance abort from 9a36324.
Deleted: the duplicate accepted/rejected/unconfirmed policy machine in
steer adoption, the raw embedded /steer runtime path, the leaf-bound
injection identity and reject-before-ack compat, and the dead target
tool-authority fingerprint. messageInjectionAttempted becomes a typed
messageInjectionDisposition (none | accepted | rejected); rejected
injections take one visible followup fallback, so non-injectable
runtimes queue instead of silently dropping.

Deliberate semantics: a registry-less active embedded run is no longer
steered by raw session id (correlation-only authority) - the message
becomes a visible followup; /steer injects under its own command
authorization instead of the inbound tool-authority gate it could
never satisfy.

* docs(protocol): describe gateway start-or-steer contract for chat.send

Targetless steer is no longer a leaf-bound compatibility path that can
reject with active-leaf-changed; it targets the selected session's
current state (inject into the direct run, else start a turn).
expectedRunId stays an exact-run fence; expectedLeafEntryId is the
non-steer transcript-branch CAS.

* fix(steering): require matching tool authority for /steer injection

The authorized-sender command gate is weaker than tool-authority equality. Make /steer and gateway injection present the same projected evidence as channel steering so mismatches fall back to a normal prompt under the sender’s own authority.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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