Skip to content

Fix GPUI branch watcher read-feedback loop on Linux - #946

Merged
AnthonyRonning merged 1 commit into
masterfrom
codex-head-watch-945-maple
Sep 16, 2026
Merged

AnthonyRonning merged 1 commit into
masterfrom
codex-head-watch-945-maple

Conversation

@AnthonyRonning

Copy link
Copy Markdown
Contributor

Fixes #945.

Problem

The chat screen's git branch watcher forwarded any notify event whose path ended in HEAD, regardless of event kind. On Linux, the inotify backend reports the app's own branch reads as open/read/close-after-read access events, so each read_branch retriggered the watcher in a feedback loop: ~100k HEAD reads in 2 seconds, ~200% CPU while idle, fans spinning non-stop.

Fix

watch_branch now filters through a head_change_event predicate that forwards:

  • semantic changes to a HEAD path (modify, create, remove, rename pairs from atomic replacement)
  • the unclassified Any/Other kinds some backends emit for real changes
  • required rescans (regardless of path)

and drops access-only events (open, read, close). Writes still arrive as Modify on every backend, so no real branch change is lost, and the directory watch stays so atomic HEAD replacement during checkout keeps working.

Tests

New test_head_watch_ignores_read_access_events covers the regression list from the issue: access-only HEAD events never schedule a refresh, real change kinds and atomic replacements still do, unrelated paths never do, and required rescans always do.

just ci passes (fmt, clippy with -D warnings across feature sets, all test suites).

Platform notes

  • macOS is not affected: the FSEvents backend has no read/open/close event kinds. A probe replicating the watcher's exact predicate and read path on macOS ran 898,111 HEAD reads in 5s against a live watch and received zero events, while an atomic HEAD replacement was still detected.
  • Linux runtime verification is pending: this was developed and validated on macOS; please confirm idle CPU and the inotify event counts on a Linux machine before merging.

Built from the head-watch-945 maple-dev-env workspace on 4178b1cc.

The chat screen's git branch watcher forwarded any event whose path ended
in HEAD, regardless of event kind. On Linux, inotify reports the app's own
branch reads as open/read/close access events, so each read retriggered
the watcher: ~100k HEAD reads in 2 seconds and ~200% CPU while idle (#945).

Filter by event kind: forward semantic changes (modify, create, remove,
rename, and the unclassified Any/Other kinds) and required rescans, and
drop access-only events. Writes still arrive as Modify on every backend,
so no real branch change is lost, and the directory watch stays so atomic
HEAD replacement during checkout keeps working.

Adds unit coverage for the new predicate: access-only HEAD events do not
schedule a refresh, real change kinds and atomic replacements still do,
unrelated paths never do, and required rescans always do.

macOS was never affected: the FSEvents backend has no read/open/close
event kinds (898k probe reads produced zero events). Linux runtime
verification is pending on the reporter's machine.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@AnthonyRonning
AnthonyRonning merged commit 7a4bef6 into master Sep 16, 2026
27 checks passed
@AnthonyRonning
AnthonyRonning deleted the codex-head-watch-945-maple branch September 16, 2026 04:14
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.

GPUI: Git HEAD watcher triggers itself on read events, consuming ~200% CPU while idle on Linux

1 participant