fix: recover from premature session-end and improve dashboard stability#2
Open
damahua wants to merge 1 commit into
Open
fix: recover from premature session-end and improve dashboard stability#2damahua wants to merge 1 commit into
damahua wants to merge 1 commit into
Conversation
A premature SessionEnd (e.g. from session resume) would delete the buffer
and write a finalized summary. Subsequent cleanOrphanedBuffers calls from
other sessions would then keep deleting the recreated buffer, causing lost
cost tracking, invisible events, and wrong timestamps.
Session recovery:
- cleanOrphanedBuffers: grace period prevents deleting recently-active
buffers; removes stale finalized summaries instead
- session-start: removes stale summaries on resume so cleanup won't
delete the new buffer
- stop: reconstructs buffer when missing (omits start_time to avoid
delta timestamp mismatch); falls back to today's date
- appendEvent: validates buffer start_time before using it for delta
encoding to prevent wrong timestamp restoration
- flushEvents: atomic rename prevents duplicate writes from parallel hooks
Dashboard fixes:
- Read pending .batch events so unflushed activity is visible
- Event deduplication in stream list, detail view, and debug entries
- Disable terminal mouse reporting to prevent scroll-on-click
- Viewport-aware stream list with stable scroll (state persisted in
Dashboard, only updated on cursor movement)
- Idle sessions show amber indicator with duration ("idle 1h 45m")
- Idle count in collapsed group summaries
- Debug mode indicator checked independently of buffer decode
- CLI session detection improved (short sessions with ≤2 prompts)
Tests:
- New premature-session-end.test.mjs (9 tests covering full recovery)
- Fixed stop.test.mjs to use transcript files (matching actual interface)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
SessionEnd(from resume/compact) no longer permanently loses session state —cleanOrphanedBuffersrespects grace periods,stophook reconstructs buffers,session-startcleans stale summaries on resumeflushEventsprevents parallel hooks from writing the same events twice; display-level dedup handles existing duplicatesChanges
session-store.mjscleanOrphanedBuffers, atomic flush,readBatchEvents(),start_timevalidation inappendEventsession-start.mjsstop.mjsstart_time(avoids delta mismatch)useTelemetry.ts.batchevents, event deduplicationEventStream.tsxStreamDetail.tsxDashboard.tsxcli.tsxstop.test.mjstranscript interfaceRoot cause
When a session resumes, Claude Code fires
SessionEndthenSessionStartwith the same session ID. TheSessionEndwrites a finalized summary and deletes the buffer. When another session starts,cleanOrphanedBufferssees the finalized summary and deletes any recreated buffer — permanently losing cost/token tracking for the still-active session.Test plan
node --test tests/premature-session-end.test.mjs— 9 tests passnode --test tests/stop.test.mjs— 4 tests passnode --test tests/session-store.test.mjs tests/session-start.test.mjs tests/session-end.test.mjs— all pass🤖 Generated with Claude Code