Skip to content

Git Diff panel: one host snapshot per change, refresh only what changed - #8126

Merged
ymichael merged 1 commit into
mainfrom
bb/git-diff-panel-one-host-read-per-change-thr_6gn43fgdt3
Nov 25, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/git-diff-panel-one-host-read-per-change-thr_6gn43fgdt3

Conversation

@ymichael

@ymichael ymichael commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

While an agent works, the Diff panel cost two host round trips a second, whether or not the diff changed. The daemon reports work-status-changed for every workspace write without fingerprinting it (apps/host-daemon/src/watch-manager.ts), including identical rewrites and writes to ignored output. The git server marked both the status and files tags stale on every such event and flushed at most once a second (plugins/git/server/invalidation.ts). Each flush made the client refetch both reads, and each refetch was one plugin.host.call. Every host files call also re-ran diffPatch for up to 10 inline patches and shipped them again, though the server and client already had them at the same revision. This is finding #1 of the server→daemon RPC audit.

What changed

The change stays inside the git plugin (server and host ship as one plugin artifact). There is no daemon wire change, so no HOST_DAEMON_PROTOCOL_VERSION bump.

  • New host method snapshot (plugins/git/host.ts, contract.ts). It reads status and every watched file list in one call, sharing one git status.
    • Each part carries a sha256 fingerprint of its result.
    • When the server passes the fingerprint it already holds (statusUnless, files[].unless) and the result still matches, that part comes back as { outcome: "unchanged" }. An unchanged file list also skips diffPatch.
  • knownPatches on files and snapshot. The server names the inline patches it holds, by path and blob revision. The host reads only the others and lists the reused paths, and the server fills them back in. The client contract (files.initialPatches) is unchanged.
  • Server flush becomes a probe (server.ts).
    • A coalesced status/files invalidation for a watched environment now makes one snapshot call with the status and the watched file-list queries.
    • The server compares the result with what it served while those reads were watched, and invalidates only the tags whose result changed. Other tags (refs, viewed) still publish directly.
    • The snapshot replaces the read memo entries, so the client's refetch is served without another host call.
    • Probes for an environment run one at a time; tags that arrive during a probe go through the coalescer again.
    • The turn-end check uses the same probe, and now compares the file lists as well as status.
  • Several repos (Find git repos inside a thread's folders and group the Changes panel by repo #8062). The snapshot follows the Changes panel's repo list: one snapshot call per repo folder, carrying that repo's watched file lists (with each extra repo's own target) and its status, plus the environment folder's status when no repo is rooted there. A single-repo environment still makes one call. The merged, repo-grouped result is compared with what was served, so a changed repo list also refreshes the panel.
  • Watched file lists keep their memo on change events. Unwatched file-list queries are evicted when the workspace changes or their last watcher leaves. The probe owns their freshness: it drops any in-flight read and replaces the entry, so a read that started before a change can't stand in for the check after it. Unwatched environments still clear on every change. If a probe fails or can't cover a tag, the server clears the memo before invalidating.
  • Shorter quiet period (server/invalidation.ts). A probe now waits 50 ms of quiet instead of 250 ms, with a 250 ms max wait instead of 500 ms. The 1 s minimum spacing per environment stays, so there is still at most one host call a second. The long debounce existed to batch client refetches; a no-op probe now costs a 275 B reply and no refetch, so it only delayed real edits.
  • server/invalidation.ts passes the environment id to publish. DIFF_FILES_INLINE_PATCH_MAX_FILES moved to contract.ts, the schema that uses it. The README and PLUGIN_OVERVIEW.md describe the new refresh.

Not changed: no-op writes still cost one background snapshot per second. It is answered unchanged in 275 B and causes no client refetch. Filtering earlier would mean host-side change detection. The daemon's work-status-changed has to stay unfiltered, because core's environment file previews depend on it for ignored files too.

How you verified

Real servers, same input (af25b0b5a60 vs this branch, fresh /tmp data dirs):

  • The workspace was a 9,101-file clone of this repo on a second enrolled daemon. It connected through a WebSocket-aware proxy that adds 100 ms each way (200 ms RTT) and logs every daemon↔server frame by request id.
  • The Diff panel was open in headless Chrome: "All changes", 3 changed files, inline patches.
  • Each run lasts 60 s and makes 11 real edits: append a line to one of 3 tracked files, every 5 s plus a random 0–1 s offset. The churn scenario also writes every 250 ms, alternating an identical rewrite of package.json and a write to a .git/info/excluded directory, which is about 230 work-status-changed events a minute.
  • Latency is measured from the edit to the new +N count in the panel. Latency cells are means over the listed runs (each run is 11 edits). Host-call counts and bytes were identical across runs to within 1 call. The branch numbers in this table were measured at f0d08f9.
per minute main, churn branch, churn main, edits only branch, edits only
git host calls 122 (61 status + 61 files) 61 snapshot (~50 answered unchanged) 24 (12 + 12) 12 snapshot
git host request bytes 365 KB 219 KB 72 KB 43 KB
git host response bytes 224 KB 45 KB 44 KB 32 KB
client status + files refetches 122 22 24 22
edit → panel, mean (runs) 603 ms (667, 669, 693, 382) 625 ms (680, 570) 744 ms (740, 748) 590 ms (590, 589)

Per action:

  • A real edit: 2 host calls → 1, and it shows up ~150 ms sooner (744 → 590 ms with 200 ms RTT).
  • A burst of no-op writes: 2 host calls with full payloads plus 2 client refetches per flush → 1 snapshot with a 275 B unchanged reply and no client refetch.

About 3.4 KB of each host request is core's contributedEnv, sent on every plugin.host.call (audit finding #9); it is out of scope here.

Latency phases for edits only, mean of 22 edits:

phase main branch
write → daemon event at proxy 90 ms 90 ms
event → host request (quiet period + 100 ms one-way) 362 ms 158 ms
host round trip 210 ms 209 ms
host response → panel 82 ms 134 ms

The last row is ~52 ms longer on the branch: after the probe invalidates, the client makes one more client→server→plugin request, which the snapshot-seeded memo answers. That cost is fixed and doesn't grow with host RTT, and the shorter quiet period more than covers it.

Under churn, latency is set by where an edit lands against the 1 s minimum spacing, which both builds share. Run-to-run spread (382–693 ms on main) is larger than the difference between builds.

Tests:

  • plugins/git/server/invalidation.test.ts: covers the 50 ms quiet period, the 250 ms max wait and the unchanged 1 s spacing.
  • plugins/git/server.test.ts (new "workspace change refreshes" block, each failing on main):
    • one snapshot and no invalidation for unchanged bursts, with later reads served from it;
    • only the changed tag is invalidated, and its refetch is served from the snapshot;
    • the host answers unchanged for parts the server holds;
    • a read in flight across a change does not stand in for the probe;
    • the host is asked only for patches the server doesn't hold, and the client still gets the full initialPatches.
  • plugins/git/host.test.ts: against a real repo, files and snapshot re-read only patches whose revision changed, and a matching fingerprint yields unchanged.
  • Existing turn-end, invalidation and CLI tests are updated for the new publish signature and host output shape.
  • pnpm exec turbo run typecheck test lint:type-aware --filter=bb-plugin-bb--git passes locally. Full suites are left to CI.

Review follow-up (6fbb7c1): A previously read alternate whitespace view now returned the new file 1.45 s after the edit, before the 3 s cache expiry. A rejected host snapshot now sends both reads through the fallback without an unhandled rejection. Both regression cases failed on the prior revision. All 301 git plugin tests, typecheck and type-aware lint passed. With the 200 ms RTT proxy, the updated branch made 61 host snapshots and 22 client status/files refetches in one minute of churn. All 11 edits reached the panel, averaging 685 ms.

🤖 Generated with Claude Code

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/git-diff-panel-one-host-read-per-change-thr_6gn43fgdt3 branch from 6fbb7c1 to 3bf7ede Compare November 25, 2026 00:20
@ymichael
ymichael merged commit d2273e7 into main Nov 25, 2026
50 checks passed
@ymichael
ymichael deleted the bb/git-diff-panel-one-host-read-per-change-thr_6gn43fgdt3 branch November 25, 2026 18:21
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