Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Long 1M-context Claude thread fails every turn with "Insufficient context allowance" after a Fast Mode change is refused by the background-work guard #17952

Closedkynjal26(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: #16073 (the background-work guard), #16147 and #15997 (same handoff error, different causes: unknown window falling back to 128k, and an instance switch). Here the window is known (1M) and nothing switches provider or instance.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Run a long Claude thread on Opus 5.5 (1M window) until contextUsage.usedTokens is above ~750k. Mine was {"usedTokens":809860,"maxTokens":1000000}.
  2. While the thread still has background work (one kind: "command" task was still listed in pendingBackgroundTasks), toggle Fast Mode on in the composer and send a message.
  3. The run is refused with: Claude is still running background agents or commands, and this model or setting change would end them. Wait for them to finish, or press Stop, then send the message again. That run (ordinal 132) is marked failed.
  4. Wait until the background tasks finish (UI shows "12 background tasks finished") and send another message.

Expected behavior

The second message starts a turn. If the refused message has to be replayed and does not fit, it is deferred or replaced with a t3_thread_read pointer, or the thread offers "Compact and retry". The turn should not fail.

Actual behavior

The second run (ordinal 133) fails immediately 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.

Every later message will fail the same way until the user runs /compact by hand, even though the model has a 1M window and ~190k tokens are still free.

Likely cause (from reading the bundled server code)

  • The refused run 132 counts as a missed run (status === "failed", never delivered), so turn start builds a delta_since_target_last_seen retry handoff for it. No handoff row is persisted for run 133. The error is thrown before persist.
  • handoffBudget returns max(0, min(tokenCap, 64000, window - native - current - max(16000, ceil(window / 4)))). With a 1M window the reserve is 250k, so once usedTokens passes ~750k the budget is 0 and even the small retry handoff can't fit. deliverContextHandoffs then throws ContextHandoffBudgetError (only deferInline / compaction skips it).
  • So the guard refusal from #16073 is what breaks the thread: the refused message creates a handoff that a long 1M thread can never afford.

Suggestions

  • When the budget is 0 for a missed-run retry, don't fail the turn: drop or defer the retry, or deliver a pointer (as already happens when coverage is too large).
  • Scale the reserve for large windows (25% of 1M = 250k is a lot of headroom to keep for a few KB of handoff), or cap it.
  • A refusal from the background-work guard probably shouldn't count as a missed run at all, since the provider never saw that message.
  • Show a "Compact and retry" action on this error.

Impact

Major degradation or frequent failure

Version or commit

0.0.46-nightly.20261010.2948

Environment

Linux x86_64, headless t3 serve (web client), Claude Code 2.1.293, model claude-opus-5-5 (effort high), Claude Max subscription.

Logs or stack traces

ContextHandoffBudgetError: 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 orchestrationV2.deliverContextHandoffs
    at orchestrationV2.providerTurnStart.start

Provider thread at failure time:

{"status":"idle","pendingBackgroundTasks":[{"kind":"command"}],"contextUsage":{"usedTokens":809860,"maxTokens":1000000}}

Runs:

132 failed  modelSelection {"model":"claude-opus-5-5","options":[{"id":"effort","value":"high"},{"id":"fastMode","value":true}]}
133 failed  (same selection)
131 completed (fastMode false)

Workaround

Send /compact in the thread (compaction uses deferInline, so it skips the budget check), then resend the message. Or start a new thread.

  1. mikeqwe(GitHub profile, opens in a new tab)commented

    Same wedge here (macOS, Claude Opus 5.5, 1M window; triggered by an effort change rather than Fast Mode). The relevant code is unchanged on main (5753207).

    One more factor keeps the thread wedged: it does not recover when the native session compacts on its own. Claude kept working in the background and auto-compacted at 02:06 UTC (compact_boundary, trigger auto, preTokens 967,336 → postTokens 16,969). T3's usage for the provider thread stayed at 753,220, because no T3 provider turn completed after 22:30:03 UTC and turn start reads usage from the provider thread or the latest provider turn (latestNativeContextUsage). T3 did receive that compact_boundary (it is in the provider protocol log at 02:06:51 UTC), but with no T3 turn running, ClaudeAdapterV2 has no turn context for it; only a compact_boundary inside a turn updates the provider turn's tokenUsage (our manual /compact at 13:03 UTC recorded 19,232). The budget stayed 0, and 8 more turns from a 40-minute heartbeat (02:25–07:06 UTC) failed. With the real usage, handoffBudget would have returned its cap (16k by default). A native compaction outside a T3 turn should also refresh or invalidate the stored usage.

  2. Another trigger for the same zero-budget wedge, on 0.0.46-nightly.20261014.3105 (3417bc3856a2). A thread-bound scheduled task ran GPT-6.1-Sol inside a long Claude Opus 5.5 thread. Claude's last usage was 840,960 / 1,000,000; the Sol turn used 87,369 / 475,000, so this was not a Codex overflow. Returning to Claude failed with ContextHandoffBudgetError (reserve 250k, budget 0, about 159k still free), as did two later turns. Manual /compact brought usage down to 14,938 and the thread resumed.

    I tested #19414 against a deterministic reproduction of this round trip: it fails on main and passes on #19414. Details and the tests: https://github.com/pingdotgg/t3code/pull/19414#issuecomment-6175454150

  3. Tested on main 70e5e384da, Linux x86_64, real web dev app, Claude Code 2.1.303, Opus 5.5 with a 1M window. Loaded a disposable native session to ~825k tokens and started sleep 180 as a Claude background command. Turning Fast Mode on and then changing effort from medium to high both completed normally while that command remained pending. After it finished, two more messages also completed. No guard refusal, handoff-budget error, or manual compaction occurred.

    The reported Fast Mode/effort trigger is fixed by bc95bbd7905: those settings now update the live Claude process without replacing it. Closing this reproduction as fixed on main. This does not establish recovery of a thread already wedged on the older nightly; the broader oversized-handoff handling remains in #19414.

    Runtime transcript, settings, token usage and run results. Browser viewport: 1280×800. macOS, Electron and mobile were not exercised.

    Fast Mode change while the command remains running: Fast Mode probe completes with background command running

    Effort change while the same command remains running: Effort probe completes with background command running

    Two later messages after command completion: Both post-background retries complete

  4. juliusmarminge closed this

Sign in to join this conversation.