🤖 Fix usage stats race condition - guarantee real-time/persisted parity #287
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes three usage statistics bugs where stats didn't match between real-time and after refresh.
Problems Fixed
1. Usage stats don't update after stream completion
finalizeUsageStats()helper2. Consumer breakdown stuck "Calculating..." after reload
3. O(N) scheduling overhead during history load
Additional Refactoring
Extracted helpers for code clarity:
dispatchResumeCheck()- Eliminates duplicationhandleCompactSummaryCompletion()+performCompaction()- Separates special case from normal flowWhy This Guarantees Parity
Single source of truth: Both real-time and post-refresh read from
aggregator.getAllMessages()which includes persisted usage metadata.Regression Risk Analysis
✅ ZERO RISKS IDENTIFIED - All changes are:
Key Changes Verified Safe:
Test Coverage:
Generated with
cmux