Codex Desktop: context compaction fails with remote compact stream disconnected
Resolved 💬 18 comments Opened May 11, 2026 by bjmark Closed Jun 29, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
Summary
Codex Desktop showed a context compaction failure while working in a local coding session.
Error message
Context compacted
Error running remote compact task: stream disconnected before completion; error sending request for url (https://chatgpt.com/backend-api/codex/responses/compact)
Context
- Product: Codex Desktop app
- Platform: macOS
- Approximate app version observed from local process:
26.506.31421 - The error appeared during automatic context compaction in an active coding thread.
Expected behavior
Context compaction should complete successfully, or retry/recover without interrupting the thread.
Actual behavior
The UI displayed the compaction failure message above.
Screenshot
The screenshot attached by the reporter shows the same error text:
Error running remote compact task: stream disconnected before completion; error sending request for url (https://chatgpt.com/backend-api/codex/responses/compact)
Notes
I do not have additional logs beyond the visible UI error at this time.
18 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Adding another user-impact report for this same Codex Desktop compaction failure.
Visible UI error from the reporter's screenshot:
The main impact is not only the error banner. The reporter says they often lose crucial accumulated context after this happens and cannot reliably retrieve or pass that context into another thread in the same project. As a result, they have to explain the same project state again from scratch in new threads.
Estimated frequency from the reporter: roughly 65% to nearly 100% of their longer threads hit this context-loss / unrecoverable-context problem.
Expected behavior: if remote compaction fails, Codex Desktop should preserve a recoverable project/thread summary or provide a reliable way to export/transfer the compacted context into another thread, so users do not lose task continuity.
Adding another concrete data point from Codex Desktop/CLI usage on a relatively large local codebase. The impact is severe enough that the product becomes effectively unusable for long-running coding work, not just noisy.
Environment:
@openai/codex@0.130.0gpt-5.5xhighObserved model/catalog data:
codex debug modelsreports forgpt-5.5:context_window = 272000max_context_window = 272000effective_context_window_percent = 95258400tokens.Earlier failing state:
model_context_window = 1000000model_auto_compact_token_limit = 900000codex_core::compact_remote/Failed to run pre-sampling compactfailures.model_context_window_tokens=Some(258400)last_api_response_total_tokens=244546failing_compaction_request_model_visible_bytes=998251After manual mitigation:
154kto159kinput tokens in one session and about147kin another, with cumulative session input totals in the millions.User impact:
model_auto_compact_token_limitvalues to keep the product usable.100000is only a local seatbelt, not a real fix.Expected behavior:
responses/compactfails or disconnects, Codex should retry/fallback/recover cleanly and preserve usable thread continuity.Related product direction: this also overlaps with the model-aware context/auto-compaction request in #16140, but the failure mode here is user-visible reliability: Codex Desktop compaction remains too fragile to support large-codebase work reliably.
The core issue is that the damn gpt-5.5 model hasn't opened up a 1M context window, but many people have configured it with the 1M setting from 5.4, which is causing 5.5 to fail to compact properly.
@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.I was able to get past a stuck state by
I'm adding
model_auto_compact_token_limit = 180000to my config.toml to try to see if that stops it from getting stuck for the time beingeh my optimism was not warranted - it's not really fixed - codex is basically unusable at the moment
I also couldn't find even a temporary solution. Sometimes compaction succeeds, but most often it doesn't. The only more or less working method is to switch to 5.4 and send a message for automatic compression (not a command). Then compaction succeeds, but there remains a risk of quality degradation due to the model change.
Additional sanitized reproduction/request from Windows Codex Desktop:
codex-cli 0.133.0-alpha.1.Error running remote compact task: stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses/compact).>85%context usage, where the remote compaction request is more likely to disconnect before completion.Request: please make automatic compaction trigger earlier, around
80%context usage, or expose a supported configurable threshold/retry/fallback path so remote compaction can complete before the thread becomes too large to compact reliably.I am seeing the same failure in Codex Desktop on Windows during automatic context compaction.
Error
Impact
This is disruptive for long-running unattended goals. The failure appears only after the thread is already large enough to need compaction, so when
/responses/compactfails the session is left in a fragile high-context state and the active goal stalls.Sanitized environment
Collected on 2026-05-26:
Relevant feature state from the Desktop-linked runtime:
Observed pattern
stream disconnected before completion.Local session search found prior session/archive records containing this same compact failure signature. I am not attaching raw rollout logs because they may contain private prompts, local paths, or tool output.
Why I suspect the Desktop runtime still matters
I saw that
openai/codex#23451added a timeout for remote compaction and that0.133.0includesAdd timeout for remote compaction requests. My standalone global CLI is now0.133.0, but the Desktop-linked runtime on this Windows installation still reportscodex-cli 0.133.0-alpha.1, and Microsoft Store reports no newer Desktop update. If Desktop is still using the alpha runtime, the released mitigation may not be active for Desktop users.Requested fixes
This appears to be a remote compaction robustness issue rather than a repository-specific problem.
Update with VPN/WebSocket evidence after OpenAI Support asked about network scope.
I refreshed the local diagnostics and the strongest suspect is now the VPN path rather than only the Desktop runtime mismatch.
New local network findings
A raw WebSocket probe to
wss://chatgpt.com/reached the server, but returned HTTP 403 instead of 101 Switching Protocols. I do not treat that as a failure by itself because it was not an authenticated Codex stream path, but it confirms the request reacheschatgpt.comrather than timing out locally.The important finding is routing. Both
chatgpt.comandauth.openai.comcurrently route through Surfshark OpenVPN:OpenAI's Help Center network guidance for ChatGPT/Codex says Codex uses WebSockets over TCP 443 to
chatgpt.com, and that proxy/firewall/TLS-inspection/security-gateway controls should not block, rewrite, or prematurely close the WebSocket handshake or long-running WebSocket connection. That matches this failure mode:Current interpretation
This may be a VPN/exit-path idle timeout or long-stream handling issue triggered specifically by Codex remote compaction. Normal ChatGPT/Codex requests can work, while the long remote compact task fails after the context is already large.
Requested product behavior
Even if VPN/network is the proximate trigger, Codex Desktop still needs a resilient failure path: bounded retries, a pre-compaction checkpoint, a local fallback/escape hatch, or a supported way to trigger compaction earlier. A remote compact stream disconnect should not strand a long-running Desktop goal.
Adding a Windows Codex Desktop data point with local log evidence that distinguishes this from a basic local connectivity/VPN failure.
Environment
User-visible behavior
A long-running Desktop thread entered automatic context compaction and stayed stuck in the UI as "auto compacting context" / "thinking" for many minutes. The thread did not recover cleanly after the compact request failed.
Key local log evidence
Automatic compaction was normally triggered by token accounting, then the remote compact HTTP call failed with a server/gateway response rather than a local network timeout:
The compact request itself:
Network/client progression from the same request:
Failure result:
There was also a local log line immediately before the 504 was surfaced:
However, the same compact request was then emitted again one second later with the same
turn_idand same approximate request size:That suggests two separate problems:
/responses/compactreturned an actual Cloudflare/backend504 Gateway Timeoutafter about 29m36s.Why this does not look like a basic local network/VPN outage
Local diagnostics at the same machine showed:
Connectivity probes:
Direct curl checks were fast:
Normal Codex Responses/WebSocket traffic in the same thread immediately before compaction was healthy, with many
transport="responses_websocket" api.path="responses"events completing in tens to hundreds of milliseconds around23:39:46-23:39:48. The failing compact HTTP request started at23:39:51.Current interpretation
This looks like a remote compaction reliability/recovery bug rather than ordinary network unreachability:
/responses/compactrequest reachedchatgpt.comand completed at the HTTP layer with504 Gateway Timeout.Requested behavior
504from/responses/compactas a recoverable compact failure with a clear UI state.shouldn't retry!, ensure it does not immediately re-enter the same compact request without a user-visible recovery path.Adding another fresh feedback data point for the same remote-compaction stream-disconnect cluster.
Visible UI error:
Observed details from the attached logs:
26.527.21038 (3328), Codex CLI0.133.0-alpha.4, session sourcevscode, modelgpt-5.5-oai, effortxhigh.HTTP 101 Switching Protocols; no doctor failures. Warnings wereauth.credentialsandmcp.config.2026-05-29T00:40:23.993Z, the/responsesWebSocket stream emittedresponse.output_item.addedwith item typecompaction.2026-05-29T00:40:51.559Z, the same/responsesWebSocket stream loggedsuccess=falsewithWebSocket protocol error: Connection reset without closing handshake, afterduration_ms=27565.2026-05-29T00:41:31.358Z.This variant is the Responses WebSocket path resetting during/after a compaction output item, rather than a local doctor/connectivity failure.
Adding a macOS Codex Desktop data point with local diagnostics. This looks broader than a basic connectivity failure and appears to involve long-running thread state / compaction input size / abnormal token counters.
Environment
User-visible error
Why this does not look like simple local connectivity
codex doctor --summaryon the same machine reported a healthy runtime and Responses WebSocket reachability:The remaining warning was unrelated local thread inventory drift, not network reachability.
Local evidence from affected long-running threads
This has occurred repeatedly on multiple long-running Codex Desktop threads. One representative thread showed:
The local rollout JSONL had grown to roughly 32 MB and included prior image payloads / large tool outputs / long compact replacement history. Locally trimming large image and string payloads reduced the rollout by ~13 MB, but compaction could still fail until a local compact checkpoint was appended and stale process state was cleared.
A second notable issue: the local
state_5.sqlitethread row had an extreme token counter, e.g.:After backing up the DB and setting the target thread
tokens_usedback to0, the running Codex Desktop app-server wrote an abnormal value back again, e.g.:That suggests the Desktop/app-server can keep stale in-memory thread state and rewrite bad counters even after the on-disk state is repaired.
Workaround that helped locally
The only reliable workaround so far has been:
compactedrecovery checkpoint at the end of the rollout.state_5.sqliteand reset only the affected thread'stokens_usedto0.If the Desktop process is not restarted, it may continue compacting old in-memory history and/or write the abnormal
tokens_usedvalue back to SQLite.Expected behavior
For long-running Desktop threads, Codex should be able to recover without manual JSONL/SQLite surgery:
tokens_usedshould not jump to hundreds of millions or be written back from stale app-server state after local recovery.Impact
This significantly impacts multi-day / long-running Codex Desktop tasks. Once a thread enters this failure mode, further work in that thread becomes unreliable until the user performs manual local repair and restarts the app.
Adding a fresh internal-feedback data point for the same remote compaction reliability cluster, with a newer TLS-shaped failure on a newer CLI.
Environment / visible details:
This is slightly different from the earlier
WebSocket protocol error: Connection reset without closing handshakereports. The reporter noted they were on the latest0.136.0and had previously been seeing the older compaction/reset failures, so this looks like a recurrence/new transport variant after the prior update guidance rather than the old stale-CLI case.I could not resolve the feedback UUID to detailed Sentry logs yet, but broad recent Sentry search still shows many
/codex/responses/compactstream disconnected before completionreports from the last day. Treating this as another breadcrumb for the same open compaction-disconnect issue unless later logs prove a distinct root cause.Adding a macOS/Desktop-adjacent data point and linking the fuller CLI report I posted in #22309.
I am seeing the same core failure shape on current local Codex surfaces: remote compact goes through
https://chatgpt.com/backend-api/codex/responses/compact, then can fail withstream disconnected before completion, leaving the user at risk of losing long-running coding context.The relevant current environment:
codex-cli 0.137.0gpt-5.5,xhigh195306 / 258400input tokenschatgpt.comvia a WireGuard-styleutun5route with MTU1380(public IP redacted)The upstream ask is the same for Desktop and CLI: remote compact should retry/resume or degrade to a recoverable handoff/fallback, rather than interrupting or wedging the active thread. A user should not need a custom local PreCompact hook to avoid losing a long coding session.
Full report with suggested recovery semantics is here: https://github.com/openai/codex/issues/22309
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.A possible workaround / diagnostic clue from another user report:
The repeated remote compaction failure (
stream disconnected before completion/peer closed connection without sending TLS close_notify) turned out to be network-path specific. The user was connected through a company-provided Wi-Fi network configured for proxying overseas traffic, and remote compaction consistently failed even after Codex automatically retried the connection.After switching from the company proxy Wi-Fi to the user's own VPN connection, remote compaction started working normally again.
This suggests that, for users seeing persistent failures specifically on long-running compaction requests, an intermediate corporate proxy / gateway timeout or idle-connection timeout may be closing the TLS stream before the compact request completes.
Possible troubleshooting step: try a different network path or VPN/proxy provider, and check corporate proxy/gateway timeout settings (especially long-lived or idle HTTPS connections). This may not be the root cause for every report, but it could be a useful workaround for some users.