feat(exec): emit rate_limits in exec mode JSONL output

Resolved 💬 1 comment Opened Mar 15, 2026 by tsubasa2830505 Closed May 16, 2026

Summary

codex exec mode always yields rate_limits: null in rollout JSONL and in TokenCount events, making it impossible to display real-time usage percentages in tooling (e.g., VS Code status bar extensions).

The latest source code in codex-rs/exec/src/event_processor_with_jsonl_output.rs (L156-167) already handles RateLimitsUpdated correctly — it checks ev.rate_limits and emits ThreadEvent::RateLimitsUpdated when present. However, ev.rate_limits is always None at runtime in exec mode.

Root Cause Analysis

I traced the data flow through the source:

  1. HTTP headers parsedcodex-rs/codex-api/src/rate_limits.rs parses x-codex-primary-used-percent, x-codex-secondary-used-percent, etc. into RateLimitSnapshot
  2. Event emittedResponseEvent::RateLimits(snapshot) is sent to the event stream
  3. State storedSessionState.latest_rate_limits is set via set_rate_limits() in codex-rs/core/src/state/session.rs:117
  4. TokenCountEvent createdsend_token_count_event() in codex-rs/core/src/codex.rs:3718 reads state.token_info_and_rate_limits() and populates TokenCountEvent { info, rate_limits }
  5. Exec handler readyevent_processor_with_jsonl_output.rs:160 checks if let Some(rate_limits) = ev.rate_limits.clone() and emits ThreadEvent::RateLimitsUpdated

But ev.rate_limits is always None.

Two possible causes:

  • (A) The API server does not send x-codex-* response headers for exec-mode sessions (different from vscode/app-server mode)
  • (B) The npm-published binary (v0.114.0) predates the RateLimitsUpdated handler code

Evidence

Rollout JSONL from exec mode (v0.114.0, 2026-03-15):

{
  "type": "event_msg",
  "payload": {
    "type": "token_count",
    "info": { "total_token_usage": { "input_tokens": 12065, "output_tokens": 3253, "total_tokens": 15318 } },
    "rate_limits": null
  }
}

Rollout JSONL from vscode mode (2025-10-16, via ChatGPT Cursor extension):

{
  "type": "event_msg",
  "payload": {
    "type": "token_count",
    "info": null,
    "rate_limits": {
      "primary": { "used_percent": 0.0, "window_minutes": 299, "resets_in_seconds": 17940 },
      "secondary": { "used_percent": 6.0, "window_minutes": 10079, "resets_in_seconds": 275281 }
    }
  }
}

Request

  1. Confirm whether the API intentionally omits x-codex-* headers for exec-mode sessions
  2. If intentional, add an alternative mechanism (e.g., a --show-rate-limits flag or a codex usage subcommand) to retrieve current rate limit status
  3. If unintentional, ensure parity so exec mode receives the same x-codex-* headers as vscode mode

Use Case

I'm building a VS Code status bar extension that displays Codex usage (session count, token consumption, rate limit %). Currently limited to SQLite-based estimates because exec mode provides no real rate_limits data. Having the actual used_percent from OpenAI would make the display accurate.

Environment

  • Codex CLI: v0.114.0 (npm i -g @openai/codex)
  • Plan: ChatGPT Team
  • Platform: macOS (Apple Silicon)
  • Source ref: event_processor_with_jsonl_output.rs L156-167

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗