Repository navigation
[STALE: REBASE FROM NEW FORK] claude ingress: report provider context overflow as "prompt is too long" - #7
Conversation
Claude Code recognizes an oversized prompt only by Anthropic's wording
("prompt is too long"). Only that wording triggers its reactive compaction
and the head-truncating retry inside /compact. A routed provider's own
overflow 400 ("Your input exceeds the context window of this model",
code context_length_exceeded) reached it verbatim and read as a generic
400. The session then resent the same oversized history on every turn and
every /compact, and never recovered (hosted agent stuck on the Codex 272k
window, COMPACTION-400-REPRO).
anthropicErrorBody now prefixes "prompt is too long: " to definite
context-overflow errors and keeps the provider text. Every Claude-ingress
error path goes through it. isDefiniteContextOverflowMessage moves from
combos/failover.ts to lib/errors.ts so both callers share one phrase list.
429s and messages that already carry the wording are left alone.
Co-Authored-By: Claude Code <noreply@anthropic.com>
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Its title has been prefixed with |
|
This PR is based on the superseded 2.65 gateway line. Rebuild the change from |
|
Trial evidence: before the merge the build ran 30.5 h on the laptop gateway and 24 h on the personal Mac Mini gateway, both with For new work:
Before opening a PR, use pinned Bun 1.4.4 with an isolated
Hosted-only behavior needs For this PR: not carried. Check whether upstream already maps provider context overflow to "prompt is too long" on 🤖 Generated with Claude Code |
Why
A hosted agent running Claude Code on GPT through OCX got stuck for good after its history outgrew the Codex 272k window (COMPACTION-400-REPRO, Pablo's agent, 2026-11-07). Every turn and every
/compactfailed.Claude Code 2.1.29x treats an error as an oversized prompt only when its message contains
prompt is too long(orinput is too long for requested model). Only that wording starts its reactive compaction and the head-truncating retry inside/compact. OCX passed OpenAI's own 400 through verbatim, so Claude Code saw a generic 400 and resent the same history forever:Change
anthropicErrorBodyinsrc/claude/outbound.tsnow prefixesprompt is too long:to definite context-overflow errors. These are matched by codecontext_length_exceededor by the existing overflow phrase list, and the provider text is kept. Every Claude-ingress error path goes through this function: the pre-stream non-ok path, the stream errors andresponse.failed.isDefiniteContextOverflowMessagemoves fromcombos/failover.tstolib/errors.tsso both callers share one list. Its behaviour is unchanged.Agent's-eye text
The error Claude Code now receives, and shows if compaction cannot recover:
Claude Code classifies it as prompt-too-long and compacts on its own; the agent does not need to act. Other 400s keep their exact text, and a test asserts this.
Tests
tests/claude-integration/claude-529-mapping.test.ts, "upstream context-window 400 reaches Claude Code as prompt is too long, provider text kept". It fails on 2.65.0-vadymhimself.15 (base) and passes here.tsc --noEmitis clean.file-size-ratchetreports GREW only onsrc/adapters/anthropic.tsandtests/codex-integration/codex-auth-api.test.ts. This PR touches neither file, so the growth predates it. structure:check passes.Eval added/updated: N/A deterministic (unit/integration test: tests/claude-integration/claude-529-mapping.test.ts)
🤖 Generated with Claude Code