Skip to content

stream disconnected before completion: stream closed before response.completed #41340

Open

Description

@njd73

What version of Codex CLI is running?

Codex CLI 0.148.0 (Also reproduced in the VS Code Codex extension)

What subscription do you have?

API Key

Which model were you using?

No response

What platform is your computer?

Linux (Ubuntu 20.04)

What terminal emulator and version are you using (if applicable)?

No response

Codex doctor report

{
  "schemaVersion": 1,
  "generatedAt": "<redacted-timestamp>",
  "overallStatus": "warning",
  "codexVersion": "0.148.0",
  "checks": {
    "app_server.status": {
      "id": "app_server.status",
      "category": "app-server",
      "status": "ok",
      "summary": "background server is not running",
      "details": {
        "control socket": "<redacted-codex-home>/app-server-control/app-server-control.sock",
        "daemon state dir": "<redacted-codex-home>/app-server-daemon",
        "mode": "ephemeral",
        "pid file": "<redacted-codex-home>/app-server-daemon/app-server.pid (missing)",
        "settings": "<redacted-codex-home>/app-server-daemon/settings.json (missing)",
        "status": "not running",
        "update-loop pid file": "<redacted-codex-home>/app-server-daemon/app-server-updater.pid (missing)"
      }
    },
    "auth.credentials": {
      "id": "auth.credentials",
      "category": "auth",
      "status": "ok",
      "summary": "auth is provided by the active model provider",
      "details": {
        "auth file": "<redacted-codex-home>/auth.json",
        "auth storage mode": "File",
        "model provider requires OpenAI auth": "false",
        "provider auth env var": "CUSTOM_PROVIDER_API_KEY (present)"
      }
    },
    "config.load": {
      "id": "config.load",
      "category": "config",
      "status": "ok",
      "summary": "config loaded",
      "details": {
        "CODEX_HOME": "<redacted-codex-home>",
        "config.toml": "<redacted-codex-home>/config.toml",
        "config.toml parse": "ok",
        "cwd": "<redacted-workspace>",
        "enabled feature flags": "<redacted-long-feature-list>",
        "feature flag overrides": "none",
        "feature flags enabled": "40",
        "log dir": "<redacted-codex-home>/log",
        "mcp servers": "0",
        "model": "provider-model-id",
        "model provider": "custom",
        "sqlite home": "<redacted-codex-home>"
      }
    },
    "git.environment": {
      "id": "git.environment",
      "category": "git",
      "status": "ok",
      "summary": "git version 2.50.1",
      "details": {
        ".git entry": "directory",
        "PATH git #1": "/usr/bin/git",
        "PATH git #2": "/bin/git",
        "PATH git entries": "2",
        "git branch": "<redacted-branch>",
        "git build options": "git version 2.50.1; cpu: x86_64; no commit associated with this build; sizeof-long: 8; sizeof-size_t: 8; shell-path: /bin/sh; libcurl: 7.68.0; zlib: 1.2.11; SHA-1: SHA1_DC; SHA-256: SHA256_BLK",
        "git exec path": "/usr/lib/git-core",
        "git version": "git version 2.50.1",
        "repo detected": "true",
        "repo root": "<redacted-workspace>",
        "selected git": "/usr/bin/git"
      }
    },
    "installation": {
      "id": "installation",
      "category": "install",
      "status": "ok",
      "summary": "installation looks consistent",
      "details": {
        "PATH codex #1": "/usr/local/bin/codex",
        "PATH codex #2": "/usr/bin/codex",
        "PATH codex #3": "/bin/codex",
        "PATH codex entries": "3",
        "current executable": "/usr/local/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin/codex",
        "install context": "npm (<redacted-package-paths>)",
        "managed by bun": "false",
        "managed by npm": "true",
        "managed by pnpm": "false",
        "managed package root": "/usr/local/lib/node_modules/@openai/codex",
        "npm update target": "/usr/local/lib/node_modules/@openai/codex"
      }
    },
    "mcp.config": {
      "id": "mcp.config",
      "category": "mcp",
      "status": "ok",
      "summary": "no MCP servers configured",
      "details": {}
    },
    "network.env": {
      "id": "network.env",
      "category": "network",
      "status": "ok",
      "summary": "network-related environment looks readable",
      "details": {
        "proxy env vars present": "HTTP_PROXY, HTTPS_PROXY, NO_PROXY, http_proxy, https_proxy"
      }
    },
    "network.provider_reachability": {
      "id": "network.provider_reachability",
      "category": "reachability",
      "status": "ok",
      "summary": "active provider endpoints are reachable over HTTP",
      "details": {
        "custom provider API base URL": "https://redacted.example/<redacted> reachable (HTTP 470)",
        "custom provider API route probe": "https://redacted.example/<redacted> route exists (HTTP 200)",
        "reachability mode": "provider auth"
      }
    },
    "network.websocket_reachability": {
      "id": "network.websocket_reachability",
      "category": "websocket",
      "status": "ok",
      "summary": "Responses WebSocket is not enabled for the active provider",
      "details": {
        "model provider": "custom",
        "provider name": "Custom OpenAI-Compatible Provider",
        "proxy env vars present": "HTTP_PROXY, HTTPS_PROXY, NO_PROXY, http_proxy, https_proxy",
        "supports websockets": "false",
        "wire API": "responses"
      }
    },
    "runtime.provenance": {
      "id": "runtime.provenance",
      "category": "runtime",
      "status": "ok",
      "summary": "running npm on linux-x86_64",
      "details": {
        "commit": "unknown",
        "current executable": "/usr/local/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/bin/codex",
        "install method": "npm (<redacted-package-paths>)",
        "platform": "linux-x86_64",
        "version": "0.148.0"
      }
    },
    "runtime.search": {
      "id": "runtime.search",
      "category": "search",
      "status": "ok",
      "summary": "search is OK (bundled)",
      "details": {
        "search command": "/usr/local/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex-path/rg",
        "search command readiness": "file exists",
        "search provider": "bundled"
      }
    },
    "sandbox.helpers": {
      "id": "sandbox.helpers",
      "category": "sandbox",
      "status": "ok",
      "summary": "sandbox configuration is readable",
      "details": {
        "approval policy": "OnRequest",
        "codex-linux-sandbox helper": "<redacted-codex-home>/tmp/<redacted>/codex-linux-sandbox",
        "execve wrapper helper": "<redacted-codex-home>/tmp/<redacted>/codex-execve-wrapper",
        "filesystem sandbox": "restricted",
        "network sandbox": "restricted"
      }
    },
    "state.paths": {
      "id": "state.paths",
      "category": "state",
      "status": "ok",
      "summary": "state paths and databases are inspectable",
      "details": {
        "CODEX_HOME": "<redacted-codex-home> (dir)",
        "active rollout files": "28 files, 1292880 total bytes, 46174 average bytes",
        "archived rollout files": "0 files, 0 total bytes, 0 average bytes",
        "goals DB": "<redacted-codex-home>/goals_1.sqlite (file)",
        "goals DB integrity": "ok",
        "log DB": "<redacted-codex-home>/logs_2.sqlite (file)",
        "log DB integrity": "ok",
        "log dir": "<redacted-codex-home>/log (missing)",
        "memories DB": "<redacted-codex-home>/memories_1.sqlite (file)",
        "memories DB integrity": "ok",
        "queue DB": "<redacted-codex-home>/queue_1.sqlite (file)",
        "queue DB integrity": "ok",
        "sqlite home": "<redacted-codex-home> (dir)",
        "state DB": "<redacted-codex-home>/state_5.sqlite (file)",
        "state DB integrity": "ok",
        "thread history DB": "<redacted-codex-home>/thread_history_1.sqlite (file)",
        "thread history DB integrity": "ok"
      }
    },
    "state.rollout_db_parity": {
      "id": "state.rollout_db_parity",
      "category": "threads",
      "status": "warning",
      "summary": "rollout files and state DB thread inventory differ",
      "details": {
        "default model provider": "custom",
        "rollout DB active files": "28",
        "rollout DB active rows": "28",
        "rollout DB archive mismatches": "0",
        "rollout DB archived files": "0",
        "rollout DB archived rows": "0",
        "rollout DB duplicate DB paths": "0",
        "rollout DB duplicate rollout thread ids": "0",
        "rollout DB malformed file names": "0",
        "rollout DB missing active rows": "6",
        "rollout DB missing active sample": [
          "<redacted-codex-home>/sessions/<redacted>/rollout-1.jsonl",
          "<redacted-codex-home>/sessions/<redacted>/rollout-2.jsonl",
          "<redacted-codex-home>/sessions/<redacted>/rollout-3.jsonl",
          "<redacted-codex-home>/sessions/<redacted>/rollout-4.jsonl",
          "<redacted-codex-home>/sessions/<redacted>/rollout-5.jsonl"
        ],
        "rollout DB missing archived rows": "0",
        "rollout DB model providers": "custom=26, openai=2",
        "rollout DB rows": "28",
        "rollout DB scan cap reached": "false",
        "rollout DB scan errors": "0",
        "rollout DB sources": "vscode=26, cli=2",
        "rollout DB stale rows": "0"
      },
      "issues": [
        {
          "severity": "warning",
          "cause": "rollout files are missing from the state DB",
          "measured": "6 active, 0 archived",
          "expected": "every rollout file has a matching threads row",
          "remedy": null,
          "fields": []
        }
      ]
    },
    "system.disk": {
      "id": "system.disk",
      "category": "disk",
      "status": "ok",
      "summary": "sufficient free disk space (1247.6 GiB)",
      "details": {
        "CODEX_HOME available": "1247.6 GiB",
        "failure threshold": "1.0 GiB",
        "warning threshold": "5.0 GiB",
        "worktree available": "1247.6 GiB"
      }
    },
    "system.environment": {
      "id": "system.environment",
      "category": "system",
      "status": "ok",
      "summary": "OS language en-US",
      "details": {
        "EDITOR": "not set",
        "LANG": "en_US.UTF-8",
        "LC_ALL": "en_US.UTF-8",
        "VISUAL": "not set",
        "os": "Ubuntu 20.4.0 (focal) [64-bit]",
        "os language": "en-US",
        "os type": "Ubuntu",
        "os version": "20.4.0"
      }
    },
    "terminal.env": {
      "id": "terminal.env",
      "category": "terminal",
      "status": "warning",
      "summary": "height 14 rows - content may scroll off (recommended >=24)",
      "details": {
        "COLORTERM": "truecolor",
        "SSH_CLIENT": "present",
        "SSH_CONNECTION": "present",
        "TERM_PROGRAM": "vscode",
        "VSCODE_IPC_HOOK_CLI": "present",
        "color output": "enabled",
        "effective locale": "en_US.UTF-8",
        "stderr is terminal": "true",
        "stdin is terminal": "true",
        "stdout is terminal": "true",
        "terminal": "VS Code",
        "terminal size": "92x14",
        "terminal version": "1.135.0"
      },
      "issues": [
        {
          "severity": "warning",
          "cause": "height 14 rows - content may scroll off (recommended >=24)",
          "measured": "92 x 14",
          "expected": ">= 24 rows",
          "remedy": "resize the window to at least 24 rows",
          "fields": [
            "terminal size"
          ]
        }
      ]
    },
    "terminal.title": {
      "id": "terminal.title",
      "category": "title",
      "status": "ok",
      "summary": "terminal title default",
      "details": {
        "terminal title activity": "true",
        "terminal title items": "activity, project-name",
        "terminal title project source": "git repo root",
        "terminal title project value": "<redacted-project>",
        "terminal title source": "default"
      }
    },
    "updates.status": {
      "id": "updates.status",
      "category": "updates",
      "status": "warning",
      "summary": "update configuration is locally consistent",
      "details": {
        "check for update on startup": "true",
        "latest version probe": "curl: (5) Could not resolve proxy: <redacted-proxy>",
        "npm update target": "/usr/local/lib/node_modules/@openai/codex",
        "update action": "npm install -g @openai/codex",
        "version cache": [
          "<redacted-codex-home>/version.json",
          "missing"
        ]
      }
    }
  }
}

What issue are you seeing?

When using Codex with a custom OpenAI-compatible provider configured for the Responses API, Codex fails with:

stream disconnected before completion: stream closed before response.completed

This happens in both:

  • Codex CLI
  • VS Code Codex extension

What steps can reproduce the bug?

  1. Install Codex CLI or the VS Code Codex extension.

  2. Configure Codex to use a custom OpenAI-compatible provider with:

`model_provider = "custom"
model = "provider-model-id"
model_reasoning_effort = "low"

[model_providers.custom]
name = "Custom OpenAI-Compatible Provider"
base_url = "https://redacted.example/v1"
env_key = "PROVIDER_API_KEY"
requires_openai_auth = false
wire_api = "responses"
supports_websockets = false`

  1. Start a new Codex session and send a prompt.

Codex fails with:

stream disconnected before completion: stream closed before response.completed

What is the expected behavior?

Codex should complete normally against the provider.

Additional information

I am using a custom OpenAI-compatible /responses provider (not the default OpenAI-hosted endpoint).

I verified outside Codex that the provider works correctly with direct streamed POST /responses calls, including:

  • basic streaming text responses
  • response.completed
  • follow-on turns using previous_response_id
  • reasoning continuity via include: ["reasoning.encrypted_content"]
  • request bodies including instructions, reasoning, store, metadata, tool_choice, tools, text, temperature, top_p, top_logprobs, truncation, and background
  • actual function tool-call lifecycle
  • extra session-like headers and client_metadata

Those direct API calls all succeed, but Codex still fails with the stream-disconnected error.

Because the provider successfully handles a near-Codex-equivalent Responses request shape via direct SSE calls, the remaining issue appears more likely to be:

  • Codex-specific headers not reproduced yet, or
  • a Codex runtime/session/stream parsing bug with custom OpenAI-compatible providers

Direct SSE testing shows that the provider emits several valid completion patterns:

  • assistant-message turns
  • reasoning-item-then-message turns
  • tool-call-only turns ending in response.completed

All of these complete successfully via direct curl. This suggests Codex may be mishandling one of these valid streamed output-item patterns rather than the provider failing to emit response.completed.

In one successful direct test, the stream emitted a function-call item, function-call arguments events, response.output_item.done, and then response.completed, with no final assistant text message. If Codex assumes successful turns always end with an assistant message, that could explain the disconnect error.

This may be related to prior Codex issues around stream disconnected before completion on the Responses path (for example #20739), but my case differs because I can reproduce the failure against a custom OpenAI-compatible provider while equivalent direct streamed /responses curl calls complete successfully with response.completed.

Activity

  1. added
    bug
    on Aug 28, 2026
  2. added
    CLI
    extension
    custom-model
    connectivity
    on Aug 28, 2026
  3. behinddwalls commented on Oct 6, 2026

    @behinddwalls

    I’m also seeing this repeatedly in Codex desktop on macOS, using a custom OpenAI-compatible provider configured with wire_api = "responses". It became frequent after I switched to 6.1 Sol (provider model ID: gpt-6.1-sol).

    Environment

    • Codex desktop: 26.930.21537, build 12776
    • Current desktop session runtime reports: 0.159.0-alpha.12.1
    • macOS 26.7.1, Apple Silicon (arm64)
    • Organization-managed custom Responses API provider, not the default OpenAI-hosted endpoint

    What the session history shows

    On October 5–6, 2026, the retained runtime logs contain 54 retry warnings for gpt-6.1-sol, spanning 8 turns across 5 threads:

    Reasoning effort Matching retry warnings
    Medium 22
    High 32

    These are retry-warning counts, not 54 independently failed turns.

    Separately, the session history records 6 turns that ultimately failed with this exact error:

    stream disconnected before completion: stream closed before response.completed
    

    All six terminal failures were at medium reasoning. In one conversation, four successive turns failed; two were simply “try again” follow-ups. High reasoning also suffers repeated disconnects: one turn logged 22 matching retry warnings over approximately 14 minutes, although it eventually completed.

    Sanitized examples from October 6 (PDT):

    11:09:39 — model=gpt-6.1-sol reasoning_effort=medium
    stream disconnected - retrying sampling request (5/5 in 3.304s)...
    sampling_error=stream disconnected before completion: stream closed before response.completed
    
    14:05:36 — model=gpt-6.1-sol reasoning_effort=high
    stream disconnected - retrying sampling request (5/5 in 3.362s)...
    sampling_error=stream disconnected before completion: stream closed before response.completed
    

    Changing reasoning effort therefore has not eliminated the problem. Automatic retries sometimes recover, but other turns fail completely, and manually retrying can fail again.

    One qualification: the retained logs also contain one matching retry warning on gpt-6-luna at medium reasoning, in a turn that subsequently completed. So I’m reporting a strong correlation with my switch to 6.1 Sol, not claiming the error is exclusive to that model.

    I have not captured the raw Responses stream or reproduced the direct-curl tests described above, so I cannot yet distinguish provider-side premature stream termination from Codex-side stream handling. What targeted diagnostics would help distinguish those cases?

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

    CLIbugconnectivitycustom-modelextension

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions