Skip to content

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

Closed

Description

@irfndi

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

Activity

  1. added
    enhancement
    on Sep 28, 2025
  2. EthanDuan05 commented on Sep 28, 2025

    @EthanDuan05

    +1

  3. ivanvanderbyl commented on Sep 29, 2025

    @ivanvanderbyl

    This started happening for me after I added the following to my AGENTS.md:

    Before writing new code, thoroughly inspect the current package and related code, helpers, and utilities to confirm the functionality does not already exist. You can ignore example code to keep your search space If you find similar logic, prefer extending or refactoring what is there rather than duplicating it; note the gaps you see before proposing changes. When existing code requires significant modification, pause to consider the higher-level abstraction that will keep the solution maintainable and idiomatic Go—rethink package boundaries, interfaces, or composition patterns before diving into implementation.
    

    The thoroughly inspect the current package and related code, helpers, and utilities threw it over the edge, seemed to fail to fit its own reasoning in context.

  4. dylan-hurd-oai commented on Oct 5, 2025

    @dylan-hurd-oai
    Contributor

    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.

    Did you have codex summarize this issue? 😁

  5. dylan-hurd-oai commented on Oct 5, 2025

    @dylan-hurd-oai
    Contributor

    This should be fixed by #4706 and is currently in the 0.45.0 alphas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions