Codex CLI "Stream disconnected before completion": fixes
Codex CLI stops long tasks with 'Stream disconnected before completion'. Two reported fixes, plus how Sledbot helps you restart and resume the agent.
Updated 7 min read
On this page
Your long Codex CLI task dies partway through with this line:
Stream disconnected before completion: response.failed event receivedYour network looks fine and you aren't on a VPN. This page covers what is known, what to try in order, and how to get your work back when it happens.
Why it happens
Nobody outside OpenAI can say for certain. The message means the response stream from the model ended with a failure event before the answer finished. These are the causes people report, most likely first.
- A very long conversation. One reply on a February 2026 thread said long context triggers it. The pattern is that short sessions work and long ones fail. We haven't reproduced it ourselves.
- The ChatGPT-login connection path. The same thread had a reply saying it happened with a ChatGPT Plus login, described it as a websocket failure, and said an API key avoided it. That is one user's result, not a verified diagnosis. OpenAI's own write-up of the agent loop confirms the two logins use different endpoints. With ChatGPT login Codex CLI uses chatgpt.com/backend-api/codex/responses, and with API-key authentication it uses api.openai.com/v1/responses. So switching login method does change the route your requests take.
- A different provider setup. The same message text shows up in reports from people running Codex against Azure-hosted models, where the cause is different (an error-parsing problem on that integration). If you use a custom provider in
~/.codex/config.toml, the fix may lie there, not in anything below. - A transient server-side failure. A stream can fail for reasons on OpenAI's side that no setting on your Mac changes. If a retry works, that is the likely story.
Fixes, most likely first
Fix 1: Hand off to a fresh conversation
Do this before a session gets long, or as soon as the error appears.
- In the agent session composer or the terminal, ask Codex for a handoff. For example:
Write a handoff prompt for a new session: the goal, what is done, what is left, files changed, and any failing tests. - Copy the prompt it writes.
- Press ⌘T (Command-T) to open New task. Choose the same space and set the agent chip to Codex CLI.
- Paste the handoff prompt and start with ⌘↩.
If Codex has already stopped responding, you can't ask it for a handoff. Open Review changes from the agent header, or look at the Changes section of the details rail, then write the summary yourself.
Prefer to split big jobs into several shorter tasks up front. Smaller tasks with a handoff between them keep each conversation short, which is the one thing the reports agree on.
Fix 2: Try an API key login
Sledbot doesn't hold Codex's login. Codex does, so the login method is Codex's setting. On first run Codex asks you to choose Sign in with ChatGPT or another available sign-in method, and that is where an API key option appears.
- Open Settings > Agents in Sledbot and pick the machine the agent runs on.
- Find Codex CLI and choose Log in…. Confirm the sheet. The login runs in a terminal pane on that machine.
- At Codex's prompt, choose the API key option and follow it.
- Start a new task with Codex CLI and run the same long job.
If the agent uses an account you added under Settings > Accounts, that account has its own CODEX_HOME config folder. Log in through that account's Log in… menu item, not the global one.
Two caveats before you switch:
- API-key use is billed separately through the OpenAI API, not through your ChatGPT plan.
- Provider keys saved in Settings > Providers are used by Sledbot's native agent, routines and Night shift. Codex CLI doesn't read them. An API key for Codex has to go through Codex's own login.
Fix 3: Update Codex and retry
An old Codex build may carry a bug that newer releases fixed. In Settings > Agents, choose Update… next to Codex CLI. It confirms, then runs the update in a terminal on that machine. Then retry with a short conversation first to see if the error is gone.
Fix 4: Resume instead of starting over
Sledbot can restart the stopped agent with its conversation:
- Choose Restart on the stopped agent, or press ⇧⌘R in the focused terminal.
- Sledbot uses Codex's own resume command (
codex resume <id>) in the same folder where it can. - If it can't, you'll see "Can't restart
<name>with its conversation". Fall back to Fix 1.
If long context is the trigger, resuming a conversation that was already huge may hit the same error again. Handing off is the safer choice for those.
Which fix matches what you see
| What you see | Likely cause | Try |
|---|---|---|
| Fails only late in long sessions | Long context | Fix 1, then split big jobs |
| Fails on a ChatGPT login, even on short tasks | Login path (one report) | Fix 2 |
| Fails right after a Codex update or on an old build | Version bug | Fix 3 |
| Fails once, retry works | Transient server-side failure | Fix 4 |
Uses Azure or a custom model_provider | Provider integration | Check that provider's setup |
How Sledbot helps you recover
- Health banner. If an agent hits provider errors 2 or more times, a banner on its header says it "keeps hitting provider errors" and offers Restart with resume and Send a nudge. We haven't confirmed that Health recognizes this exact message, so don't count on the banner appearing.
- Notifications. When you aren't looking at the agent, Sledbot can show a "
<name>hit an error" banner. Agents keep running when you quit the app, so a task you left alone is still there when you come back. - No account switch. Account fallback triggers on a usage limit. A stream error isn't one, so the agent won't switch accounts on its own.
Check what the agent changed
At the end of each agent turn in a git work tree, Sled Core snapshots the working tree into private git refs. The last 50 are kept. The app has no checkpoint screen, so use the CLI from any Sledbot terminal:
sled checkpoint lsThis lists checkpoints. sled checkpoint diff shows what changed. sled checkpoint restore restores one and takes a safety checkpoint first. See the sled command line for the full list.
Starting or restarting agents needs a MacSuite license or an active 7-day trial. After the trial, running agents keep going, but restarts open the license window instead.
Checklist before you try again
- The previous agent's changes are reviewed or committed, so nothing is lost.
- You have a handoff prompt, or your own short summary, ready.
- Codex is updated in Settings > Agents.
- You know which login Codex uses (ChatGPT or API key).
- Work in a new worktree is set the way you want it.
If nothing works
Report it to OpenAI's Codex support or the Codex project's issue tracker, because the failure is on the Codex and OpenAI side. Include:
- the exact error text and when it happened (with time zone)
- your Codex version and macOS version
- whether you use a ChatGPT login, an API key or a custom provider
- how long the conversation was, and whether short sessions work
- what you already tried
Codex CLI stops long tasks with: "Stream disconnected before completion:
response.failed event received".
Version: <codex --version>. macOS: <version>. Login: ChatGPT / API key.
It happens after roughly <N> turns in one conversation. Short sessions work.
No VPN, network is stable. Tried: updating Codex, new conversation with a
handoff prompt, API key login (result: ...). Timestamps: <date, time, zone>.For problems in Sledbot itself, such as the restart not working, use Sledbot support and mention sled doctor output. Run sled doctor in a Sledbot terminal. It checks the core, agent CLIs and their logins, git, disk and the clock.
Common questions
Is my internet connection the problem?
Probably not. The original report had no VPN and a stable network. A flaky connection can still break a stream, so retry once on a different network if the error is frequent.
Does an API key really fix it?
One user said so, and we haven't verified it. The two logins use different endpoints, so it's a reasonable thing to test, but treat the result as yours to confirm.
Will I lose the agent's work when it stops?
The files it already changed stay in the worktree. Use Review changes to see them, or sled checkpoint ls for per-turn snapshots.
Can Sledbot retry automatically?
Not for this error. You restart manually with Restart, which resumes the conversation where Codex allows it. Starting an agent covers the New task page in more detail.