Skip to content

fix(models): let --unpriced survive --top, and document the flag - #1016

Merged
iamtoruk merged 3 commits into
getagentseal:mainfrom
ozymandiashh:fix/969-unpriced-top-and-docs
Aug 18, 2026
Merged

iamtoruk merged 3 commits into
getagentseal:mainfrom
ozymandiashh:fix/969-unpriced-top-and-docs

Conversation

@ozymandiashh

@ozymandiashh ozymandiashh commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #985, which added codeburn models --unpriced for #969. Two things I said I'd take rather than leave in a first-time contributor's queue.

--unpriced --top N returned nothing

--top is applied inside aggregateModels (src/models-report.ts:234-236), after the sort by costUSD + savingsUSD descending and before the unpriced filter in src/main.ts ever runs. Unpriced rows are $0 cost by definition, and findUnpricedModels excludes anything carrying a local-savings baseline, so they're $0 savings too — which puts them last in that sort, every time. Any --top N smaller than the number of priced models therefore sliced away exactly the rows the flag exists to surface.

In table form the user got:

$ codeburn models --unpriced --top 2
No model usage found for the selected period.

Which is wrong twice: they do have unpriced models, and nothing hints that the two flags fought. Both are documented models flags, so it's a combination people land on.

The slice now runs after the filter when --unpriced is set. aggregateModels is handed topN: undefined in 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 --top interaction.

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, 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 returned the N that happened to appear earliest, and a model holding almost all of the unpriced volume was dropped if it showed up late:

fixture, emitted small-first: zz-unpriced-small (1.1k), zz-unpriced-largest (9.1k), zz-unpriced-middle (5.1k)

before: --unpriced --top 2  ->  ['zz-unpriced-small', 'zz-unpriced-largest']
after:  --unpriced --top 2  ->  ['zz-unpriced-largest', 'zz-unpriced-middle']

findUnpricedModels already 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-agent several 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 2 never truncated anything — deleting the slice line entirely left the suite green.

Verification

  • npx vitest run tests/models-report.test.ts — 32 passed
  • npx tsc --noEmit — clean
  • new test keeps unpriced rows when --unpriced is combined with --top uses a fixture where two priced models (Opus, Sonnet) both outrank the unpriced row, so --top 2 would consume both slots
  • mutation-checked three ways: restoring topN unconditionally fails with expected [] to deeply equal [...]; removing the rank sort fails with expected [ 'zz-unpriced-small', …(1) ] to deeply equal [ 'zz-unpriced-largest', …(1) ]; deleting the slice fails with to 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 --unpriced inherits that same false positive since it reuses findUnpricedModels — deliberately, so the two can't drift, but it does mean fixing #968 fixes both at once.

`--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.
@ozymandiashh
ozymandiashh marked this pull request as draft August 18, 2026 02:23
@ozymandiashh

Copy link
Copy Markdown
Collaborator Author

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 aggregateModels' sort key, and Array#sort is stable. The surviving order is Map insertion order, i.e. the order each model's first assistant call appears in the transcript. So --unpriced --top N returns the N that happen to appear earliest, and a model holding almost all the unpriced volume gets dropped if it shows up late.

My test missed it because the fixture has one unpriced model, so --top 2 never truncates anything — deleting the slice line entirely leaves the suite green.

Fixing by ranking on the order findUnpricedModels already produces (tokens descending) before slicing, which also makes the CLI and the dashboard warning agree on which N — the README sentence about this being the copyable form of the warning is not true as written until that lands.

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.
@ozymandiashh
ozymandiashh marked this pull request as ready for review August 18, 2026 02:35
@iamtoruk
iamtoruk merged commit 8ef3468 into getagentseal:main Aug 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants