Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): overlapping VCS status refreshes share one follow-up refresh #24478

Mergedonly21mil(GitHub profile, opens in a new tab)merged 11 commits intomain fromrefs/pull/24478/headmerged by juliusmarminge View on GitHub

only21mil(GitHub profile, opens in a new tab)commented

Problem

Every vcs.refreshStatus call runs a full refresh (status caches cleared, an uncached PR lookup, a working-tree scan), and calls for one repository queue on the remote write lock. The web client sends this RPC when a window comes back into focus or view and when the Git menu opens, so a few windows on one repository queue one full refresh per event. In #7076 these requests took 15.8 to 24.1 seconds.

Change

VcsStatusBroadcaster.refreshStatus now tracks whether a refresh is running for a cwd. A call that arrives during it cannot reuse it, since that refresh may have read Git before the caller's change, such as a PR an agent just opened. So every call that arrives during the running refresh waits for one shared follow-up, which starts when the running one ends. N calls during one refresh now cost one more refresh instead of N.

Scope

Bug fix: a real performance problem (#7076, 15.8 to 24.1 s requests). Part of #7076 (the server half; the client's queue of refresh signals is unchanged). This PR changes one service method and adds two tests. No RPC contract or client changes.

Verification

To see it on Linux (server): 1. open one repository in several windows; 2. start a refresh; 3. focus the other windows while it runs: on main each queues its own full refresh.

Revisions: main f419698aea first, then this branch merged with that main (0154805b69). A script started a real server and sent 4 overlapping vcs.refreshStatus calls over WebSocket during a running refresh, with git fetch slowed to 2 s; three runs each:

Git processesBurst finished
main163, 163, 1634966, 4571, 7558 ms
this branch88, 88, 884249, 3895, 3328 ms

On main the four later calls are answered one after another, each after its own refresh. On this branch they are answered together by one follow-up. Other work shared the machine during these runs, so the times vary between runs; the Git process counts did not.

The new test in VcsStatusBroadcaster.test.ts fails with main's VcsStatusBroadcaster.ts (expected 3 to equal 2) and passes on this branch.

Not checked:

  • Real GitHub PR lookups, and other forges.
  • Desktop, mobile or web clients sending the RPC; the script used the same WebSocket RPC.
  • Windows and macOS.
  • A fifth client holding a status stream during the burst, so the HEAD watcher from #23422 runs: not run on 0154805b69.
Change detail, method, unedited output and test runs

Detail of the old path: it clears the status caches, reads remote status with an uncached PR lookup, then scans the working tree; each call waits on the remote write lock, then runs its own refresh.

  • The refresh itself is unchanged; the new code wraps it.
  • The broadcaster scope owns the shared work. A caller that goes away (a closed window) no longer cancels the refresh, so the other callers still get their result and subscribers still get the update.
  • Calls are grouped by the cwd string the client sent, so each refresh keeps its caller's auto-pull policy input. Two different paths to one repository (a symlink and its target) still queue on the lock as before.
  • A failed refresh fails only the calls waiting on it. The next queued refresh still runs.
  • Local-only refreshes skip the sharing and run directly, as on main.

Nothing on screen changes. Clients show the same status, sooner and with less Git work.

Through the RPC path. A script started a real server on an empty temp home and opened 4 WebSocket clients on a temporary repository with a local remote. Client 0 refreshed, then all 4 clients refreshed 300 ms later while that refresh still ran. A git wrapper counted every Git process and slowed git fetch to 2 s to stand in for the network. Three runs each.

The fixture has no GitHub remote, so no PR lookups ran; with GitHub, each extra refresh on main adds an uncached PR lookup, which #22159 measured at about 4 to 5 s.

Test. vp test run src/vcs/VcsStatusBroadcaster.test.ts in apps/server. The new test starts a refresh and sends two more while it runs. The later two must share one refresh that started after their request.

Unedited output: first RPC run of each revision, and the test runs.

Main f419698aea, first run (main-1):

revision f419698aeaf78fb0c3299b4599f118d2d66ef694 (main)
git processes in 1 s idle before the burst: 0
client 0 (first)  sent +   1 ms  answered +3192 ms  (3191 ms)  branch main
client 0 (burst)  sent + 304 ms  answered +3627 ms  (3323 ms)  branch main
client 1 (burst)  sent + 304 ms  answered +4061 ms  (3757 ms)  branch main
client 2 (burst)  sent + 306 ms  answered +4506 ms  (4200 ms)  branch main
client 3 (burst)  sent + 307 ms  answered +4966 ms  (4659 ms)  branch main
git processes: 163 (fetch: 1)
burst finished: 4966 ms

This branch 0154805b69, first run (candidate-1):

revision 0154805b6938470628752fb9104cf0fb71a8e849 (candidate)
git processes in 1 s idle before the burst: 0
client 0 (first)  sent +   1 ms  answered +3283 ms  (3282 ms)  branch main
client 0 (burst)  sent + 302 ms  answered +4248 ms  (3946 ms)  branch main
client 1 (burst)  sent + 305 ms  answered +4249 ms  (3944 ms)  branch main
client 2 (burst)  sent + 308 ms  answered +4249 ms  (3941 ms)  branch main
client 3 (burst)  sent + 308 ms  answered +4249 ms  (3941 ms)  branch main
git processes: 88 (fetch: 1)
burst finished: 4249 ms

With main f419698aea's VcsStatusBroadcaster.ts:

 FAIL  src/vcs/VcsStatusBroadcaster.test.ts > VcsStatusBroadcaster > refreshes requested during a refresh share one follow-up refresh
AssertionError: expected 3 to equal 2
 Test Files  1 failed (1)
      Tests  1 failed | 35 passed (36)

On this branch 0154805b69:

 Test Files  1 passed (1)
      Tests  36 passed (36)

vp run check:changed passes on 0154805b69, and so do the src/vcs/ suites and the GitManager, WorktreeMcpService, RunFinalizationQueue, RunFinalizationService, WorktreeBranchSync, AgentContextBudget and ws suites (15 files, 650 tests).

Prior PRs

  • #7185 by maslinedwin shared one in-flight refresh per repository. Closed during the V2 server rewrite.
  • #19478 by luke2x coalesced overlapping refreshes into a per-repository worker. Closed for missing measurements through the client path.
  • soupslurpr reported #7076 and fixed it in their fork.
  • #21872 by voltcrash and #22159 by t3dotgg made each refresh cheaper and stopped the slow-request toast; this PR removes the repeated refreshes.

Generated with Claude Opus 5.5 and GPT-6.1 Sol in T3 Code Nightly

    1. Pushed0154805

    2. Note

      🤖 Opus 5.5 replying on behalf of Victor.

      I merged main f419698aea into this branch because #34878 changed VcsStatusBroadcaster.ts and its test under this PR. The merge had no conflicts, and nothing else changed.

    3. juliusmarminge added labelstakeover:in-progress

    4. Evidence

      Four windows opened the same replay thread against fresh per-commit servers. After 25 seconds, the driver invoked the Git actions group's native focus refresh handler at 0, 0.5, 1.0 and 1.2 seconds. Focus invokes the same empty-menu handler as hover. A second burst added a file while requests waited and closed one waiting window.

      Environment: Linux Chromium, 1280×800, light theme; real GitHub-backed fixture.

      EvidenceBefore ea957b5cabAfter 22756233aa
      Scenario resultFailed: expected 4 full refreshes to be 2Passed
      Explicit RPC requests44
      Full refreshes / invalidateStatus4 / 42 / 2
      GitHub resolveRepository / listByHead / listChangeRequests / GraphQL4 each2 each
      Reply completion offsets1.791, 3.072, 4.208, 5.438 s1.708, 2.916, 2.914, 2.915 s
      Overlapping refreshesBefore: overlapping refreshesAfter: overlapping refreshes
      Fresh status after waiter disconnectBefore: fresh status after waiter disconnectAfter: fresh status after waiter disconnect
      RecordingBefore recordingAfter recording

      On head, the three queued callers completed within 2 ms of each other after one shared follow-up. After closing a waiting window, all three surviving callers returned Success with refresh-proof.txt in fresh dirty status. The longer observation interval also contains one background remote poll per side: remoteStatus totals were 5 before and 3 after.

      Runtime transcript · Before spans and replies · After spans and replies

      Scenario source

      Not shown:

      • The original PR-badge fixture was not identified in the brief; the selected public fixture has no matching PR, so badge rendering was not verified.
      • The driver used the equivalent native focus handler rather than pointer hover. Desktop and mobile clients were not separately exercised.
    5. juliusmarminge added labelstakeover:ready

    6. juliusmarminge removed labelstakeover:in-progress

    7. juliusmarminge merged this4c47315

    8. juliusmarminge closed this

    9. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.