Better conversation usage tracking#37
Conversation
Greptile SummaryThis PR introduces session-scoped tracking of discarded assistant responses — tokens spent on replies later removed by edit-and-rerun or regeneration — and exposes them in a new
Confidence Score: 5/5Safe to merge — the discard tally is accumulated correctly, reset on every conversation boundary, and never mutates existing state in place. The accumulation logic in mergeDiscarded always starts from a fresh emptyUsage copy of the current state, so store updates cannot corrupt the tally. Both entry-points capture the old message reference before reassigning the array slot. Reset paths cover all conversation-change surfaces and test coverage is thorough. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User edits or regenerates] --> B{Which action?}
B -->|deleteMessagesAfter| C[Slice removed messages]
B -->|replaceAssistantMessage| D[Capture old message ref]
C --> E[mergeDiscarded: fold usage + mode overhead]
D --> E
E --> F[discardedUsage accumulates\ndiscardedResponseCount++]
F --> G[Store update: new discardedUsage object]
H[setMessages / clearMessages\n/ setCurrentConversation] --> I[Reset discardedUsage = emptyUsage\ndiscardedResponseCount = 0]
G --> J[useTotalUsage re-runs]
I --> J
J --> K[grandTotal = total + modeOverhead\nspentTotal = grandTotal + discarded + titleGeneration]
K --> L{spentTotal.totalTokens == 0?}
L -->|Yes| M[return null — chip hidden]
L -->|No| N[TotalUsageResult with spentTotal]
N --> O[ChatHeader chip shows spentTotal\nTooltip breaks down context / discarded / title / total]
Reviews (3): Last reviewed commit: "Review fixes" | Re-trigger Greptile |
No description provided.