Skip to content

Codex CLI stream repeatedly reconnects then falls back after websocket closes before response.completed #30933

Open

Description

@uditgoenka

Summary

Codex CLI can enter a repeated reconnect loop during a model turn when the WebSocket stream closes before response.completed. The UI retries up to 5/5, then falls back from WebSockets to HTTPS transport, but the user is left waiting in a degraded/stalled state instead of seeing a clean recovery, retry boundary, or actionable error.

This report is intentionally sanitized. The screenshots only show the generic transport error text and no private prompt/output data, so I am transcribing the visible messages rather than attaching session contents.

Environment

  • Codex CLI: codex-cli 0.142.5
  • Platform: macOS arm64
  • Model/profile visible in TUI: gpt-5.5 xhigh
  • Invocation shape: interactive Codex CLI session resumed from local history
  • Network/account details and private thread contents are intentionally omitted

Visible UI messages

The TUI showed repeated reconnect attempts:

Reconnecting... 3/5 (42s • esc to interrupt)
└ Stream disconnected before completion: websocket closed by server before response.completed

Then later:

Reconnecting... 5/5 (1m 04s • esc to interrupt)
└ Stream disconnected before completion: websocket closed by server before response.completed

After exhausting WebSocket reconnect attempts, the TUI showed:

⚠ Falling back from WebSockets to HTTPS transport. stream disconnected before completion: websocket closed by server before response.completed

Impact

  • The active turn appears unreliable/stalled for over a minute.
  • The user has to decide whether to interrupt, wait, or retry, without a clear state like “request recovered over HTTPS,” “request will be retried safely,” or “turn failed and no work is continuing.”
  • In long-running or critical resumed sessions, this is risky because interrupting may alter goal/turn state while waiting can burn time and possibly usage.

Reproduction shape

I do not have a minimal synthetic repro, but the observed shape is:

  1. Resume an existing Codex CLI session.
  2. Start or continue a model turn using gpt-5.5 xhigh.
  3. During streaming, the WebSocket closes before response.completed.
  4. Codex shows reconnect attempts 3/5 through 5/5 over about one minute.
  5. Codex falls back from WebSockets to HTTPS transport with the same websocket closed by server before response.completed message.

Expected behavior

  • WebSocket-to-HTTPS fallback should be seamless if the request can continue safely.
  • If continuation is not safe, the UI should mark the turn failed with an explicit terminal state and preserve the accepted user message.
  • The UI should expose enough diagnostic detail to distinguish:
    • transient transport reconnecting;
    • successful fallback and continued stream;
    • unrecoverable stream failure;
    • detached/unknown backend turn still running.
  • Interrupting during reconnect/fallback should not leave ambiguous goal/session state.

Actual behavior

  • The UI shows repeated reconnect attempts and fallback text, but not a clear terminal or recovered state.
  • The user sees a long stalled/reconnecting period and must manually decide whether to interrupt.
  • The exact error text repeats: websocket closed by server before response.completed.

Suggested fixes

  1. Add a clear post-fallback state: recovered over HTTPS, retrying safely, failed terminally, or backend state unknown.
  2. Show a request/turn diagnostic id in the UI or logs for this failure path.
  3. Preserve accepted user prompts and active goal state cleanly across reconnect/fallback/interrupt boundaries.
  4. Add an HTTPS-only or disable-WebSockets option for users/networks that repeatedly hit this condition.
  5. Avoid making esc/interrupt the only practical recovery action when the backend turn state is uncertain.

Related issues

These look closely related, but I am filing this separately with current CLI/version details and the exact observed retry/fallback sequence:

Privacy note

No raw transcript, prompts, outputs, credentials, project names, or private paths are included here.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    connectivityIssues involving networking or endpoint connectivity problems (disconnections)
    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal display
    on Jul 2, 2026
  2. ErnieAtLYD commented on Sep 25, 2026

    @ErnieAtLYD

    Environment

    • macOS
    • Codex CLI 0.157.0
    • Standalone install:
      ~/.local/bin/codex -> ~/.codex/packages/standalone/current/bin/codex
    • Authentication: ChatGPT
    • Model: gpt-6-sol

    Problem

    Even a minimal Codex CLI request repeatedly reconnects and never completes.

    Reproduction:

    cd /tmp
    codex exec --skip-git-repo-check "Reply with only the word OK"

    Result:

    ERROR: Reconnecting... 2/5
    ERROR: Reconnecting... 3/5
    ERROR: Reconnecting... 4/5
    ERROR: Reconnecting... 5/5
    warning: Falling back from WebSockets to HTTPS transport.
    stream disconnected before completion: websocket closed by server before response.completed
    ERROR: Reconnecting... 1/5
    ERROR: Reconnecting... 2/5
    

    I originally encountered this while invoking a local skill, but reproduced it outside the project directory with a one-word prompt.

    Things I've ruled out / tested

    • codex login status reports Logged in using ChatGPT.
    • $OPENAI_API_KEY is unset.
    • Reproduces from /tmp, so it is not specific to my project/repository.
    • Tried --enable skip_host_skill_discovery; problem persists.
    • Tried a custom provider with:
      supports_websockets=false
    • The HTTP-only provider still enters the reconnect loop.
    • Updating Codex leaves me on the current 0.157.0 build.
    • There are skill-context-budget warnings in my setup, but the connection failure reproduces independently with a trivial prompt outside my project.

    Example session IDs:

    01a0dae7-0763-73e1-a470-05eb95572cb3
    01a0dae8-8449-7230-a0d0-ef975ffae1ee
    01a0daeb-4673-7272-b5a8-fc2142b5d532
    01a0daed-bdab-7702-ba8e-44fb60a87958
    01a0daef-74a2-7ad3-b608-ddc3a88b7756
    

    Happy to provide additional diagnostics if useful.

  3. piemvibes-hue commented on Oct 8, 2026

    @piemvibes-hue

    The 5/5 reconnect-exhausted limbo is one of the states my watchdog was built for — after retries are spent the thread just goes quiet mid-turn. agentwatch polls ~/.codex (rollouts + sqlite stores incl. per-turn history), detects the stall/orphaned turn, and resumes the same thread via codex queue (live surface) or codex exec resume (dead thread). Verifies the thread actually resumes work, notifies via ntfy.sh/webhook if it gives up. MIT, zero deps: https://github.com/piemvibes-hue/agentwatch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLITUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal displaybugSomething isn't workingconnectivityIssues involving networking or endpoint connectivity problems (disconnections)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions