Repository navigation
fix(models): let --unpriced survive --top, and document the flag - #1016
Conversation
`--top` is applied inside `aggregateModels`, before the unpriced filter runs, on rows sorted by cost + savings descending. Unpriced rows are $0 on both -- `findUnpricedModels` excludes anything carrying a local-savings baseline -- so they always sort last, and any `--top N` smaller than the number of priced models removed exactly the rows `--unpriced` exists to show. In table form the user then read "No model usage found for the selected period", which is the wrong answer twice over: they do have unpriced models, and nothing tells them the two flags fought. The slice now happens after the filter when `--unpriced` is set. Also adds the flag to the README models table and a changelog entry -- it was added for getagentseal#969, and a filter nobody can discover does not help anyone find their unpriced models. Follow-up to getagentseal#985.
|
Holding as a draft: an adversarial pass found the fix is half-right. Filtering before slicing is necessary but not sufficient — every unpriced row is $0 on both cost and savings, so they are all tied under My test missed it because the fixture has one unpriced model, so Fixing by ranking on the order |
Filtering before the slice was necessary but not sufficient. Every unpriced row is $0 on both cost and savings -- findUnpricedModels excludes anything carrying a local-savings baseline -- so they all tie under aggregateModels' sort key, and Array#sort is stable. The surviving order was Map insertion order: the order each model's first assistant call appears in the transcript. So --unpriced --top N kept the N that showed up earliest, and a model holding almost all of the unpriced volume was dropped if it appeared late. findUnpricedModels already sorts by tokens descending, then calls, then model name, and the dashboard warning renders that order. It is now called once over the whole row set, its order becomes a rank index, and the rows are ranked before the slice -- so the CLI and the warning agree on which N, which is what the README row claims. In the breakdown modes several rows share one model, so they share that model's rank and N still counts rows. The previous test could not catch this: its fixture held one unpriced model, so --top 2 never truncated anything and deleting the slice line left the suite green. It now uses three unpriced models emitted in an order that differs from their size order, and asserts which two survive rather than only how many.
# Conflicts: # CHANGELOG.md
Follow-up to #985, which added
codeburn models --unpricedfor #969. Two things I said I'd take rather than leave in a first-time contributor's queue.--unpriced --top Nreturned nothing--topis applied insideaggregateModels(src/models-report.ts:234-236), after the sort bycostUSD + savingsUSDdescending and before the unpriced filter insrc/main.tsever runs. Unpriced rows are $0 cost by definition, andfindUnpricedModelsexcludes anything carrying a local-savings baseline, so they're $0 savings too — which puts them last in that sort, every time. Any--top Nsmaller than the number of priced models therefore sliced away exactly the rows the flag exists to surface.In table form the user got:
Which is wrong twice: they do have unpriced models, and nothing hints that the two flags fought. Both are documented
modelsflags, so it's a combination people land on.The slice now runs after the filter when
--unpricedis set.aggregateModelsis handedtopN: undefinedin that mode and the rows are sliced afterwards.Docs
The flag is now in the README Models table alongside the others, with a changelog entry under Added crediting @kocaemre, plus one under Fixed for the
--topinteraction.Second pass: the fix was half-right
An adversarial pass over this branch found that filtering before the slice is necessary but not sufficient.
Every unpriced row is $0 on both cost and savings, so they all tie under
aggregateModels' sort key, andArray#sortis stable. The surviving order was Map insertion order — the order each model's first assistant call appears in the transcript. So--unpriced --top Nreturned the N that happened to appear earliest, and a model holding almost all of the unpriced volume was dropped if it showed up late:findUnpricedModelsalready sorts by tokens descending, then calls, then model name — and that is exactly the order the dashboard warning renders. It is now called once over the whole row set, its output becomes a rank index, and rows are ranked before the slice. That also makes the README row honest: the CLI and the warning now agree on which N, which they did not before. In--by-task/--by-agentseveral rows share one model, so they share that model's rank and N still counts rows.My original test could not have caught this. Its fixture held one unpriced model, so
--top 2never truncated anything — deleting thesliceline entirely left the suite green.Verification
npx vitest run tests/models-report.test.ts— 32 passednpx tsc --noEmit— cleankeeps unpriced rows when --unpriced is combined with --topuses a fixture where two priced models (Opus, Sonnet) both outrank the unpriced row, so--top 2would consume both slotstopNunconditionally fails withexpected [] to deeply equal [...]; removing the rank sort fails withexpected [ 'zz-unpriced-small', …(1) ] to deeply equal [ 'zz-unpriced-largest', …(1) ]; deleting the slice fails withto have a length of 2 but got 3. Each returns 32/32 when reverted.Still open on #969
The issue's original complaint was that the TUI warning is truncated at every terminal width, hiding both the model list and the fix command. This makes the escape hatch discoverable and correct, but it doesn't touch the warning itself. #968 is also still open and relevant: the warning fires on subscription-billed models where $0 is genuinely correct, and
--unpricedinherits that same false positive since it reusesfindUnpricedModels— deliberately, so the two can't drift, but it does mean fixing #968 fixes both at once.