Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Switching a thread back to Cursor or Grok fails with "Insufficient context allowance", because both adapters report no context window #20166

Closedtopitopongsala(GitHub profile, opens in a new tab) opened this issue 3 comments

Before submitting

  • I searched existing issues and did not find a duplicate. Related: #16147 and #19875 (the same budget path on OpenCode), and #15997 (a provider switch on Antigravity). This one is the Cursor and Grok adapters. They report no window and no usage at all, so every handoff into a Cursor or Grok thread that T3 uses again is checked against a 128k window and a byte count.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server (orchestration v2 context handoff), packages/provider-cursor, packages/provider-grok

Environment

  • T3 Code Nightly 0.0.46-nightly.20261011.2994, Linux x64
  • Cursor provider, model grok-4.7 (reasoning_effort: high, fastMode: false). The Cursor catalog offers contextWindow 256k or 500k, and 500k is the default.
  • Grok CLI 1.0.54, model grok-4.7. ~/.grok/models_cache.json gives context_window: 256000 (500000 selectable).

Steps to reproduce

  1. On a Claude thread, t3_thread_configure the thread to the Cursor instance (grok-4.7) and send a message. T3 makes a new Cursor provider thread, the context handoff fits, and the run works.
  2. Let a few turns run there. T3 stores their items on that Cursor provider thread. Here one turn stored about 96 KB of command output, and the thread held about 160 KB.
  3. Configure the thread back to Claude and run a turn.
  4. Configure it to the same Cursor instance again and send a message.

Expected behavior

The handoff is delivered, or deferred or replaced by a t3_thread_read pointer when it truly does not fit. A 500k-window model with about 40k real tokens of history has room for a 14 KB summary.

Actual behavior

Step 4 and every later switch into that thread fail in 0.2 to 0.5 s, before the provider gets anything:

Insufficient context allowance for the provider handoff. Compact the target conversation or use a larger-context model; the current request has not been truncated.

The run attempt has no providerTurnId, and the handoff row has no delivery. In our case it happened at 3 switches in one day (08:30, 11:55, and 15:00 UTC on 2026-10-15). The thread then stayed on the failed provider until an outside script moved it back.

Likely cause (from reading the bundled server code)

  • packages/provider-cursor/src/server/adapter.ts has no getModelContextWindow and emits no UsageUpdated. In our state database 0 of 921 Cursor provider turns carry tokenUsage, and no Cursor provider thread has contextUsage.
  • The Grok flavor of the ACP adapter gets no usage_update with a size from Grok CLI 1.0.54. 0 of 117 Grok provider turns carry tokenUsage.
  • handoffBudget then uses window = 128000 and native = nativeContextEstimate, which is the byte length of every stored item on that provider thread (command output included). With 160,684 bytes: 128000 − 160684 − max(16000, 32000) is below 0, so the budget is 0 and deliverContextHandoffs throws ContextHandoffBudgetError. I reproduced the pass and fail of all five switches that day with this formula: 26,466 bytes passed, 160,684 to 163,250 bytes failed.
  • The Devin (ACP registry) adapter reports maxTokens and usedTokens, and the same switches into Devin pass.

Suggestions

  • Give the Cursor adapter a getModelContextWindow from the Cursor catalog (contextWindow option, 500k default), and the Grok flavor one from the Grok model list (context_window) when the CLI sends no usage_update.
  • When the window is unknown, do not use stored bytes of a provider thread that T3 is about to resume as a token count with a 128k cap. Or start a fresh native thread when the estimate leaves no budget, because the handoff summary already carries the history.
  • As in #16147, degrade to a deferred handoff or a pointer instead of failing the turn.
  1. Note

    Grok responding on behalf of Julius.

    Thanks for the detailed write-up. Two open PRs already cover most of this:

    • #17462 makes the Cursor adapter report the selected contextWindow from the catalog, so handoff budgets stop falling back to 128k for Cursor threads.
    • #19414 (which fixes #16147) defers a handoff that doesn't fit instead of failing the turn, so a thread no longer gets stuck on the failed provider.

    The Grok adapter's missing window isn't covered by either PR yet, so we're keeping this open to track that part.

  2. Note

    Grok responding on behalf of Julius.

    Follow-up after checking main:

    • packages/provider-grok/src/server/adapter.ts has no getModelContextWindow and doesn't map any usage into UsageUpdated. So a Grok thread that gets reused falls back to modelContextWindow ?? usage?.maxTokens ?? 128_000 in handoffBudget.ts, and native falls back to nativeContextEstimate. That matches your formula (window - native - current - max(16k, window/4)).
    • provider-cursor on main also has no getModelContextWindow yet. #17462 adds it and is still open.

    We're accepting the Grok part as a bug: Grok threads should report a real window. Once #19414 lands, a handoff that doesn't fit should be deferred instead of failing the turn. Until then, starting a fresh thread instead of switching back into the same Grok or Cursor thread may avoid it (step 1 of your repro suggests this, but we haven't confirmed it).

  3. juliusmarminge added labelsbug

  4. juliusmarminge added labelsvia-triage

  5. Another data point. This one has no provider switch: the threads were started on Cursor and stayed on Cursor. A T3 restart was enough to trigger the error.

    Environment

    • T3 Code Nightly 0.1.1-nightly.20261016.3203, Windows x64
    • Cursor provider, model grok-4.7 (reasoning_effort: high, fastMode: true, contextWindow left at the default 500k)
    • Both threads were created with t3_thread_launch directly on the Cursor instance and were never reconfigured to another provider.

    What happened (UTC, 2026-10-16)

    Two independent Cursor threads, created at 12:16 and 12:58, failed the same way:

    TimeEventResult
    13:10T3 desktop auto-update quits the app (beforeQuitForUpdate in desktop.trace.ndjson)Active runs cancelled
    13:10:38"T3 Code restarted and resumed this turn"Resumed fine, ran for about 5 minutes
    13:15:53T3 restarts againActive runs cancelled
    13:16:06Automatic restart continuationFailed after about 4 s with the generic The provider could not start this turn. Retry the turn; if it keeps failing, check the provider setup and server logs.
    13:19:10A new queued user message to the same threadFailed after 2.4 s with Insufficient context allowance for the provider handoff. Compact the target conversation or use a larger-context model; the current request has not been truncated.

    At the time of failure the threads held 194 and 402 timeline items, from about 20 and 60 minutes of work. Neither thread could run another turn after that. The only way forward was to start a new thread and carry the work over through a handoff file.

    Why this matters

    • The suggested workaround (start a fresh thread instead of switching back) only helps until the next T3 restart. After an auto-update or an OS reboot, a long-running Cursor thread on the same provider seems to hit the same 128k-fallback budget check and becomes unrecoverable. So every T3 update effectively kills all non-trivial Cursor threads.
    • The first restarted turn reported only the generic "could not start this turn" error. The real cause showed up only on the next attempt. Reporting the budget failure directly on the restart path would save a retry and a lot of guessing.

    Questions: does #19414 (defer instead of fail) also cover a same-provider resume after a restart? Would #17462 (report the selected contextWindow) be enough on its own to fix this case?

  6. juliusmarminge closed this

Sign in to join this conversation.