# fix\(server\): a handoff too large for the context window no longer wedges the thread · PR \#19414 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/19414)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: open

Source repository: Unavailable fork

Source branch: fix/defer-oversized-handoffs

Target branch: main

Head commit: cdc28c82a5f4a014abc82d0c3de4c3e20cc343c0

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/19414)

[Commits](https://git.cafe/pingdotgg/t3code/pull/19414/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/19414/diffs?format=markdown)

## Description

---

## Problem

An oversized context handoff can fail every new turn on a thread. On a near-full Codex conversation, dispatching a deferred run, interrupting it before provider start, and sending “Continue” fails with “Insufficient context allowance” even though the provider can still accept the user's prompt.

## Change

Defer a handoff that cannot fit the existing allowance and send the user's prompt unchanged. Keep its history on the existing durable handoff record and retry it on later turns to the same provider thread. Pending or uncertain delivery preserves the retry marker; confirmed delivery clears it. Missed-run recovery reuses deferred history instead of allocating duplicate handoffs.

The reserve policy stays the same. No provider protocol or client behavior changes. Original implementation by @Alb11747; this update preserves that implementation and authorship, merges current main, and adds the interrupted-before-start Codex regression.

## Scope and approval

Fixes https://github.com/pingdotgg/t3code/issues/23275

GitCafe: https://git.cafe/pingdotgg/t3code/issues/23275

Triaged bug via the automated issue flow. This preserves the [maintainer's same-provider deferral scope](https://git.cafe/pingdotgg/t3code/pulls/19414). Forwarding portable fork/merge history to another provider remains outside this fix.

## Verification

- New focused regression fails on main [fef851bee0](https://git.cafe/pingdotgg/t3code/commit/fef851bee0) with the reported context-allowance error and passes at [cdc28c82a5](https://git.cafe/pingdotgg/t3code/commit/cdc28c82a5).
- 93 focused tests pass: `ProviderSwitch.integration.test.ts` and `ContextHandoffBudget.test.ts` (51), `ProviderTurnStartService.test.ts` (32), and provider-core `failure.test.ts` (10). Coverage includes repeated deferral, uncertain native delivery, abandoned inline preparation, compaction, and eventual delivery.
- Scoped server, provider-core, and contracts typechecks pass. Changed TypeScript files pass lint with three existing unused-variable warnings; formatting and diff whitespace checks pass.
- Independent GPT-6.1-Sol and Claude Opus 5.5 full-diff reviews found no blockers.

Evidence (server behavior; [visual matrix is empty](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/d8edbce0260583eb/proof-matrix.md)):

| Scenario | Before: main `fef851bee0` | After: `cdc28c82a5` |
| --- | --- | --- |
| Near-full Codex, deferred run interrupted before provider start, then Continue | Real Codex completed at 39,761 / 41,800 tokens; interrupted run never started; Continue failed. [Transcript](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/992f81b8a1551036/runtime.log), [driver](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/2858d7802dbfc9fd/repro.mjs) | Real Codex completed at 31,969 / 41,800 tokens (76.48%). Interrupted attempt had zero provider turns; Continue completed on the same native thread with its text unchanged. The persisted handoff retained the missed message, remained ready and deferred, and had no delivery record. [Transcript](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/19bac2472cef90d5/runtime-after-safe.jsonl), [driver](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/bf3e00ad255617ed/repro-after.mjs), [read-only verifier](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/eaeca074ad8bafad/verify-after.mjs) |

Environment: Linux fs-40, real development server with isolated worktree state, Codex GPT-6.1-Sol at low reasoning effort, configured context window 44,000 and auto-compaction threshold 42,000. The main failure was also observed in the real web client. No renderer changed, so screenshots and recordings are not the behavior proof.

Earlier real-provider verification at [3cc0592815](https://git.cafe/pingdotgg/t3code/commit/3cc0592815) covered repeated budget-zero turns, a server restart, native delivery during compaction, and no later replay using Codex and Claude: [verifier](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/7aae487f57e13165/19414-live.mjs), [results](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/3cd0b794a7f7f2bf/verdict.json).

Fresh live-provider coverage is Codex on Linux. Native desktop/mobile clients and Cursor, Grok, OpenCode, and Antigravity were not separately exercised; they use the shared turn-start service.

Original takeover: GPT-6-Astra and GPT-6.1-Sol through Codex in T3 Code. This update: GPT-6.1-Sol through Codex in T3 Code; regression and integration by Claude Opus 5.5; independent reviews by GPT-6.1-Sol and Claude Opus 5.5.

