Repository navigation
feat(models): carry the billing route on the call; key every model row on it - #1448
Conversation
fbe3049 to
4c5591a
Compare
iamtoruk
left a comment
There was a problem hiding this comment.
Thanks. Direction is fine, mechanism is not yet.
Seeded three Claude sessions on one machine: direct, anthropic.claude-haiku-4-5-20251001-v1:0, and us.anthropic.claude-haiku-4-5-20251001-v1:0. codeburn models prints two rows both called Haiku 4.5 (Bedrock), $1.65 and $1.50, with nothing to tell them apart. status --format menubar-json prints one row at $3.15. Before this PR both surfaces showed three distinct rows. So "every Bedrock spelling folds to one row" and "desktop and codeburn models agree without further work" are not true: models-report keys on resolveCanonicalModelId, everything else keys on getShortModelName.
The merged row is also the thing you cite #1053 against. us. prices 10% above the bare id. Blending them under one label is two SKUs in one row.
The id shapes you can show on disk are <vendor>.<model> and -v1:0. #1449 says Claude Code drops the profile prefix. So drop the ARN regex, the bedrock/ prefix, the :300k tag, and cut the vendor table to what you have sessions for. Stability and TwelveLabs do not write coding transcripts.
The looksLikeLocalModel fix is right and is the only bug in here. It does not need the route machinery; -v\d+:\d+$ is a version, not a tag. Happy to take that on its own today as a separate small PR.
On the rest: a display suffix puts billing into a string that three surfaces key differently. Put the route on the call as a field first, then render it. That is #1450. Land that shape, and this becomes small.
One correction for later: the daily cache stores the display key, not raw ids. No bump is needed here only because getShortModelName is idempotent and the old key happened to be the raw id. Do not carry that assumption into #1450.
Checked: 46 adversarial ids incl. Vertex, Azure, OpenRouter and Ollama tags, zero misclassified; direct ids unchanged; pricing still on the full id; OTLP wire untouched; tsc clean; 4,126 tests pass.
|
Reproduced with three seeded Claude sessions (direct, Taking your split:
Thanks for the adversarial-id pass. |
…w on it The same model billed through a different door is a different invoice, and the door decides whether the spend is metered. Claude Code and Codex on fixed-fee plans plus API usage on top (Bedrock, OpenRouter) is one machine's month; "how much of it was metered?" had no answer because every surface keyed model rows on the display name alone, and the surfaces did not even agree on that key: models-report folded on resolveCanonicalModelId, the rest on getShortModelName. getagentseal#1448's first cut changed one of them and shipped two same-label rows in `models` next to one blended row in the menubar. Route as a field, one row key: - `ParsedProviderCall.route` / `.billing`, threaded through ParsedApiCall and CachedCall (validator, four spread sites). Two sources feed it: the model id when the door renames the model (`getModelRoute`: Bedrock `<vendor>.<model>[-vN:M]`, optional `us.`/`eu.`/`global.` profile prefix, vendors anthropic/openai — the shapes on disk, nothing wider), and the provider's own column when it does not (`routeFromProviderField`: Hermes `billing_provider` bedrock / bedrock-mantle / openrouter, incl. path and colon spellings). Direct doors map to no route: the unsuffixed row is the direct row. - `modelRowKey(model, route)`: short name plus the door label. A cross-region profile is a dearer SKU and keeps its own row, "(Bedrock us)" (getagentseal#1053). Idempotent, so a display-keyed daily row re-keys to itself. Called from parser.ts modelBreakdown, day-aggregator (day and slice models), usage-aggregator, menubar-json, model-breakdown, models-report (fold on canonical id + route; `route` on the row and in JSON), session-output, model-efficiency, overview, sessions-report, telemetry-snapshot, compare-cohorts, compare-stats, live-sessions. - Hermes forwards billing_provider -> route and cost_status -> billing: `included` is subscription, `actual` or a metered door is metered, an `unknown` direct session asserts neither (Claude Max and an API key look the same to Hermes). Parse version `billing-route-v1` re-parses once. - DAILY_CACHE_VERSION 32 -> 33: day.models keyed by the row key, so a column-sourced route survives into the finalized day; hermes joins the pending-rederive table at 33. Pricing is untouched: getModelCosts runs on the raw id. getShortModelName is untouched. Tests: model-routes (id shape, column, key, idempotence, no dollar moves); hermes route/billing per billing_provider x cost_status; day-aggregator v33 keys incl. a column-sourced route; cli-route-surfaces runs the real CLI over the three sessions the getagentseal#1448 review seeded and asserts models, menubar current + history, and the daily cache carry the same three rows at the prices main showed. Closes getagentseal#1450
4c5591a to
d5d6a91
Compare
|
Reworked in place per the review: the route is now a field on the call ( |
iamtoruk
left a comment
There was a problem hiding this comment.
Numbers check out. On a copy of my real cache, all 142 finalized days match main to the twelfth decimal, 272,985 calls both sides, $37,898.85 both sides. Only today moves, and it moves in both directions between two main runs, so that is drift. Cold rederive costs 3.3 s once.
One thing to know: preserved-from-expired-logs goes from $23,554.65 to $24,839.95. Two days, 15 and 16 Aug, flip to carried, same cost and calls on both sides. I bumped DAILY_CACHE_VERSION to 33 on main with none of your code and got the identical $24,839.95, so it is the version bump, not you. Nothing lost.
The three seeded sessions now agree on models, the menubar payload, the daily cache, overview, sessions, telemetry, live sessions and compare, at the prices main showed. That is what I asked for.
One defect left, and it is the one I rejected the first time in a narrower form. bedrock and bedrock-mantle are two route ids with one label. models-report folds on the route id, everything else keys on the label. A Hermes user with both doors for one model gets two rows in models both called GPT-5.6 Sol (Bedrock) with nothing to tell them apart, and one merged row in the menubar. Reproduced through aggregateModels. Fold on the row key, not the route id.
Two cuts while you are in there. billing has no readers at all, so hold it for #1451 with the rest. Drop openrouter and bedrock-mantle until someone has sessions, the same way the id shapes went last time. Also granular-history still keys on the raw id, so the desktop timeline will be the only surface disagreeing; fine to leave, but say so in the body.
Rest is verified: 4,163 tests, locks 36, tsc clean, merges clean.
… and the routes without sessions
# Conflicts: # CHANGELOG.md # src/providers/hermes.ts
|
Applied all four. The fold in models-report now keys on the row key, not the route id: the identity is the alias-resolved id plus the row key's own door suffix, so two route ids that render one label land on one row.
Also cut an unrelated line in telemetry-snapshot that the rework had touched. Real cache, 496 MB copy, main vs branch: all 142 finalized days match, $37,898.851498 and 272,985 calls on both sides, 38 lifetime model rows identical in name and cost. Only today moves, and it moves between two consecutive main runs too. No Bedrock or column-sourced route exists in that cache, so nothing folded or renamed there. The menubar history rows the v33 bump re-derives — stale v32 days written before Grok Bot landed — match main with only DAILY_CACHE_VERSION bumped and none of this code, 0 day mismatches. 4203 tests, locks 36, tsc clean, main merged. |
Conflicts kept both sides: menubar buildTopModels merges on modelRowKey (getagentseal#1448) while staying uncapped and carrying per-model counts; Overview.tsx keeps main's chart bucketing next to the topModels-sourced model table; usage-aggregator takes both import sets; snapshot render version renumbered to 9 over main's v8 (streak/periodTotals), with the changelog revisions updated to match.
Summary
Closes #1449, closes #1450. Reworked in place after the reviews below: the route is a field on the call first, rendered second, with one row key across every surface. Series: this → #1451 (
--routefilters, payload fields, "By billing" grouping, and the per-callmetered/subscriptionsplit).ParsedProviderCall.route, threaded throughParsedApiCallandCachedCall. Two sources feed it: the model id when the door renames the model (getModelRoute— Bedrock's<vendor>.<model>[-vN:M]with an optionalus./eu./global.profile prefix, vendorsanthropicandopenaionly, the shapes on disk and nothing wider), and the provider's own column when it does not (routeFromProviderField— Hermesbilling_provider). Direct doors map to no route: the unsuffixed row is the direct row.modelRowKey(model, route)= short name + door label. The cross-region profile is a dearer SKU and keeps its own row,(Bedrock us)(fix(models): resolve and merge raw ids in models report #1053). Idempotent, so a display-keyed daily row re-keys to itself. Called from every site that used to key or label rows its own way —parser.tsmodelBreakdown,day-aggregator(day and provider-slice models),usage-aggregator,menubar-json,model-breakdown,models-report,session-output,model-efficiency,overview,sessions-report,telemetry-snapshot,compare-cohorts,compare-stats,live-sessions.getShortModelNameis untouched.models-reportfolds on the row key, not the route id. The fold identity is the alias-resolved id plus the row key's own door suffix (modelFoldKey). Two route ids that render one label — one door with two endpoint names — therefore land on one row instead of two rows the reader cannot tell apart, which is what the second review caught.day.modelsis keyed by the row key, so a column-sourced route survives into the finalized day (the raw id alone cannot carry it).hermesjoinsPENDING_REDERIVE_PROVIDER_VERSIONSat 33; ladder entry added. Parse versionbilling-route-v1re-parses cached Hermes sessions once.getModelCostsruns on the raw id.Registered routes:
bedrockonly.openrouterandbedrock-mantleare real Hermesbilling_providervalues, but nobody has sessions for them yet, so they are held back under the same rule the id shapes were cut by last round. They map to no route today, exactly like an unknown door.One surface deliberately disagrees.
granular-history.tsstill keys its buckets on the raw model id, so the desktop Trend timeline is the only place where a Bedrock id and its direct sibling are not named the way every other surface names them. Left as is; noted here so it is a known gap and not a surprise.Why this shape
On the first review: the first cut put the route in a display string that three surfaces keyed differently (
models-reportonresolveCanonicalModelId, the rest ongetShortModelName) and shipped two same-label rows next to one blended row. This PR makes the route a field first and gives every surface one key function. On the second review: folding on the route id reintroduced the twin-row defect in a narrower form, so the fold now carries the row key's suffix and never the id.Testing
npm test— 4203 passed / 5 skipped;npm run test:locks(36);npx tsc --noEmitclean;npm run buildmain; no conflicts leftThe test the first cut lacked.
tests/cli-route-surfaces.test.tsruns the real CLI (tsx src/cli.ts) over the three Claude sessions the review seeded — direct,anthropic.…-v1:0,us.anthropic.…-v1:0— and assertsmodels --format json,status --format menubar-json(current.topModelsandhistory.daily[].topModels) and the on-diskdaily-cache.v33.jsoncarry the same three rows:Haiku 4.5,Haiku 4.5 (Bedrock),Haiku 4.5 (Bedrock us), at the pricesmainshowed for the raw ids (bare Bedrock = direct;us.profile above both).The fold.
tests/model-routes.test.tspinsmodelFoldKeyto the row key: the key carries(Bedrock)and never the route id, so a second door added under an existing label folds instead of twinning.tests/day-aggregator.test.tsasserts a column-routed call and an id-shaped one of the same SKU land on one row in the finalized day, with the cross-region profile still apart.Real data. On a copy of a real 496 MB cache,
report --period lifetime --format jsonandmodels --format jsononmainand on this branch: all 142 finalized days match, $37,898.851498 and 272,985 calls on both sides; 38 lifetime model rows, identical names and costs. Only today moves, in both directions between two consecutivemainruns — live sessions appending. No Bedrock or column-sourced route exists in that cache, so no row folded or changed name there. The menubar history rows that the v33 bump re-derives (stale v32 days written before the Grok Bot provider landed) were checked againstmainwith onlyDAILY_CACHE_VERSIONbumped and none of this code: identical, 0 day mismatches.Not proven with real data: any route other than Bedrock, which is why only
bedrockis registered.Affiliation: none. I run Bedrock through an employer AWS account alongside Claude Max and ChatGPT plans and wanted the metered share.