Repository navigation
Fix: Say the spend band is proxy-wide when drilled into a session - #1372
Conversation
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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
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
left a comment
There was a problem hiding this comment.
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]
| // scope rather than arriving at it. | ||
| func (m *model) spendBandNeedsScopeMarker() bool { | ||
| switch m.pane { | ||
| case paneEvents, paneDetail: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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]>
Addresses #1116.
The confusion
A reader who drills into a session and sees
LAST 1H $7.53 · TODAY $31.25 · 7 DAYS ~$618.07above 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
$0or "unknown" when a session has no cost. That figure does not exist to show:fetchSpendSpan), and the server rejectssession=alongside a symbolic window. So there is no per-session total to put in the band.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$0for the drilled session would be precisely that.So the number stays and the ambiguity goes instead.
The change
The band leads with
ALL SESSIONSon the two panes that show a single session, and nowhere else: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
spendBandCellshas 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:Both the plain and styled renderers take the flag, so the two stay width-identical — the property
TestRenderSpendBand_StylingCostsNoColumnsholds andapp.go's row reservation relies on.drewstill reports whether a figure reached the screen, so the spend drawer cannot open under a band that is only a label.Verification
go vetandgofmtclean.cmd/agentop/tuihas 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