Skip to content

perf(ui): fix timer accumulation on repeated session enter/exit#153

Merged
renato0307 merged 1 commit intomainfrom
fix/timer-accumulation-on-session-reattach
Mar 19, 2026
Merged

perf(ui): fix timer accumulation on repeated session enter/exit#153
renato0307 merged 1 commit intomainfrom
fix/timer-accumulation-on-session-reattach

Conversation

@renato0307
Copy link
Copy Markdown
Owner

Summary

  • Each Init() call was starting new tea.Tick timers without canceling the previous ones, causing stale timers to accumulate across attach/detach cycles
  • After ~10 attach/detach cycles, 20-50 concurrent poll timers would be firing every 2 seconds, progressively slowing down the UI
  • Fix applies the generation counter pattern: Init() increments pollGen/tipGen; handlers discard messages from old generations
  • Also fixes a flaky test (TestGetWorktreeForBranch_WorktreeExists) caused by the macOS /var/folders/private/var/folders symlink

Test plan

  • Run go test ./internal/... — all tests pass
  • Build and run rocha-fix/timer-accumulation-on-session-reattach-v1 run --dev
  • Enter and exit a session 10+ times — UI should remain responsive throughout, with no CPU spikes

Each call to SessionList.Init() was starting new tea.Tick timers without
invalidating the previous ones. After multiple attach/detach cycles, tens
of concurrent poll timers would be running simultaneously, flooding the
Bubble Tea message queue with checkStateMsg, showTipMsg, and hideTipMsg,
causing progressive UI slowdown.

Fix using the generation counter pattern: Init() increments pollGen and
tipGen; each timer closure captures the current generation. The message
handlers discard any message whose generation does not match the current
one, ensuring only the latest Init() cycle drives the poll loop.

Also fixes TestGetWorktreeForBranch_WorktreeExists to resolve symlinks
before comparing paths, handling the macOS /var/folders symlink.
@renato0307 renato0307 merged commit ef8cf4f into main Mar 19, 2026
2 checks passed
@renato0307 renato0307 deleted the fix/timer-accumulation-on-session-reattach branch March 19, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant