You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What terminal emulator and version are you using (if applicable)?
powershell
What issue are you seeing?
I keep getting this issue ofternly, when I running the codex, it will sometimes getting this error duing the process, which may mess up my codes Error running remote compact task: stream disconnected before completion: error sending request for url(https://chatgpt.com/backend-api/codex/responses/compact)
after this, this session is not usable anymore, no matter what I type in, it keep shows this error, so I have to start a new session
eventually find out it might be the internet issue, after use some reliable proxies this issue never happen again...
but still dont know why the session will be messed up and can not be recovered
Your on windows, so I'm not sure it still uses reqwest, and I don't know if the Windows version has the 30 default timeout that is ridiculously short for that many tokens. But I submitted a fix for a similar problem in linux: #14860
Adjust the stream_idle_timeout_ms parameter in config.toml. ----------------------------demo---------------------------
model = "gpt-5.4" model_reasoning_effort = "xhigh" personality = "pragmatic" sandbox_mode = "danger-full-access" model_provider = "def"
[model_providers.def] name = "OpenAI Data Residency"
stream_max_retries = 10
stream_idle_timeout_ms = 600000
this may really help me !!!
Please let us know if you still experience issues or not. I would be grateful to find out if there is an alternative path to modify the timeout that affects compact.
Adjust the stream_idle_timeout_ms parameter in config.toml. ----------------------------demo---------------------------
model = "gpt-5.4" model_reasoning_effort = "xhigh" personality = "pragmatic" sandbox_mode = "danger-full-access" model_provider = "def"
[model_providers.def] name = "OpenAI Data Residency"
stream_max_retries = 10
stream_idle_timeout_ms = 600000
this may really help me !!!
Please let us know if you still experience issues or not. I would be grateful to find out if there is an alternative path to modify the timeout that affects compact.
Adjust the stream_idle_timeout_ms parameter in config.toml. ----------------------------demo---------------------------
model = "gpt-5.4" model_reasoning_effort = "xhigh" personality = "pragmatic" sandbox_mode = "danger-full-access" model_provider = "def"
[model_providers.def] name = "OpenAI Data Residency"
stream_max_retries = 10
stream_idle_timeout_ms = 600000
this may really help me !!!
Please let us know if you still experience issues or not. I would be grateful to find out if there is an alternative path to modify the timeout that affects compact.
It works on the Codex app.
I confirmed this solution works for me too. On Linux (Ubuntu).
@cihadturhan You need the model_provider = "def" in the top section. that bottom part is just defining the def model provider. Your settings currently define def, but not specify for the app to actually use it.
NOTE: for resuming sessions, sadly they are tied to provider. So you will not see past sessions for the default "openai" provider after the change. Though I just asked a new context to walk me through moving my old context to the new provider.
@cihadturhan You need the model_provider = "def" in the top section. that bottom part is just defining the def model provider. Your settings currently define def, but not specify for the app to actually use it.
NOTE: for resuming sessions, sadly they are tied to provider. So you will not see past sessions for the default "openai" provider after the change. Though I just asked a new context to walk me through moving my old context to the new provider.
Just to tack on to your note for future users: If you were to edit the db you can set all of the current threads to use the new provider. It requires having a sqlite editor. sqlite3 is small and free.
temporarily remove the model_provider = "def" from the config file
quit codex
cd ~/.codex/ (or equivalent depending on OS)
run: sqlite3 state_5.sqlite "UPDATE threads SET model_provider = 'def';"
put back in the model_provider = "def" entry in the config file
restart codex
Once you change this entry it will view all current threads as being owned by the "def" provider. You will have your entire thread history now assigned to def with no need to manually copy them over.
[model_providers.def] name = "OpenAI Data Residency" stream_idle_timeout_ms = 600000
What is the special meaning of def and OpenAI Data Residency? Can I just use another name? I don't understand the working principle of this configuration
codex_core::session::turn: Failed to run pre-sampling compact
Pattern:
The thread was near the model context limit: 240805 / 258400 tokens.
The failure occurred before sampling, during remote compaction.
Retrying the same old thread hit the same failure again.
Starting a new thread avoids the issue, which suggests this is tied to the remote compact path for long histories rather than local project code or local shell/tool execution.
I also found older local occurrences of the same compact error on 2026-04-25, with compaction request sizes around ~1MB.
Expected behavior:
Remote compaction should complete, or fail with a recovery path that keeps the old thread usable.
If the compact request is too large or the stream is interrupted, Codex should ideally retry with a smaller compact payload or offer a manual resume/new-thread handoff instead of leaving the session blocked at pre-sampling compact.
Here is another potential workaround. You manually compact the thread yourself. Go to the folder that the thread is located in usually ~/.codex/sessions/(date thread was made). Then make a copy of the thread's jsonl file. Afterwards, you can start a new thread, hand this file directly to codex and tell it that it's a jsonl file in codex's format and inform it that it is too large to parse. Ask it to build a python script to compact the entries. Request for it to compact everything between but ignore the first 20 lines and last 100 or so. Once it is done you can replace the file and restart codex. Then the thread will compact.
In my case the issues was codex dealing with mcp servers that returned massive amounts of data that stay cached in the conversation but are too big to transfer for compacting. I was having codex generate my game graphics using comfyui and the results were being stored as base64 encoded images which bloated the token counts into the millions.
Here is the prompt (with reasoning) that I provided codex:
"I have a massive Codex .jsonl session file named rollout-b11c.jsonl. It is bloated to 34 million tokens because of massive ComfyUI MCP tool payloads.
Please write and execute a local Python script to perform a 'structural compaction' on this file. The script should read the file line-by-line, parse the JSON, and do the following:
If the line is a normal user or assistant message, keep it exactly as is.
If the line contains a function_call to mcp__comfyui__, modify the arguments string. Strip out any massive data but leave a summary like: {"control_type": "depth", "status": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="}.
If the line is a function_call_output from comfyui, replace the massive output payload with a simple summary string: "[Tool execution successful. Image generated and saved. Detailed JSON output removed for context compaction.]"
Save the modified lines to a new file named compacted_rollout.jsonl.
Ensure the script maintains perfectly valid JSONL syntax for every line so it doesn't break the chat application."
Hope this helps. It has worked for me twice now. Now I can just run the python file it made and I can skip the AI for this step entirely.
Additional reproduction details and temporary workaround that may help isolate the failure:
The user initially suspected VPN / network configuration, but reproduced the same remote compaction failure across multiple environments:
Codex App on Windows, Linux, and macOS
dorm network, faculty network, and cellular network
after increasing local idle/request timeout settings to roughly 15 minutes
The notable pattern is that the failing remote compaction path appears to cut out at about 5m01s. This suggests the remaining failure may be tied to a fixed deadline / timeout on the special remote compact path rather than a general network/VPN problem.
Error:
Error running remote compact task: stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses/compact)
This is not a real alternate provider. The apparent effect is that Codex no longer detects the provider as exactly OpenAI, so it avoids the special /responses/compact remote compaction path and falls back to normal/local compaction through the regular Responses/WebSocket path.
Observed result:
Several sessions that previously failed remote compaction started compacting successfully with this workaround.
Compaction completed in under ~10 seconds in cases that previously failed.
Early testing across Ubuntu and macOS showed multiple successful compactions over longer-running tasks.
Downside: because the provider name differs, previous Codex history/resume filtering may not show the same sessions normally.
This seems consistent with #19400: Codex currently decides remote compaction by provider identity, not by whether the active model / endpoint combination can reliably use /responses/compact.
Possible fix directions:
Add an explicit user config option to disable remote compaction, e.g. remote_compaction = "never" or use_remote_compaction = false.
Make remote compaction model/endpoint aware, and fall back to local compaction when /responses/compact fails or times out.
If the remote compact endpoint has a fixed timeout around 5 minutes, expose/document it or make the client retry/fallback gracefully.
This workaround should probably be treated only as temporary, but it strongly suggests the normal Responses path is healthy while the special remote compact endpoint is the brittle part.
The goal is not to claim that all /responses/compact failures are caused by the user's network. It is to give users a concrete way to test one specific failure class: whether the same network/proxy/VPN/gateway path used by Codex can keep a long-idle HTTPS request alive for more than 90 seconds.
The proposed self-test uses slee.pt, which intentionally waits before replying. This is different from a basic connectivity check against chatgpt.com, because the failure mode here is about surviving a long silent wait, not just DNS/TLS/connectivity.
If slee.pt >90s is cut off early on the same path used by Codex, that user has evidence of a transport-path idle cutoff that can directly explain stream disconnected before completion during remote compaction. If it succeeds, that specific explanation becomes less likely and the report can focus more on backend/client compaction behavior.
This may help triage the many duplicate stream disconnected before completion reports by separating network-path idle cutoff from remote compact service/client failures.
Remote compact needs a resumable receipt, not just a longer timeout.
Record compact task id, source thread id, request size/token estimate, started_at, last_stream_event_at, timeout source, retry count, partial summary checkpoint, and recovery action. Then a stream disconnect can resume or fall back to local/manual compaction instead of poisoning the session into repeating the same error forever.
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.
Activity
github-actions commentedon Mar 13, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
IPRIT commentedon Mar 13, 2026
I confirm the issue :(
AminoBatlog commentedon Mar 13, 2026
eventually find out it might be the internet issue, after use some reliable proxies this issue never happen again...
but still dont know why the session will be messed up and can not be recovered
Grallen commentedon Mar 16, 2026
Your on windows, so I'm not sure it still uses
reqwest, and I don't know if the Windows version has the 30 default timeout that is ridiculously short for that many tokens. But I submitted a fix for a similar problem in linux: #14860powerslid3 commentedon Mar 17, 2026
Same
weisonyoung commentedon Mar 23, 2026
Adjust the stream_idle_timeout_ms parameter in config.toml.
----------------------------demo---------------------------
model = "gpt-5.4"
model_reasoning_effort = "xhigh"
personality = "pragmatic"
sandbox_mode = "danger-full-access"
model_provider = "def"
[model_providers.def]
name = "OpenAI Data Residency"
stream_idle_timeout_ms = 600000
Ada2pro commentedon Mar 23, 2026
this may really help me !!!
Grallen commentedon Mar 23, 2026
Please let us know if you still experience issues or not. I would be grateful to find out if there is an alternative path to modify the timeout that affects compact.
weisonyoung commentedon Mar 24, 2026
It works on the Codex app.
Grallen commentedon Mar 25, 2026
I confirmed this solution works for me too. On Linux (Ubuntu).
cihadturhan commentedon Mar 26, 2026
Does not work!
Tyux commentedon Apr 2, 2026
Does not work!
Grallen commentedon Apr 2, 2026
@cihadturhan You need the
model_provider = "def"in the top section. that bottom part is just defining the def model provider. Your settings currently define def, but not specify for the app to actually use it.NOTE: for resuming sessions, sadly they are tied to provider. So you will not see past sessions for the default "openai" provider after the change. Though I just asked a new context to walk me through moving my old context to the new provider.
lodlock commentedon Apr 9, 2026
Just to tack on to your note for future users: If you were to edit the db you can set all of the current threads to use the new provider. It requires having a sqlite editor. sqlite3 is small and free.
Once you change this entry it will view all current threads as being owned by the "def" provider. You will have your entire thread history now assigned to def with no need to manually copy them over.
qixing-jk commentedon Apr 9, 2026
What is the special meaning of def and OpenAI Data Residency? Can I just use another name? I don't understand the working principle of this configuration
FriendsHL commentedon Apr 30, 2026
I hit the same remote compaction failure again today, with concrete log metrics that may help narrow it down.
Environment:
26.422.62136 (2176)macOS 15.6.1, Darwin24.6.0,arm64gpt-5.50.125.0Visible error:
Observed timestamps:
2026-04-30 17:22:56 Asia/Shanghai2026-04-30 17:24:04 Asia/ShanghaiRelevant sanitized log details from
codex-tui.log:Immediately after the second failure:
Pattern:
240805 / 258400tokens.2026-04-25, with compaction request sizes around ~1MB.Expected behavior:
lodlock commentedon May 2, 2026
Here is another potential workaround. You manually compact the thread yourself. Go to the folder that the thread is located in usually ~/.codex/sessions/(date thread was made). Then make a copy of the thread's jsonl file. Afterwards, you can start a new thread, hand this file directly to codex and tell it that it's a jsonl file in codex's format and inform it that it is too large to parse. Ask it to build a python script to compact the entries. Request for it to compact everything between but ignore the first 20 lines and last 100 or so. Once it is done you can replace the file and restart codex. Then the thread will compact.
In my case the issues was codex dealing with mcp servers that returned massive amounts of data that stay cached in the conversation but are too big to transfer for compacting. I was having codex generate my game graphics using comfyui and the results were being stored as base64 encoded images which bloated the token counts into the millions.
Here is the prompt (with reasoning) that I provided codex:
"I have a massive Codex .jsonl session file named rollout-b11c.jsonl. It is bloated to 34 million tokens because of massive ComfyUI MCP tool payloads.
Please write and execute a local Python script to perform a 'structural compaction' on this file. The script should read the file line-by-line, parse the JSON, and do the following:
If the line is a normal user or assistant message, keep it exactly as is.
If the line contains a function_call to mcp__comfyui__, modify the arguments string. Strip out any massive data but leave a summary like: {"control_type": "depth", "status": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="}.
If the line is a function_call_output from comfyui, replace the massive output payload with a simple summary string: "[Tool execution successful. Image generated and saved. Detailed JSON output removed for context compaction.]"
Save the modified lines to a new file named compacted_rollout.jsonl.
Ensure the script maintains perfectly valid JSONL syntax for every line so it doesn't break the chat application."
Hope this helps. It has worked for me twice now. Now I can just run the python file it made and I can skip the AI for this step entirely.
FriendsHL commentedon May 2, 2026
zixuanjiang332 commentedon May 3, 2026
Additional reproduction details and temporary workaround that may help isolate the failure:
The user initially suspected VPN / network configuration, but reproduced the same remote compaction failure across multiple environments:
The notable pattern is that the failing remote compaction path appears to cut out at about 5m01s. This suggests the remaining failure may be tied to a fixed deadline / timeout on the special remote compact path rather than a general network/VPN problem.
Error:
Temporary workaround tested by the user:
This is not a real alternate provider. The apparent effect is that Codex no longer detects the provider as exactly
OpenAI, so it avoids the special/responses/compactremote compaction path and falls back to normal/local compaction through the regular Responses/WebSocket path.Observed result:
This seems consistent with #19400: Codex currently decides remote compaction by provider identity, not by whether the active model / endpoint combination can reliably use
/responses/compact.Possible fix directions:
remote_compaction = "never"oruse_remote_compaction = false./responses/compactfails or times out.This workaround should probably be treated only as temporary, but it strongly suggests the normal Responses path is healthy while the special remote compact endpoint is the brittle part.
joelreymont commentedon May 5, 2026
Thread ID 019dc54d-4fe7-7f12-a99c-678425fc5aee.
No VPN.
yuweuii commentedon May 15, 2026
@etraut-openai looping you in because you previously commented in #14860 that increasing timeouts may paper over an underlying latency issue.
I opened a focused diagnostic issue here: #22798
The goal is not to claim that all
/responses/compactfailures are caused by the user's network. It is to give users a concrete way to test one specific failure class: whether the same network/proxy/VPN/gateway path used by Codex can keep a long-idle HTTPS request alive for more than 90 seconds.The proposed self-test uses
slee.pt, which intentionally waits before replying. This is different from a basic connectivity check againstchatgpt.com, because the failure mode here is about surviving a long silent wait, not just DNS/TLS/connectivity.If
slee.pt>90s is cut off early on the same path used by Codex, that user has evidence of a transport-path idle cutoff that can directly explainstream disconnected before completionduring remote compaction. If it succeeds, that specific explanation becomes less likely and the report can focus more on backend/client compaction behavior.This may help triage the many duplicate
stream disconnected before completionreports by separating network-path idle cutoff from remote compact service/client failures.Necmttn commentedon Jun 22, 2026
Remote compact needs a resumable receipt, not just a longer timeout.
Record compact task id, source thread id, request size/token estimate, started_at, last_stream_event_at, timeout source, retry count, partial summary checkpoint, and recovery action. Then a stream disconnect can resume or fall back to local/manual compaction instead of poisoning the session into repeating the same error forever.
Generated with ax - https://github.com/Necmttn/ax
FriendsHL commentedon Jun 22, 2026
etraut-openai commentedon Jun 29, 2026
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
/feedbackand open a new bug report.