codex icon indicating copy to clipboard operation
codex copied to clipboard

Bug when I send a first message "stream error: ..."

Open dam62500 opened this issue 1 year ago • 65 comments

What version of Codex is running?

0.3.0

Which model were you using?

codex-mini-latest

What platform is your computer?

MacOS

What steps can reproduce the bug?

1 ) codex login 2 ) codex 3 ) type prompt -> enter

What is the expected behavior?

send "Hello" Expect to get "Hello" from Codex Mini

What do you see instead?

user say "hello"

event BackgroundEvent(BackgroundEventEvent { message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 1/10 in 191ms…" })

event BackgroundEvent(BackgroundEventEvent { message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 2/10 in 239ms…" })

event BackgroundEvent(BackgroundEventEvent { message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 3/10 in 362ms…" })

event BackgroundEvent(BackgroundEventEvent { message: "stream error: stream disconnected before completion: stream closed before response.completed; retrying 4/10 in 461ms…" })

Additional information

No response

dam62500 avatar Jul 08 '25 09:07 dam62500

  • workdir: /home/dflandrin/PhpstormProjects/test-codex-cli
  • model: codex-mini-latest
  • provider: openai
  • approval: UnlessTrusted
  • sandbox: read-only
  • reasoning effort: medium
  • reasoning summaries: auto

dam62500 avatar Jul 08 '25 09:07 dam62500

Same problem for me. This happened when I updates to v0.3. node v22.17.0 ubuntu 24.04

aristoHero avatar Jul 08 '25 11:07 aristoHero

hey @dam62500 , what is your Node.js version?

yusuf-eren avatar Jul 08 '25 12:07 yusuf-eren

@yusuf-eren node v18.16.0 on Mac ( 2019 / Intel ) Don't work too with Windows 11, node v20.18.0. ( same problem )

dam62500 avatar Jul 08 '25 12:07 dam62500

Same, with node v20.13.1 on mac

GiladR1979 avatar Jul 08 '25 12:07 GiladR1979

I tested it on v18.16.0, v20.18.3, v22.16.0. Also tried uninstalling and clean installing via brew install codex, but still couldn't reproduce the bug.

Are you using a config.toml file? It should be located at ~/.codex/config.toml
See: config docs

If so, could you share its contents?

yusuf-eren avatar Jul 08 '25 12:07 yusuf-eren

Same issue. Same version and OS

LiutongZhou avatar Jul 08 '25 14:07 LiutongZhou

Having the same issue on MacOS / Darwin 24.3.0. No config.toml exists, just the auth.json,

It looks like this error is actually being triggered from submission of the (initial internally-generated) API Key creation request, NOT the user specified prompt. So this probably won't occur if you are connected to an Organisation with an existing API key, I would recommend testing if the issue is reproducable from a fresh OpenAI account - perhaps at least a fresh Org.

Sample from the codex-tui.log file:

2025-07-08T18:24:14.288188Z INFO Configuring session: model=codex-mini-latest; provider=ModelProviderInfo { name: "OpenAI", base_url: "https://api.openai.com/v1", env_key: Some("OPENAI_API_KEY"), env_key_instructions: Some("Create an API key (https://platform.openai.com) and export it as an environment variable."), wire_api: Responses, query_params: None, http_headers: Some({"version": "0.3.0", "originator": "codex_cli_rs"}), env_http_headers: Some({"OpenAI-Organization": "OPENAI_ORGANIZATION", "OpenAI-Project": "OPENAI_PROJECT"}) } 2025-07-08T18:24:16.099177Z WARN stream disconnected - retrying turn (1/10 in 211ms)... 2025-07-08T18:24:17.657017Z WARN stream disconnected - retrying turn (2/10 in 276ms)... 2025-07-08T18:24:19.706377Z WARN stream disconnected - retrying turn (3/10 in 364ms)... 2025-07-08T18:24:21.013135Z WARN stream disconnected - retrying turn (4/10 in 471ms)... 2025-07-08T18:24:22.278961Z WARN stream disconnected - retrying turn (5/10 in 544ms)... 2025-07-08T18:24:23.432097Z WARN stream disconnected - retrying turn (6/10 in 808ms)... 2025-07-08T18:24:24.947856Z WARN stream disconnected - retrying turn (7/10 in 1.052s)... 2025-07-08T18:24:26.719088Z WARN stream disconnected - retrying turn (8/10 in 1.358s)... 2025-07-08T18:24:28.690865Z WARN stream disconnected - retrying turn (9/10 in 1.591s)... 2025-07-08T18:24:32.318628Z WARN stream disconnected - retrying turn (10/10 in 2.221s)... 2025-07-08T18:24:35.114276Z INFO Turn error: stream disconnected before completion: stream closed before response.completed

Enderboi avatar Jul 08 '25 18:07 Enderboi

same here

PiotrKlimczak avatar Jul 08 '25 21:07 PiotrKlimczak

same

bNTyARH1NeSTX avatar Jul 08 '25 21:07 bNTyARH1NeSTX

I have the same issue node: v22.7.0, Ubuntu 24. I didn't have config.toml, so I created one according to the docs. This is what I have currently:

model_provider = "openai"
model = "gpt-3.5-turbo"
http_headers = { }

[model_providers.openai]
name = "OpenAI"
base_url = "https://api.openai.com/v1"
env_key = "OPENAI_API_KEY"

but nothing changed. It is essencially the same as gpt-4 and the codex-mini:

2025-07-08T21:56:43.069851Z  INFO Configuring session: model=gpt-4; provider=ModelProviderInfo { name: "OpenAI", base_url: "https://api.openai.com/v1", env_key: Some("OPENAI_API_KEY"), env_key_instructions: Some("Create an API key (https://platform.openai.com) and export it as an environment variable."), wire_api: Responses, query_params: None, http_headers: Some({"version": "0.3.0", "originator": "codex_cli_rs"}), env_http_headers: Some({"OpenAI-Project": "OPENAI_PROJECT", "OpenAI-Organization": "OPENAI_ORGANIZATION"}) }
2025-07-08T21:56:54.875488Z  WARN stream disconnected - retrying turn (1/10 in 184ms)...
2025-07-08T21:56:55.886712Z  WARN stream disconnected - retrying turn (2/10 in 241ms)...
2025-07-08T21:56:56.441631Z  WARN stream disconnected - retrying turn (3/10 in 361ms)...
2025-07-08T21:56:57.123050Z  WARN stream disconnected - retrying turn (4/10 in 444ms)...
2025-07-08T21:56:58.573299Z  WARN stream disconnected - retrying turn (5/10 in 623ms)...
2025-07-08T21:56:59.483054Z  WARN stream disconnected - retrying turn (6/10 in 788ms)...
2025-07-08T21:57:00.572255Z  WARN stream disconnected - retrying turn (7/10 in 924ms)...
2025-07-08T21:57:01.801383Z  WARN stream disconnected - retrying turn (8/10 in 1.308s)...
2025-07-08T21:57:03.393756Z  WARN stream disconnected - retrying turn (9/10 in 1.772s)...
2025-07-08T21:57:05.435836Z  WARN stream disconnected - retrying turn (10/10 in 2.248s)...
2025-07-08T21:57:07.963374Z  INFO Turn error: stream disconnected before completion: stream closed before response.completed

jkbrlw avatar Jul 08 '25 22:07 jkbrlw

still unresolved?

jagcardenas avatar Jul 08 '25 22:07 jagcardenas

I also get the same error. I'll show you the scenarios I tried below

1.npm install -g @openai/codex
2.codex login
3.codex
4.'hello world'
5.stream error: stream disconnected before completion: stream closed before response.completed

devMtn30 avatar Jul 09 '25 04:07 devMtn30

same

yonathanarbel avatar Jul 09 '25 05:07 yonathanarbel

same

weiting-tw avatar Jul 09 '25 08:07 weiting-tw

I also get the same error. I'll show you the scenarios I tried below

1.npm install -g @openai/codex
2.codex login
3.codex
4.'hello world'
5.stream error: stream disconnected before completion: stream closed before response.completed

I found that the following message was displayed after codex login: Sorry, your subscription must be active for more than 7 days to redeem credits.

devMtn30 avatar Jul 09 '25 08:07 devMtn30

I also encountered this issue on a newly created platform account, linking it to a longstanding ChatGPT identity. I suspect the CLI is failing on the attempt to redeem free credit on Pro/Plus accounts. Likely on the 7 day minimum account age check.

When I switched the CLI to use an older API key on another account, it started working.

cammymcp avatar Jul 09 '25 09:07 cammymcp

Well it turns out I only needed to put something in my Organization Balance for it to work.

GiladR1979 avatar Jul 09 '25 10:07 GiladR1979

Well it turns out I only needed to put something in my Organization Balance for it to work.

I tried adding money to my organization balance and this did not resolve for me.

timsehn avatar Jul 09 '25 16:07 timsehn

I also generated a new key, not using codex login and tried setting OPENAI_API_KEY to that. It still resulted in the stream error on first prompt.

timsehn avatar Jul 09 '25 17:07 timsehn