Stream error: “Your input exceeds the context window” when Codex streams large tool output (e.g., 300+ tests)

Resolved 💬 4 comments Opened Sep 28, 2025 by irfndi Closed Oct 5, 2025

What feature would you like to see?

Summary

  • When Codex CLI streams large command output back to the model (e.g., running >300

tests), the session repeatedly fails with “Your input exceeds the context window” and
disconnects after retries.

Steps To Reproduce

  1. Open Codex in a repo with a large test suite (e.g., >300 tests).
  2. Ask Codex to run tests, for example:
  • make test or
  • bun x vitest run
  1. Observe Codex CLI logs during the run.

Expected Behavior

  • Codex should handle large tool outputs gracefully:
  • Chunk or truncate output.
  • Summarize long output before sending to the model.
  • Continue the session without disconnecting.

Actual Behavior

  • Codex retries several times and then fails with a context window error.

Observed Logs

⚠️ stream error: stream disconnected before completion: Your input exceeds the context
window of this model. Please adjust your input and try again.; retrying 1/5 in 202ms…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context
window of this model. Please adjust your input and try again.; retrying 2/5 in 418ms…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context
window of this model. Please adjust your input and try again.; retrying 3/5 in 810ms…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context
window of this model. Please adjust your input and try again.; retrying 4/5 in 1.621s…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context
window of this model. Please adjust your input and try again.; retrying 5/5 in 3.28s…

■ stream disconnected before completion: Your input exceeds the context window of this
model. Please adjust your input and try again.

Minimal Repro (alternative)

  • Any large output triggers it, not only tests:
  1. Start Codex in any folder.
  2. Ask it to run a command that prints a lot, e.g.:
  • yes "x" | head -c 3000000
  1. Codex attempts to stream the entire output to the model and hits the context

limit.

Environment

  • Codex CLI version: 0.42.0
  • OS: macOS 15.6.1
  • Node version: 24.2.0
  • Bun version (if applicable): 1.2.2
  • Model: gpt-5-high
  • Terminal/shell: zsh in ghostty

Impact

  • Prevents using Codex for CI-like tasks (tests, lint, builds) where output can exceed

the model’s token budget.

  • Causes session interruptions and lost context.

Workarounds Tried

  • Use less verbose reporters: bun x vitest run --reporter=dot or --silent.
  • Pipe output to a file and ask Codex to summarize the file:
  • bun x vitest run --reporter=json > test-output.json and then “summarize test-

output.json”.

  • Tail only the last N lines: bun x vitest run | tail -n 400.

Hypothesis

  • Tool result payloads are forwarded to the model without enforcing a token/byte budget

or auto-summarization. Large outputs push the prompt beyond the model’s context window,
causing the stream to disconnect.

Suggested Fixes

  • Add a hard cap on tool-result size sent to the model with:
  • Automatic chunking + iterative summarization.
  • Configurable truncation strategy (head/tail/middle) and max bytes/tokens.
  • Provide a setting to store full tool outputs as artifacts/files and send only

summaries + links/paths into the chat context.

  • Consider auto-dropping or summarizing older conversation turns when approaching

context limits, with a visible notice.

Additional Context

  • Reproduces consistently on large test runs (300+ tests) in our Next.js monorepo.
  • Happy to provide a minimal reproduction repo or additional debug logs if helpful.

If you’d like, I can open this issue for you using the GitHub CLI. Otherwise, paste
the above into a new issue at https://github.com/openai/codex/issues/new and add the
missing environment details.

Are you interested in implementing this feature?

_No response_

Additional information

_No response_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗