Commit e4646a2
authored
🤖 fix: refresh usage and consumer breakdown on message deletion (#694)
## Problem
When messages are deleted (via `/clear` command or manual deletion), the
**Context Usage** section and **Breakdown by Consumer** chart showed
stale data until the next API response.
## Root Cause
The delete message handler only bumped the main `states` store but not:
1. `usageStore` - which powers the Context Usage section
2. Consumer calculation - which powers the Breakdown by Consumer chart
The system uses a two-store architecture:
- **Usage Store** (fast, metadata-only) - Context Usage UI
- **Consumer Store** (slow, tokenization-based) - Consumer breakdown UI
Both need to update when message structure changes.
## Solution
Added two lines to the delete message handler:
```typescript
if (isDeleteMessage(data)) {
aggregator.handleDeleteMessage(data);
this.states.bump(workspaceId);
this.checkAndBumpRecencyIfChanged();
this.usageStore.bump(workspaceId); // ← NEW
this.consumerManager.scheduleCalculation(workspaceId, aggregator); // ← NEW
return;
}
```
This follows the same pattern used in `tool-call-end` and caught-up
handlers for structural changes that require recalculation.
## Testing
1. Send messages to see usage and consumer breakdown populate
2. Run `/clear` command (or delete messages manually)
3. Verify both Context Usage and Breakdown by Consumer update
immediately
4. Both sections should show zeros or empty state
## Changes
- **Files modified**: 1 (`src/browser/stores/WorkspaceStore.ts`)
- **Lines changed**: +3
- **Pattern**: Mirrors existing structural change handlers
_Generated with `mux`_1 parent 9e1f0aa commit e4646a2
1 file changed
+2
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
795 | 795 | | |
796 | 796 | | |
797 | 797 | | |
| 798 | + | |
| 799 | + | |
798 | 800 | | |
799 | 801 | | |
800 | 802 | | |
| |||
0 commit comments