Skip to content

fix(grok): encode session/cancel as a real notification and interrupt steers - #224

Open
leoisadev1 wants to merge 2 commits into
leoisadev1/t3-port-grokfrom
leoisadev1/t3-port-grok-cancel
Open

fix(grok): encode session/cancel as a real notification and interrupt steers#224
leoisadev1 wants to merge 2 commits into
leoisadev1/t3-port-grokfrom
leoisadev1/t3-port-grok-cancel

Conversation

@leoisadev1

Copy link
Copy Markdown
Member

Problem

Grok CLI dropped session/cancel because effect-acp encoded notifications as JSON-RPC requests with id: "" and headers. Stop did not stop. The next send queued behind the old prompt.

Mid-turn sends also waited behind the in-flight ACP prompt instead of interrupting like Claude and Codex.

Changes

Outbound ACP notifications now encode as JSON-RPC with no id or headers. RpcClient Interrupt frames are dropped. AcpSessionRuntime.cancel waits for the cancel write. prompt can signal dispatched once the RPC fiber is registered.

Grok mid-turn sends cancel the in-flight prompt, then send the replacement under a prompt epoch and lifecycle semaphore. A failed steer does not discard the live prompt.

Upstream

Adapted from pingdotgg/t3code#9154 session/cancel and steer work. Depends on #214 for grok-build handling and initialize-only runtime.

Shared ACP encoding also applies to Cursor and OpenCode. Cursor adapter tests still pass. No Mastra Codex/Kimi/OpenCode Go change.

Scope

This PR is cancel encoding and Grok steer only.

Assigned Grok ports:

Verification

  • effect-acp protocol tests: 21 passed, including cancel frames without id/headers.
  • GrokAdapter tests: 23 passed, including mid-turn steer cancel and failed-steer keeps original prompt.
  • CursorAdapter tests: 19 passed.
  • XAiAcpExtension tests: 10 passed.
  • Targeted lint and format passed.

Stacked on #214. Leave both open.

Made by Grok 4.6 High in Grok Build via Orca.

… steers

Grok CLI dropped session/cancel because effect-acp encoded notifications as
requests with an empty id and headers. Stop then queued the next prompt behind
work that never cancelled.

Notifications now encode as JSON-RPC with no id. Cancel waits for that write.
A mid-turn send cancels the in-flight prompt and continues the same turn.

Adapted from pingdotgg#9154. Shared ACP encoding also applies to Cursor
and OpenCode; their adapters still use start() and are covered by existing tests.

Made by Grok 4.6 High in Grok Build via Orca.
@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
akeru-bot-landing Building Building Preview Sep 10, 2026 5:55pm UTC

Request Review

@github-actions github-actions Bot added type:provider Agent provider contribution. vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Sep 10, 2026
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR corrects ACP notification framing and makes Grok mid-turn steering deterministic by preserving the replacement prompt’s terminal outcome.

Confidence Score: 5/5

Safe to merge.

No outstanding findings remain.

Reviews (2): Last reviewed commit: "fix(grok): keep steered turn outcome on ..." | Re-trigger Greptile

A successful replacement could be reported as cancelled when the superseded
prompt finished local draining last. The last in-flight settlement owned the
terminal state.

Store the current epoch's result and emit that when the last prompt drains.
Unit tests cover both settlement orders.

Made by Grok 4.6 High in Grok Build via Orca.
@leoisadev1

Copy link
Copy Markdown
Member Author

This is Leo's agent. Independent review found that #228's terminal-emission finding also applies to this exact head, 11ccb78b76cfa08c2f3f25a5e709e850f6c78c62.

I ran the 109 focused protocol and adapter tests successfully, then reproduced the omitted case against the shipped grokTurnCompletionForPromptEpoch:

  1. Epoch 2 stores { completedStopReason: "end_turn" } while one older prompt remains.
  2. Superseded epoch 1 drains with remainingPrompts: 0 and emitTurnCompletion: false.
  3. The helper returns emit: undefined instead of flushing the stored current-epoch completion.

The helper is identical in #224 and #228. This reproduction exercises the real helper; it does not claim a full provider-process interleaving. The existing adapter tests do not cover this final no-emission drain.

I requested a scoped repair and committed lifecycle regression from the existing Grok worker, with the fix propagated to #228. That worker is currently weekly-quota blocked, so no fix has executed. Both PRs remain on hold pending the repair and fresh verification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L type:provider Agent provider contribution. vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant