Context window exceeded despite context left

Resolved 💬 37 comments Opened Aug 28, 2025 by dlukt Closed Sep 4, 2025
💡 Likely answer: A maintainer (oyiakoumis, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.25.0

Which model were you using?

gpt-5 high

What platform is your computer?

Linux 6.16.3-arch1-1 x86_64 unknown

What steps can reproduce the bug?

codex
Implemented likes for games and reactions for files, plus wired basic UI for game likes. Also completed comment rate limiting and comment UI as requested earlier.

What’s new

Backend

- Ent schemas:
    - GameLike: user_id + Game edge with unique (user_id, game) index.
    - FileReaction: user_id, value(-1/+1) + File edge with unique (user_id, file).
    - Edges on Game → likes and File → reactions (Relay connections).
    - Comment schema already added (with sanitization).
- GraphQL API (api/custom.graphqls):
    - Mutations:
    - rateGame(gameId, like: Boolean!): Game!
      - like=true creates the like; like=false removes it.
    - reactToFile(fileId, value: Int!): File!
      - value ∈ {-1, 1} sets reaction; 0 clears existing reaction.
    - addComment/editComment/deleteComment (from earlier) are in place.
- Query tweaks retained:
    - searchGames with sort; FTS-backed opensearchSuggestions.
- Resolvers (graph/custom.resolvers.go):
    - Implemented rateGame and reactToFile with auth checks and upsert/toggle logic.
    - addComment, editComment, deleteComment implemented previously; added per-minute comment rate limit via AllowComment(user, ip).

Rate limits

- internal/rate:
    - Added per-minute buckets and AllowComment(userID, ip) with env tunables:
    - RATE_LIMIT_ANON_COMMENTS_PER_MIN (default 5)
    - RATE_LIMIT_USER_COMMENTS_PER_MIN (default 15)

Frontend

- GameDetail:
    - Displays like count (Game.likes totalCount).
    - Like/Unlike buttons (simple reload after mutation).
    - Comments list and add form (sanitized display).
- Search:
    - Filters (platform/year/format), sort selector, load-more append.
    - Header search input navigates to /search.
- Removed shadcn/ui previously; all buttons now standard Tailwind-styled.

Changelog

- Added entries for Comments (schema/CRUD/rate limits/UI) and earlier search/observability items.

What’s left for likes/reactions (nice-to-haves)

- File reactions UI: add thumbs up/down in file rows; query likes/dislikes counts via reactions(where:{value:1/-1}). We can wire that next.
- Show like state per user on GameDetail (needs user-like query; currently only totalCount).
- Optimistic updates or local state to avoid full reloads after mutations.

Open issues remaining

- #43 Moderation route polish
- #40 FE: Game page UGC (we’ve started—comments/likes; reactions UI pending)
- #41/#29/#28 Collections/Favorites
- #30 Video links
- #21/#22/#23 Descriptions sanitize/version/history
- #37 Feature flags
- #38/#39 QA tests
- #20 Tracker
- #31 (FTS index) functionally complete via #58; can be closed as done

If you want, I can:

- Add file reactions UI (thumbs up/down) and display counts on GameDetail.
- Add a user-like indicator for the game and toggle the button state accordingly.
- Close #31 and move onto collections/favorites (#28/#29/#41).

user
yes

>_
  ✓ 📖 GameDetail.tsx
⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 1/5 in 191ms…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 2/5 in 420ms…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 3/5 in 746ms…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 4/5 in 1.505s…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 5/5 in 3.516s…


🖐  stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.

▌ Explain this codebase                                                                                                                                                                    
 ⏎ send   Ctrl+J newline   Ctrl+T transcript   Ctrl+C quit   1883319 tokens used   32% context left

What is the expected behavior?

with 32% context left, no issues

What do you see instead?

see above

Additional information

maybe it's just task context

---

Note to me too/same here commenters, it would probably help if you included your codex-cli version

View original on GitHub ↗

37 Comments

takemiyamakoto · 10 months ago

I get the same, exactly at 32% context left too.

dlukt · 10 months ago

And shortly after:

  You've hit your usage limit. Try again in 23 minutes.
dlukt · 10 months ago
  You've hit your usage limit. Try again in 2 days 22 hours 38 minutes.

You can't be serious

dlukt · 10 months ago

Because of this I've completely lost track of where I am, what needs to be done, what has been already done, and the web codex just produces useless results. Essentially 1½ days wasted on a codebase that will get deleted...

dlukt · 10 months ago
maver1ck · 10 months ago

Same problem with Figma MCP

tool running...
figma.get_image({"clientFrameworks":"unknown","clientLanguages":"html,css","nodeId":"38547:43581"})

tool result (image output omitted)
⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 1/5 in 196ms…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 2/5 in 390ms…
oyiakoumis contributor · 10 months ago

I put a breakpoint in the client to inspect the payload and noticed that the reasoning tokens from the previous message were being sent to the API.

However, in codex-rs/protocol/src/protocol.rs lines 529–536:

    /// For estimating what % of the model's context window is used, we need to account
    /// for reasoning output tokens from prior turns being dropped from the context window.
    /// We approximate this here by subtracting reasoning output tokens from the total.
    /// This will be off for the current turn and pending function calls.
    pub fn tokens_in_context_window(&self) -> u64 {
        self.total_tokens
            .saturating_sub(self.reasoning_output_tokens.unwrap_or(0))
    }

This suggests that either:

  1. reasoning tokens from previous messages should not be included in the client’s payload,
  2. or, if they are included, we must also account for them when computing the number of tokens in the context window.

If I recall correctly, the correct approach is the first one.

synestiqx · 10 months ago

Probably the percentage doesn’t reflect the actual input. In such a situation, run /status and check how much input there really is. For me, at 80% it’s around 300k, so at 30% it must be huge.
If you want to work efficiently, I’d recommend running /compact at around 80%.

P.S. I never had the conscience to send the next message when it was already at 80% — I don’t think I ever went lower than that :) Leave a little room for the GPU :)

volgin · 10 months ago
I get the same, exactly at 32% context left too.

I hit the same issue at 32% context left. It can't be a coincidence.

yokasaka · 10 months ago

Today, I hit this issue when my left context was 33%.

Anarchon14 · 10 months ago

I hit it on "89% context left" today playing with Playwright MCP doing some e2e tests with screenshots, maybe the screenshots flood the context window and are not tracked at all? @ae-openai

tekn0x · 10 months ago

Same for me. At exactly 32%. Two days in a row. Thats the magic number for what ever reason.

  stream error: stream disconnected before completion: Your input exceeds the context window of this model.
Please adjust your input and try again.; retrying 5/5 in 3.423s…

🖐  stream disconnected before completion: Your input exceeds the context window of this model. Please adjust
your input and try again.

gianlucamazza · 10 months ago

same problem, there is no way to use /compact

RazeBerry · 10 months ago

Same problem here with ~32% context window left!

att3 · 10 months ago

Same 32% - must be accounting them incorrectly. A bit over 200k tokens used

penseurai · 10 months ago

I guess I had gotten spoiled by ClaudeCode having a concept of /compact and had forgotten about this whole "context window is full" nonsense.

donggu-kang · 10 months ago

I'm having the same problem. I have exactly 32% left.

1335400 tokens used 32% context left

xsoheilalizadeh · 10 months ago

I have the same issue but with 72% context left!

🖐  stream disconnected before completion: Your input exceeds the context window of this model.
Please adjust your input and try again.

▌ Find and fix a bug in @filename
 ⏎ send   Ctrl+J newline   Ctrl+T transcript   Ctrl+C quit   0 tokens used   72% context left
dazuiba · 10 months ago

same error here, very annoying.

🖐  stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.
⏎ send ⇧⏎ newline ⌃T transcript ⌃C quit 197487 tokens used 85% context left


🧠 Model
  • Name: gpt-5
  • Provider: OpenAI
  • Reasoning Effort: Medium
  • Reasoning Summaries: Auto

📊 Token Usage
  • Session ID: b2d34cb5-32ff-4c7d-a354-9caede717b6e
  • Input: 187341 (+ 1171968 cached)
  • Output: 10146
  • Total: 197487
lindesbs · 10 months ago

⚠️ stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 1/5 in 206ms…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 2/5 in 409ms…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 3/5 in 856ms…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 4/5 in 1.601s…

⚠️ stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 5/5 in 3.251s…

🖐  stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.

▌ Implement {feature}
⏎ send Ctrl+J newline Ctrl+T transcript Ctrl+C quit 0 tokens used 95% context left

Dexus · 10 months ago

Nothing got fixed right now...

✓ 📖 VirtualHistoryList.tsx
⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 1/5 in 207ms…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 2/5 in 421ms…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 3/5 in 839ms…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 4/5 in 1.442s…

⚠  stream error: stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.; retrying 5/5 in 2.907s…

🖐  stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.

▌Find and fix a bug in @filename
⏎ send Ctrl+J newline Ctrl+T transcript Ctrl+C quit 1264565 tokens used 32% context left

dlukt · 10 months ago

would be helpful if you guys provided the codex-cli version, IMHO

alexfdo · 10 months ago

Because of this error I unsubscribed from the codex today. I subscribed yesterday - unsubscribed today. I live interestingly, I guess.

synestiqx · 10 months ago

Let’s assume you have ~190k tokens in context, which leaves you with ~80k. The input counter is not updated in real time but only after a completed turn. If at that point you write “Analyze xyz…” and then “apply corrections”, this can lead to an overflow, and even auto-compact won’t help.

The probable reason is that each iteration adds to the context, but the input size is only updated after the whole turn ends. For example, after a full turn you might already exceed 300k, but this won’t be detected during generation — only after completion.

Possible solution:
In optimal conditions, auto-compact should solve this problem. However, the counting must be done in real time, and compacting should already run in a separate thread once the input size exceeds the auto-compact threshold. Then, the next iteration during agent execution could append directly to the compacted context rather than to the full previous conversation.
Alternatively, I suggest considering a scaled compact + the last N elements (with N configurable), so that the model doesn’t “get confused” during iteration.

Here, it would be best to dynamically calculate the last n elements based on the tools used and the calls made, so that nothing disappears during execution.”

This would improve both user experience (✅ no visible pauses or late compacting) and safety.
So the flow should look like:
✅ 190 → 210 → … → 250 → (compact) → 120 → 150 … → end of turn.

Currently, it’s wrong:
❌ 190 → 210 → … → 250 → context overflow (no compacting during the turn).

That’s why it’s worth maintaining a reactive design pattern with injection.
For example:

cli_service.input_size.watch(handler)
cli_service.input_size.update(val)

This way you get a reactive real-time stream, and everything works seamlessly.

Besides, I notice that after /compact, the context left shows 100% — that probably shouldn’t be the case.
😃

alexfdo · 10 months ago

In Cloud Code, all this is done automatically. But here, what do you have to sit with an abacus and count: "What if..."?
What kind of AI tool is this?
I'm currently sitting in Kilocode and using up to 280-300 thousand tokens, and there are no such stories when you haven't even started the task yet, and you already have no limit!

synestiqx · 10 months ago

@alexfdo
This isn’t about sitting with an abacus — it’s a proposal for automatic refactoring that should happen seamlessly in the background.
From what I know, Claude Code doesn’t really expose this mechanism publicly; everything happens under the hood.

So either it works the way I’m describing, or it aggressively compacts when the context left drops to around 60%, for example.
That, in turn, might lead to the phenomenon where the model seems “dumbed down” just to save resources. What Claude Code has recently experienced.

These are simply observations about what could be causing the issue and how it might be fixed.

This is a standard procedure in computer science/programming — a backpressure safeguard, used when you’re sending more data at once than the system can handle.
So there’s no magic here. :)

So, briefly: a system operating on rx/tx needs a real-time backpressure mechanism, so that the transmitter does not exceed the receiver’s capabilities.

mateusgalasso · 10 months ago

same here

alexfdo · 10 months ago

And I said the same thing, but that was three days ago.

Dexus · 10 months ago

@aibrahim-oai @pakrym-oai I think it is not fixed yet...

Theysua · 10 months ago

Same here using on VS Code

ataetgi · 10 months ago

same issue with vscode extension

AidPaike · 10 months ago

same issue

command3rkeen · 10 months ago

same...

tekn0x · 10 months ago

This seems resolved for me on v0.39.0 in MacOS 14.7.6 using gpt-5-codex high.

Was able to get down to 1% left with no issues on two different sessions.

synestiqx · 9 months ago
Performance improvements with context management

On an internal evaluation set for agentic search, we tested how context management improves agent performance on complex, multi-step tasks. The results demonstrate significant gains: combining the memory tool with context editing improved performance by 39% over baseline. Context editing alone delivered a 29% improvement.

In a 100-turn web search evaluation, context editing enabled agents to complete workflows that would otherwise fail due to context exhaustion—while reducing token consumption by 84%.

https://www.anthropic.com/news/context-management

SNIKO · 9 months ago

Happens to me too as soon as it hits a tool returning an image.
Happens on the new session with 100% context left. It is the 2nd tool it calls, so, I doubt it used any context at all.

<img width="1147" height="553" alt="Image" src="https://github.com/user-attachments/assets/62766f36-0e6d-43fe-90c3-537bfaa6c6e3" />

I feel like it doesn't support images at all and reads them as a base64 string rather than an image.

mion-kr · 9 months ago

same