Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): show Grok usage limit errors #6396

ClosedSunkenInTime(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/6396/headopened View on GitHub

What Changed

  • treat xAI rate_limit and error prompt completions as failed ACP requests instead of successful fallback completions
  • emit one failed terminal turn, restore the Grok session to ready, and retain the selected model
  • cover the private xAI notification and full Grok adapter flow with a focused ACP mock

Why

Grok reports usage exhaustion through its private _x.ai/session/prompt_complete notification before the standard prompt request settles. T3 raced that notification against the prompt RPC, normalized the unknown rate_limit stop reason to end_turn, and cancelled the real error path. The thread therefore appeared to complete with no response or visible explanation.

The fallback now preserves failure semantics at the xAI adapter boundary and surfaces a stable, provider-specific message without synthesizing or clearing any model selection.

UI Changes

Before, a Grok usage limit could leave an empty completed turn with no error. After, the thread fails once with a visible usage-limit message while the selected Grok model remains in the composer.

Grok usage limit shown in the T3 chat surface

Verification

  • vp test run apps/server/src/provider/acp/XAiAcpExtension.test.ts apps/server/src/provider/Layers/GrokAdapter.test.ts (32 tests passed)
  • vp run --filter ./apps/server typecheck
  • targeted vp fmt --check and vp lint for all changed files
  • full Computer Use verification in Safari against an isolated T3 environment and an exact rate_limit ACP mock: the thread entered Failed, displayed the error once, returned the session to ready, and kept Grok Build selected

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included screenshot evidence for the user-visible behavior
  • No animation or timing behavior changed, so a video is not applicable

Implemented with gpt-5.6-sol through the Codex harness in T3 Code.

Note

Show Grok usage limit errors when xAI rate limit is reached

  • Adds a settleXAiPromptCompletion helper in XAiAcpExtension.ts that inspects the stopReason from xAI prompt completions and fails the pending Deferred with an AcpRequestError (code -32003, message "Grok usage limit reached. Try again later.") when stopReason is rate_limit.
  • Previously, all prompt completions resolved successfully regardless of stop reason; now rate_limit and error stop reasons produce typed failures that propagate to the adapter layer.
  • Adds a mock flag T3_ACP_EMIT_XAI_RATE_LIMIT_THEN_HANG to acp-mock-agent.ts for local testing of rate-limit behavior.
Macroscope summarized 360e13f.

Note

Medium Risk Changes Grok/xAI prompt settlement semantics for rate_limit and error completions; incorrect handling could mis-report failures or break hung-prompt fallback, but scope is limited to the xAI ACP extension with targeted tests.

Overview Grok usage limits and xAI prompt errors now fail the turn instead of looking like a silent success.

When _x.ai/session/prompt_complete arrives with stopReason rate_limit or error, XAiAcpExtension resolves the pending prompt via new settleXAiPromptCompletion by failing the deferred with AcpRequestError (usage limit uses code -32003 and "Grok usage limit reached. Try again later."; generic errors use agentResult when present). Pending completions are typed to allow failure, so this no longer races into a fake successful end_turn completion.

The ACP mock adds T3_ACP_EMIT_XAI_RATE_LIMIT_THEN_HANG to simulate rate-limit-then-hang behavior. Tests cover the xAI extension and full Grok adapter path: failed turn, session back to ready, and selected model unchanged.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 360e13fb05395825e6bf70a6c93ea0611992b113. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 998c14cd-0660-4c7a-9f1a-cc65b204f8af

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    3. Approvability

      Verdict: Approved 360e13f

      Straightforward bug fix that surfaces rate limit errors from Grok to users with a clear error message. Limited scope (error handling only), clear intent, and comprehensive test coverage.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      I am closing this because #8358 has landed in main and covers the same Grok usage-limit error handling. I checked the current implementation and did not find any remaining change from this PR that we still need to merge.

      Thank you for putting this together. The closure is only because the work is now covered elsewhere, not because there was a problem with your contribution.

Sign in to join this conversation.