Repository navigation
fix(agent): count token usage in SSE model-call records - #280
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The host
model_calls.jsonlrecord is the scored token source. Some upstreams, including ChatGPT's Codex backend, stream Responses SSE without advertisingtext/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)gpt-6-lunasession: host log counted 10891/5 tokens, matching Codexturn.completedMade with Cursor