Skip to content

Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying. #18052

Closed

Description

@evilfps

What version of the Codex App are you using (From “About Codex” dialog)?

26.409.20454

What subscription do you have?

Pro

What platform is your computer?

Darwin 25.4.0 arm64 arm

What issue are you seeing?

Image

Long task suddenly says “chat ran out of room, start new thread or clear hist.” Then whole chat dies, no more output. Stops mid-task. Never happened this often, even on 30-day-old chats. Thanks for checking! Same happened with 5.4 and 5.3 codex.

What steps can reproduce the bug?

Uploaded thread: 019d9134-df50-7423-b31f-7cb056e14f9a

What is the expected behavior?

It never used to happen that I run of out of room in chats but it happened thrice in a day.

Additional information

No response

Activity

  1. added
    appIssues related to the Codex desktop app
    on Apr 16, 2026
  2. added
    bugSomething isn't working
    contextIssues related to context management (including compaction)
    on Apr 16, 2026
  3. github-actions commented on Apr 16, 2026

    @github-actions
    Contributor
  4. removed
    appIssues related to the Codex desktop app
    on Apr 16, 2026
  5. marked Autocompact fails #18572 as a duplicate of this issue on Apr 19, 2026
  6. leofratu commented on Apr 24, 2026

    @leofratu

    +1

  7. Ghxst commented on Apr 30, 2026

    @Ghxst

    happened for me

    Image
  8. augard commented on May 3, 2026

    @augard

    Happend to me in two threads over this weekend with latest version.
    Error running remote compact task: { "error": { "message": "Your input exceeds the context window of this model. Please adjust your input and try again.", "type": "invalid_request_error", "param": "input", "code": "context_length_exceeded" } }

  9. leofratu commented on May 4, 2026

    @leofratu

    Found a solution, issue is likely due to the compaction limits. Edit the config to auto compact limit at 160K and context window to 250K the auto compact limit is to high due to 5.4 having a higher context window. Edit it manually, and it should work.

    @augard , @Ghxst

  10. NevenSumonja commented on May 23, 2026

    @NevenSumonja

    I am seeing what looks like the same issue in Codex Desktop, across multiple workspaces, not just one long thread.

    Sanitized environment:

    • Codex Desktop: 26.519.41501
    • Codex CLI/runtime: 0.133.0-alpha.1
    • Platform: macOS on Apple Silicon
    • Model configured locally: gpt-5.5

    Observed behavior:

    • Threads eventually fail with:
      Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying.
    • This now happens across multiple repositories/workspaces.
    • Starting fresh threads helps temporarily, but active rollout/session state keeps growing again.
    • Archiving/pruning one workspace does not resolve the broader problem.
    • Codex Desktop no longer exposes per-thread context usage indicator (wheel)
  11. martinmclee commented on Jun 11, 2026

    @martinmclee

    Additional report (template format)

    What version of the Codex App are you using (From “About Codex” dialog)?

    • Noted in my session log only; current session is openai/codex desktop/CLI session.

    What version of the Codex CLI is running?

    • Noticed on current client session from user-side reconnect loop (no newer local diagnostics pasted yet).

    What subscription do you have?

    • Pro (from prior report context)

    What platform is your computer?

    • Windows 11 (user desktop)

    Which model were you using?

    • gpt-5.3-codex-spark xhigh

    What terminal emulator and version are you using (if applicable)?

    • PowerShell

    What issue are you seeing?

    • Repeating hard stop on long-running sessions with:
      Reconnecting /2
      Error running remote compact task: stream disconnected before completion: Incomplete response returned, reason: max_output_tokens
    • Followed by message: Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying.

    What steps can reproduce the bug?

    • Run a long Codex thread using gpt-5.3-codex-spark xhigh.
    • Let it approach automatic compaction.
    • On compact attempt, see remote compact error above.
    • Session shows repeated Context compacted / Reconnecting /2 loops and stalls.

    Exact examples from this session

    • session id: 019eab5f-ebaf-7873-b407-1995e54516fd
    • timestamps: around 5:09 PM and 5:10 PM local
    • thread status text shown in UI: Context automatically compacted and Reconnecting /2

    What is the expected behavior?

    • Compaction should fail gracefully with recoverability or automatic retry without forcing a hard session reset.

    Additional context

    • This appears to be the same class of failure already in this issue chain (e.g. context_length_exceeded class around compaction), but I’m explicitly confirming that gpt-5.3-codex-spark xhigh reproduces it.
    • I’m filing this to increase priority for same-user pressure because it blocks long unattended runs.
  12. martinmclee commented on Jun 11, 2026

    @martinmclee

    Follow-up with exact local context (from my machine)

    I’m adding concrete template values I could collect locally:

    What version of the Codex CLI is running?

    • codex --version: codex-cli 0.139.0 (from C:\Users\User\AppData\Roaming\npm\node_modules\@openai\codex\package.json)

    What subscription do you have?

    • Not collected from local machine state without touching auth/token files.
    • Please update this to your known account tier if this is sensitive (Pro/Codex/Plus/etc).

    Which model were you using?

    • Local config shows: model = "gpt-5.3-codex-spark" and model_reasoning_effort = "xhigh"

    What platform is your computer?

    • Microsoft Windows 11 Home 10.0.26200 (x64 / 64-bit processor)

    What terminal emulator and version are you using?

    • PowerShell 5.1.26100.8457

    If you want, I can do one more pass to lock exact Codex App build string if you can share how you launch/update the desktop bundle.

  13. SmartManoj commented on Jun 11, 2026

    @SmartManoj

    Suggested fix:

    diff --git a/codex-rs/core/src/compact_remote.rs b/codex-rs/core/src/compact_remote.rs
    index 93457053f52..b68aa127d2a 100644
    --- a/codex-rs/core/src/compact_remote.rs
    +++ b/codex-rs/core/src/compact_remote.rs
    @@ -375,7 +375,13 @@ pub(crate) fn trim_function_call_history_to_fit_context_window(
                 .get(index)
                 .and_then(rewritten_output_for_context_window)
             else {
    -            break;
    +            // This item cannot be truncated (e.g. reasoning or a plain message).
    +            // Skip it and keep scanning older items for tool outputs we can
    +            // shrink; breaking here would leave history over the context window
    +            // whenever a non-truncatable item sits between us and an output,
    +            // which surfaces as a `context_length_exceeded` error during remote
    +            // compaction.
    +            continue;
             };
             let mut items = history.raw_items().to_vec();
             items[index] = rewritten_item;

    Commit: 257acee4

    Image
  14. martinmclee commented on Jun 17, 2026

    @martinmclee

    I can also reproduce this exact error with a Spark variant.

    Error running remote compact task:
    {
    "error": {
    "message": "Your input exceeds the context window of this model. Please adjust your input and try again.",
    "type": "invalid_request_error",
    "param": "input",
    "code": "context_length_exceeded"
    }
    }

    This is with gpt-5.3-codex-spark and appears to match the same remote compaction overflow failure mode, so likely a Spark-specific compaction path issue rather than user input alone.

  15. etraut-openai commented on Jun 29, 2026

    @etraut-openai
    Contributor

    Thanks for reporting this problem. Until recently, Codex used a separate endpoint and server-side logic for compaction. We recently switched to a more robust approach where the compaction logic is moved locally using the same endpoint as normal turns. This eliminates "remote compaction" errors and increases the stability and reliability of compaction operations. If you see further problems with compaction, please use /feedback and open a new bug report.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcontextIssues related to context management (including compaction)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions