Skip to content

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

Closed

Description

@AnthonyRonning

Problem

The Maple Agent GPUI client consumes roughly two CPU cores while idle on Linux, with no active agent turn. Its Git branch watcher responds to its own reads of .git/HEAD, creating a continuous feedback loop.

Observed on commit 4178b1cce97ad9039db49ba5ecf33dbd3e79ef2b, built with the component's pinned Nix environment using nix develop --no-update-lock-file -c just release. Environment: Linux, Hyprland/Wayland, Intel Iris Xe graphics.

Cause

ChatScreen::watch_branch forwards any event whose path ends in HEAD, without filtering its event kind:

if touches_head || event.need_rescan() {
    tx.send(()).ok();
}

The receiver invokes read_branch, which calls git_branch and reads HEAD with std::fs::read_to_string. The resolved notify 8 Linux inotify backend emits access events for file opens and closes after reads. Those events satisfy the same path check and trigger another branch read.

Sequence: read HEAD → open/close-read events → watcher notification → read HEAD again.

The receiver drains queued notifications per burst, but that does not stop new events generated by each subsequent read. The unchanged-branch check prevents unnecessary label changes but happens after the filesystem read has already generated more events.

Runtime evidence

  • A five-second sample measured about 200% process CPU, equivalent to two full cores.
  • Per-thread sampling showed substantial work in the main UI thread, the notify-rs inoti watcher thread, and Tokio workers.
  • The app's inotify watch was confirmed to target the selected checkout's .git directory by matching its inode.
  • An independent inotify observer counted only HEAD events; it did not read HEAD itself.
App state Sample duration HEAD reads HEAD opens HEAD closes after read
Running idle 2 seconds 100,334 100,333 100,333
Process briefly paused 2 seconds 0 0 0
Process resumed 2 seconds 109,959 109,960 109,958

No HEAD modification or close-after-write events were observed in those samples. The app was resumed immediately after the diagnostic pause. This corroborates a read-driven feedback loop rather than an active agent turn or ongoing Git writes.

Expected behavior / suggested fix

An idle branch label should not cause continuous filesystem reads or significant CPU use.

Filter branch-watcher events by semantic change: ignore read/open/close-read access events, while preserving relevant HEAD modifications, creation, removal, rename/replacement, and required rescans. Keep the directory watch so atomic HEAD replacement during checkout remains supported. Debouncing alone is not sufficient to remove the self-triggering loop.

Suggested regression coverage:

  • Access-only HEAD events do not schedule branch refreshes.
  • Real HEAD changes and atomic replacements still update the branch label.
  • Unrelated paths do not schedule refreshes; required rescans still do.
  • Linux runtime smoke confirms repeated branch reads do not trigger further refreshes and idle CPU returns to a low level.

No fix has been implemented yet. Runtime confirmation is limited to Linux; other platforms have not been tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions