codex icon indicating copy to clipboard operation
codex copied to clipboard

Input exceeds context window error

Open guidedways opened this issue 3 months ago β€’ 10 comments

What version of Codex is running?

0.27.0

Which model were you using?

gpt5-high

What platform is your computer?

macOS

What steps can reproduce the bug?

πŸ–β€Š stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and
try again.

 Working (18s β€’ Esc to interrupt)

β–Œ Write tests for @filename
 ⏎ send   Shift+⏎ newline   Ctrl+T transcript   Ctrl+C quit   2445968 tokens used   29% context left

29% left and it was only making minor edits and suddenly stopped.

What is the expected behavior?

If it's trying to read in a randomly large file, it should either read a portion in or state what it's doing. No transparency into what it's doing and why it's failing.

What do you see instead?

πŸ–β€Š stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.

No clue what I'm supposed to do - adjust which input? Codex was on its own

Additional information

Ask codex to make a minor refactor involving removal of a parameter in a function.

guidedways avatar Aug 30 '25 02:08 guidedways

Interestingly, a /compact only increased the context by 3%? Is this expected? I was hoping to regain at least 90% of the original context.

codex
Compact task completed

β–Œ Write tests for @filename
 ⏎ send   Shift+⏎ newline   Ctrl+T transcript   Ctrl+C quit   272054 tokens used   32% context left

guidedways avatar Aug 30 '25 02:08 guidedways

I should add - after I posted the above, my next prompt suddenly bumped it to 90%! So this looks like a glitch.

guidedways avatar Aug 30 '25 06:08 guidedways

In this topic, I probably described this problem

AdsQnn avatar Aug 30 '25 13:08 AdsQnn

same issue: https://github.com/openai/codex/issues/2825

oyiakoumis avatar Aug 31 '25 12:08 oyiakoumis

Same issue here, similar behavior where compact does not gain much context back and i have 30-40% left despite getting htis message

gabrielbryk avatar Sep 01 '25 20:09 gabrielbryk

This is happening to me pretty frequently now, but only on one of 3 projects.

rbergman avatar Sep 02 '25 16:09 rbergman

On Codex $200 plan, I get Stream disconnected before completion: input exceeds context window even with ~98% window left. Seems like it disconnects too early.

vixkram avatar Sep 03 '25 00:09 vixkram

Same here, 30% context left.

Image

nachoal avatar Sep 04 '25 23:09 nachoal

And same here, 30% context left...

s-a-n-i-n avatar Sep 06 '25 21:09 s-a-n-i-n

And same here 32% context left

Vamsi-klu avatar Sep 06 '25 22:09 Vamsi-klu

Does anyone have a workaround? How do I create a new set of prompts? As it were, how do I clear the input cache?

MilesAheadToo avatar Sep 09 '25 12:09 MilesAheadToo

try to create a new session or a new chat. this is working for me. If are you using a terminal, do a logoff and logon.

rporcionato avatar Sep 09 '25 23:09 rporcionato

90% context left!!! And that was after the FIRST prompt in that context. This was the fifth or sixth time, I tried that.Yesterday, I had that error even with 98% context left.

Image

Codex is just useless!!! Im working for hours here, and did accomplish almost nothing.

hpmartini avatar Sep 10 '25 14:09 hpmartini

same here

mateusgalasso avatar Sep 16 '25 01:09 mateusgalasso

same here

abutun avatar Sep 17 '25 05:09 abutun

Error still persists. Getting the same error

akamalov avatar Sep 17 '25 14:09 akamalov

getting the same error in the vs code extension

Image

FearMyShotz avatar Sep 17 '25 14:09 FearMyShotz

Mismo error por aquΓ­, pero me he dado cuenta de 2 cosas 1β€” el error solo ocurre en conversaciones largas (al menos en mi caso) 2β€” al iniciar un chat nuevo el error desaparece, ya que el contexto se reinicia

Bernyabreu42 avatar Sep 18 '25 06:09 Bernyabreu42

Same here. Very annoying error since I don't know how to recover. "/compact" doesn't work.

Image

rrainist avatar Sep 18 '25 06:09 rrainist

This happened to me with 95% of my context window still available

Image

i have to restart codex in the server terminal for it to resume

DevVig avatar Sep 18 '25 07:09 DevVig

Happening to me too on codex-cli 0.39.0

@bolinfest Is it possible to assign someone to this bug please πŸ™

DenisGorbachev avatar Sep 19 '25 23:09 DenisGorbachev

@DevVig I have a question: have you run /compact before, or is this your first session? Or did you resume it using resume?

AdsQnn avatar Sep 19 '25 23:09 AdsQnn

happening to me too in codex extension in cursor

alooshxl avatar Sep 26 '25 02:09 alooshxl

Same here, cli and Cursor extension. On the Pro tier.

billkie avatar Sep 29 '25 12:09 billkie

here this always happens when the model tries to read a big image. then it gets stuck in it. have no idea how it works, but It must be something related to chat history.

claude code has the same exact issue btw

Rodrigo-JM avatar Sep 29 '25 19:09 Rodrigo-JM

Yeah this is so annoying. As a $200/mo pro user, I'd expect Codex to compact automatically if its getting close to the limit. The problem is that this will even happen when its progressing through a single prompt, especially when refactoring.. Switching to Claude 4.5 for time being.

mgunnin avatar Sep 29 '25 20:09 mgunnin

Also happening to me, on codex version 0.44.0

tazabreu avatar Oct 05 '25 14:10 tazabreu

Let’s assume you start with around 190k tokens in context, leaving roughly 80k available.
The input counter, however, isn’t updated in real time β€” it only refreshes after a completed turn.
So if, within the same turn, you issue something like β€œAnalyze xyz…” followed by β€œapply corrections,”
it can cause a context overflow that even auto-compaction can’t handle.

The root cause is that each iteration adds to the context,
but the system doesn’t realize it until the entire turn finishes.
As a result, during generation you might already exceed 300k tokens,
yet this isn’t detected until after the fact β€” too late for prevention.

In optimal conditions, auto-compaction should mitigate this.
But for that to work, token counting must be done in real time,
and compaction should run in a separate thread the moment the size passes the threshold.
Then, subsequent iterations could append directly to the compacted context
instead of the full conversation history.

Alternatively, a scaled compaction + last N elements approach could work,
where N is configurable and dynamically adjusted based on the tools used
and the number of active calls β€” ensuring nothing critical disappears mid-execution.

This would improve both stability and user experience
(βœ… no visible pauses or late compaction, smoother flow overall).

The correct behavior should look like this:
βœ… 190 β†’ 210 β†’ … β†’ 250 β†’ (compact) β†’ 120 β†’ 150 β†’ … β†’ end of turn

Currently, it behaves incorrectly:
❌ 190 β†’ 210 β†’ … β†’ 250 β†’ context overflow (no compaction during the turn)

Claude has access to real-time information about the current context state,
and in such situations, it automatically interrupts generation
before a context overflow can occur.

AdsQnn avatar Oct 05 '25 15:10 AdsQnn

I found what the cause of premature stream disconnect (i.e., before context = 0) is for me. It is when I resume a conversation that was, when previously loaded, in full approval mode, and order it to do things that require full approval mode before first setting approval to full (as when you resume a convo, even if it was in full approval mode before closing the codex session, it loads auto approval when you resume it). For example I'll be working with codex on a problem in full approval mode. End the conversation. Resume it, forget to switch back to full approval, and get it continue doing what it was doing before, which required full approval, then it occurs (the premature stream disconnect issue).

I tried everything to be able to resume the convo from where the alleged bug happens - resuming via codex resume ID. Resuming via codex resume then selecting the convo. In the convo, switching to full approval and trying to get it to continue after the issue started happening. Merely getting it to say hi. None of those tactics broke the wall.

I started a new convo, and directed it to the broken chat's transcript, sort of quizzing it to get it back up to speed. Usually regained context pretty effectively this way.

xxrraa avatar Oct 06 '25 22:10 xxrraa

This is killing my workflow. What is the deal here? Such great models but without a proper agentic client. Terrible UX.

fullofcaffeine avatar Oct 07 '25 00:10 fullofcaffeine