Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: OpenCode thread wedges with "Insufficient context allowance" after delegate_task result when model window is unknown #16147

Closedsree-akkineni(GitHub profile, opens in a new tab) opened this issue 9 comments

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_task result.
  • 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 per opencode models)

Steps to reproduce

  1. Run a long OpenCode thread. Here contextUsage.usedTokens was ~581k, which is fine for a 1M model.
  2. From that thread, delegate work to Codex with delegate_task and let it finish. The result is queued as a context handoff (strategy: manual_context, status: ready).
  3. 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 contextUsage was { "usedTokens": 581117 } with no maxTokens. That means the OpenCode adapter's windowOf(cwd, model) returned undefined for this thread. readModels fills contextWindows from client.model.list with a 5s timeout and errors ignored, so a slow or failed lookup leaves the window unknown.
  • handoffBudget then falls back to a 128k window: 128k − 581k − reserve gives a budget of 0. Even a short summary handoff can't fit, so deliverContextHandoffs throws ContextHandoffBudgetError on 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_read pointer (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.

  1. 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 a delegate_task result waiting to be delivered.

    What I found

    • When a delegate_task finishes, it writes a ready manual_context handoff onto the parent thread (Orchestrator.ts). The next turn prices it with handoffBudget. If both the stored maxTokens and the live model window are missing, that function assumes a 128k window and reserves a quarter of it (ContextHandoffBudget.ts). With usedTokens at 581117, the budget comes out to 0. A real 1M window would leave room.
    • deliverContextHandoffs then throws ContextHandoffBudgetError before injecting anything. The t3_thread_read pointer is only used when its marker fits the budget, so a 0 budget fails the turn instead of deferring. The handoff stays ready, 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.
    • OpenCode only learns the window from 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 by readModelsOnce. 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 whether model.list timed out, errored, or omitted this model.
    • /compact defers delivery when the budget is short instead of failing, so once compaction lowers usedTokens the queued handoffs go through inline. That matches your workaround.

    Likely fix area

    • Making the OpenCode window lookup more reliable, for example by retrying a failed or timed-out model.list instead of marking the directory known up front.
    • Having handoff delivery degrade when the budget is 0 (defer it, or use a pointer) instead of failing every turn.
    • Revisiting the 128k fallback when measured usage already exceeds it.

    A maintainer will decide on the fix direction.

  2. juliusmarminge added labelsbug

  3. juliusmarminge added labelsvia-triage

  4. Runiir(GitHub profile, opens in a new tab)commented

    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, including gpt-6-luna and gpt-6.1-sol children.

    Observed timeline on 2026-10-11 (UTC), from t3_thread_read durable activity and run state:

    1. Parent run 28 started at 07:18:37.350.

    2. Its last normal tool result was at 07:33:19.363; a compaction activity item became running at 07:33:19.399.

    3. Several child results/notifications arrived afterward (including at 07:45, 08:13, and 08:23), but no subsequent parent provider activity appeared. A user status message at 08:57:21 went unanswered. At approximately 09:58, the parent still reported running with the same active run. This was over two hours without coordinator progress.

    4. At 09:59:41, t3_thread_send(mode="restart") returned delivery="restarted", status="starting", and the same run 28 ID. At 10:00:30, there was still no new provider activity; the thread remained starting. The accepted restart receipt did not demonstrate actual recovery.

    5. The user pressed Stop. At 10:00:51.981, durable activity recorded interruption with Run interrupted before provider start.

    6. A mobile Continue message started run 29 at 10:01:16. It failed at 10:01:16.897 with 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.
    7. The user sent /compact at 10:01:34.162. Run 30 started and recorded Compacting context at 10: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.

  5. 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)

    1. A batch of delegate_task children ran from the parent thread; 8 results queued as context handoffs — all strategy: "manual_context", status: "ready", transfer type subagent_result (rows in orchestration_v2_projection_context_handoffs), created over at least ~20 minutes (00:47Z–01:06Z), never delivered.

    2. Provider turn ordinal 5 started 00:36:21Z and stayed running. The first turn failure (~01:21Z) surfaced only as Provider error: Provider turn failed.; a retry surfaced the full error via the server span orchestrationV2.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.

    3. Every retry re-failed identically (including the "Continue working" affordance) while all 8 handoffs stayed ready — the backlog does not drain across turns.

    4. Unlike the OpenCode case above (handoffBudget clamped to 0 with no maxTokens), 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.ts lines 82–85: if (historyCost(selected.messages, selected.context) > budget) { if (input.deferInline) return …; return yield* new ContextHandoffBudgetError(); } — ordinary turns throw; the deferInline short-circuit only applies when inject === 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 from 20261013.3080.

    Recovery Not recovered on this build; the thread was abandoned for a stable-channel session. Per this report and #17952, manual /compact is 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.

    Related: #15997, #17952, #16244, #18620.

  6. 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-14 at approximately 02: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.265Z 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. Subsequent completion wake turns and ordinary user messages failed at the same gate, before further native execution.
    • The installed handoffBudget reserves max(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 /compact command / 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.

  7. 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 installed server.asar match main at 2993dfc069: handoffBudget, deliverContextHandoffs, the turn-start handoff filter, missed-run recovery, and causeMessage.
    • A custom Codex-driver provider instance (an OpenAI-compatible proxy), model claude-sonnet-5-5. The same native thread had earlier run on gpt-6-astra and claude-opus-5-5.
    • A parent thread running a long chain of async delegate_task children.

    Measurements (statev2.sqlite, read-only)

    • Provider-thread contextUsage: {usedTokens: 743810, maxTokens: 950000}, with no autoCompactThreshold.
    • 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)

    TimeEvent
    04:37:40desktop.lifecycle.beforeQuitForUpdate. The auto-update ends the long-lived parent run (cancelled).
    04:37:56The 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:51A user message fails with "Insufficient context allowance for the provider handoff..."
    04:47, 05:14, 05:31Each 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_seen retry handoff.

    The only way forward for the thread was /compact. That path passes deferInline: 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

    1. 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.
    2. 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.
    3. The restart continuation's real error is lost. The restart-continuation run shows only the generic ProviderAdapterTurnStartError text. At this activity level server.trace.ndjson rotates 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.

  8. 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 deliverContextHandoffs failed with ContextHandoffBudgetError after a manual re-sign-in restarted the session. The thread's last reported usage was 195,810 of a 258,400 window. With the max(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 set autoCompactThreshold, and nothing calls compactThread on this error, so the only way out is a manual /compact.

    #19414 (defer the oversized handoff) would have let this turn go through.

  9. Additional verified incident on macOS arm64, T3 0.0.46-nightly.20261015.3145, Codex parent gpt-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 /compact command once at 09:42:16.
    • 09:44:37: durable activity recorded Context compacted and 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_status and 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_read activity 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_status fallback, and filters legacy result handoffs at startup.

    GitHub ancestry confirms that release v0.1.1-nightly.20261020.3401 contains merge commit 4f5ff17172c5f2bde61a09aafb23011ae4d38538. 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.

  10. 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.

  11. Thanks. I tested the v0.1.2 stable source tag (published 2026-10-22; tag commit 044f072, which includes the #22117 merge commit 4f5ff171) with the targeted server tests on Windows/Node 26.12.1. DelegatedCompletionDelivery.test.ts and ContextHandoffBudget.test.ts passed. In the broader four-file run, ProviderTurnStartService.test.ts had two startup-order assertion failures (cleanup-first and startup-first); both OrchestratorMcpToolkit.integration.test.ts cases failed before their assertions because the test fixture path resolved with a duplicated Windows drive prefix. Overall, 73/77 tests passed. The ProviderTurnStartService.memory.test.ts file named in the PR was absent at the v0.1.2 tag; the result-message regression is present in DelegatedCompletionDelivery.test.ts and 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.