The best way to control Claude Code, Codex and more from any computer or phone
fix(server): overlapping VCS status refreshes share one follow-up refresh (#24478)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 14, 2026 at 01:23 UTC
4c473155380de68ac20dfa7dd45ab716cc911583
2 files changed
+139
-2
apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+87
-1
@@ -80,7 +80,7 @@ function layerTestFor(state: {
80
remoteStatusError?: GitManagerError;
81
backgroundWorkEnabled?: boolean;
82
automaticFetchInterval?: Effect.Effect<Duration.Duration>;
83
- beforeRemoteStatus?: Effect.Effect<void>;
83
+ beforeRemoteStatus?: Effect.Effect<void, GitManagerError>;
84
beforeLocalStatus?: Effect.Effect<void>;
85
beforeCurrentBranch?: Effect.Effect<void>;
86
beforeInvalidate?: Effect.Effect<void>;
@@ -1724,6 +1724,92 @@ describe("VcsStatusBroadcaster", () => {
1724
assert.isTrue(Option.isSome(yield* Deferred.poll(remoteInterrupted)));
1725
}).pipe(Effect.provide(layerTest));
1726
});
1727
+
1728
+ it.effect("refreshes requested during a refresh share one follow-up refresh", () => {
1729
+ const state: Parameters<typeof layerTestFor>[0] = {
1730
+ currentLocalStatus: baseLocalStatus,
1731
+ currentRemoteStatus: baseRemoteStatus,
1732
+ localStatusCalls: 0,
1733
+ remoteStatusCalls: 0,
1734
+ localInvalidationCalls: 0,
1735
+ remoteInvalidationCalls: 0,
1736
+ };
1737
+
1738
+ return Effect.gen(function* () {
1739
+ const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1740
+ const fetchStarted = yield* Deferred.make<void>();
1741
+ const finishFetch = yield* Deferred.make<void>();
1742
+ state.beforeRemoteStatus = Deferred.succeed(fetchStarted, undefined).pipe(
1743
+ Effect.andThen(Deferred.await(finishFetch)),
1744
+ );
1745
+ const first = yield* broadcaster.refreshStatus("/repo").pipe(Effect.forkScoped);
1746
+ yield* Deferred.await(fetchStarted);
1747
+ // Every read after the first sees a PR, so a caller that reused the
1748
+ // first refresh would get a status from before its own request.
1749
+ state.beforeRemoteStatus = Effect.sync(() => {
1750
+ state.currentRemoteStatus = remoteStatusWithPr;
1751
+ });
1752
+ const later = yield* Effect.all(
1753
+ [broadcaster.refreshStatus("/repo"), broadcaster.refreshStatus("/repo")],
1754
+ { concurrency: "unbounded" },
1755
+ ).pipe(Effect.forkScoped({ startImmediately: true }));
1756
+ yield* Deferred.succeed(finishFetch, undefined);
1757
+
1758
+ assert.isNull((yield* Fiber.join(first)).pr);
1759
+ const [second, third] = yield* Fiber.join(later);
1760
+ assert.deepStrictEqual(second.pr, remoteStatusWithPr.pr);
1761
+ assert.deepStrictEqual(third.pr, remoteStatusWithPr.pr);
1762
+ assert.equal(state.remoteStatusCalls, 2);
1763
+
1764
+ yield* broadcaster.refreshStatus("/repo");
1765
+ assert.equal(state.remoteStatusCalls, 3);
1766
+ }).pipe(Effect.provide(layerTestFor(state)));
1767
+ });
1768
+
1769
+ it.effect("a failed refresh releases interrupted waiters and runs the shared follow-up", () => {
1770
+ const state: Parameters<typeof layerTestFor>[0] = {
1771
+ currentLocalStatus: baseLocalStatus,
1772
+ currentRemoteStatus: remoteStatusWithPr,
1773
+ localStatusCalls: 0,
1774
+ remoteStatusCalls: 0,
1775
+ localInvalidationCalls: 0,
1776
+ remoteInvalidationCalls: 0,
1777
+ };
1778
+
1779
+ return Effect.gen(function* () {
1780
+ const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1781
+ const started = yield* Deferred.make<void>();
1782
+ const release = yield* Deferred.make<void>();
1783
+ state.beforeRemoteStatus = Deferred.succeed(started, undefined).pipe(
1784
+ Effect.andThen(Deferred.await(release)),
1785
+ Effect.andThen(
1786
+ Effect.fail(
1787
+ new GitManagerError({
1788
+ operation: "VcsStatusBroadcaster.test",
1789
+ cwd: "/repo",
1790
+ detail: "remote status failed",
1791
+ }),
1792
+ ),
1793
+ ),
1794
+ );
1795
+ const first = yield* broadcaster.refreshStatus("/repo").pipe(Effect.exit, Effect.forkScoped);
1796
+ yield* Deferred.await(started);
1797
+ const interrupted = yield* broadcaster
1798
+ .refreshStatus("/repo")
1799
+ .pipe(Effect.forkScoped({ startImmediately: true }));
1800
+ const remaining = yield* broadcaster
1801
+ .refreshStatus("/repo")
1802
+ .pipe(Effect.forkScoped({ startImmediately: true }));
1803
+ yield* Fiber.interrupt(interrupted);
1804
+ state.beforeRemoteStatus = Effect.void;
1805
+ yield* Deferred.succeed(release, undefined);
1806
+ assert.isTrue(Exit.isFailure(yield* Fiber.join(first)));
1807
+ assert.deepStrictEqual((yield* Fiber.join(remaining)).pr, remoteStatusWithPr.pr);
1808
+ assert.equal(state.remoteStatusCalls, 1);
1809
+ yield* broadcaster.refreshStatus("/repo");
1810
+ assert.equal(state.remoteStatusCalls, 2);
1811
+ }).pipe(Effect.provide(layerTestFor(state)));
1812
+ });
1813
});
1814
1815
const newState = (): Parameters<typeof layerTestFor>[0] => ({
apps/server/src/vcs/VcsStatusBroadcaster.ts
+52
-1
@@ -799,6 +799,57 @@ export const make = Effect.gen(function* () {
799
}
800
});
801
802
+ // A request made during a refresh needs a read that starts after it, so overlapping requests
803
+ // share one follow-up. Keyed by raw cwd because auto-pull policy depends on it.
804
+ // Missing means idle; null means running with no follow-up queued.
805
+ type SharedRefresh = Deferred.Deferred<VcsStatusResult, GitManagerServiceError>;
806
+ const queuedRefreshesRef = yield* Ref.make(new Map<string, SharedRefresh | null>());
807
+
808
+ const runQueuedRefreshes = Effect.fn("VcsStatusBroadcaster.runQueuedRefreshes")(function* (
809
+ rawCwd: string,
810
+ first: SharedRefresh,
811
+ ) {
812
+ let next: SharedRefresh | null = first;
813
+ while (next !== null) {
814
+ yield* Deferred.into(refreshStatus(rawCwd), next);
815
+ next = yield* Ref.modify(queuedRefreshesRef, (queued) => {
816
+ const followUp = queued.get(rawCwd) ?? null;
817
+ const nextQueued = new Map(queued);
818
+ if (followUp === null) {
819
+ nextQueued.delete(rawCwd);
820
+ } else {
821
+ nextQueued.set(rawCwd, null);
822
+ }
823
+ return [followUp, nextQueued] as const;
824
+ });
825
+ }
826
+ });
827
+
828
+ const shareQueuedRefreshStatus: VcsStatusBroadcaster["Service"]["refreshStatus"] = Effect.fn(
829
+ "VcsStatusBroadcaster.shareQueuedRefreshStatus",
830
+ )(function* (rawCwd, options) {
831
+ if (options?.localOnly) return yield* refreshStatus(rawCwd, options);
832
+ const requested = yield* Deferred.make<VcsStatusResult, GitManagerServiceError>();
833
+ // Registering and forking together keeps an interrupt from leaving an entry with no worker.
834
+ const shared = yield* Effect.uninterruptible(
835
+ Effect.gen(function* () {
836
+ const followUp = yield* Ref.modify(
837
+ queuedRefreshesRef,
838
+ (queued): readonly [SharedRefresh | undefined, Map<string, SharedRefresh | null>] => {
839
+ if (!queued.has(rawCwd)) return [undefined, new Map(queued).set(rawCwd, null)];
840
+ const followUp = queued.get(rawCwd) ?? requested;
841
+ return [followUp, new Map(queued).set(rawCwd, followUp)];
842
+ },
843
+ );
844
+ if (followUp !== undefined) return followUp;
845
+ // The broadcaster scope owns the work, so one caller's interrupt does not cancel it for the rest.
846
+ yield* runQueuedRefreshes(rawCwd, requested).pipe(Effect.forkIn(broadcasterScope));
847
+ return requested;
848
+ }),
849
+ );
850
+ return yield* Deferred.await(shared);
851
+ });
852
+
853
// Serialize branch publication and cache invalidation with detailed reads and refreshes.
854
const refreshBranchStatusCore = Effect.fn("VcsStatusBroadcaster.refreshBranchStatusCore")(
855
(cwd: string) =>
@@ -1028,7 +1079,7 @@ export const make = Effect.gen(function* () {
1079
),
1080
getStatus,
1081
refreshLocalStatus,
1031
- refreshStatus,
1082
+ refreshStatus: shareQueuedRefreshStatus,
1083
refreshPullRequestStatus,
1084
streamStatus,
1085
});