From 63c6423af2d7a416b048ed47aaba497710627b53 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 23:58:21 +0000 Subject: [PATCH 1/2] test(server): a remote poll that moves no ref does not re-read local status Repro for #39986: on main every 30 s VCS poll re-reads full local status even when the ref snapshot is unchanged. Co-Authored-By: Claude Opus 5.5 --- .../src/vcs/VcsStatusBroadcaster.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts index e367bacb5a7dc..95635c359ce2d 100644 --- a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts +++ b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts @@ -1332,6 +1332,44 @@ describe("VcsStatusBroadcaster", () => { }).pipe(Effect.provide(layerTestFor(state))); }); + it.effect("a remote poll that moves no ref does not re-read local status", () => { + const state: Parameters[0] = { + currentLocalStatus: baseLocalStatus, + currentRemoteStatus: baseRemoteStatus, + localStatusCalls: 0, + remoteStatusCalls: 0, + localInvalidationCalls: 0, + remoteInvalidationCalls: 0, + }; + + return Effect.gen(function* () { + const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster; + yield* broadcaster.getStatus({ cwd: "/repo" }); + const subscribed = yield* Deferred.make(); + const remoteUpdates = yield* Queue.unbounded(); + yield* broadcaster.streamStatus({ cwd: "/repo" }).pipe( + Stream.runForEach((event) => { + if (event._tag === "snapshot") return Deferred.succeed(subscribed, undefined); + if (event._tag === "remoteUpdated") return Queue.offer(remoteUpdates, undefined); + return Effect.void; + }), + Effect.forkScoped, + ); + yield* Deferred.await(subscribed); + state.currentRemoteStatus = remoteStatusWithPr; + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(remoteUpdates); + const localCalls = state.localStatusCalls; + const remoteCalls = state.remoteStatusCalls; + + state.currentRemoteStatus = baseRemoteStatus; + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(remoteUpdates); + assert.equal(state.remoteStatusCalls, remoteCalls + 1); + assert.equal(state.localStatusCalls, localCalls); + }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped); + }); + it.effect("reads Changes totals only while a subscriber shows them", () => { const branchChanges = { baseRef: "origin/main", insertions: 3, deletions: 1 }; const state: Parameters[0] = { From a560485e57b9bac88185f7a8ae7f4aad0dad19e7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 01:59:18 +0000 Subject: [PATCH 2/2] fix(server): idle Git polls no longer re-read local status when no ref moved The 30-second remote poll re-read full local status after every remote read, even when nothing was fetched and no ref moved. Each poll now compares `readRefSnapshot` with the snapshot from its last local read and re-reads only when refs changed, as refreshRemoteAndLocalTotals already does. Fixes pingdotgg/t3code#39986 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/vcs/VcsStatusBroadcaster.test.ts | 6 ++++++ apps/server/src/vcs/VcsStatusBroadcaster.ts | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts index 95635c359ce2d..69c33b785bd41 100644 --- a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts +++ b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts @@ -1367,6 +1367,12 @@ describe("VcsStatusBroadcaster", () => { yield* Queue.take(remoteUpdates); assert.equal(state.remoteStatusCalls, remoteCalls + 1); assert.equal(state.localStatusCalls, localCalls); + + state.refSnapshot = "fetched"; + state.currentRemoteStatus = remoteStatusWithPr; + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(remoteUpdates); + assert.equal(state.localStatusCalls, localCalls + 1); }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped); }); diff --git a/apps/server/src/vcs/VcsStatusBroadcaster.ts b/apps/server/src/vcs/VcsStatusBroadcaster.ts index c39b826951025..8a507e799c827 100644 --- a/apps/server/src/vcs/VcsStatusBroadcaster.ts +++ b/apps/server/src/vcs/VcsStatusBroadcaster.ts @@ -668,6 +668,8 @@ export const make = Effect.gen(function* () { options?: { readonly refreshUpstream?: boolean; readonly policyCwds?: ReadonlyArray; + /** Refs seen by this caller's last local read; skips the re-read while they hold. */ + readonly refsAtLocalRead?: Ref.Ref; }, ) { return yield* withRemoteWriteLock( @@ -680,7 +682,17 @@ export const make = Effect.gen(function* () { : yield* maybeAutoPull(cwd, remoteRead, options?.policyCwds ?? [cwd]); if (pulled !== null) return pulled.remote; // Base refs and merge bases can move without changing divergence counts. - yield* refreshLocalStatusCore(cwd); + const refsAtLocalRead = options?.refsAtLocalRead; + if (refsAtLocalRead === undefined) { + yield* refreshLocalStatusCore(cwd); + } else { + const refs = yield* workflow.readRefSnapshot(cwd); + if (refs === null || refs !== (yield* Ref.get(refsAtLocalRead))) { + yield* Ref.set(refsAtLocalRead, null); + yield* refreshLocalStatusCore(cwd); + yield* Ref.set(refsAtLocalRead, refs); + } + } return yield* updateCachedRemoteStatus(cwd, remoteRead, { publish: true }); }), ); @@ -771,6 +783,7 @@ export const make = Effect.gen(function* () { ) { const consecutiveFailuresRef = yield* Ref.make(0); const needsInitialRefreshRef = yield* Ref.make(refreshImmediately); + const refsAtLocalReadRef = yield* Ref.make(null); const refreshRemoteStatusIfEnabled = Effect.gen(function* () { const configuredInterval = yield* automaticFetchInterval; const activeInterval = Duration.isZero(configuredInterval) @@ -800,6 +813,7 @@ export const make = Effect.gen(function* () { const exit = yield* refreshRemoteStatus(cwd, { refreshUpstream: !Duration.isZero(configuredInterval), policyCwds: [...demandCwds.keys()], + refsAtLocalRead: refsAtLocalReadRef, }).pipe(Effect.exit); if (Exit.isSuccess(exit)) { yield* Ref.set(needsInitialRefreshRef, false);