Skip to content

Re-create failed worktree watchers and stop reinspecting on every read - #1555

Merged
milanb17 merged 1 commit into
mainfrom
mb/issue-1548-investigation-38fdd2
Nov 19, 2026
Merged

milanb17 merged 1 commit into
mainfrom
mb/issue-1548-investigation-38fdd2

Conversation

@milanb17

@milanb17 milanb17 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1548.

Problem

A live worktree's cached inspection was reused only while its watchers were healthy. One watcher error (or a failed subscribe) marked the worktree unhealthy and dropped the subscription, and nothing ever resubscribed or cleared the flag. From then on every 1 s refresh pass and every GET re-ran a full inspection (git calls plus an lstat of every working file) for every live board on that worktree, until the app restarted.

Change

A worktree is either watched or not:

  • Watched: the cached inspection is reused until a watcher event changes the epoch. Unchanged.
  • A watcher is missing: the cached inspection is reused for 10 s. The next read after that subscribes again, then inspects.

A watcher error only drops the subscription. There is no retry timer or backoff: resubscribing happens as part of the 10 s check, so a watcher that keeps failing is bounded by the same rule. Watcher failures are now logged; they were silent before.

Measured

One live board on a 3,000-file repository, refreshed once a second, with a watcher error injected at 10 s. Figures are for the 30 s after the error; CPU is the server process only.

Inspections git spawns Server CPU
Before 30 120 about 80 ms/s
After, watcher comes back 1 4 about 5 ms/s
After, watcher cannot come back 3 12 about 12 ms/s

Trade-offs

  • If the worktree was inspected in the 10 s before its watcher fails, the board can lag an edit by up to 10 s, once per outage.
  • A missing watcher is only resubscribed when something reads the worktree.
  • If resubscribing never succeeds, the worktree is inspected every 10 s.

Testing

The existing "continues capturing after watchers fail" test now also checks that repeated refreshes after a watcher error run no inspection. The case where resubscribing keeps failing has no automated test. Typecheck and lint pass. Not reproduced in a running Desktop.

@milanb17
milanb17 force-pushed the mb/issue-1548-investigation-38fdd2 branch 2 times, most recently from 3aa45ab to 005cf32 Compare November 19, 2026 19:47
One watcher error, or a failed subscribe, marked a live worktree unhealthy
for good. Every refresh tick and GET then re-ran a full inspection (git
ls-files plus an lstat per working file) for every live board on it, until
the app restarted.

A worktree with a missing watcher now reuses its last inspection for ten
seconds. The next read after that subscribes again and then inspects, so a
watcher that comes back costs one inspection and one that cannot costs one
every ten seconds. Watcher failures are logged.

Closes #1548.

Agent-Session: f5bf6b6e-2f61-4a5d-a234-befeae23de4d
Agent-Session: 33d99bfe-0d11-4a51-86b9-0a2f51551005
@milanb17 milanb17 changed the title Re-create failed worktree watchers and throttle unwatched inspections Re-create failed worktree watchers and stop reinspecting on every read Nov 19, 2026
@milanb17
milanb17 force-pushed the mb/issue-1548-investigation-38fdd2 branch from 005cf32 to 7f46f87 Compare November 19, 2026 20:17
@milanb17
milanb17 enabled auto-merge (squash) November 19, 2026 20:23
@milanb17
milanb17 merged commit 99cbce4 into main Nov 19, 2026
3 checks passed
@milanb17
milanb17 deleted the mb/issue-1548-investigation-38fdd2 branch November 19, 2026 20:31
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.

One file watcher error makes a live worktree board re-run git every second until restart

2 participants