CLI crashes with “server_error: The server had an error while processing your request” when context window is nearly exhausted
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
- Install the latest CLI:
``bash``
npm install -g @openai/codex
- Start an interactive session:
``bash``
codex
- Enter or paste a very long prompt (or build up many turns) until you see:
````
— 1% context left
- Continue chatting or issue another prompt.
- 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:
- Prompt the user to trim or clear history (e.g. suggest
/clear), - Automatically drop the oldest tokens before continuing, or
- Smart auto-compact mechanism
- 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
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗