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

Resolved 💬 11 comments Opened Apr 16, 2026 by evilfps Closed Jun 29, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

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?

<img width="898" height="447" alt="Image" src="https://github.com/user-attachments/assets/15ee6aac-900a-415e-82e0-54d251f29983" />

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_

View original on GitHub ↗

11 Comments

github-actions[bot] contributor · 3 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #17392
  • #16377
  • #17940

Powered by Codex Action

leofratu · 2 months ago

+1

Ghxst · 2 months ago

happened for me

<img width="832" height="77" alt="Image" src="https://github.com/user-attachments/assets/8ad8c8a4-67f0-4508-b353-99e0743fcc7e" />

augard · 2 months ago

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" } }

leofratu · 2 months ago

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

NevenSumonja · 1 month ago

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)
martinmclee · 1 month ago

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.
martinmclee · 1 month ago

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.

SmartManoj · 1 month ago

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: https://github.com/openai/codex/commit/257acee4

<img width="1449" height="295" alt="Image" src="https://github.com/user-attachments/assets/5c3e48f5-f98d-448f-b753-daad041e477b" />

martinmclee · 1 month ago

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.

etraut-openai contributor · 21 days ago

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.