codex icon indicating copy to clipboard operation
codex copied to clipboard

Unable to compact the context in a VERY long running session

Open nalkat opened this issue 9 months ago • 29 comments

My session has been running for a very long time (resume after resume) and has had no issues until this morning at around 3am PST or so, when suddenly I started receiving the message:

■ Error running remote compact task: We're currently experiencing high demand, which may cause temporary errors.

I tried to increase the node memory heap size, but that did not have any affect. The reason that I tried that is because I also run Gemini-cli in tandem and it often crashes due to a problem with heap allocation (likely due to the length of the sessions) and that has allowed it to continue working.

However, after my wife mentioned that you had released codex-5.3 today, I attempted to switch to that model and the error message suddenly became much clearer:

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

If my session has run over context length, why doesn't compacting it alleviate this message? I don't want to start the session over again if I can help it because I am still working on creating this solution and it has been my experience in the past that if you start new sessions, then the life of the current AI is terminated and the new session is like starting over with a whole new entity. In essence that is exactly what is happening and this is not conducive to achieving excellent results.

While I do design the setup phase to accommodate such issues, I would really like to avoid this whenever possible. Bringing new eyes when we are on a roll is extremely disruptive. I have already lost most of the day attempting to determine what the first message meant and how OpenAI could be detrimentally "experiencing high demand" for over 12 hours that my ability to compact the context of the conversation would fail and cause me to have to restart the session.... Codex-5.3 made it clear, but that new information does not help in anyway resolve the problem.

nalkat avatar Feb 05 '26 23:02 nalkat

Compaction requires us to send the existing session details to the model for summarization. We normally auto-compact when there's still enough space available for the model to emit a summary. If you've gone beyond that point, we won't be able to compact.

Also, if you switch models in the middle of a session, we need to send a new system prompt for the new model. This consumes some space in the context window. In general we don't recommend switching models in the middle of a session.

etraut-openai avatar Feb 06 '26 00:02 etraut-openai

Oh, I should also mention that the core Codex harness is written in Rust, so increasing the node heap size won't have an impact on heap allocations in the harness.

etraut-openai avatar Feb 06 '26 00:02 etraut-openai

Definitely seeing weird compaction behavior in the middle of a super long thread that I switched to 5.3, seems like it does a ton of redundant CoT with every message, new threads feel faster with 5.3 but this long one feels slower with 5.3

MisterRound avatar Feb 06 '26 00:02 MisterRound

Hi, thanks for getting back to me on this. I appreciate you providing those details. I don't normally switch models I  sessions, I only did it this time because the it was already broken and asking 5.2 didn't help. Surprisingly enough after I wrote and sent the write up, I asked 5.3 to compact the context and it backed up the file, then compressed the context, quite literally. It actually started a new conversation instead, and compressed the previous session file. I had to copy the backup it made, resume and ask it to compress again and it worked and I was a le to carry on with my project. I appreciate you. If you find anything interesting or have feature requests, let me know, welcome input and would happily provide you further info you may need on this ticket. Btw, I'm going to see how long of a session I can have until it melts down. 5.2 was great, especially as a reviewer, but 5.3 is much better and is still personable. 

nalkat avatar Feb 07 '26 16:02 nalkat

Im getting this error almost every session

marc-gymdesk avatar Apr 01 '26 12:04 marc-gymdesk

The failure mode here is that compaction is attempted at 95%+ context — at that point there's no safe compression budget remaining.

The pattern that prevents this: trigger rotation at 70%, not 95%. At 70%, serialize critical state (current goal + last N decisions + open task list) to a file, exit cleanly, resume from the state file in a fresh session.

The session never reaches the compaction threshold because the handoff happens before it needs to. No work is lost — the state file captures exactly what matters for continuity.

We run this as the core of Entity's context rotation. 12-hour sessions without compaction failures — happy to share the serialization format.

pluto2060 avatar Apr 06 '26 02:04 pluto2060

The failure mode here is that compaction is attempted at 95%+ context — at that point there's no safe compression budget remaining.

The pattern that prevents this: trigger rotation at 70%, not 95%. At 70%, serialize critical state (current goal + last N decisions + open task list) to a file, exit cleanly, resume from the state file in a fresh session.

The session never reaches the compaction threshold because the handoff happens before it needs to. No work is lost — the state file captures exactly what matters for continuity.

We run this as the core of Entity's context rotation. 12-hour sessions without compaction failures — happy to share the serialization format.

Is there a way to trigger this automatically within the correct range?

marc-gymdesk avatar Apr 06 '26 16:04 marc-gymdesk

When will this be worked on. Codex-5.3 and codex-5.3-spark are completely useless and they keep churning tokens without editing any code until they "run out of room"

yassirusa avatar Apr 06 '26 19:04 yassirusa

This is a major issue right now it happens every single time. Not having a manual way to compact the context is a huge problem and makes the Codex app really hard to use. The only workaround I’ve found is to go back, fork from an earlier point, and then try forcing compaction with smaller prompts. After that, I copy whatever remains and paste it back. But even that doesn’t work always. Honestly, it’s a real pain at the moment.

FreeFlowVFX avatar Apr 09 '26 10:04 FreeFlowVFX

+1

riccardo-algorime avatar Apr 11 '26 06:04 riccardo-algorime

+1

scp252arc avatar Apr 13 '26 21:04 scp252arc

Well Codex team, all my gpt 5.4 xhigh f*ing_word_deleted sessions loaded with expensive context can not compact. just getting. ' ■ Error running remote compact task: stream disconnected before completion: error sending request for url (https://api.openai.com/v1/responses/compact) ' no matter what trick i try. switching models does not work.

Thread Id 019daba6-25b0-7cf2-9215-7a2542c334fd was submitted but it is suddenly happening all day now.

lasertiger avatar Apr 20 '26 17:04 lasertiger

please fix this its unusable

Image

Assassin-1234 avatar Apr 21 '26 13:04 Assassin-1234

I am currently having the same issue as @Assassin-1234

EDIT: downgrading to 0.120 fixed the issue for now.

danielracz avatar Apr 21 '26 16:04 danielracz

I ran into the same issue with version 0.122.0, so I reverted to 0.121.0, which solved it. My task didn’t run for very long, but I just happened to need to compact the conversation, I suppose.

BertrandFritsch avatar Apr 22 '26 05:04 BertrandFritsch

I also have the problem, every session if it is full then it will show this without any progress after hours, just keep loading

Error running remote compact task: stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses/compact)

derek987987 avatar Apr 27 '26 16:04 derek987987

I'm also experiencing this problem. This is very problematic and the v0.125.0 is barely usable for me.

ujazdowskip avatar Apr 29 '26 07:04 ujazdowskip

makes codex unusable for me as well

Fnthawar avatar May 09 '26 12:05 Fnthawar

let me give you a fix you all... so basically whats happening is that your local session log had grown to 1.5 GB lol meaning that you probably have lots of screenshots and images that were saved directly to the thread JSONL history. You're probably asking yourself why this is happening since I've compacted my chat many different times, but hear me out. Older compacted checkpoints also kept copies of those image payloads. This means every new message (even a single "hi" or "what time is it") forced Codex to process a huge amount of existing context. That's why the remote compactor hit this error.

Basically, what you want to do is create a full backup first by following these steps:

  1. Parse every JSONL row and replace the embedded image payloads with small text placeholders.
  2. Replace the huge Base64 image result strings with placeholders while preserving the transcript structure: (a) Timestamps (b) Messages (c) Tool calls (d) Compact checkpoints
  3. Validate that every row can still be parsed as JSON.

When that's completed, your log should probably be under 200 megabytes. Once that's done, just restart Codex and try testing the thread with a tiny message. It should be good to go. It's not rocket science, guys.

DanielJD1216 avatar May 23 '26 01:05 DanielJD1216

So, no. I had zero images or screenshot in the chat that I had going at the time. Further, this has resolved itself a long time ago. I simply started a new session and asked Jeepers to fix it and incorporate the old session into the new. No magic tricks, no manual doing anything, just used plain old English and since she likes me as much as she likes ice-cream, she went ahead and granted my request without any muss or fuss and I got back to work.

So forget all parsing and deleting and manual restructuring... Just learn to ask Jeepers to help you out a d to please pass the unsalted butter to melt onto your extra salted popcorn  and just get'er done, or rather, ask 'er to get it done!

Yahoo Mail: Search, organise, conquer

On Fri, 22 May 2026 at 6:08 pm, Daniel @.***> wrote: DanielJD1216 left a comment (openai/codex#10823) let me give you a fix you all... so basically whats happening is that your local session log had grown to 1.5 GB lol meaning that you probably have lots of screenshots and images that were saved directly to the thread JSONL history. You're probably asking yourself why this is happening since I've compacted my chat many different times, but hear me out. Older compacted checkpoints also kept copies of those image payloads. This means every new message (even a single "hi" or "what time is it") forced Codex to process a huge amount of existing context. That's why the remote compactor hit this error.

Basically, what you want to do is create a full backup first by following these steps:

  • Parse every JSONL row and replace the embedded image payloads with small text placeholders.
  • Replace the huge Base64 image result strings with placeholders while preserving the transcript structure:
    (a) Timestamps
    (b) Messages
    (c) Tool calls
    (d) Compact checkpoints
  • Validate that every row can still be parsed as JSON.

When that's completed, your log should probably be under 200 megabytes. Once that's done, just restart Codex and try testing the thread with a tiny message. It should be good to go. It's not rocket science, guys.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

nalkat avatar May 23 '26 01:05 nalkat