fix: make TUI subprocess calls async to resolve UI freezing (#215)#249
Open
dion-jy wants to merge 1 commit intosmtg-ai:mainfrom
Open
fix: make TUI subprocess calls async to resolve UI freezing (#215)#249dion-jy wants to merge 1 commit intosmtg-ai:mainfrom
dion-jy wants to merge 1 commit intosmtg-ai:mainfrom
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
…sync (smtg-ai#215) The TUI becomes unresponsive with multi-second keystroke delays because synchronous subprocess calls (tmux capture-pane, git add -N, git diff) block the bubbletea event loop. This commit moves all expensive operations to background goroutines via tea.Cmd: 1. Metadata polling (app/app.go): HasUpdated() and Diff() now run in a goroutine, sending results back as metadataResultMsg for safe application on the main thread. 2. Preview capture (app/app.go): CapturePaneContent() runs async via previewResultMsg. Tick interval increased from 100ms to 200ms. 3. Trust screen handling (session/tmux/tmux.go): The 30-45s polling loop now runs in a goroutine so Start() returns immediately. 4. Diff stats (session/instance.go): Added SetDiffStats() for the async metadata path to safely write results on the main thread. Closes smtg-ai#215 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fc5f1a1 to
a93b8ec
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
7 tasks
|
Hey @dion-jy — great work on this, I have a similar PR open (#253) that tackles the same root issue. Wanted to flag it so the maintainers can see both and decide how to proceed, but I think they're different enough to land separately. The main differences:
Not trying to compete, just wanted to make the overlap visible. Happy to coordinate if it helps. |
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
tmux capture-pane,git diff): moved from synchronousUpdate()to asynctea.Cmdpattern — UI blocking drops from 100ms+ to µs per ticktmux capture-pane): same async pattern applied — no longer freezes UI while capturing pane contentStart()to a background goroutine — session creation returns immediatelyFixes #215
Problem
The bubbletea
Update()handler was calling subprocess commands synchronously. Every metadata tick blocked the entire UI for 100-500ms depending on disk speed. With multiple sessions, this scaled linearly (e.g., 8 sessions × 200ms = 1.6s of UI freeze per tick cycle). Even with a single session, keystrokes were noticeably delayed.Approach
Converted blocking subprocess calls into the standard bubbletea async pattern:
Update()captures state and returns atea.Cmdclosure (returns in µs)Thread safety is maintained because:
Changed files
app/app.gosession/instance.goSetDiffStats()for async result applicationsession/tmux/tmux.goui/preview.goSetPreviewContent()for async previewui/tabbed_window.goSetPreviewContent()delegationBenchmark results (before → after)
(you can check benchmark code here, https://github.com/CUN-bjy/claude-squad/tree/fix/tui-performance-215-with-tests)
Note: Total work time is unchanged — subprocesses still run in the background. The improvement is in UI blocking time (how long keystrokes are delayed).
Test plan
go test ./...)go test -race ./...)If you find my work helpful, fuel the next commit with a coffee ☕

🤖 Generated with Claude Code