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>
This commit is contained in:
BillionClaw 2026-03-16 07:11:07 +08:00 committed by GitHub
parent 07ec05b0f1
commit 5776cd5d81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 10 deletions

View file

@ -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
}

View file

@ -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
}