Fix Codex model attribution for large turn contexts - #1012
Conversation
|
Additional reproduction note: this was reproduced with CodexBar 0.26.1 / build 63 after clearing the Codex cost cache and refreshing. The affected Codex Desktop subagent logs had |
|
Thanks for the clear repro here. This is the same underlying Codex That fix keeps the retained JSONL prefix for oversized rows, recovers the model from long Closing this PR as superseded by #1014 rather than merging two overlapping branches. Appreciate the detailed reproduction notes. |
Summary
turn_contextlines up to the existing 256 KiB scanner limit instead of truncating them at 32 KiB.turn_contextwhose model metadata must be used for subsequent token rows.Root cause
Codex subagent sessions can write large
turn_contextJSONL lines because the payload includes role instructions, skill context, and other runtime metadata. The Codex cost scanner already allows lines up to 256 KiB, but it only preserved a 32 KiB prefix before parsing.When a
turn_contextline is larger than 32 KiB,CostUsageJsonl.scanmarks it as truncated and the scanner skips the line entirely. If latertoken_countrows do not carry their own model metadata,currentModelis never populated and the row falls back togpt-5.Local reproduction context
I reproduced this with CodexBar 0.26.1 / build 63 on macOS using local Codex Desktop session logs.
Observed environment/details:
CodexBar 0.26.1Codex Desktop0.131.0-alpha.9~/.codex/sessions/2026/05/15/turn_context.payload.modelwasgpt-5.5token_countrows had noinfo.model/info.model_nameturn_contextline was 34,789 bytes, just over the scanner's old 32 KiB prefix limitAfter clearing CodexBar's cost cache and refreshing with 0.26.1, the daily cost cache still bucketed the affected 2026-05-15 subagent usage under
gpt-5:The
gpt-5bucket above came from seven subagent session files whose sourceturn_context.payload.modelwasgpt-5.5. This changes the estimated cost because the affected tokens are priced asgpt-5instead ofgpt-5.5.Fix
Use the existing
maxLineBytesvalue as the preserved prefix for Codex scanner lines. This keeps the current 256 KiB guardrail while allowing large-but-validturn_contextrows to be parsed and used for model attribution.Validation
swift test --filter CostUsageScannerPriorityTestsswift test --filter CostUsageScanner