Repository navigation
Push-refresh git status on repo metadata changes and shell command completion - #7086
Conversation
…mpletion Branch switches and commits made inside terminals now surface through push signals instead of waiting for the 30s terminal-only fallback poll: - The git-common watch now also covers the primary checkout's HEAD, packed-refs, and index (a few stat calls per tick; no new native watchers). - worktrees:changed events nudge the active worktree's coalesced git status runner (visibility-gated, 3s floor). - OSC 133;D command completion dispatches a window event that nudges the same runner for the active worktree. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThis PR extends git-common watching in the main process to detect changes to primary checkout metadata files (HEAD, packed-refs, index) at the common-dir root, generalizing the poller into a reusable snapshot-diff mechanism. In the renderer, it introduces a new terminal command finished event dispatched from the PTY connection lifecycle, and a Changes
Related PRs: None specified. Suggested labels: main-process, renderer, git-status, testing Suggested reviewers: None specified. 🐰 A HEAD moves swift beneath the git, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 193e6c8a-2292-4927-8461-8c9c16ae3801
📒 Files selected for processing (10)
src/main/ipc/worktree-base-directory-event-filter.test.tssrc/main/ipc/worktree-base-directory-event-filter.tssrc/main/ipc/worktree-base-directory-poller.test.tssrc/main/ipc/worktree-git-common-watch.tssrc/renderer/src/components/right-sidebar/git-status-push-signal-refresh.test.tssrc/renderer/src/components/right-sidebar/git-status-push-signal-refresh.tssrc/renderer/src/components/right-sidebar/useGitStatusPolling.test.tssrc/renderer/src/components/right-sidebar/useGitStatusPolling.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/hooks/terminal-command-finished-event.ts
| return { | ||
| unsubscribe: async () => { | ||
| await Promise.all([narrowWatch.unsubscribe(), primaryMetadataPoll.unsubscribe()]) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Inconsistent error handling in combined unsubscribe.
Promise.all([narrowWatch.unsubscribe(), primaryMetadataPoll.unsubscribe()]) propagates a rejection if either call throws, whereas the existing subscription in this file swallows unsubscribe errors (current.unsubscribe().catch(() => {}), Line 252). An unhandled rejection here could surface as an uncaught error to whatever calls startGitCommonWatch(...).unsubscribe().
🔧 Proposed fix for consistent error swallowing
return {
unsubscribe: async () => {
- await Promise.all([narrowWatch.unsubscribe(), primaryMetadataPoll.unsubscribe()])
+ await Promise.all([
+ narrowWatch.unsubscribe().catch(() => {}),
+ primaryMetadataPoll.unsubscribe().catch(() => {})
+ ])
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| return { | |
| unsubscribe: async () => { | |
| await Promise.all([narrowWatch.unsubscribe(), primaryMetadataPoll.unsubscribe()]) | |
| } | |
| } | |
| } | |
| return { | |
| unsubscribe: async () => { | |
| await Promise.all([ | |
| narrowWatch.unsubscribe().catch(() => {}), | |
| primaryMetadataPoll.unsubscribe().catch(() => {}) | |
| ]) | |
| } | |
| } | |
| } |
…mpletion (stablyai#7086) Branch switches and commits made inside terminals now surface through push signals instead of waiting for the 30s terminal-only fallback poll: - The git-common watch now also covers the primary checkout's HEAD, packed-refs, and index (a few stat calls per tick; no new native watchers). - worktrees:changed events nudge the active worktree's coalesced git status runner (visibility-gated, 3s floor). - OSC 133;D command completion dispatches a window event that nudges the same runner for the active worktree. Co-authored-by: Orca <[email protected]>
ELI5
PR #7069 slowed the terminal-only git status poll from 3s to 30s, accepting that a branch switch typed in a shell could take up to 30s to show in the sidebar. This PR removes that tradeoff: branch switches and commits now push a refresh the moment they hit disk, so the sidebar updates in well under a second — faster than the old 3s poll ever was — while idle polling stays at the slow 30s backstop cadence.
What changed
Three small pieces, all reusing existing plumbing:
Primary-checkout coverage in the git-common watch (
worktree-git-common-watch.ts). The repo-metadata watch previously only observedworktrees/(linked-worktree metadata). It now also tracks the primary checkout'sHEAD,packed-refs, andindexvia a fewstatcalls per 2s tick — no new native watchers, so the fseventsd zero-client property from Cut fseventsd load: fix macOS exclusion cap, drop wide always-on FSEvents streams #7068 is preserved. The event filter (worktree-base-directory-event-filter.ts) matches those three top-level files and nothing else (noobjects/,FETCH_HEAD, orrefs/**churn).worktrees:changed→ git status nudge (git-status-push-signal-refresh.ts). The renderer already receives a debouncedworktrees:changedpush whenever repo metadata changes; it previously only refreshed the worktree list. Now it also nudges the active worktree's coalesced git-status runner (3s min interval, visibility-gated, same gating as the poll — including the macOS app-container privacy suppression and huge-status pause).Shell command completion → git status nudge (
terminal-command-finished-event.ts,pty-connection.ts). The command-lifecycle handler that already parses "command finished" markers per pane now dispatches a window event with the pane'sworktreeId; the same hook nudges status when the finished command belongs to the active worktree. Covers dirty-state changes from any shell command, not just HEAD moves, wherever shell integration markers are present.Why the feedback loop is safe
git statuscan rewrite.git/index(stat-cache refresh), which re-triggers the metadata watch. This converges: the follow-up status finds a fresh cache and doesn't write, so no further event fires. Worst case under sustained git activity is one status per 3s (the coalescer floor) — exactly the old interactive poll rate, and only while the window is visible.Verification
pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/worktree-base-directory-event-filter.test.ts src/main/ipc/worktree-base-directory-poller.test.ts src/main/ipc/worktree-base-directory-watcher.test.ts src/renderer/src/components/right-sidebar/git-status-push-signal-refresh.test.ts src/renderer/src/components/right-sidebar/useGitStatusPolling.test.ts src/renderer/src/components/right-sidebar/useGitStatusPolling.rerender.test.ts src/renderer/src/lib/passive-macos-app-data-access.test.ts— 50 tests passpnpm run typecheck:web,pnpm run typecheck:node,oxlint,oxfmt --check— cleangit checkout -b→ sidebar branch label + status head updated in 454ms (primary checkout, poller path) and 411ms (linked worktree, native stream path). Before this PR the same scenario waited for the 30s fallback tick. Visible UI confirmed: the worktree card rendered the new branch name.Tradeoffs and user-visible impact
statcalls per 2s tick per repo (primary metadata), zero new native watchers, zero new timers in the renderer.Made with Orca 🐋