Attribute Codex sessions to their model from thread settings - #6478
Attribute Codex sessions to their model from thread settings#6478dalmasluca wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Attributes native Codex token usage to session models rather than the generic codex bucket.
Changes:
- Pre-scans sessions for their first model event.
- Handles newer
thread_settings_appliedevents.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Suppressed comments (2)
shell/plugins/model-usage/scripts/codex_usage_scanner.py:212
thread_settings_appliedexposes its model directly on the event payload, but this reads a nestedthread_settings.model. For newer sessions that omitturn_context, the pre-pass therefore keepscurrent_modelascodex, so the generic bucket this PR is intended to remove remains. Readpayload.modelfirst (retaining the nested lookup only as a compatibility fallback).
if payload.get("type") == "thread_settings_applied":
current_model = model_name((payload.get("thread_settings") or {}).get("model") or current_model)
shell/plugins/model-usage/scripts/codex_usage_scanner.py:234
- The normal scan repeats the same incorrect nesting: native
thread_settings_appliedrecords putmodeldirectly inpayload, not underpayload.thread_settings. As written, later model events are ignored and token counts continue to use the seeded or generic model.
if payload.get("type") == "thread_settings_applied":
current_model = model_name((payload.get("thread_settings") or {}).get("model") or current_model)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| # A session may log token counts before its first model event. Read the | ||
| # first model the file records so those early counts land on the real | ||
| # model instead of a generic "codex" bucket. | ||
| with path.open(errors="replace") as handle: |
There was a problem hiding this comment.
Resolved in acc7251. The new rollout-thread.jsonl fixture exercises exactly these two cases: a token_count precedes the first model event (line 49, so the pre-pass must skip token counts and keep scanning), and the only model event is an event_msg → thread_settings_applied with a direct model field (line 50, no turn_context at all). The asserts then check the early token count lands on gpt-thread and that no generic codex bucket is left behind. The same fixture drives the turn_context pre-pass path from the primary rollout, and the pi-router fixture asserts provider-strict filtering (47a7f0c).
|
Addressed the review comment plus a follow-up edge case (commit 47a7f0c):
|
Summary
Fixes the generic
codexmodel bucket incodex_usage_scanner.pyby attributing native Codex session tokens to their real model.Two issues caused tokens to fall into a catch-all
codexbucket:thread_settings_applied(notturn_context), so the model was never picked up.codexmodel, even when the session later revealed its model.Both are fixed: the scanner now reads
thread_settings_applied.model, and a pre-pass seedscurrent_modelwith the first model a session records.Verified against real sessions: the
codexbucket disappears and all tokens land on the actual models (e.g.gpt-5.6-sol,gpt-5.6-terra,gpt-5.6-luna,gpt-5.4...).Notes
Tests