bug: codex "cannot parse json" and "cannot iterate over a consumed stream" errors
What version of Codex is running?
0.1.2504221401
Which model were you using?
o4-mini
What platform is your computer?
darwin | arm64 | 24.5.0
What steps can reproduce the bug?
Repro Steps
- Start codex cli
codex - Type in anything at all (full messages, to just "hi" with no spaces or other chars)
- Press enter
Variant
- Typing any slash command DOES work
What is the expected behavior?
In my first attempts I was giving directions to provide context and would have expected that I would get a reply telling me to that in some form. Later I was just typing "hello" or "hi" and would have just expected one of the canned responses about "I'm here to help" or whatever.
What do you see instead?
Minified error outputs. The 1 I captured is below and has an error from the subject of this issue in it. I also included a bit above so that you can see the prompt and that I had just cleared it in case any artifacts were causing the issue. Hope it helps 😄
system
Terminal cleared
system
Invalid command "/c". Use /help to retrieve the list of commands.
system
Command history cleared
user
hello
╭──────────────────────────────────────────────────────────────────────────────────────────────╮
│( ● ) 0s Thinking. │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
send q or ctrl+c to exit | send "/clear" to reset | send "/help" for commands | press enter
to send | shift+enter for new line — 100% context left
file:///usr/local/lib/node_modules/@openai/codex/dist/cli.js:475
`,"\r"]);Kg.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function xke(e,t){for(let a=t??0;a<e.length;a++){if(e[a]===10)return{preceding:a,index:a+1,carriage:!1};if(e[a]===13)return{preceding:a,index:a+1,carriage:!0}}return null}function wse(e){for(let n=0;n<e.length-1;n++){if(e[n]===10&&e[n+1]===10||e[n]===13&&e[n+1]===13)return n+2;if(e[n]===13&&e[n+1]===10&&n+3<e.length&&e[n+2]===13&&e[n+3]===10)return n+4}return-1}m();function L7(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let r=await t.read();return r?.done&&t.releaseLock(),r}catch(r){throw t.releaseLock(),r}},async return(){let r=t.cancel();return t.releaseLock(),await r,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}var xd=class e{constructor(t,r){this.iterator=t,this.controller=r}static fromSSEResponse(t,r){let n=!1;async function*a(){if(n)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let i=!1;try{for await(let o of Oke(t,r))if(!i){if(o.data.startsWith("[DONE]")){i=!0;continue}if(o.event===null||o.event.startsWith("response.")||o.event.startsWith("transcript.")){let c;try{c=JSON.parse(o.data)}catch(d){throw console.error("Could not parse message into JSON:",o.data),console.error("From chunk:",o.raw),d}if(c&&c.error)throw new Si(void 0,c.error,void 0,P7(t.headers));yield c}else{let c;try{c=JSON.parse(o.data)}catch(d){throw console.error("Could not parse message into JSON:",o.data),console.error("From chunk:",o.raw),d}if(o.event=="error")throw new Si(void 0,c.error,c.message,void 0);yield{event:o.event,data:c}}}i=!0}catch(o){if(o instanceof Error&&o.name==="AbortError")return;throw o}finally{i||r.abort()}}return new e(a,r)}static fromReadableStream(t,r){let n=!1;async function*a(){let o=new Kg,c=L7(t);for await(let d of c)for(let f of o.decode(d))yield f;for(let d of o.flush())yield d}async function*i(){if(n)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let o=!1;try{for await(let c of a())o||c&&(yield JSON.parse(c));o=!0}catch(c){if(c instanceof Error&&c.name==="AbortError")return;throw c}finally{o||r.abort()}}return new e(i,r)}[Symbol.asyncIterator](){return this.iterator()}tee(){let t=[],r=[],n=this.iterator(),a=i=>({next:()=>{if(i.length===0){let o=n.next();t.push(o),r.push(o)}return i.shift()}});return[new e(()=>a(t),this.controller),new e(()=>a(r),this.controller)]}toReadableStream(){let t=this,r,n=new TextEncoder;return new bO({async start(){r=t[Symbol.asyncIterator]()},async pull(a){try{let{value:i,done:o}=await r.next();if(o)return a.close();let c=n.encode(JSON.stringify(i)+`
e [Error]: An error occurred while processing your request. You can retry your request, or contact us through our help center at help.openai.com if the error persists. Please include the request ID req_b22710fd458b0aae502efe78a66d3ae7 in your message.
at e.a [as iterator] (file:///usr/local/lib/node_modules/@openai/codex/dist/cli.js:475:1514)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async fE.run (file:///usr/local/lib/node_modules/@openai/codex/dist/cli.js:492:2763) {
status: undefined,
headers: undefined,
request_id: undefined,
error: {
type: 'server_error',
code: 'server_error',
message: 'An error occurred while processing your request. You can retry your request, or contact us through our help center at help.openai.com if the error persists. Please include the request ID req_b22710fd458b0aae502efe78a66d3ae7 in your message.',
param: null
},
code: 'server_error',
param: null,
type: 'server_error'
}
Node.js v22.15.0
Additional information
I also found the session file for the command above. You can see the invalid command thing when I typed /c and <tab> for completion on the clear command. I still see the issue when I don't use completion however.
{
"session": {
"timestamp": "2025-04-23T23:12:53.246Z",
"id": "567de520-f50d-4a0b-a9f0-e50c9315b280",
"instructions": ""
},
"items": [
{
"id": "clear-1745449966837",
"type": "message",
"role": "system",
"content": [
{
"type": "input_text",
"text": "Terminal cleared"
}
]
},
{
"id": "invalidcommand-1745449970271",
"type": "message",
"role": "system",
"content": [
{
"type": "input_text",
"text": "Invalid command \"/c\". Use /help to retrieve the list of commands."
}
]
},
{
"id": "clearhistory-1745449970284",
"type": "message",
"role": "system",
"content": [
{
"type": "input_text",
"text": "Command history cleared"
}
]
},
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "hello"
}
],
"type": "message"
}
]
}
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗