@devries-cameron20 / t3code-1 / commits / a5d21a3ce4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(server): command palette status rows skip the Changes totals they never show (#32351)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Andrei committed Nov 15, 2026 at 13:49 UTC a5d21a3ce466d143c74f7bb3810b290d9e99eb51
4 files changed +228 -31
apps/server/src/git/GitManager.ts
+32 -9
@@ -102,6 +102,11 @@ export interface GitRunStackedActionOptions {
102 readonly progressReporter?: GitActionProgressReporter;
103 }
104
105 +export interface GitLocalStatusOptions {
106 + /** Defaults to true. The branch-wide totals cost about half of a local status read. */
107 + readonly includeBranchChanges?: boolean;
108 +}
109 +
110 export interface GitRemoteStatusOptions extends GitVcsDriver.GitRemoteStatusOptions {
111 readonly refreshMissingPullRequest?: boolean;
112 }
@@ -132,6 +137,7 @@ export class GitManager extends Context.Service<
137 ) => Effect.Effect<VcsStatusResult, GitManagerServiceError>;
138 readonly localStatus: (
139 input: VcsStatusInput,
140 + options?: GitLocalStatusOptions,
141 ) => Effect.Effect<VcsStatusLocalResult, GitManagerServiceError>;
142 readonly remoteStatus: (
143 input: VcsStatusInput,
@@ -1202,9 +1208,12 @@ export const make = Effect.gen(function* () {
1208 behindCount: 0,
1209 aheadOfDefaultCount: 0,
1210 };
1205 - const readLocalStatus = Effect.fn("readLocalStatus")(function* (cwd: string) {
1211 + const readLocalStatus = Effect.fn("readLocalStatus")(function* (
1212 + cwd: string,
1213 + includeBranchChanges: boolean,
1214 + ) {
1215 const details = yield* gitCore
1207 - .statusDetailsLocal(cwd, { includeDivergence: false, includeBranchChanges: true })
1216 + .statusDetailsLocal(cwd, { includeDivergence: false, includeBranchChanges })
1217 .pipe(
1218 Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(nonRepositoryStatusDetails)),
1219 );
@@ -1223,13 +1232,22 @@ export const make = Effect.gen(function* () {
1232 ...(details.branchChanges ? { branchChanges: details.branchChanges } : {}),
1233 } satisfies VcsStatusLocalResult;
1234 });
1226 - const localStatusResultCache = yield* Cache.makeWith(readLocalStatus, {
1227 - capacity: STATUS_RESULT_CACHE_CAPACITY,
1228 - timeToLive: (exit) => (Exit.isSuccess(exit) ? STATUS_RESULT_CACHE_TTL : Duration.zero),
1229 - });
1235 + const makeLocalStatusResultCache = (includeBranchChanges: boolean) =>
1236 + Cache.makeWith((cwd: string) => readLocalStatus(cwd, includeBranchChanges), {
1237 + capacity: STATUS_RESULT_CACHE_CAPACITY,
1238 + timeToLive: (exit) => (Exit.isSuccess(exit) ? STATUS_RESULT_CACHE_TTL : Duration.zero),
1239 + });
1240 + // Separate entries, so a read without totals is never served to a caller that shows them.
1241 + const localStatusResultCache = yield* makeLocalStatusResultCache(true);
1242 + const localStatusWithoutBranchChangesCache = yield* makeLocalStatusResultCache(false);
1243 const invalidateLocalStatusResultCache = (cwd: string) =>
1244 normalizeStatusCacheKey(cwd).pipe(
1232 - Effect.flatMap((cacheKey) => Cache.invalidate(localStatusResultCache, cacheKey)),
1245 + Effect.flatMap((cacheKey) =>
1246 + Effect.all([
1247 + Cache.invalidate(localStatusResultCache, cacheKey),
1248 + Cache.invalidate(localStatusWithoutBranchChangesCache, cacheKey),
1249 + ]),
1250 + ),
1251 );
1252 const prLookupEpochByCwd = new Map<string, number>();
1253 const prLookupEpoch = (cwd: string) => prLookupEpochByCwd.get(cwd) ?? 0;
@@ -2554,9 +2572,14 @@ export const make = Effect.gen(function* () {
2572 });
2573
2574 const localStatus: GitManager["Service"]["localStatus"] = Effect.fn("localStatus")(
2557 - function* (input) {
2575 + function* (input, options) {
2576 const cacheKey = yield* normalizeStatusCacheKey(input.cwd);
2559 - return yield* Cache.get(localStatusResultCache, cacheKey);
2577 + return yield* Cache.get(
2578 + options?.includeBranchChanges === false
2579 + ? localStatusWithoutBranchChangesCache
2580 + : localStatusResultCache,
2581 + cacheKey,
2582 + );
2583 },
2584 );
2585 const remoteStatus: GitManager["Service"]["remoteStatus"] = Effect.fn("remoteStatus")(
apps/server/src/git/GitWorkflowService.ts
+3 -2
@@ -51,6 +51,7 @@ export class GitWorkflowService extends Context.Service<
51 ) => Effect.Effect<VcsStatusResult, GitManagerServiceError>;
52 readonly localStatus: (
53 input: VcsStatusInput,
54 + options?: GitManager.GitLocalStatusOptions,
55 ) => Effect.Effect<VcsStatusLocalResult, GitManagerServiceError>;
56 readonly currentBranch: (cwd: string) => Effect.Effect<string | null, GitManagerServiceError>;
57 readonly upstreamDivergence: (cwd: string) => Effect.Effect<
@@ -341,11 +342,11 @@ export const make = Effect.gen(function* () {
342 ),
343 );
344 }),
344 - localStatus: Effect.fn("GitWorkflowService.localStatus")(function (input) {
345 + localStatus: Effect.fn("GitWorkflowService.localStatus")(function (input, options) {
346 return detectGitRepositoryForStatus("GitWorkflowService.localStatus", input.cwd).pipe(
347 Effect.flatMap((isGitRepository) =>
348 isGitRepository
348 - ? gitManager.localStatus(input)
349 + ? gitManager.localStatus(input, options)
350 : Effect.succeed(nonRepositoryLocalStatus()),
351 ),
352 );
apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+124 -6
@@ -78,6 +78,7 @@ function layerTestFor(state: {
78 localInvalidationCalls: number;
79 remoteInvalidationCalls: number;
80 remoteStatusRefreshUpstreamValues?: Array<boolean | undefined>;
81 + localStatusBranchChanges?: Array<boolean>;
82 refSnapshot?: string | null;
83 remoteStatusError?: GitManagerError;
84 backgroundWorkEnabled?: boolean;
@@ -109,9 +110,13 @@ function layerTestFor(state: {
110 ),
111 Layer.provide(
112 Layer.mock(GitWorkflowService.GitWorkflowService)({
112 - localStatus: () =>
113 + localStatus: (_input, options) =>
114 Effect.suspend(() => {
115 state.localStatusCalls += 1;
116 + const includeBranchChanges = options?.includeBranchChanges !== false;
117 + state.localStatusBranchChanges?.push(includeBranchChanges);
118 + const { branchChanges: _branchChanges, ...withoutBranchChanges } =
119 + state.currentLocalStatus;
120 if (state.failLocalStatus) {
121 return (state.onLocalStatusFailure ?? Effect.void).pipe(
122 Effect.andThen(
@@ -126,7 +131,7 @@ function layerTestFor(state: {
131 );
132 }
133 return (state.beforeLocalStatus ?? Effect.void).pipe(
129 - Effect.as(state.currentLocalStatus),
134 + Effect.as(includeBranchChanges ? state.currentLocalStatus : withoutBranchChanges),
135 );
136 }),
137 repositoryRoot: () => Effect.sync(() => (state.currentLocalStatus.isRepo ? "/repo" : null)),
@@ -1158,6 +1163,116 @@ describe("VcsStatusBroadcaster", () => {
1163 }).pipe(Effect.provide(layerTestFor(state)));
1164 });
1165
1166 + it.effect("reads Changes totals only while a subscriber shows them", () => {
1167 + const branchChanges = { baseRef: "origin/main", insertions: 3, deletions: 1 };
1168 + const state: Parameters<typeof layerTestFor>[0] = {
1169 + currentLocalStatus: { ...baseLocalStatus, branchChanges },
1170 + currentRemoteStatus: baseRemoteStatus,
1171 + localStatusCalls: 0,
1172 + remoteStatusCalls: 0,
1173 + localInvalidationCalls: 0,
1174 + remoteInvalidationCalls: 0,
1175 + localStatusBranchChanges: [],
1176 + };
1177 +
1178 + return Effect.gen(function* () {
1179 + const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1180 + const paletteEvents = yield* Queue.unbounded<VcsStatusStreamEvent>();
1181 + yield* broadcaster.streamStatus({ cwd: "/repo", includeRemote: false }).pipe(
1182 + Stream.runForEach((event) => Queue.offer(paletteEvents, event)),
1183 + Effect.forkScoped,
1184 + );
1185 + const paletteSnapshot = yield* Queue.take(paletteEvents);
1186 + assert.strictEqual(paletteSnapshot._tag, "snapshot");
1187 + if (paletteSnapshot._tag === "snapshot") {
1188 + assert.isUndefined(paletteSnapshot.local.branchChanges);
1189 + }
1190 + yield* broadcaster.refreshLocalStatus("/repo");
1191 + assert.deepStrictEqual(state.localStatusBranchChanges, [false, false]);
1192 +
1193 + const headerScope = yield* Scope.make();
1194 + const headerEvents = yield* Queue.unbounded<VcsStatusStreamEvent>();
1195 + yield* broadcaster.streamStatus({ cwd: "/repo" }).pipe(
1196 + Stream.runForEach((event) => Queue.offer(headerEvents, event)),
1197 + Effect.forkIn(headerScope),
1198 + );
1199 + const headerSnapshot = yield* Queue.take(headerEvents);
1200 + assert.strictEqual(headerSnapshot._tag, "snapshot");
1201 + if (headerSnapshot._tag === "snapshot") {
1202 + assert.deepStrictEqual(headerSnapshot.local.branchChanges, branchChanges);
1203 + }
1204 + const paletteUpdate = yield* Queue.take(paletteEvents);
1205 + assert.strictEqual(paletteUpdate._tag, "localUpdated");
1206 + if (paletteUpdate._tag === "localUpdated") {
1207 + assert.deepStrictEqual(paletteUpdate.local.branchChanges, branchChanges);
1208 + }
1209 + // The header's first remote poll also rereads local status.
1210 + while ((yield* Queue.take(headerEvents))._tag !== "remoteUpdated") {}
1211 + const turnEnd = yield* broadcaster.refreshLocalStatus("/repo");
1212 + assert.deepStrictEqual(turnEnd.branchChanges, branchChanges);
1213 +
1214 + yield* Scope.close(headerScope, Exit.void);
1215 + yield* broadcaster.refreshLocalStatus("/repo");
1216 + assert.deepStrictEqual(state.localStatusBranchChanges, [
1217 + false,
1218 + false,
1219 + true,
1220 + true,
1221 + true,
1222 + false,
1223 + ]);
1224 + }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1225 + });
1226 +
1227 + it.effect("a light refresh that a header joins mid-read publishes Changes totals", () => {
1228 + const branchChanges = { baseRef: "origin/main", insertions: 3, deletions: 1 };
1229 + const state: Parameters<typeof layerTestFor>[0] = {
1230 + currentLocalStatus: { ...baseLocalStatus, branchChanges },
1231 + currentRemoteStatus: baseRemoteStatus,
1232 + localStatusCalls: 0,
1233 + remoteStatusCalls: 0,
1234 + localInvalidationCalls: 0,
1235 + remoteInvalidationCalls: 0,
1236 + localStatusBranchChanges: [],
1237 + fileSystem: FileSystem.makeNoop({ realPath: (cwd) => Effect.succeed(cwd) }),
1238 + };
1239 +
1240 + return Effect.gen(function* () {
1241 + const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1242 + const subscribeHeader = Effect.fn("subscribeHeader")(function* (scope: Scope.Scope) {
1243 + const events = yield* Queue.unbounded<VcsStatusStreamEvent>();
1244 + yield* broadcaster.streamStatus({ cwd: "/repo" }).pipe(
1245 + Stream.runForEach((event) => Queue.offer(events, event)),
1246 + Effect.forkIn(scope, { startImmediately: true }),
1247 + );
1248 + return events;
1249 + });
1250 + const firstHeader = yield* Scope.make();
1251 + const firstEvents = yield* subscribeHeader(firstHeader);
1252 + while ((yield* Queue.take(firstEvents))._tag !== "remoteUpdated") {}
1253 + yield* Scope.close(firstHeader, Exit.void);
1254 +
1255 + const readStarted = yield* Deferred.make<void>();
1256 + const finishRead = yield* Deferred.make<void>();
1257 + state.beforeLocalStatus = Deferred.succeed(readStarted, undefined).pipe(
1258 + Effect.andThen(Deferred.await(finishRead)),
1259 + );
1260 + const turnEnd = yield* broadcaster.refreshLocalStatus("/repo").pipe(Effect.forkScoped);
1261 + yield* Deferred.await(readStarted);
1262 + // Starting immediately registers the header's demand before it waits behind the read.
1263 + const secondEvents = yield* subscribeHeader(yield* Scope.make());
1264 + yield* Deferred.succeed(finishRead, undefined);
1265 + const snapshot = yield* Queue.take(secondEvents);
1266 + assert.strictEqual(snapshot._tag, "snapshot");
1267 + if (snapshot._tag === "snapshot") {
1268 + assert.deepStrictEqual(snapshot.local.branchChanges, branchChanges);
1269 + }
1270 +
1271 + assert.deepStrictEqual((yield* Fiber.join(turnEnd)).branchChanges, branchChanges);
1272 + assert.deepStrictEqual(state.localStatusBranchChanges?.slice(-2), [false, true]);
1273 + }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1274 + });
1275 +
1276 it.effect("an explicit refresh reads local totals after the fetch", () => {
1277 return Effect.gen(function* () {
1278 const fetchStarted = yield* Deferred.make<void>();
@@ -1233,7 +1348,7 @@ describe("VcsStatusBroadcaster", () => {
1348 event._tag === "snapshot" ? Deferred.succeed(subscribed, undefined) : Effect.void,
1349 ),
1350 Stream.filter((event) => event._tag !== "snapshot"),
1236 - Stream.take(3),
1351 + Stream.take(4),
1352 Stream.runCollect,
1353 Effect.forkScoped,
1354 );
@@ -1254,7 +1369,8 @@ describe("VcsStatusBroadcaster", () => {
1369 assert.deepStrictEqual(moved.branchChanges, totals(0).branchChanges);
1370 assert.deepStrictEqual(
1371 [...(yield* Fiber.join(events))].map((event) => event._tag),
1257 - ["remoteUpdated", "remoteUpdated", "localUpdated"],
1372 + // The first refresh adds the totals this palette-style subscription skipped.
1373 + ["localUpdated", "remoteUpdated", "remoteUpdated", "localUpdated"],
1374 );
1375
1376 state.localStatusCalls = 0;
@@ -2097,8 +2213,10 @@ it.effect("serializes branch reads with detailed refresh publication", () => {
2213 yield* Fiber.join(older);
2214 yield* Fiber.join(newer);
2215 state.branchRead = () => Effect.succeed("new");
2100 - const result = yield* b.getStatus({ cwd: "/repo" });
2101 - assert.equal(result.refName, "new");
2216 + const result = yield* b
2217 + .streamStatus({ cwd: "/repo", includeRemote: false })
2218 + .pipe(Stream.runHead, Effect.flatMap(Effect.fromOption));
2219 + assert.equal(result._tag === "snapshot" && result.local.refName, "new");
2220 assert.equal(state.localStatusCalls, 1);
2221 }).pipe(Effect.provide(layerTestFor(state)));
2222 });
apps/server/src/vcs/VcsStatusBroadcaster.ts
+69 -14
@@ -143,8 +143,12 @@ interface CachedRemoteStatus extends CachedValue<VcsStatusRemoteResult | null> {
143 readonly branch: string | null;
144 }
145
146 +interface CachedLocalStatus extends CachedValue<VcsStatusLocalResult> {
147 + readonly includesBranchChanges: boolean;
148 +}
149 +
150 interface CachedVcsStatus {
147 - readonly local: CachedValue<VcsStatusLocalResult> | null;
151 + readonly local: CachedLocalStatus | null;
152 readonly remote: CachedRemoteStatus | null;
153 }
154
@@ -315,14 +319,51 @@ export const make = Effect.gen(function* () {
319 return yield* Ref.get(cacheRef).pipe(Effect.map((cache) => cache.get(cwd) ?? null));
320 });
321
322 + // Only full subscribers and direct reads show Changes totals. Command palette rows subscribe
323 + // without remote status and skip them, which halves the git processes a burst of rows spawns.
324 + const branchChangesDemand = new Map<string, number>();
325 + const wantsBranchChanges = (cwd: string) => branchChangesDemand.has(cwd);
326 + const acquireBranchChangesDemand = (cwd: string) =>
327 + Effect.acquireRelease(
328 + Effect.sync(() => {
329 + branchChangesDemand.set(cwd, (branchChangesDemand.get(cwd) ?? 0) + 1);
330 + }),
331 + () =>
332 + Effect.sync(() => {
333 + const count = (branchChangesDemand.get(cwd) ?? 1) - 1;
334 + if (count > 0) branchChangesDemand.set(cwd, count);
335 + else branchChangesDemand.delete(cwd);
336 + }),
337 + );
338 +
339 + const readLocalStatus = Effect.fn("VcsStatusBroadcaster.readLocalStatus")(function* (
340 + cwd: string,
341 + ) {
342 + const includeBranchChanges = wantsBranchChanges(cwd);
343 + const local = yield* workflow.localStatus({ cwd }, { includeBranchChanges });
344 + // A subscriber that shows totals arrived during the read and must not receive it without them.
345 + if (!includeBranchChanges && wantsBranchChanges(cwd)) {
346 + return {
347 + local: yield* workflow.localStatus({ cwd }, { includeBranchChanges: true }),
348 + includesBranchChanges: true,
349 + };
350 + }
351 + return { local, includesBranchChanges: includeBranchChanges };
352 + });
353 +
354 const updateCachedLocalStatus = Effect.fn("VcsStatusBroadcaster.updateCachedLocalStatus")(
355 function* (
356 cwd: string,
321 - local: VcsStatusLocalResult,
357 + read: { readonly local: VcsStatusLocalResult; readonly includesBranchChanges: boolean },
358 observation: number,
359 options?: { publish?: boolean },
360 ) {
325 - const nextLocal = { fingerprint: fingerprintStatusPart(local), value: local };
361 + const { local, includesBranchChanges } = read;
362 + const nextLocal = {
363 + fingerprint: fingerprintStatusPart(local),
364 + value: local,
365 + includesBranchChanges,
366 + };
367 const [localChanged, remoteCleared] = yield* Ref.modify(cacheRef, (cache) => {
368 const previous = cache.get(cwd) ?? { local: null, remote: null };
369 const remote = previous.remote?.branch === local.refName ? previous.remote : null;
@@ -373,16 +414,17 @@ export const make = Effect.gen(function* () {
414 options?: { publish?: boolean },
415 ) {
416 const observation = ++branchObservation;
376 - const local = yield* workflow.localStatus({ cwd });
377 - return yield* updateCachedLocalStatus(cwd, local, observation, options);
417 + return yield* updateCachedLocalStatus(cwd, yield* readLocalStatus(cwd), observation, options);
418 });
419
420 const getOrLoadLocalStatusUnlocked = Effect.fn("VcsStatusBroadcaster.getOrLoadLocalStatus")(
421 function* (cwd: string) {
422 const cached = yield* getCachedStatus(cwd);
423 if (cached?.local) {
384 - const branch = yield* workflow.currentBranch(cwd);
385 - if (branch === cached.local.value.refName) return cached.local.value;
424 + if (cached.local.includesBranchChanges || !wantsBranchChanges(cwd)) {
425 + const branch = yield* workflow.currentBranch(cwd);
426 + if (branch === cached.local.value.refName) return cached.local.value;
427 + }
428 yield* workflow.invalidateLocalStatus(cwd);
429 return yield* loadLocalStatus(cwd, { publish: true });
430 }
@@ -407,6 +449,7 @@ export const make = Effect.gen(function* () {
449 "VcsStatusBroadcaster.getStatus",
450 )(function* (input) {
451 const cwd = yield* withFileSystem(normalizeCwd(input.cwd));
452 + yield* acquireBranchChangesDemand(cwd);
453 yield* getOrLoadLocalStatus(cwd);
454 const cached = yield* getCachedStatus(cwd);
455 if (cached?.local && cached.remote) {
@@ -423,14 +466,18 @@ export const make = Effect.gen(function* () {
466 return mergeGitStatusParts(parts.local, parts.remote);
467 }),
468 );
426 - });
469 + }, Effect.scoped);
470
471 // A refresh that started after a request saw every change that request could mean, so queued
472 // callers share it instead of each running git status again.
473 const localRefreshRequests = new Map<string, number>();
474 const localRefreshResults = new Map<
475 string,
433 - { readonly startedAt: number; readonly local: VcsStatusLocalResult }
476 + {
477 + readonly startedAt: number;
478 + readonly local: VcsStatusLocalResult;
479 + readonly includesBranchChanges: boolean;
480 + }
481 >();
482 const refreshLocalStatusCore = Effect.fn("VcsStatusBroadcaster.refreshLocalStatusCore")(
483 function* (cwd: string) {
@@ -440,13 +487,19 @@ export const make = Effect.gen(function* () {
487 cwd,
488 Effect.gen(function* () {
489 const shared = localRefreshResults.get(cwd);
443 - if (shared !== undefined && shared.startedAt >= requestedAt) return shared.local;
490 + if (
491 + shared !== undefined &&
492 + shared.startedAt >= requestedAt &&
493 + (shared.includesBranchChanges || !wantsBranchChanges(cwd))
494 + ) {
495 + return shared.local;
496 + }
497 const startedAt = localRefreshRequests.get(cwd) ?? requestedAt;
498 yield* workflow.invalidateLocalStatus(cwd);
499 const observation = ++branchObservation;
447 - const local = yield* workflow.localStatus({ cwd });
448 - localRefreshResults.set(cwd, { startedAt, local });
449 - return yield* updateCachedLocalStatus(cwd, local, observation, { publish: true });
500 + const read = yield* readLocalStatus(cwd);
501 + localRefreshResults.set(cwd, { startedAt, ...read });
502 + return yield* updateCachedLocalStatus(cwd, read, observation, { publish: true });
503 }),
504 );
505 },
@@ -623,6 +676,7 @@ export const make = Effect.gen(function* () {
676 "VcsStatusBroadcaster.refreshStatus",
677 )(function* (rawCwd, options) {
678 const cwd = yield* withFileSystem(normalizeCwd(rawCwd));
679 + yield* acquireBranchChangesDemand(cwd);
680 const refsBeforeLocalRead = options?.localOnly ? null : yield* workflow.readRefSnapshot(cwd);
681 yield* refreshLocalStatusCore(cwd);
682 if (options?.localOnly) {
@@ -631,7 +685,7 @@ export const make = Effect.gen(function* () {
685 return mergeGitStatusParts(parts.local, parts.remote);
686 }
687 return yield* refreshRemoteAndLocalTotals(cwd, rawCwd, refsBeforeLocalRead);
634 - });
688 + }, Effect.scoped);
689
690 const refreshAfterCheckout: VcsStatusBroadcaster["Service"]["refreshAfterCheckout"] = Effect.fn(
691 "VcsStatusBroadcaster.refreshAfterCheckout",
@@ -1055,6 +1109,7 @@ export const make = Effect.gen(function* () {
1109 else detailedSubscribers.set(cwd, remaining);
1110 }),
1111 );
1112 + if (input.includeRemote !== false) yield* acquireBranchChangesDemand(cwd);
1113 const subscription = yield* PubSub.subscribe(changesPubSub);
1114 // Watch before reading so a checkout in between still publishes.
1115 yield* Effect.acquireRelease(retainHeadWatcher(cwd), () => releaseHeadWatcher(cwd));