Skip to content

fix: remove blocking sleep from preexec hook causing command lag - #1444

Merged
lawrencecchen merged 1 commit into
manaflow-ai:mainfrom
BillionClaw:fix/socket-mode-command-lag
Mar 15, 2026
Merged

lawrencecchen merged 1 commit into
manaflow-ai:mainfrom
BillionClaw:fix/socket-mode-command-lag

Conversation

@BillionClaw

@BillionClaw BillionClaw commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When socket connection mode is set to anything other than "off", running any command introduces noticeable lag (~100ms+ per command). Commands like ls and clear feel sluggish compared to when socket mode is "off" or other terminals.

Fixes #1436

Root Cause

The _cmux_stop_pr_poll_loop function in both zsh and bash shell integration scripts had a blocking sleep 0.1 call. This function is invoked in the preexec hook (before every command) when socket mode is not "off", causing at least 100ms of blocking delay on every single command execution.

When socket mode is "off", the PR poll loop is never started (due to socket path checks), so _CMUX_PR_POLL_PID is never set, and the blocking sleep is never executed.

Change Summary

  • Modified _cmux_stop_pr_poll_loop in cmux-zsh-integration.zsh
  • Modified _cmux_stop_pr_poll_loop in cmux-bash-integration.bash
  • Replaced the TERM → sleep 0.1 → conditional KILL pattern with direct SIGKILL
  • Added clear comments explaining the change

The PR poll loop is a lightweight background process that just runs gh pr view periodically. It is safe to kill abruptly with SIGKILL without waiting for graceful termination.

Verification

# Syntax validation
zsh -n Resources/shell-integration/cmux-zsh-integration.zsh
bash -n Resources/shell-integration/cmux-bash-integration.bash

# No trailing whitespace or other issues
git diff --check

All checks passed.

Risk

None. The PR poll loop is a stateless periodic gh pr view query. Killing it abruptly does not corrupt any state or lose any data. The next command will simply start a fresh poll loop if needed.


Summary by cubic

Removes ~100ms command lag in socket mode by eliminating a blocking sleep in the preexec hook. Replaces the TERM→sleep→KILL sequence with a direct SIGKILL to stop the PR poll loop in both zsh and bash integrations, fixing #1436.

Written for commit eb7c7d0. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Improved efficiency of internal poll process termination by using a more direct approach, eliminating intermediate delays and simplifying the shutdown sequence.

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 manaflow-ai#1436
@vercel

vercel Bot commented Mar 14, 2026

Copy link
Copy Markdown

@BillionClaw is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitai Bot commented Mar 14, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 03e5ab96-7a59-400e-91dd-6a495a4752ab

📥 Commits

Reviewing files that changed from the base of the PR and between 6c203b5 and eb7c7d0.

📒 Files selected for processing (2)
  • Resources/shell-integration/cmux-bash-integration.bash
  • Resources/shell-integration/cmux-zsh-integration.zsh

📝 Walkthrough

Walkthrough

The _cmux_stop_pr_poll_loop function in both bash and zsh shell integrations has been refactored to directly issue SIGKILL to poll processes instead of attempting graceful termination with SIGTERM, followed by a sleep delay and conditional SIGKILL. The new approach eliminates blocking delays during process termination.

Changes

Cohort / File(s) Summary
Poll Process Termination Logic
Resources/shell-integration/cmux-bash-integration.bash, Resources/shell-integration/cmux-zsh-integration.zsh
Changed _cmux_stop_pr_poll_loop to directly issue SIGKILL via _cmux_kill_process_tree instead of SIGTERM followed by sleep and conditional kill. Removes intermediate delay and verification step. Zsh version includes comment noting SIGKILL usage to prevent blocking in preexec hook.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Through bash and zsh we swiftly bound,
No sleeping delays will slow us down!
Direct KILL signals, swift and true,
Lag be gone—commands break right through! 🐰⚡

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing a blocking sleep from the preexec hook that was causing command lag.
Description check ✅ Passed The description clearly explains the problem, root cause, and solution, with verification steps provided. However, it deviates from the template structure and lacks some template sections.
Linked Issues check ✅ Passed The PR directly addresses issue #1436 by removing the blocking sleep from the preexec hook, eliminating the ~100ms command lag reported when socket mode is enabled.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the command lag issue by modifying the _cmux_stop_pr_poll_loop function in both shell integration scripts as required.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@lawrencecchen
lawrencecchen merged commit 5776cd5 into manaflow-ai:main Mar 15, 2026
3 of 4 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 17, 2026
5 of 6 tasks
bn-l pushed a commit to bn-l/cmux that referenced this pull request Apr 3, 2026
…aflow-ai#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 manaflow-ai#1436

Co-authored-by: BillionClaw <267901332+BillionClaw@users.noreply.github.com>
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.

Socket connection mode set to options other than "off" introduces lag when running any command.

2 participants