Skip to content

Fix: Explain a withheld cell on agentop cost --by currency - #1241

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/by-currency-mixed-cell-caveat
Oct 2, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/by-currency-mixed-cell-caveat

Conversation

@huang195

@huang195 huang195 commented Oct 2, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #1177. On agentop cost --by currency, a row that is not one of the window's units renders (mixed) with nothing under the table saying why. The caveat that explains (mixed) cells on other axes was gated !byUnit.

Before, from the issue:

  CURRENCY                             REQUESTS     TOKENS           COST
  USD                                      1000          0        $146.36
  (other)                                    57          0        (mixed)
  credits                                    57          0   0.08 credits

After:

  CURRENCY                             REQUESTS     TOKENS           COST
  USD                                      1000          0        $146.36
  (other)                                    57          0        (mixed)
  credits                                    57          0   0.08 credits
  ! (other) may hold more than one unit, which cannot be added

Why not the fix the issue suggested

Gating the existing caveat on !labelled alone does explain the cell, but in the wrong words. It prints "use --by currency for a figure per unit" under the --by currency table, sending the reader to the table they are already looking at. It also prints under every mixed currency table, including ones that withheld nothing. Every window this axis exists for is mixed. So the currency axis gets its own sentence, gated on the cells actually withheld rather than on labelled.

Correction to the issue's reachable set

The issue says a minute past maxLabelsPerMinute puts (other) on the currency axis. It doesn't: ledger.overflowKeyFor folds the four label fields into (other) but keeps the row's unit, so a capped minute's overflow row is labelled with its real unit on this axis. The producer that can do it is ledger.Fold's per-response cap: usage.CapSeries folds a window holding more than MaxSeriesInResponse (16) units into (other). That is rare, but it can happen, and the fix is the same either way. The ring does not serve group=currency at all (#1188).

Changes

  • cmd/agentop/cmd_cost.go: writeCostBreakdown collects the labels it withholds and, on the currency axis, prints one line naming them. The other axes' caveat is unchanged. mixedCostCell's godoc now covers the currency axis, where "the second wants --by currency" stops being advice.
  • cmd/agentop/cmd_cost_test.go:
    • TestRunCost_ByCurrencyWithholdsACappedRowOnAMixedWindow (the fixture the issue points at) asserts the note is present, and that the table does not tell the reader to use --by currency.
    • TestRunCost_ByCurrencyLabelsEachRowInItsOwnUnit asserts that a mixed currency table that withheld nothing prints no caveat.
    • Both are scoped with breakdownSection, since the summary above prints the --by currency advice legitimately.

Test plan

  • The new assertion fails on unmodified main (the issue's render, verbatim).
  • Mutation-checked:
    • the issue's candidate fix (HOLE_bycurrency_withheld_cell_unexplained: gate on !labelled, no new sentence) fails 3 assertions across both tests;
    • gating the new sentence on !labelled instead of the withheld cells fails the no-caveat assertion.
  • GOWORK=off go test -count=1 ./... (with SSL_CERT_FILE unset), go vet ./..., gofmt -l . clean in cmd/agentop.
  • docs/pricing.md and cmd/agentop/README.md checked. Their (mixed) wording is still accurate, so neither changes.

Assisted-By: Claude (Anthropic AI) [email protected]

On the currency axis a row's label is its unit, and a label that is not
one of the window's reported units falls through to "(mixed)" when the
window is mixed. The caveat that explains a "(mixed)" cell was gated
!byUnit, so on --by currency the cell was printed with nothing under
the table saying why.

Gating that caveat on !labelled alone, the fix the issue suggested,
prints "use --by currency for a figure per unit" under the currency
table itself, and under every mixed currency table, including the ones
that withheld nothing. So the currency axis gets its own sentence,
printed only when a cell there was actually withheld:

  ! (other) may hold more than one unit, which cannot be added

The one producer that can put such a row on this axis is ledger.Fold's
response cap: usage.CapSeries folds a window past MaxSeriesInResponse
(16) units into "(other)". The ledger's per-minute overflow keeps each
row's unit (overflowKeyFor), so a capped minute does not produce one.

Fixes rossoctl#1177.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 requested a review from a team as a code owner October 2, 2026 20:39
@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 6090762e-5783-46fc-965c-60cd12fad4a3

📥 Commits

Reviewing files that changed from the base of the PR and between 32c0848 and 8362676.

📒 Files selected for processing (2)
  • cmd/agentop/cmd_cost.go
  • cmd/agentop/cmd_cost_test.go
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. I verified the claims rather than reading them, and they hold.

Mutation-checked the tests myself, since the value of this change is entirely in the gate being right:

  • Reverting cmd_cost.go to main and keeping the new tests fails TestRunCost_ByCurrencyWithholdsACappedRowOnAMixedWindow, reproducing the issue's render verbatim. The assertion is load-bearing, not vacuous.
  • Re-gating the new sentence on !labelled instead of on the withheld cells fails TestRunCost_ByCurrencyLabelsEachRowInItsOwnUnit — and does so in a way worth noting: it prints ! may hold more than one unit, which cannot be added with an empty label, because withheld is empty on a table that withheld nothing. The gate and the slice it joins are the same fact, so coupling them is what keeps that line from ever rendering blank.

The correction to #1177's reachable set is right, and checking it was the part I expected to disagree with:

  • ledger.overflowKeyFor (core/cost/ledger/row.go) folds all four label fields but keeps the unit, under its own BUT NOT THE UNIT comment — so a minute past maxLabelsPerMinute lands on this axis labelled with its real unit, exactly as the PR says, and is not a producer of a withheld cell.
  • usage.CapSeries at core/cost/ledger/query.go:424 with MaxSeriesInResponse = 16 is the producer. It also merges into exactly one (other) band, which is why the " and " join cannot produce an awkward list in practice; ordering stays deterministic through SortSeriesLabels.

Declining the issue's suggested fix was the right call, and for the reason given: !labelled prints "use --by currency for a figure per unit" under the --by currency table, pointing the reader at the table they are already reading, and prints it under every mixed currency table including ones that withheld nothing. Every window this axis exists for is mixed, so labelled is not the signal.

Scoping both tests with breakdownSection matters more than it looks: that helper t.Fatalfs if it captures the summary's caveat, so neither assertion can pass against the wrong sentence.

go vet and gofmt -l clean. Full cmd/agentop suite passes — the only failures in my environment are pre-existing sandbox artifacts in unrelated systemd/service tests (/private/var/select/sh: Operation not permitted), which fail on main too. All 28 CI checks green.

One thing to carry across, not a change request: the reachable-set correction is the most durable finding here, and it currently lives only in this PR description. Worth a comment on #1177 so the next reader does not re-derive that overflowKeyFor keeps the unit.

一丝不苟 — yī sī bù gǒu, "not one thread careless". The mutation testing earns it.

@huang195
huang195 merged commit 3a7c64f into rossoctl:main Oct 2, 2026
28 checks passed
@huang195
huang195 deleted the fix/by-currency-mixed-cell-caveat branch October 2, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

abctl cost --by currency: a withheld (mixed) cell is unexplained on that axis

2 participants