Repository navigation
Fix shell integration idle HEAD-change polling #1702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -277,7 +277,7 @@ _cmux_install_winch_guard | |
|
|
||
| _cmux_git_resolve_head_path() { | ||
| # Resolve the HEAD file path without invoking git (fast; works for worktrees). | ||
| local dir="$PWD" | ||
| local dir="${1:-$PWD}" | ||
| while true; do | ||
| if [[ -d "$dir/.git" ]]; then | ||
| print -r -- "$dir/.git/HEAD" | ||
|
|
@@ -313,6 +313,36 @@ _cmux_git_head_signature() { | |
| return 1 | ||
| } | ||
|
|
||
| _cmux_update_git_head_tracking() { | ||
| local repo_path="${1:-$PWD}" | ||
| if [[ "$repo_path" != "$_CMUX_GIT_HEAD_LAST_PWD" ]]; then | ||
| _CMUX_GIT_HEAD_LAST_PWD="$repo_path" | ||
| _CMUX_GIT_HEAD_PATH="$(_cmux_git_resolve_head_path "$repo_path" 2>/dev/null || true)" | ||
| _CMUX_GIT_HEAD_SIGNATURE="" | ||
| fi | ||
|
|
||
| [[ -n "$_CMUX_GIT_HEAD_PATH" ]] || return 1 | ||
|
|
||
| local head_signature="" | ||
| head_signature="$(_cmux_git_head_signature "$_CMUX_GIT_HEAD_PATH" 2>/dev/null || true)" | ||
| [[ -n "$head_signature" ]] || return 1 | ||
|
|
||
| if [[ -z "$_CMUX_GIT_HEAD_SIGNATURE" ]]; then | ||
| # The first observed HEAD value establishes the baseline for this shell | ||
| # session/context. Don't treat it as a branch change or we'll clear | ||
| # restore-seeded PR badges before the first background probe runs. | ||
| _CMUX_GIT_HEAD_SIGNATURE="$head_signature" | ||
| return 1 | ||
| fi | ||
|
|
||
| if [[ "$head_signature" != "$_CMUX_GIT_HEAD_SIGNATURE" ]]; then | ||
| _CMUX_GIT_HEAD_SIGNATURE="$head_signature" | ||
| return 0 | ||
| fi | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| _cmux_report_tty_payload() { | ||
| [[ -n "$CMUX_TAB_ID" ]] || return 0 | ||
| [[ -n "$_CMUX_TTY_NAME" ]] || return 0 | ||
|
|
@@ -534,35 +564,44 @@ _cmux_kill_process_tree() { | |
| kill "-$signal" "$pid" >/dev/null 2>&1 || true | ||
| } | ||
|
|
||
| _cmux_start_probe_timeout_watchdog() { | ||
| local probe_pid="$1" | ||
| local timeout="${2:-0}" | ||
| [[ -n "$probe_pid" ]] || return 1 | ||
| (( timeout > 0 )) || return 1 | ||
|
|
||
| ( | ||
| sleep "$timeout" | ||
| kill -0 "$probe_pid" >/dev/null 2>&1 || exit 0 | ||
| _cmux_kill_process_tree "$probe_pid" KILL | ||
| ) >/dev/null 2>&1 & | ||
|
|
||
| print -r -- "$!" | ||
| } | ||
|
|
||
| _cmux_stop_probe_timeout_watchdog() { | ||
| local watchdog_pid="$1" | ||
| [[ -n "$watchdog_pid" ]] || return 0 | ||
| _cmux_kill_process_tree "$watchdog_pid" KILL | ||
| wait "$watchdog_pid" >/dev/null 2>&1 || true | ||
| } | ||
|
|
||
| _cmux_run_pr_probe_with_timeout() { | ||
| local repo_path="$1" | ||
| local probe_pid="" | ||
| local started_at=$EPOCHSECONDS | ||
| local now=$started_at | ||
| local watchdog_pid="" | ||
|
|
||
| ( | ||
| _cmux_report_pr_for_path "$repo_path" | ||
| ) & | ||
| probe_pid=$! | ||
|
|
||
| while kill -0 "$probe_pid" >/dev/null 2>&1; do | ||
| sleep 1 | ||
| now=$EPOCHSECONDS | ||
| if (( _CMUX_ASYNC_JOB_TIMEOUT > 0 )) && (( now - started_at >= _CMUX_ASYNC_JOB_TIMEOUT )); then | ||
| _cmux_kill_process_tree "$probe_pid" TERM | ||
| sleep 0.2 | ||
| if kill -0 "$probe_pid" >/dev/null 2>&1; then | ||
| _cmux_kill_process_tree "$probe_pid" KILL | ||
| sleep 0.2 | ||
| fi | ||
| if ! kill -0 "$probe_pid" >/dev/null 2>&1; then | ||
| wait "$probe_pid" >/dev/null 2>&1 || true | ||
| fi | ||
| return 1 | ||
| fi | ||
| done | ||
| watchdog_pid="$(_cmux_start_probe_timeout_watchdog "$probe_pid" "$_CMUX_ASYNC_JOB_TIMEOUT" 2>/dev/null || true)" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Starting the timeout watchdog via command substitution can detach it from the poll-loop lifecycle, leaving a stale watchdog that may later SIGKILL a reused PID. Prompt for AI agents |
||
|
|
||
| wait "$probe_pid" | ||
| local probe_status=$? | ||
| _cmux_stop_probe_timeout_watchdog "$watchdog_pid" | ||
| return "$probe_status" | ||
| } | ||
|
|
||
| _cmux_stop_pr_poll_loop() { | ||
|
|
@@ -595,6 +634,14 @@ _cmux_start_pr_poll_loop() { | |
| { | ||
| while true; do | ||
| kill -0 "$watch_shell_pid" >/dev/null 2>&1 || break | ||
| if _cmux_update_git_head_tracking "$watch_pwd"; then | ||
| _CMUX_GIT_FORCE=1 | ||
| _CMUX_PR_FORCE=1 | ||
| _cmux_clear_pr_for_panel | ||
| { | ||
| _cmux_report_git_branch_for_path "$watch_pwd" | ||
| } >/dev/null 2>&1 &! | ||
| fi | ||
| _cmux_run_pr_probe_with_timeout "$watch_pwd" || true | ||
| sleep "$interval" | ||
| done | ||
|
|
@@ -732,30 +779,13 @@ _cmux_precmd() { | |
|
|
||
| # Git branch can change without a `git ...`-prefixed command (aliases like `gco`, | ||
| # tools like `gh pr checkout`, etc.). Detect HEAD changes and force a refresh. | ||
| if [[ "$pwd" != "$_CMUX_GIT_HEAD_LAST_PWD" ]]; then | ||
| _CMUX_GIT_HEAD_LAST_PWD="$pwd" | ||
| _CMUX_GIT_HEAD_PATH="$(_cmux_git_resolve_head_path 2>/dev/null || true)" | ||
| _CMUX_GIT_HEAD_SIGNATURE="" | ||
| fi | ||
| if [[ -n "$_CMUX_GIT_HEAD_PATH" ]]; then | ||
| local head_signature | ||
| head_signature="$(_cmux_git_head_signature "$_CMUX_GIT_HEAD_PATH" 2>/dev/null || true)" | ||
| if [[ -n "$head_signature" ]]; then | ||
| if [[ -z "$_CMUX_GIT_HEAD_SIGNATURE" ]]; then | ||
| # The first observed HEAD value establishes the baseline for this | ||
| # shell session. Don't treat it as a branch change or we'll clear | ||
| # restore-seeded PR badges before the first background probe runs. | ||
| _CMUX_GIT_HEAD_SIGNATURE="$head_signature" | ||
| elif [[ "$head_signature" != "$_CMUX_GIT_HEAD_SIGNATURE" ]]; then | ||
| _CMUX_GIT_HEAD_SIGNATURE="$head_signature" | ||
| git_head_changed=1 | ||
| # Treat HEAD file change like a git command — force-replace any | ||
| # running probe so the sidebar picks up the new branch immediately. | ||
| _CMUX_GIT_FORCE=1 | ||
| _CMUX_PR_FORCE=1 | ||
| should_git=1 | ||
| fi | ||
| fi | ||
| if _cmux_update_git_head_tracking "$pwd"; then | ||
| git_head_changed=1 | ||
| # Treat HEAD file change like a git command — force-replace any | ||
| # running probe so the sidebar picks up the new branch immediately. | ||
| _CMUX_GIT_FORCE=1 | ||
| _CMUX_PR_FORCE=1 | ||
| should_git=1 | ||
| fi | ||
|
|
||
| if [[ "$pwd" != "$_CMUX_GIT_LAST_PWD" ]]; then | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.