CLI crashes with “server_error: The server had an error while processing your request” when context window is nearly exhausted

Resolved 💬 2 comments Opened Apr 16, 2025 by alokwhitewolf Closed Aug 7, 2025

When using the @openai/codex CLI interactively with a very large conversation history, once the API context window is nearly full (e.g. “1% context left”), the CLI throws an internal server error and exits rather than gracefully warning or trimming the context.

## Reproduction Steps

  1. Install the latest CLI:

``bash
npm install -g @openai/codex
``

  1. Start an interactive session:

``bash
codex
``

  1. Enter or paste a very long prompt (or build up many turns) until you see:

``
— 1% context left
``

  1. Continue chatting or issue another prompt.
  2. Observe the CLI crash with a stack trace similar to:

``text
file:///…/codex/dist/cli.js:443
…pg.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Fwe(e,t){…}

[Error]: The server had an error while processing your request. Sorry about that!
at e.a [as iterator] (…/cli.js:443:1514)
at process.processTicksAndRejections (node:internal/…)
at async I0.run (…/cli.js:460:2356) {
status: undefined,
headers: undefined,
request_id: undefined,
error: {
type: 'server_error',
message: 'The server had an error while processing your request. Sorry about that!',
}
}
``

## Expected Behavior

  • Detect that the context window is exhausted (or about to be) and either:
  1. Prompt the user to trim or clear history (e.g. suggest /clear),
  2. Automatically drop the oldest tokens before continuing, or
  3. Smart auto-compact mechanism
  4. At minimum, emit a clear warning instead of an unhandled server error.

## Actual Behavior
Once the API rejects due to context overflow, the CLI surfaces a raw server error stack trace and exits.

## Environment

  • macOS 13.5
  • Node.js v20.18.3 (via nvm)
  • No custom configuration

View original on GitHub ↗

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