Bug Report: `/compact` Command Fails in Chat Completions API Mode

Resolved 💬 3 comments Opened Aug 18, 2025 by thekoc Closed Aug 25, 2025

What version of Codex is running?

codex-cli 0.22.0

Which model were you using?

gpt-5

What platform is your computer?

_No response_

What steps can reproduce the bug?

  1. Configure a provider with wire_api: chat
  2. Start a conversation with any prompt
  3. Trigger the /compact command
  4. Result: Error message "🖐 stream disconnected before completion: token_usage was None in ResponseEvent::Completed"

What is the expected behavior?

_No response_

What do you see instead?

The /compact command (summarization feature) fails when using the Chat Completions API mode, causing the stream to disconnect and the session to become unresponsive.

Additional information

Possible reason:

  1. Chat parser never populates token usage:

```rust src/chat_completions.rs
// In the Chat SSE parser, Completed events are created with token_usage: None
ResponseEvent::Completed {
response_id: String::new(),
token_usage: None
}


2. **Compact flow requires token usage:**
```rust src/codex.rs
// In drain_to_completed, None token_usage causes an error
match event {
    ResponseEvent::Completed { token_usage } => {
        if let Some(token_usage) = token_usage {
            // Success path...
        } else {
            return Err(CodexErr::Stream(
                "token_usage was None in ResponseEvent::Completed",
                None,
            ));
        }
    }
    // ...
}

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗