Repository navigation
Attribute Codex sessions to their model from thread settings - #6478
dalmasluca wants to merge 2 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):
|
|
Heads up: #6603 just landed on The Usage collection now lives in standalone collectors in The upside: adding an agent no longer touches the panel at all. Ship a collector that prints the record contract, optionally add an If you'd like to update this PR to the new structure, rebase on — Claude Fable 5, written on behalf of @dhh |
Pi/omp sessions were attributed to Codex when the api field merely started with 'openai-codex'. A third-party router that serves the same gpt models behind an openai-codex-style api was therefore charged to this subscription and added its buckets to the Codex record. Keep attribution strict to the provider, matching the codex scanner guidance and the Claude collector fix (omacom#6655): only sessions whose provider is exactly 'openai-codex' count. Add a regression test where a third-party-router session using the openai-codex-responses api must not land in the Codex record.
Sessions that never emit turn_context fall into a generic 'codex' bucket. Newer sessions record the model in thread_settings_applied instead (and omit turn_context), while a session may also log token counts before its first model event. Seed the model from the first model-bearing entry in a pre-pass, and follow thread_settings_applied updates during the token scan, so those turns land on the real model. Add a regression test where the model only appears in thread_settings_applied and the first token count precedes it.
47a7f0c to
0fe3590
Compare
|
Reviewed at 0fe3590. The native-session problem this fixes does not reproduce on current Codex, and the new in-loop What was checked. On a disposable Omarchy worker I ran the collector from The defect. Codex emits The test. The new fixture only has one model, so the pre-pass alone satisfies both new assertions; removing the in-loop handler leaves them passing. It cannot catch the case above. If you have sessions that lack On the earlier Copilot comment: the model is at The pi change (attributing by The second opinion was Codex Medium. It agreed that the native-session failure is not shown on current Codex and that the pi change is a policy choice (independence is not guaranteed, since it can read this session's work). It independently found the steered-turn misattribution and the vacuous assertion; I checked both against Codex's source and this branch and reproduced the first on the worker. This is waiting on the author: evidence of the failing session shape, and a rebase. The pi policy question is waiting on the maintainer. |
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