Repository navigation
Fix: Explain a withheld cell on agentop cost --by currency - #1241
Conversation
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]>
|
Warning Review limit reachedYou'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. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
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. Comment |
mrsabath
left a comment
There was a problem hiding this comment.
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.gotomainand keeping the new tests failsTestRunCost_ByCurrencyWithholdsACappedRowOnAMixedWindow, reproducing the issue's render verbatim. The assertion is load-bearing, not vacuous. - Re-gating the new sentence on
!labelledinstead of on the withheld cells failsTestRunCost_ByCurrencyLabelsEachRowInItsOwnUnit— and does so in a way worth noting: it prints! may hold more than one unit, which cannot be addedwith an empty label, becausewithheldis 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 ownBUT NOT THE UNITcomment — so a minute pastmaxLabelsPerMinutelands on this axis labelled with its real unit, exactly as the PR says, and is not a producer of a withheld cell.usage.CapSeriesatcore/cost/ledger/query.go:424withMaxSeriesInResponse = 16is 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 throughSortSeriesLabels.
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.
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:
After:
Why not the fix the issue suggested
Gating the existing caveat on
!labelledalone does explain the cell, but in the wrong words. It prints "use --by currency for a figure per unit" under the--by currencytable, 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 onlabelled.Correction to the issue's reachable set
The issue says a minute past
maxLabelsPerMinuteputs(other)on the currency axis. It doesn't:ledger.overflowKeyForfolds 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 isledger.Fold's per-response cap:usage.CapSeriesfolds a window holding more thanMaxSeriesInResponse(16) units into(other). That is rare, but it can happen, and the fix is the same either way. The ring does not servegroup=currencyat all (#1188).Changes
cmd/agentop/cmd_cost.go:writeCostBreakdowncollects 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_ByCurrencyLabelsEachRowInItsOwnUnitasserts that a mixed currency table that withheld nothing prints no caveat.breakdownSection, since the summary above prints the--by currencyadvice legitimately.Test plan
HOLE_bycurrency_withheld_cell_unexplained: gate on!labelled, no new sentence) fails 3 assertions across both tests;!labelledinstead of the withheld cells fails the no-caveat assertion.GOWORK=off go test -count=1 ./...(withSSL_CERT_FILEunset),go vet ./...,gofmt -l .clean incmd/agentop.docs/pricing.mdandcmd/agentop/README.mdchecked. Their(mixed)wording is still accurate, so neither changes.Assisted-By: Claude (Anthropic AI) [email protected]