Skip to content

perf(zsh): read git HEAD in the watcher without forking a subshell - #20702

Open
sozercan wants to merge 3 commits into
manaflow-ai:mainfrom
sozercan:perf/zsh-git-head-watch-no-fork
Open

sozercan wants to merge 3 commits into
manaflow-ai:mainfrom
sozercan:perf/zsh-git-head-watch-no-fork

Conversation

@sozercan

@sozercan sozercan commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

Each pane whose shell is inside a git repository runs a git HEAD watcher that polls once per second while a command is in the foreground. The poll read HEAD through $(_cmux_git_head_signature ...), so every poll forked a subshell. With many panes open this adds a steady stream of short-lived processes, roughly one per pane per second, even when nothing is happening.

The watcher now reads HEAD with _cmux_git_head_signature_into_reply, which returns the value through REPLY like _cmux_tmux_shell_env_signature_into_reply already does, so the loop no longer forks. _cmux_git_head_signature keeps its printing interface as a thin wrapper for existing callers. Branch-change detection is unchanged, and the reads stay status-neutral (|| true) so a missing HEAD can't abort an ERR_EXIT shell.

Testing

  • Added tests/test_zsh_git_head_watch_no_fork.py. It starts the real watcher loop and records the PID that performs each HEAD read.
    • Before the fix (0f52094b74): fails, 3 of 3 HEAD polls ran in a forked subshell.
    • After the fix (f09de881ff): passes, git HEAD watcher polled 3 times without forking.
  • These existing watcher tests pass on f09de881ff: test_issue_15066_zsh_watcher_sleep.py, test_issue_10926_watcher_pid_reuse_guard.py, test_shell_no_git_watch.py and test_shell_git_branch_stale_cwd.py.
  • The new test is registered in the macos-cli-no-socket lane; validate_test_execution_registry.py passes.
  • python3 scripts/verify-local.py: 17/17 checks passed. This is a shell-script-only change, so I didn't run a native build or test it live in a tagged build.

Changelog

Changed: The zsh git branch watcher no longer starts a new process every second in each pane

Proof

Not user-visible. The sidebar's branch and PR updates behave the same; only the per-poll process launch is gone.

Checklist

  • Behavior changes have added or updated tests, or Testing says why not

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Improvements
    • Git HEAD monitoring in the zsh integration now reads repository state without spawning extra subshells during its initial check and polling loop, reducing unnecessary process overhead. The watcher continues to check for changes to the current Git HEAD, with fewer extra processes involved in those checks. This improvement is limited to Git HEAD monitoring in the zsh integration.

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
The git HEAD watcher polls once per second in every pane whose shell is
inside a git repository. Reading HEAD through $(...) forked a subshell on
each poll, so many open panes caused a steady stream of process launches.
Return the signature through REPLY, as the tmux env signature already does.

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 17:52
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for opening your first cmux pull request!

We're a small team and the outside-PR queue is long, so a reply can take a while, sometimes longer than we'd like. If this one goes quiet and you'd like eyes on it, comment here and we'll pick it up.

A few things that help:

  • Start here covers what reviewers look for, what CI runs for you, and what happens next.
  • If the CLA check asks, reply with the sentence it gives you.
  • You don't need to run the app-host or UI tests locally. CI runs the ones your diff touches once a maintainer approves the first workflow run.
  • The verification ladder shows which checks fit your change. Say in the description which ones you ran.
  • If we end up fixing the same problem another way, we'll credit you with a Co-authored-by trailer and link the fix here.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: manaflow-ai/cmux/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3c9f6a04-5eb3-4e1d-bf1f-f1aa9bafad6a
📥 Commits

Reviewing files that changed from the base of the PR and between 67efa43 and f09de88.

📒 Files selected for processing: 2
  • Resources/shell-integration/cmux-zsh-integration.zsh
  • tests/test-execution.toml

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

The zsh Git HEAD watcher now reads signatures into REPLY instead of using command substitutions. A regression test checks that repeated watcher reads run in the watcher process.

Changes: Zsh Git HEAD watcher

Layer / File(s) Summary
Read signatures into REPLY
Resources/shell-integration/cmux-zsh-integration.zsh
A new helper reads the first line of a readable HEAD file into REPLY. The existing printing helper delegates to it.
Use the reader in the watcher and test process IDs
Resources/shell-integration/cmux-zsh-integration.zsh, tests/test_zsh_git_head_watch_no_fork.py, tests/test-execution.toml
The watcher uses the helper for its initial signature and each poll. The regression test checks that multiple reads use the watcher process ID. The execution registry runs the test alone in the macos-cli-no-socket lane.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: austinywang

Merge Risk: ⚪ Minimal · up to f09de

The watcher reads HEAD without a per-poll subshell, and a regression test is registered for the macOS CLI lane. No actionable merge-blocking risk is established by the supplied evidence; the change is ready for normal checks.

Pre-merge checks: Passed 24 · Failed 1

Failed 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 24 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Cmux Cloud Persistent Session And Early Input Passed PASS. The pull request changes only zsh Git HEAD watcher logic and related Python test registration. It does not modify Cloud terminal creation, persistent cmux-tui transport, manual renderers, Ghostt…
Cmux Swift Actor Isolation Passed The pull request changes only a Zsh integration script, a Python regression test, and a TOML test registry. The reviewed diff contains no Swift files or Swift production code, so it introduces no Swif…
Cmux Swift Blocking Runtime Passed The pull request changes only a Zsh integration script, a Python test, and TOML test configuration. The authoritative diff contains no Swift files, so it introduces no production Swift blocking or tim…
Cmux Browser Automation Off-Main Passed PASS: This pull request changes only zsh Git HEAD watcher code and its Python test registration. It does not change browser socket automation commands, Sources/TerminalController.swift, `ControlComm…
Cmux Expensive Synchronous Load Passed The pull request changes only a zsh integration script and Python/TOML tests. The reviewed diff contains no production Swift changes and no agent-history load or Swift main-actor path. The custom fail…
Cmux Cache Substitution Correctness Passed PASS: The reviewed production change is Zsh, with a Python regression test and TOML test registration. It does not modify Swift, TypeScript, or JavaScript production code, so the cache-substitution co…
Cmux No Hacky Sleeps Passed The production diff replaces command substitution with a REPLY helper. It does not add or expand a sleep, timer, or polling loop. The existing one-second _cmux_sleep_cs 100 in `_cmux_start_git_hea…
Cmux Algorithmic Complexity Passed PASS: The production diff replaces command substitution with a direct REPLY helper and reads one HEAD line per watcher poll. It does not scan a scalable collection, sort or filter records, perform p…
Cmux Swift Concurrency Passed The pull request changes only a zsh integration script, a Python test, and a TOML test registry. It introduces no Swift code or Swift concurrency pattern.
Cmux Swift @Concurrent Passed The pull request changes only Zsh, Python, and TOML files. The reviewed diff contains no Swift files and introduces no Swift async functions, actor isolation, or @concurrent usage. The Swift-specific …
Cmux Swift Package Boundaries Passed PASS: The pull request changes only Zsh integration code and Python/TOML test files. The authoritative diff contains no production Swift changes, so the Swift package boundary rule does not apply.
Cmux Swiftpm Lockfiles Passed The PR changes only the zsh integration and test files. It does not modify Package.swift, Package.resolved, .gitignore, workflows, or Xcode project package references. The SwiftPM lockfile policy is t…
Cmux Swift Logging Passed The pull request changes only a zsh integration script and Python test/config files. No Swift files or Swift logging statements are added or materially changed, so the Swift logging rule does not appl…
Cmux User-Facing Error Privacy Passed PASS. The production diff adds no user-facing error or diagnostic text. _cmux_git_head_signature_into_reply returns the HEAD line through REPLY, and the existing wrapper keeps its prior print inte…
Cmux Full Internationalization Passed PASS: The PR changes zsh watcher behavior and adds test/registry files only. It adds no Swift UI text, app catalog or Info.plist entries, web UI/API/markdown/changelog copy, or locale data. The new sh…
Cmux Swiftui State Layout Passed PASS: The pull request changes only the zsh integration and Python/TOML test files. It contains no Swift or SwiftUI changes, so the SwiftUI state-layout rules do not apply.
Cmux Architecture Rethink Passed PASS. The pull request changes only Zsh integration code and Python test registration. It contains no Swift architecture change, so the specified Swift rethink failure conditions do not apply.
Cmux Swift Auxiliary Window Close Shortcuts Passed PASS: The pull request changes only a zsh integration script and Python/TOML test files. It adds no Swift code and does not add or modify cmux-owned auxiliary windows. The auxiliary-window close-short…
Cmux Source Artifacts Passed All three changed paths are intentional source, test, and test-registry files. The zsh integration change is hand-written product source, the Python file is a targeted regression test with runtime-onl…
Cmux No Test Or Debug Seam In Production Source Passed PASS: The pull request changes only the zsh integration script and test files. It adds or changes no Swift file under a production Sources/ path, so the specified production test/debug seam conditio…
Title check Passed The title clearly and concisely describes the primary change: avoiding subshell forks when the zsh Git HEAD watcher reads HEAD.
Description check Passed The description includes the required Summary, Testing, Changelog, Proof, and Checklist sections. It explains the problem, implementation, test coverage, verification results, and limits of validation…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Copilot AI 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.

🟡 Changes recommended

Read failures can terminate ERR_EXIT watchers, and the new regression test is not registered for CI execution.

2 open findings
What changed in this PR

Removes per-poll zsh subshell creation from the Git HEAD watcher.

Changes:

  • Adds a REPLY-based HEAD reader while preserving the printing wrapper.
  • Adds regression coverage for watcher process reuse.
File Description
Resources/​shell-integration/​cmux-zsh-integration.zsh Reads HEAD without command substitution.
tests/​test_zsh_git_head_watch_no_fork.py Verifies polling occurs in the watcher process.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_zsh_git_head_watch_no_fork.py
Comment thread Resources/shell-integration/cmux-zsh-integration.zsh Outdated
Restore the || true guard so a missing or unreadable HEAD cannot abort an
ERR_EXIT shell, and register the no-fork regression in the
macos-cli-no-socket lane.

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 18:06

Copilot AI 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.

🟢 Approval recommended

The focused optimization preserves status handling and includes appropriate regression coverage.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@sozercan

Copy link
Copy Markdown
Author

I have read the CLA Document v2.2 and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 14, 2026

This branch has not been deployed

No deployments
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.

2 participants