Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand.

enum CodexParserHash {
static let value = "cfd84d13ad7d4cfa"
static let value = "5dc8605a458f782f"
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,11 @@ enum CostUsageScanner {
self.turnID = turnID
self.eventIndex = eventIndex
self.timestampUnixMs = timestampUnixMs
self.input = input
self.cached = cached
self.output = output
self.input = max(0, input)
// Clamp cached to not exceed input (toks scale: clamped_cached = min(cached, input))
// prevents inflated totals when malformed JSONL reports more cached than input.
self.cached = min(max(0, cached), max(0, input))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep aggregate and row token counts consistent

When a token_count has cached_input_tokens > input_tokens—the exact malformed case targeted here—the parser's add(...) calls still store the unclamped cached count in usage.days, while this initializer stores a different value in codexRows. codexCanonicalPricingRows then cannot reconcile the row with its aggregate and drops it, so reports still expose the inflated cacheReadTokens from usage.days; they also lose row-only reasoning and can return no cost for priority or authoritative-cost groups. Apply the clamp before both representations are recorded, and cover the scanner-to-report path rather than only constructing this row.

AGENTS.md reference: AGENTS.md:L19-L25

Useful? React with 👍 / 👎.

self.output = max(0, output)
self.reasoning = reasoning.map { min(max(0, $0), max(0, output)) }
self.knownCostNanos = knownCostNanos
self.unpricedTokens = unpricedTokens
Expand Down