🧾 parse: expand usage.iterations into per-model attempt rows - #487
Merged
Conversation
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
Closes #456.
Billed
usage.iterationsentries served by a different model than the turn's — refused fallback attempts and cross-model advisor calls — were silently folded into the serving model's totals. This PR expands informative iterations at parse time into per-model attempt rows (message_idkeyed<id>:it:<idx>), so every aggregation surface (models panel, projects, buckets,Recost) attributes tokens and cost to the model that actually consumed them.🔧 What changed
pkg/parse— newexpandIterations+toMessages: own-model entries fold into the parent (iterations are authoritative when informative — also repairs the rare near-zeroed/under-reported outer usage), each non-zero foreign entry becomes an attempt row inheriting the full envelope. Fail-open paths (undecodable blob, oversized probe, missingmessage.id) keep today's behavior byte-for-byte.ParseWithErrors) and the incremental tail path (ParseFromOffsetWithErrors) that the indexer/watcher actually use. The tail path was initially missed and caught by the real-data differential below; a regression test now pins it.pkg/cache—SchemaVersion"11"→"12"with zero schema-text changes: the bump only forces the wipe-and-rebuild that backfills attempt rows from historic JSONL on first launch. Quota history (usage_samples/usage_limits) survives, as pinned by the new migration test.InsertMessagesidempotently, redistribute inModelAggregates, and re-price against their own model's rate inRecost— all with no SQL changes (design claim held on first run).📊 Real-data differential (live JSONL, ts < 2026-08-06T07:00Z)
Baseline binary (pre-change) vs this branch, both cold-indexing the same tree:
cache_write_5mrepaired on 17 informative parentsTotals: 124,970 → 124,993 rows (+23 attempt rows, matching the 40 informative turns on this machine), +2,807,877 tokens, +$35.95 — previously misattributed or invisible.
✅ Testing
go test ./...— all packages passmake lint— 0 issuesindex --rebuilddifferential above; cost-only movers individually verified as informative-turn parents with repaired cache columns📣 Surface changes (for release notes batching)
messagesrows keyed<id>:it:<idx>; per-model totals shift accordingly.🤖 Generated with Claude Code