From 5776cd5d8124a8fc4d21172b7e2ae35ea0e2c7a5 Mon Sep 17 00:00:00 2001 From: BillionClaw Date: Mon, 16 Mar 2026 07:11:07 +0800 Subject: [PATCH] fix: remove blocking sleep from preexec hook causing command lag (#1444) When socket connection mode is not 'off', the shell integration runs _cmux_stop_pr_poll_loop in the preexec hook before every command. This function had a blocking 'sleep 0.1' call that caused noticeable lag on every command execution. The fix replaces the TERM+sleep+KILL pattern with direct SIGKILL. The PR poll loop is a lightweight background process that only runs 'gh pr view' periodically - it's safe to kill abruptly without waiting for graceful termination. Fixes #1436 Co-authored-by: BillionClaw <267901332+BillionClaw@users.noreply.github.com> --- Resources/shell-integration/cmux-bash-integration.bash | 8 +++----- Resources/shell-integration/cmux-zsh-integration.zsh | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Resources/shell-integration/cmux-bash-integration.bash b/Resources/shell-integration/cmux-bash-integration.bash index 4a22e3a1..338844d0 100644 --- a/Resources/shell-integration/cmux-bash-integration.bash +++ b/Resources/shell-integration/cmux-bash-integration.bash @@ -263,11 +263,9 @@ _cmux_run_pr_probe_with_timeout() { _cmux_stop_pr_poll_loop() { if [[ -n "$_CMUX_PR_POLL_PID" ]]; then - _cmux_kill_process_tree "$_CMUX_PR_POLL_PID" TERM - sleep 0.1 - if kill -0 "$_CMUX_PR_POLL_PID" >/dev/null 2>&1; then - _cmux_kill_process_tree "$_CMUX_PR_POLL_PID" KILL - fi + # Use SIGKILL directly to avoid blocking sleep in preexec. + # The poll loop is lightweight and safe to kill abruptly. + _cmux_kill_process_tree "$_CMUX_PR_POLL_PID" KILL _CMUX_PR_POLL_PID="" fi } diff --git a/Resources/shell-integration/cmux-zsh-integration.zsh b/Resources/shell-integration/cmux-zsh-integration.zsh index e9bbf235..aeef42d2 100644 --- a/Resources/shell-integration/cmux-zsh-integration.zsh +++ b/Resources/shell-integration/cmux-zsh-integration.zsh @@ -288,11 +288,9 @@ _cmux_run_pr_probe_with_timeout() { _cmux_stop_pr_poll_loop() { if [[ -n "$_CMUX_PR_POLL_PID" ]]; then - _cmux_kill_process_tree "$_CMUX_PR_POLL_PID" TERM - sleep 0.1 - if kill -0 "$_CMUX_PR_POLL_PID" >/dev/null 2>&1; then - _cmux_kill_process_tree "$_CMUX_PR_POLL_PID" KILL - fi + # Use SIGKILL directly to avoid blocking sleep in preexec. + # The poll loop is lightweight and safe to kill abruptly. + _cmux_kill_process_tree "$_CMUX_PR_POLL_PID" KILL _CMUX_PR_POLL_PID="" fi }