# agent: Treat context window overflows as prompt-too-large errors \(\#60525\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/d7c922c4a3702a3278e24325499255e66f55d919)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: d7c922c4a3702a3278e24325499255e66f55d919

Requested commit: d7c922c4a3702a3278e24325499255e66f55d919

Commit: d7c922c4a3702a3278e24325499255e66f55d919

Tree: cf90c35f5bfe5a767485b81230e9aa6e43fd8f60

Author: Lukas Wirth

Committer: GitHub

## Message

```
agent: Treat context window overflows as prompt-too-large errors (#60525)

Map OpenAI's context_length_exceeded errors (both the in-stream error
events sent by the Responses API / ChatGPT Codex backend and HTTP 400
responses carrying the code) to
LanguageModelCompletionError::PromptTooLarge. This stops pointless
retries and surfaces the dedicated token-limit UI instead of a raw error
string.

Also record a synthetic request token usage when a completion fails with
PromptTooLarge, so the context indicator reports Exceeded rather than
the stale usage of the last successful request, and the next prompt
qualifies for auto-compaction.

Ought to help a bit with
https://github.com/zed-industries/zed/issues/59600

Release Notes:

- N/A or Added/Fixed/Improved ...

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
```

## Parents

- [905e955a702707cd81a2e5bae9b381a7a9c7f614](https://git.cafe/gitcafe/zed/commit/905e955a702707cd81a2e5bae9b381a7a9c7f614?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/d7c922c4a3702a3278e24325499255e66f55d919?format=markdown)
