codex
codex copied to clipboard
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:
npm install -g @openai/codex - Start an interactive session:
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:
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.
- Prompt the user to trim or clear history (e.g. suggest
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
Ty for the detailed issue report and suggested fixes! I think a good start would be to implement
- Prompt the user to trim or clear history (e.g. suggest /clear) and
- At minimum, emit a clear warning instead of an unhandled server error
from your suggestions.
Would you like to put up a PR?
Thank you for the feedback! Please try again on the latest version of Codex CLI. If the issue persists, let us know.