Skip to content

Fix: Say the spend band is proxy-wide when drilled into a session - #1372

Merged
mrsabath merged 3 commits into
mainfrom
fix/spendlabel
Oct 14, 2026
Merged

mrsabath merged 3 commits into
mainfrom
fix/spendlabel

Conversation

@mrsabath

@mrsabath mrsabath commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Addresses #1116.

The confusion

A reader who drills into a session and sees LAST 1H $7.53 · TODAY $31.25 · 7 DAYS ~$618.07 above twelve rows that cost nothing reads those figures as that session's. The reporter did, on a Bob session whose own events carried no cost at all.

Why the issue's requested fix is not available

The issue asks for $0 or "unknown" when a session has no cost. That figure does not exist to show:

  • The cost ledger's row key carries no session dimension by design (fetchSpendSpan), and the server rejects session= alongside a symbolic window. So there is no per-session total to put in the band.
  • The band is deliberately all-sessions (spendState), so that it keeps reading when the Usage pane is scoped to one session — which is exactly when someone is looking at cost.

fetchSpendSpan's own comment already rules out the alternative: "The band is a per-proxy reading, and making it look otherwise would be a wrong number wearing a right label." Showing $0 for the drilled session would be precisely that.

So the number stays and the ambiguity goes instead.

The change

The band leads with ALL SESSIONS on the two panes that show a single session, and nowhere else:

sessions list: LAST 1H $4.04 · TODAY $18.80 · 7 DAYS $216.44 · THIS MONTH $703.18
drilled in   : ALL SESSIONS · LAST 1H $4.04 · TODAY $18.80 · 7 DAYS $216.44 · THIS MONTH $703.18

The sessions list needs no marker — there is no single session on screen to mis-attribute the figures to, and a permanent marker would be noise on the pane agentop is mostly used on. The Usage pane is excluded too: it states its own scope, and a user who scoped it chose that scope rather than arriving at it.

The marker never costs a reading

It is added after spendBandCells has chosen its best-fitting set of readings, rather than as a fifth cell inside that enumeration — whose sixteen-subset width arithmetic is measured, monotone in width, and documented at length. A reading with no scope label still informs; a scope label with no reading informs about nothing, so the marker is the first thing dropped as the terminal narrows. Measured:

w=60 drilled : LAST 1H $4.04 · TODAY $18.80 · THIS MONTH $703.18
w=40 drilled : TODAY $18.80 · THIS MONTH $703.18

Both the plain and styled renderers take the flag, so the two stay width-identical — the property TestRenderSpendBand_StylingCostsNoColumns holds and app.go's row reservation relies on. drew still reports whether a figure reached the screen, so the spend drawer cannot open under a band that is only a label.

Verification

  • Three new tests: the marker appears only when drilled in and leaves the readings untouched; it never displaces a reading or overflows the budget at every width from 1 to 120; and the pane predicate covers events / detail / sessions / usage / no-session-selected.
  • Every existing spend and band test still passes, including the width-parity invariant.
  • go vet and gofmt clean. cmd/agentop/tui has 3 pre-existing failures (router/server-picker) verified identical on an untouched checkout of the same base commit.

If you'd rather go further

This treats the ambiguity, not the absence. If a genuine per-session spend figure is wanted, that is a ledger change — adding a session dimension to the row key — and a much larger piece of work worth its own issue. Happy to file it.

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

Summary by CodeRabbit

  • New Features
    • On the Events and Detail views, spend bands now show an “ALL SESSIONS” marker when a session is selected and the marker fits alongside the readings.
    • If space is limited, the marker is omitted so spend readings remain visible and the band stays within the available width.

Addresses #1116.

A reader who enters a session and sees "LAST 1H $7.53 · TODAY $31.25"
above twelve rows that cost nothing reads those figures as that
session's. The reporter did, on a Bob session whose own events carried no
cost at all.

The figures are the whole proxy's, and they cannot be anything else: the
cost ledger's row key carries no session dimension by design, so there is
no per-session total available to put here. The band is also
deliberately all-sessions so it keeps reading while the Usage pane is
scoped to one session — which is exactly when someone is looking at cost.

So what the issue asked for, $0 for the drilled session, is not
available: it would be a figure the ledger cannot support, and
fetchSpendSpan's own comment rules out "a wrong number wearing a right
label". The number therefore stays and the ambiguity goes — the band
leads with ALL SESSIONS on the two panes that show a single session
(events and event detail), and nowhere else. The sessions list needs no
marker, since there is no single session on screen to mis-attribute the
figures to, and the Usage pane states its own scope.

The marker is added AFTER spendBandCells has chosen its best-fitting set
of readings rather than as a fifth cell inside that enumeration, so it
cannot cost a figure: a reading with no scope label still informs, where
a scope label with no reading informs about nothing. It is consequently
the first thing dropped as the terminal narrows — measured, it is gone by
60 columns while all four readings survive to 46. Both the plain and
styled renderers take the flag, so the two stay width-identical, which is
what app.go's row reservation relies on.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
@mrsabath
mrsabath requested a review from a team as a code owner October 13, 2026 19:14
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 768c7019-d4eb-46d1-80ec-cbdc72b35e9b
📥 Commits

Reviewing files that changed from the base of the PR and between 25e158a and 56e2c5d.

📒 Files selected for processing: 2
  • cmd/agentop/tui/spend_band.go
  • cmd/agentop/tui/spend_band_test.go
🚧 Files skipped from review as they are similar to previous changes: 1
  • cmd/agentop/tui/spend_band.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The spend-band renderer now accepts a scope flag and can add an “ALL SESSIONS” marker when it fits. The app passes the scope state for the selected pane. Tests cover marker conditions, width limits, and updated renderer calls.

Changes: Scoped spend-band rendering

Layer / File(s) Summary
Render and validate the scope marker
cmd/agentop/tui/spend_band.go, cmd/agentop/tui/app.go, cmd/agentop/tui/*_test.go
The app passes scope state to the renderer. Plain and styled rendering add the marker only when it fits the width. Tests cover pane and session conditions, width limits, styled output, and updated renderer calls.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: huang195

Merge Risk: ⚪ Minimal · up to 56e2c

This change adds an ALL SESSIONS label to the spend band on the events and event-detail panes. It only appears when it fits, and it never displaces a spend figure. No merge-blocking risk was found.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: labeling the spend band as proxy-wide when viewing a session.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 6 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

The demo drills into a session, so the band there now leads with ALL
SESSIONS and the committed cortex-demo.svg went stale — ci.yaml's
"Go CI (README demo)" job caught it via TestCommittedAssetIsCurrent.

Regenerated with `go -C scripts/readme-demo run .`. Three lines, one per
frame showing a drilled-in band, each gaining the marker and nothing
else — which also confirms the marker reaches the real rendered app on
exactly the frames it should.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>

@huang195 huang195 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.

The approach is sound: it fixes the ambiguity without inventing a per-session figure the ledger can't back, and it agrees with fetchSpendSpan's comment that the band is a proxy-wide reading. The marker goes on only after the band has chosen which figures fit, so it never displaces a reading, and the README demo SVG was regenerated. No must-fix issues, just two suggestions and two nits inline.

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

Comment thread cmd/agentop/tui/spend_band_test.go Resolved
// scope rather than arriving at it.
func (m *model) spendBandNeedsScopeMarker() bool {
switch m.pane {
case paneEvents, paneDetail:

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.

suggestion: Only paneEvents and paneDetail are allowed here. The demo shows the manifest view getting the marker, so it seems to be a detail sub-view. Is there any other pane that shows a single session? If there is, it will still have the original confusion. Inverting the check to "not the sessions list and not Usage" would cover any future single-session pane by default.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Your first question: no, the manifest view is part of paneDetail, so it is already covered — your reading of the demo was right.

On inverting the check, I went and measured it rather than reasoning about it, and it comes out worse. The reason is selectedSess lifetime: it is set on entering a session and cleared only by a connection switch or X, never by leaving the pane. So "a session is selected" stays true while the user is on other panes. Enumerating all ten with a session selected:

pane allowlist inverted
Namespaces false true
Pods false true
Sessions false false
Events true true
Detail true true
Pipeline false true
PluginDetail false true
Catalog false true
Usage false false
Agents false true

The inversion marks six panes that show no session at all, so it trades one hypothetical missing marker for six certain spurious ones.

But the gap you identified is real: the allowlist says nothing about an eleventh pane, which would silently get no marker and carry exactly the #1116 ambiguity. So I kept the allowlist and gave it a failure mode, using the idiom this package already has for it — TestPaneKeysCoverAllPanes. The new TestSpendBandNeedsScopeMarker_EveryPaneIsClassified enumerates paneID(0)..lastPaneID and requires each pane in exactly one of two lists, single-session or many; a new paneID fails until someone classifies it, with a message saying to add it to spendBandNeedsScopeMarker if it shows one session.

I verified the test fails on an unclassified pane rather than just passing today — dropped paneAgents from both lists and got pane 9 is in 0 of the two lists, want exactly 1.

The function's doc now explains why it is an allowlist rather than an exclusion list, since that is the non-obvious part and the next person will reasonably wonder the same thing you did.

Comment thread cmd/agentop/tui/spend_band_test.go Resolved
Comment thread cmd/agentop/tui/spend_band.go Resolved
Four review findings, all on the tests and comments rather than the
behaviour.

The width sweep asserting that the styled band costs no columns only
ran scoped=false, so the claim went untested on the path this branch
adds — the one that prepends a marker and mutes it. It now loops over
both, with a guard that the scoped sweep really does reach a marker at
that width, since both loops would pass vacuously otherwise.

The no-overflow assertion read `got > w && width(unscoped) <= w`,
which goes silent at any width where the unscoped band already
overflows. Measured: neither form overflows at any width from 1 to 120,
and a sibling test already says so unconditionally, so this one asserts
`got <= w` outright.

spendBandNeedsScopeMarker keeps its allowlist. Inverting it to "not
the sessions list and not Usage" was considered and is worse:
selectedSess is cleared only by a connection switch or a clear, not by
leaving the pane, so it stays set on Pipeline, PluginDetail, Catalog,
Agents, Namespaces and Pods — six panes that show no session, all of
which the inversion would mark. What the allowlist did lack is a
failure mode for a future single-session pane, so a new test
enumerates the real pane range and requires each pane to be classified,
the way TestPaneKeysCoverAllPanes guards paneKeys. Verified it fails on
an unclassified pane.

The #1116 reasoning was told three times. It stays on
allSessionsMarker, where the decision lives; the other two point at it,
19 comment lines shorter.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
@mrsabath
mrsabath merged commit 9a8d235 into main Oct 14, 2026
29 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 14, 2026
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.

2 participants