fix(events): background interactive hooks to prevent tmux freeze#53
Merged
Conversation
Interactive hooks (pane_focus, window_focus, session_changed) fire on client interactions (mouse scroll, window/session switch). A synchronous run-shell blocks the tmux server's command queue while `demux event` does DB work, which can stall on the SQLite lock, freezing the on-screen paint mid-redraw. Backgrounding these hooks (-b flag) allows tmux rendering to continue while the event handler runs concurrently. Serialize via withEventLock to prevent concurrent sidebar mutations. - Add -b flag to paneFocus, windowFocus, sessionChanged hooks - Wrap pane_focus DB operations in withEventLock for serialization - Add TestInteractiveHooksAreBackgrounded to guard hook backgrounding
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.
Context
Interactive hooks fire on user interactions (mouse scroll, window/session switch).
Currently, these hooks use synchronous
run-shellcommands, which block the tmuxserver's command queue while
demux eventperforms database work. When DBoperations stall on the SQLite lock (held by state-writer hooks), the tmux
server freezes mid-redraw, tearing the visual paint and breaking copy-mode
selection rendering.
This fix backgrounds the interactive hooks to allow tmux rendering to continue
while event handlers run concurrently, preventing the visual freeze.
What does this PR do
-bflag topane_focus,window_focus, andsession_changedhooks tobackground their execution, preventing the tmux server from blocking on DB work.
pane_focusevent handler logic inwithEventLockto serializeconcurrent invocations (since the hooks are now backgrounded) and prevent race
conditions in sidebar repositioning.
TestInteractiveHooksAreBackgroundedto verify that all four interactivehooks (
after-select-pane,client-focus-in,after-select-window,client-session-changed) have the-bflag set.Out of scope
None. All changes are contained to the event hook system.
Manual QA
Prerequisites
1. demux is built and in PATH
Expected: output shows version (e.g.,
demux dev).2. Hooks are registered in the test tmux server
Expected: output includes
after-select-pane,after-select-window,client-focus-inwith-bflag in their run-shell commands.Setup
tmux new-session -d -s test-render -c ~ -x 120 -y 40 demux attach test-renderScenario 1 — Rapid pane switches don't freeze render
Rapidly switch between panes in a multi-pane window
follows focus cleanly.
Scenario 2 — Rapid window switches don't freeze render
Create multiple windows and switch between them rapidly
without lag or paint tears.
Scenario 3 — Test suite passes
Run the test for hook backgrounding
Expected: test passes, confirming all four interactive hooks have
-bset.Run all tmux hook tests:
go test ./internal/tmuxhooks -vExpected: all tests pass.