Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(grok): health check, model selection, and stop all work against the real CLI #9154

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 9 commits intomain fromrefs/pull/9154/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Grok Build had a cluster of reliability problems that made it feel broken even when the CLI itself was fine:

  • The provider health check opened a full ACP session. authenticate could launch a browser login on its own, and session/new booted every configured MCP server, so background checks hung, timed out, and persisted error over a working install. It also never reported auth state.
  • Picking the built-in Grok Build model failed with unknown model id, because grok-build is the CLI's product name, not a model id its ACP accepts.
  • Stop did not stop. The next message queued behind the old prompt, which kept running to completion.
  • Mid-turn sends queued instead of interrupting like Claude and Codex.

What changed

Health check without a session. grok --version, then grok models for login state and slugs, then a single ACP initialize and reads models from _meta.modelState. No authenticate, no session/new. A failed initialize degrades to warning with the CLI's model list instead of error. XAI_API_KEY counts as authenticated. Against Grok CLI 1.0.13 this returns ready, authenticated, and both models with reasoning options in about 1.2 s.

grok-build means "the session's current model". It is never sent in session/set_model. No hardcoded alias to rot when the next model ships. The mock agent now advertises versioned ids like the real CLI so this cannot regress silently.

Stop actually cancels. This was the root cause behind both stop issues. effect-acp encoded notifications through the Request path, so session/cancel went out as {"id":"","headers":[]}. Grok CLI parses that as a malformed request and drops it. The mock agent was lenient and hid this. Notifications now serialize with no id. Verified live: Stop then a new send answers the new prompt immediately with nothing leaked from the old one. Before this fix the old prompt's output kept streaming into the new turn.

Mid-turn sends interrupt. Takes over #8286 by @mavenskylab with authorship preserved, plus one follow-up that replaces the eight-yieldNow sync loop with a Deferred the ACP runtime settles once the prompt RPC is registered.

Verification

  • Focused tests for the health check parser, model-state builder, product-slug handling, ACP notification encoding, and the existing Grok, Cursor, and ACP runtime suites. 211 passing.
  • Live against Grok CLI 1.0.13: health check snapshot, and stop-then-resend with wire capture of every frame T3 wrote to the agent.

Closes #7746, #5852, #7505, #6075, #8283, #8461.

Written by Claude Fable 5.1 in Claude Code.


Note

Medium Risk Shared ACP protocol and cancel timing changes affect all ACP-backed providers, not only Grok; Grok steer adds epoch-based concurrency that must stay consistent with interrupt and settlement paths.

Overview Fixes Grok reliability by aligning probes and turn control with the real CLI, and repairs ACP session/cancel so Grok (and other agents) actually receive cancellation frames.

Provider health check no longer runs authenticate or session/new. It probes grok --version, parses grok models for login state and slugs, then a short ACP initialize to read models from _meta.modelState. Unauthenticated CLIs error with a login hint; failed initialize degrades to warning with CLI-listed models. XAI_API_KEY overrides CLI login for auth reporting.

Model selection: the built-in grok-build slug is T3’s product name—it is never sent in session/set_model; choosing it keeps the session’s current ACP model (reasoning changes still apply to that model). The mock agent advertises versioned ids like production.

Mid-turn sends (steer) on Grok now session/cancel the in-flight prompt, then send the replacement under a prompt epoch / lifecycle semaphore, so new input interrupts like Claude/Codex instead of queueing behind the old prompt.

effect-acp: outbound notifications encode as proper JSON-RPC (no id or headers); RPC Interrupt control messages are dropped. AcpSessionRuntime.cancel awaits the cancel write before completing; prompt can signal dispatched once the prompt RPC is registered for steer races.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2b9bde5aedfbd8d315c6c70c60ecd1f7f49a7475. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix Grok health check, model selection, and concurrent turn steering

  • Rewrites checkGrokProviderStatus to probe via ACP initialize only (no session creation), then fall back to grok models CLI output and built-in models; derives auth state from XAI_API_KEY or CLI login text
  • Treats the grok-build product slug as "keep current session model" in applyGrokAcpModelSelection — it is no longer sent through session/set_model; reasoning changes apply to the resolved current model
  • Reworks GrokAdapter.sendTurn with a prompt epoch and lifecycle semaphore so a concurrent turn cancels the active ACP prompt before starting a replacement, skips superseded prompts, preserves the original prompt when replacement prep fails, and emits exactly one terminal event per turn
  • Encodes outbound ACP notifications through encodeJsonRpcNotification without id or headers, and discards @effect/rpc/Interrupt messages so they are not sent to ACP agents
  • Risk: discoverGrokModelsViaAcpInitialize now sends only initialize — any code relying on session creation during discovery will no longer get it; sendNotification encoding failures now surface as ACP protocol parse errors rather than native TypeErrors
Macroscope summarized 2b9bde5.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.1 KiB13.3 KiB+172 B (+1.3%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB−3 B (−0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.2 KiB6.4 KiB+175 B (+2.7%)7.8 KiB✅
      CodexLive turn WebSocket decoded54.7 KiB55.6 KiB+910 B (+1.6%)66.4 KiB✅
      CodexLive turn messages810+2 (+25.0%)21✅
      ClaudeTotal thread wire13.4 KiB13.5 KiB+24 B (+0.2%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB+10 B (+0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.6 KiB+14 B (+0.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.8 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages10100 (0.0%)21✅

      Baseline: 8efd4e9 · PR result: 2b9bde5 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b7f5d8f798bb064e90083926c0e192a5ac40ae34. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR makes cross-cutting production changes to Grok health checks, effective model defaults, prompt steering, and shared ACP cancellation/wire behavior. It also adds a static-analysis suppression, so the change requires human review under the configured criteria.

      Notes:

      • No code objects were reviewed. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.