Skip to content

Push-refresh git status on repo metadata changes and shell command completion - #7086

Merged
nwparker merged 1 commit into
mainfrom
nwparker/git-status-push
Jul 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/git-status-push

Conversation

@nwparker

@nwparker nwparker commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. Primary-checkout coverage in the git-common watch (worktree-git-common-watch.ts). The repo-metadata watch previously only observed worktrees/ (linked-worktree metadata). It now also tracks the primary checkout's HEAD, packed-refs, and index via a few stat calls 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 (no objects/, FETCH_HEAD, or refs/** churn).

  2. worktrees:changed → git status nudge (git-status-push-signal-refresh.ts). The renderer already receives a debounced worktrees:changed push 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).

  3. 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's worktreeId; 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 status can 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 pass
  • pnpm run typecheck:web, pnpm run typecheck:node, oxlint, oxfmt --check — clean
  • E2E latency (dev build, CDP-instrumented, Source Control closed, no open files): external git 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

  • Terminal-only branch switches: up to 30s → sub-second on macOS/local. Effectively removes Reduce idle git status polling #7069's one acknowledged degradation.
  • Idle cost: +3 stat calls per 2s tick per repo (primary metadata), zero new native watchers, zero new timers in the renderer.
  • Shells without integration markers on remote hosts still lean on the repo-metadata push (filesystem-truth based, works for any tool that touches git) and the 30s backstop.
  • Remote web client: no preload bridge, so the push subscription is skipped there; the existing poll behavior is unchanged.

Made with Orca 🐋

…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]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This 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 useGitStatusPushSignalRefresh hook that refreshes git status on worktree changes or terminal command completion (gated by window visibility and active repo/worktree), wired into the existing useGitStatusPolling hook alongside a new terminal-only polling interval constant.

Changes

  • Main process: expanded matchingGitCommonRepoIds filter to include primary checkout metadata files; added snapshotPrimaryCheckoutMetadata, generalized startSnapshotDiffPoller, snapshotGitCommonAndPrimaryMetadata, and updated startGitCommonWatch platform behavior.
  • Renderer: added ORCA_TERMINAL_COMMAND_FINISHED_EVENT/dispatchTerminalCommandFinishedEvent, dispatched from pty-connection.ts; added useGitStatusPushSignalRefresh hook; wired it and a new TERMINAL_ONLY_STATUS_POLL_INTERVAL_MS constant into useGitStatusPolling.
  • Tests: new/updated test coverage across all above areas.

Related PRs: None specified.

Suggested labels: main-process, renderer, git-status, testing

Suggested reviewers: None specified.

🐰 A HEAD moves swift beneath the git,
A poller wakes to catch each bit,
Terminals finish, signals fly,
Status refreshes with a nudge, not a sigh.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the required template and is missing Screenshots, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description using the repository template and add the missing sections, including screenshots, testing checklist, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: push-refreshing git status from repo metadata changes and shell completion.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 193e6c8a-2292-4927-8461-8c9c16ae3801

📥 Commits

Reviewing files that changed from the base of the PR and between 6dafe8c and 4622a5d.

📒 Files selected for processing (10)
  • src/main/ipc/worktree-base-directory-event-filter.test.ts
  • src/main/ipc/worktree-base-directory-event-filter.ts
  • src/main/ipc/worktree-base-directory-poller.test.ts
  • src/main/ipc/worktree-git-common-watch.ts
  • src/renderer/src/components/right-sidebar/git-status-push-signal-refresh.test.ts
  • src/renderer/src/components/right-sidebar/git-status-push-signal-refresh.ts
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.test.ts
  • src/renderer/src/components/right-sidebar/useGitStatusPolling.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/hooks/terminal-command-finished-event.ts

Comment on lines +275 to 280
return {
unsubscribe: async () => {
await Promise.all([narrowWatch.unsubscribe(), primaryMetadataPoll.unsubscribe()])
}
}
}

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.

🩺 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.

Suggested change
return {
unsubscribe: async () => {
await Promise.all([narrowWatch.unsubscribe(), primaryMetadataPoll.unsubscribe()])
}
}
}
return {
unsubscribe: async () => {
await Promise.all([
narrowWatch.unsubscribe().catch(() => {}),
primaryMetadataPoll.unsubscribe().catch(() => {})
])
}
}
}

@nwparker
nwparker merged commit b07ea4a into main Jul 2, 2026
2 of 3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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.

1 participant