Skip to content

fix(watcher): filter ignored paths before publishing events, handle worktree git dirs#21453

Open
drrcool wants to merge 3 commits intoanomalyco:devfrom
drrcool:fix/watcher-ignore-filter
Open

fix(watcher): filter ignored paths before publishing events, handle worktree git dirs#21453
drrcool wants to merge 3 commits intoanomalyco:devfrom
drrcool:fix/watcher-ignore-filter

Conversation

@drrcool
Copy link
Copy Markdown

@drrcool drrcool commented Apr 8, 2026

Issue for this PR

Closes #21452

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The review panel was flickering/rerenderering every few seconds when OPENCODE_EXPERIMENTAL_FILEWATCHER=true (which the desktop app forces on). Two bugs compounded each other:

Backend (watcher.ts): The parcel/watcher callback was shared across both subscriptions (worktree dir and git dir) and published every incoming event without filtering through FileIgnore.match(). So build artifacts like out/renderer/index.js or .turbo/ lock files fired file.watcher.updated events and triggered refreshVcs() even though those paths match the ignore patterns. Fix: move the callback inside subscribe() so each subscription gets its own; run non-git events through FileIgnore.match() before publishing; only let HEAD through on the git-dir subscription (the only file there that signals a real branch/commit change).

Frontend (session.tsx): The file.watcher.updated listener skipped paths with startsWith(".git/"), but in git worktrees the git dir is an absolute path like /path/to/.git/worktrees/<branch>/HEAD, so those events slipped through. Fix: also check includes("/.git/") and normalize Windows backslashes first.

How did you verify your code works?

Ran the desktop app with electron-vite dev running alongside (which writes to out/, a path FileIgnore should suppress). Before the fix, /vcs/diff was being fetched in a tight loop — confirmed via browser devtools network tab. After the fix, refreshVcs() is only called on actual source file changes.

Screenshots / recordings

N/A — this is a flicker fix, the change is the absence of spurious network requests.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@drrcool drrcool requested a review from adamdotdevin as a code owner April 8, 2026 05:05
Copilot AI review requested due to automatic review settings April 8, 2026 05:05
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes excessive UI refresh/flicker caused by unfiltered filesystem watcher events, especially from ignored build artifacts and git worktree .git paths. It tightens backend event filtering before publishing and improves frontend filtering for absolute git-dir paths.

Changes:

  • Backend: filter watcher events via FileIgnore.match() before publishing, and restrict git-dir publishing to HEAD only.
  • Backend: add a rel() helper to safely compute paths relative to the subscribed directory for filtering decisions.
  • Frontend: normalize path separators and ignore both relative .git/... and absolute .../.git/... watcher events before triggering refreshVcs().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/opencode/src/file/watcher.ts Filters ignored paths prior to publishing file.watcher.updated and narrows git-dir events to HEAD to avoid noisy updates.
packages/app/src/pages/session.tsx Prevents spurious VCS refreshes by correctly identifying .git paths in worktree/absolute and Windows path forms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@drrcool drrcool closed this Apr 8, 2026
@drrcool drrcool reopened this Apr 8, 2026
…orktree git dirs

The parcel/watcher callback was shared and published all filesystem events
without re-filtering through FileIgnore. Build artifacts and lock files in
ignored directories (out/, .turbo/, etc.) fired watcher events that drove
repeated refreshVcs() calls and made the review panel flicker.

Also fixes the frontend listener to handle absolute .git/worktrees/... paths
produced by git worktrees, which bypassed the old startsWith('.git/') check.

Fixes anomalyco#21452
@drrcool drrcool force-pushed the fix/watcher-ignore-filter branch from 036a100 to ca5e4bf Compare April 9, 2026 13:48
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.

fix: review panel flickers/rerenders on every filesystem event including ignored paths

2 participants