fix(cli): show live session spend in TUI sidebar during active turn - #11506
Conversation
Implements 2026-06-20-034-fix-tui-live-spent-cost.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by gpt-5.4-20260305 · Input: 55.5K · Output: 5.4K · Cached: 302.1K Review guidance: REVIEW.md from base branch |
|
This lands on the right layer. `session().cost` is the persisted aggregate that only moves on a `session.updated.1` event or a full session-list load, so it stays stale for the whole in-flight turn while the per-message cost is already arriving live. Summing `item.cost` across the assistant messages reads those same live values the adjacent `state` memo already derives from `msg()`, so the sidebar stays internally consistent with the token/context line right next to it. The `Math.max` is the right guard, not just a tiebreak: if the client is holding a truncated message window, `total` can undercount and the persisted aggregate wins, so the displayed value never regresses below the session total. Mid-turn `total` leads and climbs; once the projector persists the aggregate they converge. Matches the traced root cause exactly. |
|
Thanks for tracing it to that layer so precisely. That matches what I saw: mid-turn the summed |
|
I can confirm this resolved the issue for me. |
|
This fix will be ship with the next release? My Kilo version is 7.4.1 on MacOS and I've the bug too. Thanks mate 👍 |
|
It merged after 7.4.1 was cut, so it should land in the next release. Until then 7.4.1 still has the bug, no workaround needed once you update. |
…ent-cost fix(cli): show live session spend in TUI sidebar during active turn
Issue
Fixes #11480
Context
The TUI sidebar showed live spend as
$0.00while an assistant turn was still running, even though token count and context percentage updated live.session.costis only the persisted session aggregate, which is stale until the turn finalizes, so the sidebar read0mid-turn.Implementation
In
sidebar/context.tsx, thecostmemo now sumscostacross the live assistant messages and takesMath.maxof that againstsession()?.cost. During an active turn the per-message sum leads; once the aggregate is persisted it wins (or ties), so the displayed value never regresses. This mirrors how the adjacenttokens/ context-percent memos already derive from the live message list rather than the session aggregate. Client-only change; no server or protocol changes.Screenshots
$0.00during an active turnN/A for a static capture in this environment — the change is a derived-value calculation in the sidebar memo. See verification below.
How to Test
Manual/local verification
$0.00, and settles at the session total when the turn finalizes.Reviewer test steps
Blocked checks and substitute verification
bun test ./test/cli/tui/usage.test.tscould not complete in this environment (missing@opentui/solid/preload, an environment/runtime dependency unrelated to the change). Substitute verification: reviewed thatcostnow derives from the samemsg()live-message list the existingtokens/context memos use, and thatMath.maxpreserves the persisted aggregate so the value is monotonic across turn finalization.Checklist
Get in Touch
AI was used for assistance.