Skip to content

Context window exceeded despite context left #2825

Closed

Description

@dlukt

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

Activity

  1. takemiyamakoto commented on Aug 28, 2025

    @takemiyamakoto

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

  2. dlukt commented on Aug 28, 2025

    @dlukt
    Author

    And shortly after:

      You've hit your usage limit. Try again in 23 minutes.
    
  3. dlukt commented on Aug 28, 2025

    @dlukt
    Author
      You've hit your usage limit. Try again in 2 days 22 hours 38 minutes.
    

    You can't be serious

  4. dlukt commented on Aug 28, 2025

    @dlukt
    Author

    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...

  5. dlukt commented on Aug 28, 2025

    @dlukt
    Author
  6. maver1ck commented on Aug 28, 2025

    @maver1ck

    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…
    
    
  7. oyiakoumis commented on Aug 28, 2025

    @oyiakoumis
    Contributor

    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.

  8. adsqx commented on Aug 31, 2025

    @adsqx

    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 :)

  9. volgin commented on Sep 1, 2025

    @volgin

    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.

  10. yokasaka commented on Sep 2, 2025

    @yokasaka

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

  11. Anarchon14 commented on Sep 2, 2025

    @Anarchon14

    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

  12. tekn0x commented on Sep 2, 2025

    @tekn0x

    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.

  13. gianlucamazza commented on Sep 3, 2025

    @gianlucamazza

    same problem, there is no way to use /compact

  14. RazeBerry commented on Sep 4, 2025

    @RazeBerry

    Same problem here with ~32% context window left!

  15. 10 remaining items

  16. alexfdo commented on Sep 13, 2025

    @alexfdo

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

  17. adsqx commented on Sep 13, 2025

    @adsqx

    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.
    😃

  18. alexfdo commented on Sep 13, 2025

    @alexfdo

    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!

  19. adsqx commented on Sep 13, 2025

    @adsqx

    @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.

  20. mateusgalasso commented on Sep 16, 2025

    @mateusgalasso

    same here

  21. alexfdo commented on Sep 16, 2025

    @alexfdo

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

  22. Dexus commented on Sep 16, 2025

    @Dexus

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

  23. Theysua commented on Sep 17, 2025

    @Theysua

    Same here using on VS Code

  24. ataetgi commented on Sep 18, 2025

    @ataetgi

    same issue with vscode extension

  25. AidPaike commented on Sep 19, 2025

    @AidPaike

    same issue

  26. command3rkeen commented on Sep 20, 2025

    @command3rkeen

    same...

  27. tekn0x commented on Sep 21, 2025

    @tekn0x

    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.

  28. adsqx commented on Sep 30, 2025

    @adsqx

    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

  29. SNIKO commented on Oct 7, 2025

    @SNIKO

    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.

    Image

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

  30. mion-kr commented on Oct 21, 2025

    @mion-kr

    same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions