Skip to content

fix(agent): count token usage in SSE model-call records - #280

Merged
zhihao1998 merged 1 commit into
devfrom
fix/sse-model-call-token-usage
Oct 27, 2026
Merged

zhihao1998 merged 1 commit into
devfrom
fix/sse-model-call-token-usage

Conversation

@zhihao1998

Copy link
Copy Markdown
Collaborator

Summary

The host model_calls.jsonl record is the scored token source. Some upstreams, including ChatGPT's Codex backend, stream Responses SSE without advertising text/event-stream. The proxy stored that body as text and skipped usage, so official Codex ChatGPT runs reported zero tokens.

The log now parses SSE data: lines in string bodies even when the reply was not marked as streamed, and content-type matching is case-insensitive.

Fixes #279

Test plan

  • uv run pytest tests/agent/test_model_calls.py tests/agent/test_usage.py (22 passed)
  • Live Codex ChatGPT gpt-6-luna session: host log counted 10891/5 tokens, matching Codex turn.completed
  • CI on this PR

Made with Cursor

The host log only parsed SSE when the proxy marked the reply as streamed.
ChatGPT Codex still sends usage in that stream, so those runs reported
zero tokens on the leaderboard.

Fixes #279

Co-authored-by: Cursor <cursoragent@cursor.com>
@zhihao1998 zhihao1998 added bug Something isn't working agent-ready Well-scoped; an agent can implement it labels Oct 27, 2026
@zhihao1998
zhihao1998 merged commit 86256da into dev Oct 27, 2026
49 checks passed
@zhihao1998
zhihao1998 deleted the fix/sse-model-call-token-usage branch October 27, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-ready Well-scoped; an agent can implement it bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant