[Bug]: OpenCode thread wedges with "Insufficient context allowance" after delegate_task result when model window is unknown #16147
Before submitting#
- I searched existing issues and did not find a duplicate. Related: #15997, which has the same error and the same thread wedging but a different trigger (Antigravity/Pi). This one is OpenCode with a
delegate_taskresult. - I included enough detail to reproduce or investigate the problem.
Area#
apps/server (orchestration v2 context handoff, OpenCode adapter)
Environment#
- T3 Code Nightly
0.0.46-nightly.20261003.2610, macOS arm64 - OpenCode
2.0.22 - Model
opencode-go/deepseek-v4.1-flash(1M context peropencode models)
Steps to reproduce#
- Run a long OpenCode thread. Here
contextUsage.usedTokenswas ~581k, which is fine for a 1M model. - From that thread, delegate work to Codex with
delegate_taskand let it finish. The result is queued as a context handoff (strategy: manual_context,status: ready). - Send any message in the thread.
Expected behavior#
The subagent result is delivered on the next turn (inline, or deferred/pointer if it doesn't fit), and the thread keeps working.
Actual behavior#
Every turn fails with:
Provider error: Insufficient context allowance for the provider handoff. Compact the target conversation or use a larger-context model; the current request has not been truncated.
Plain messages ("Status?", "hi") fail too, so the thread is unusable until /compact is run manually. After /compact, the next turn delivered both queued handoffs inline and the thread recovered.
Likely cause (from reading the bundled server code)#
- The provider thread's
contextUsagewas{ "usedTokens": 581117 }with nomaxTokens. That means the OpenCode adapter'swindowOf(cwd, model)returned undefined for this thread.readModelsfillscontextWindowsfromclient.model.listwith a 5s timeout and errors ignored, so a slow or failed lookup leaves the window unknown. handoffBudgetthen falls back to a 128k window:128k − 581k − reservegives a budget of 0. Even a short summary handoff can't fit, sodeliverContextHandoffsthrowsContextHandoffBudgetErroron every turn.
Suggestions#
- Make the OpenCode window lookup reliable: retry
model.list, or fall back to the model's catalog limit rather than 128k for 1M-context models. - When the handoff budget is 0, degrade instead of failing the turn. For example, defer the handoff or deliver a
t3_thread_readpointer (this already happens when coverage is too large), or show a one-click "Compact and retry" with the error.
Workaround#
Run /compact in the thread. To prevent it, cap the model's limit.context (e.g. 128000) in OpenCode config so OpenCode auto-compacts before T3's fallback window is reached.
Note from the reporter#
Big fan of the product and happy to be using it. I'm a non-technical user who has gotten proficient with coding agents. My Claude Code was helping me manage T3 and caught this, so take that for what it's worth.
juliusmarminge added labelsbug
juliusmarminge added labelsvia-triage
Additional related incident with a Codex parent, rather than OpenCode. This confirms the same handoff error in another provider; it does not establish the missing-model-window root cause described above.
Environment:
- Linux desktop AppImage/backend, viewed from the T3 mobile app.
- Installed T3 Code:
0.0.46-nightly.20261011.2955(read from the running application's package metadata). - Installed Codex CLI:
0.162.1; live Codex app-server processes present. - Parent model:
gpt-6.1-sol, full-access; long conversation with multiple app-owned delegated repair/review tasks, includinggpt-6-lunaandgpt-6.1-solchildren.
Observed timeline on 2026-10-11 (UTC), from
t3_thread_readdurable activity and run state:Parent run 28 started at
07:18:37.350.Its last normal tool result was at
07:33:19.363; acompactionactivity item becamerunningat07:33:19.399.Several child results/notifications arrived afterward (including at
07:45,08:13, and08:23), but no subsequent parent provider activity appeared. A user status message at08:57:21went unanswered. At approximately09:58, the parent still reportedrunningwith the same active run. This was over two hours without coordinator progress.At
09:59:41,t3_thread_send(mode="restart")returneddelivery="restarted",status="starting", and the same run 28 ID. At10:00:30, there was still no new provider activity; the thread remainedstarting. The accepted restart receipt did not demonstrate actual recovery.The user pressed Stop. At
10:00:51.981, durable activity recorded interruption withRun interrupted before provider start.A mobile
Continuemessage started run 29 at10:01:16. It failed at10:01:16.897with the exact error: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 user sent
/compactat10:01:34.162. Run 30 started and recordedCompacting contextat10:01:34.958. The user subsequently confirmed that manual/compact, followed by resuming with a new message, fixed the thread and restored progress. Stop followed by another ordinary message alone had produced the handoff error above.
A recurring child monitor also stalled on an older active turn while newer scheduled turns accumulated (latest queued ordinal observed: 225). We paused that existing schedule to prevent further queue growth. This may be a separate failure; it is not evidence that the monitor caused the parent's stall. Another thread in the same app remained responsive, so we have not established a server-wide lockout.
No deterministic reproduction, token/window measurements, raw provider error explaining the original compaction stall, or effect-outbox inspection yet. The hypothesis is that a long conversation plus pending child-result handoffs exhausted the handoff allowance, with compaction/restart failing to recover cleanly; the cause is unconfirmed.
Related but distinct: #17468 (Codex stop/start stalls), #17512 (lost child completion), #17825 (checkpoint capture stalls). Useful investigation areas are bounded compaction/restart recovery, visible restart completion/failure, and deferring queued result handoffs when the allowance is exhausted rather than preventing the parent from resuming.
Sanitized report only: no prompts, raw logs, database, screenshots, host addresses, or local project paths attached.
Additional confirmation on the current nightly — a Codex parent with a known window and a genuine budget overflow (not the unknown-window case above), plus a batch angle: 8 queued results costed all-or-nothing.
Environment
- T3 Code Nightly
0.0.46-nightly.20261013.3080(bundled server; newest nightly as of 2026-10-13), macOS arm64 - Codex CLI
0.162.1(T3 codex driver) - Parent model
gpt-6-luna, reasoning effort max, full access; long conversation (goal tracker showed ~610k tokens processed over ~42m)
What happened (2026-10-13, UTC)
A batch of
delegate_taskchildren ran from the parent thread; 8 results queued as context handoffs — allstrategy: "manual_context",status: "ready", transfer typesubagent_result(rows inorchestration_v2_projection_context_handoffs), created over at least ~20 minutes (00:47Z–01:06Z), never delivered.Provider turn ordinal 5 started 00:36:21Z and stayed
running. The first turn failure (~01:21Z) surfaced only asProvider error: Provider turn failed.; a retry surfaced the full error via the server spanorchestrationV2.deliverContextHandoffs: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 retry re-failed identically (including the "Continue working" affordance) while all 8 handoffs stayed
ready— the backlog does not drain across turns.Unlike the OpenCode case above (
handoffBudgetclamped to 0 with nomaxTokens), codex reports the window — here the coverage plus selected history from the 8 queued results genuinely exceeded the budget.
Code path (main, unfixed in this build)
apps/server/src/orchestration-v2/ContextHandoffDelivery.tslines 82–85:if (historyCost(selected.messages, selected.context) > budget) { if (input.deferInline) return …; return yield* new ContextHandoffBudgetError(); }— ordinary turns throw; thedeferInlineshort-circuit only applies wheninject === undefined(lines 39–40). Coverage is built from all pending handoffs (lines 42–47), so a batch is costed all-or-nothing with no incremental drain. Fixes already proposed: #16244 and #18620 — both still open; verified absent from20261013.3080.Recovery Not recovered on this build; the thread was abandoned for a stable-channel session. Per this report and #17952, manual
/compactis the working recovery — I can re-test the batch scenario on the next nightly after #16244/#18620 merge if useful.Sanitized report only: no prompts, raw logs, database contents, screenshots, host addresses, or local project paths attached. Counts and statuses were read from local projection tables.
- T3 Code Nightly
Additional observed Codex incident with a known context window. This appears covered by #19414; reporting measurements rather than opening a duplicate issue or competing fix.
- Windows desktop, T3 Code Nightly installed resources dated 2026-10-12 (exact release/commit not established); Codex parent using
gpt-6.1-sol, with asynchronous delegated tasks. - Native rollout recorded five successful compactions, most recently
2026-10-13T23:16:37.682Z. - Last successful parent turn finished on
2026-10-14at approximately02:21:43Z. Its usage was 356,824 / 475,000 tokens, confirmed both by the native token-count event and T3's persisted provider-thread contextUsage. The latter had no autoCompactThreshold field. - A delegated-result wake turn failed at
02:27:25.265ZwithInsufficient context allowance for the provider handoff. Compact the target conversation or use a larger-context model; the current request has not been truncated.Subsequent completion wake turns and ordinary user messages failed at the same gate, before further native execution. - The installed
handoffBudgetreservesmax(16000, ceil(window / 4)). Even before charging current user text,475000 - 356824 - 118750 = -574, clamped to zero. Thus substantial physical headroom remained while pending handoff delivery could not start.
The current main source still throws ContextHandoffBudgetError in ContextHandoffDelivery.ts when selected handoff history exceeds that budget. #19414's deferral-and-later-delivery path directly addresses this failure gate. Automatic native compaction would be a separate policy choice, as discussed in #15213 / #13123; these observations do not establish approval for that direction.
The dedicated
/compactcommand / Compact context action was not tested in this incident. A plain-language request to compact was an ordinary message and failed; it is not evidence that the dedicated action is broken. Work was recovered into a fresh conversation.No live-provider validation of #19414, new local test run, or claim of a merged/deployed fix is included. Sanitized report only: no prompts, raw logs/database, local project paths, credentials, or conversation identifiers attached.
- Windows desktop, T3 Code Nightly installed resources dated 2026-10-12 (exact release/commit not established); Codex parent using
Another known-window data point, from the latest nightly. In this case the wedge stayed hidden until an auto-update restart, and then delegated-task completion wakes kept it going on their own. This is still the zero-budget gate that #19414 removes. I'm not reporting a new root cause.
Environment
- T3 Code Nightly
0.1.1-nightly.20261017.3238, Windows x64. The relevant functions in the installedserver.asarmatchmainat2993dfc069:handoffBudget,deliverContextHandoffs, the turn-start handoff filter, missed-run recovery, andcauseMessage. - A custom Codex-driver provider instance (an OpenAI-compatible proxy), model
claude-sonnet-5-5. The same native thread had earlier run ongpt-6-astraandclaude-opus-5-5. - A parent thread running a long chain of async
delegate_taskchildren.
Measurements (
statev2.sqlite, read-only)- Provider-thread
contextUsage:{usedTokens: 743810, maxTokens: 950000}, with noautoCompactThreshold. budget = max(0, min(16000, 64000, 950000 - 743810 - current - ceil(950000/4)=237500)) = 0. That is -31,310 before the user text is even counted.- Usage crossed the zero line (712,500) at about 02:57 UTC. Native turns then kept succeeding up to 743,810 for another ~80 minutes. They were continuations inside one long-lived run, so turn start never ran the gate.
Timeline (UTC, 2026-10-17)
Time Event 04:37:40 desktop.lifecycle.beforeQuitForUpdate. The auto-update ends the long-lived parent run (cancelled).04:37:56 The restart continuation fails with the generic "The provider could not start this turn". The underlying cause isn't kept anywhere I can find (see point 3 below). 04:41:51 A user message fails with "Insufficient context allowance for the provider handoff..." 04:47, 05:14, 05:31 Each delegated-task completion wake fails the same way about 30 s after it starts. Each failure adds another missed run with no provider turn, so the next start always builds a delta_since_target_last_seenretry handoff.The only way forward for the thread was
/compact. That path passesdeferInline: true, so it skips the gate. Whether it actually recovers also depends on a fresh, lower usage report arriving after compaction.What this adds to #16147 / #19414
- The wedge is latent before it's visible. A parent that stays inside one long run can go well past
window - max(16k, window/4)with no warning. The first restart, including an unattended auto-update, then wedges it with nothing in the UI beforehand. A warning, or an automatic compaction before the restart continuation, would have avoided this. - The 25% reserve is large on big windows. At 950k, T3 refuses a few-KB handoff with ~206k tokens still free. #19414 keeps the reserve policy as it is. The deferral fixes the wedge, but on large windows handoffs will stay deferred for a long time.
- The restart continuation's real error is lost. The restart-continuation run shows only the generic
ProviderAdapterTurnStartErrortext. At this activity levelserver.trace.ndjsonrotates out in about 45 minutes (10 x 10 MB), so the cause can't be recovered later.
Looking forward to #19414 landing. Happy to re-test once it's in a nightly.
- T3 Code Nightly
Note
Written by an AI agent on behalf of @Project516, from this machine's logs and the source.
Same failure with Codex and a known window, on T3 Code 0.1.0 (Linux arm64), model
gpt-6.1-sol.At 16:48:53 UTC
deliverContextHandoffsfailed withContextHandoffBudgetErrorafter a manual re-sign-in restarted the session. The thread's last reported usage was 195,810 of a 258,400 window. With themax(16k, window/4)reserve (64,600) the budget is below zero, so it clamps to 0 and any pending handoff fails. The Codex adapter does not setautoCompactThreshold, and nothing callscompactThreadon this error, so the only way out is a manual/compact.#19414 (defer the oversized handoff) would have let this turn go through.
Additional verified incident on macOS arm64, T3
0.0.46-nightly.20261015.3145, Codex parentgpt-6-astra, with app-owned Claude subagents. Reporting here following the duplicate guidance on #19768.This occurred on the older installed build, not on the build containing #22117.
Observed sequence — 20 October 2026, UTC#
- 09:39:58: a delegated-task completion woke the parent; startup failed 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.
- 09:40:59: an ordinary user “resume” message started another run; it failed with the same error at 09:41:08.
- With no active parent run, we sent the native
/compactcommand once at 09:42:16. - 09:44:37: durable activity recorded
Context compactedand the compaction run completed. - Another delegated result arrived during compaction. Its queued notification automatically started the next parent run afterward.
- By 09:45:45, the parent had fetched both completed tasks through
task_statusand read their saved deliverables. No additional “resume” command, model change, fork, global threshold change or server restart was needed.
Evidence was checked through
t3_thread_readactivity and run states, rather than treating command acceptance as recovery. Token occupancy and the exact handoff-budget calculation were not measured for this occurrence. This is an observed incident and recovery, not a deterministic minimal repro.Relevant upstream fix / recommendation#
While preparing this report, we found #22117 merged at 07:03 UTC today. It removes the redundant subagent-result history handoff, delivers results through the normal completion message with bounded inline content /
task_statusfallback, and filters legacy result handoffs at startup.GitHub ancestry confirms that release
v0.1.1-nightly.20261020.3401contains merge commit4f5ff17172c5f2bde61a09aafb23011ae4d38538. We have not yet upgraded or live-tested that release, so this is not a claim that recovery on our affected installation is verified with the new code.For this delegated-result trigger, adopting and validating #22117 appears preferable to introducing a separate automatic-compaction policy. #19414 remains relevant to the broader oversized-history-handoff case. The useful acceptance check is that an existing long parent with legacy result records can receive multiple child completions without manual compaction, while preserving result retrieval and delivery acknowledgements; #22117 already includes regression coverage in that direction.
No new or independent root cause is claimed. No private prompts, conversation IDs, local project paths, raw logs, database files or credentials are attached.
- 09:39:58: a delegated-task completion woke the parent; startup failed with:
Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Thanks for the report. One part of this is fixed on main in #22117. Please test on the nightly built from main on 2026-10-21, or on the next stable release. One part is still open: unknown OpenCode window still falls back to 128k, so other manual handoffs can still wedge the thread. If that part still matters to you, please open a new issue for that part only.
t3dotgg(GitHub profile, opens in a new tab) closed this
Thanks. I tested the v0.1.2 stable source tag (published 2026-10-22; tag commit
044f072, which includes the #22117 merge commit4f5ff171) with the targeted server tests on Windows/Node 26.12.1.DelegatedCompletionDelivery.test.tsandContextHandoffBudget.test.tspassed. In the broader four-file run,ProviderTurnStartService.test.tshad two startup-order assertion failures (cleanup-firstandstartup-first); bothOrchestratorMcpToolkit.integration.test.tscases failed before their assertions because the test fixture path resolved with a duplicated Windows drive prefix. Overall, 73/77 tests passed. TheProviderTurnStartService.memory.test.tsfile named in the PR was absent at the v0.1.2 tag; the result-message regression is present inDelegatedCompletionDelivery.test.tsand passed.This was source-level regression testing at the stable release tag, not a run of the packaged desktop app or a live OpenCode thread, so I cannot claim a live-use retest.
My additional report here used Codex with a known 475k context window, not the separate unknown-OpenCode-window case. I have no first-hand evidence that the latter affects my report, so I did not open a new issue for it.
Sign in to join this conversation.
Note
Grok responding on behalf of Julius.
Triage#
Thanks for such a thorough report, @sree-akkineni! Your reading of the bundled code was spot on, and the numbers match current
main. The error and the stuck thread are the same as #15997, but the cause is different: here it's an OpenCode thread whose measured usage is past the fallback window, with adelegate_taskresult waiting to be delivered.What I found#
delegate_taskfinishes, it writes a readymanual_contexthandoff onto the parent thread (Orchestrator.ts). The next turn prices it withhandoffBudget. If both the storedmaxTokensand the live model window are missing, that function assumes a 128k window and reserves a quarter of it (ContextHandoffBudget.ts). WithusedTokensat 581117, the budget comes out to 0. A real 1M window would leave room.deliverContextHandoffsthen throwsContextHandoffBudgetErrorbefore injecting anything. Thet3_thread_readpointer is only used when its marker fits the budget, so a 0 budget fails the turn instead of deferring. The handoff staysready, later turns pick it up again (ProviderTurnStartService.ts), and each failed turn adds another missed-run handoff. That's why "Status?" and "hi" keep failing.client.model.list, with a 5 second timeout and errors ignored (OpenCode2AdapterV2.ts,readModels). The directory is marked known when the read starts, so a timeout or failed read isn't retried byreadModelsOnce. Turns that fail in handoff delivery never reach the adapter, so they don't trigger the post-turn catalog retry either. The report doesn't show whethermodel.listtimed out, errored, or omitted this model./compactdefers delivery when the budget is short instead of failing, so once compaction lowersusedTokensthe queued handoffs go through inline. That matches your workaround.Likely fix area#
model.listinstead of marking the directory known up front.A maintainer will decide on the fix direction.