# fix\(opencode\): actionable error when a session outgrows the model window · PR \#23908 · pingdotgg/t3code

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

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

Visibility: public

State: open

Source repository: Unavailable fork

Source branch: t3/fix-opencode-oversized-invalid-request

Target branch: main

Head commit: ba63cde9cd35f4b927d861512200c945803822cf

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

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

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

## Description

---

## Problem

An OpenCode session that outgrows the model's context window dies with the provider's generic text: "The request contains invalid parameters. Check the request body for any errors or inconsistencies." (`provider.invalid-request`). Nothing indicates size is the cause, so every retry fails identically — I watched this kill four long-running threads across three projects (#20142, with per-incident evidence).

## Fix

In the v2 adapter's submit drain-failure path, when the rejection is `InvalidRequestError` **and** there is positive size evidence (the model window is known and this turn's observed input already meets it), the terminal failure now says what actually happened and how to recover:

> This session has grown past the model's context window (8,700,000 tokens used of 1,000,000). Fork from an earlier completed run or start a fresh thread; retrying this run will fail the same way.

Anything without size evidence (unknown window, refused first prompt, genuine malformed request) keeps the exact original error — verified by unit cases for each branch.

Deliberately out of scope: reaping the lingering `opencode serve`. That server is instance-shared with a 30s idle TTL (`OpenCodeServerOwner`) and is needed for the very recovery this message prescribes (retry/fork reuses the session), so killing it on failure would break recovery, not fix it.

## Verification

- New `oversizedSession.test.ts`: 5/5 pass (fires at/above window, ignores other rejections, below-window requests, unknown windows, prompt-less failures).
- Full `provider-opencode` suite: 16 files / 128 tests pass.
- Package `tsc --noEmit`: clean (only pre-existing suggestions elsewhere).
- `vp lint` on all three touched files: clean.

Fixes #20142. See also #19986 (fork-while-running) and discussion #23540 (queued forks) — this PR covers the error-mapping half; those cover the fork-UX half.

Built with Muse Spark 1.3 (opencode) in T3 Code.


