openai / openai/codex

stream disconnected before completion: stream closed before response.completed

Open
#41,340 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug CLI connectivity custom-model extension
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the stream disconnect with Codex CLI 0.148.0 against the custom OpenAI-compatible provider described in the report, then trace the Responses API stream termination handling. Done means a valid stream no longer ends with “stream closed before response.completed,” including when used through the VS Code Codex extension.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, cli, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.