The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
fix(server): the startup automatic pull waits for a slow fetch (#39915)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Sergiy Dybskiy committed
Nov 20, 2026 at 17:25 UTC
f2ec853fbbb6ed84f6c08aa156d3b7d9e9f7385f
4 files changed
+60
-1
apps/server/src/serverRuntimeStartup.ts
+4
-1
@@ -202,7 +202,10 @@ export const autoPullProjects = Effect.fn("autoPullProjects")(function* (
202
workspaceRoots,
203
(cwd) =>
204
Effect.gen(function* () {
205
- const status = yield* git.statusDetails(cwd);
205
+ // Startup checks once, so it waits for the fetch rather than reading the old references.
206
+ const status = yield* git
207
+ .statusDetails(cwd)
208
+ .pipe(Effect.provideService(GitVcsDriver.AwaitStatusFetch, true));
209
if (
210
!status.isRepo ||
211
!status.isDefaultBranch ||
apps/server/src/vcs/GitVcsDriver.ts
+9
@@ -320,6 +320,15 @@ export interface GitRemoteStatusOptions {
320
readonly refreshUpstream?: boolean;
321
}
322
323
+/**
324
+ * Set by a one-time reader, such as the startup automatic pull, that has no later poll to see a
325
+ * slow status fetch land. Its status read waits for a running fetch instead of using the last
326
+ * fetched references after five seconds. The fetch keeps its own safety limit.
327
+ */
328
+export const AwaitStatusFetch = Context.Reference<boolean>("t3/vcs/AwaitStatusFetch", {
329
+ defaultValue: () => false,
330
+});
331
+
332
/** Set by background discovery so its Git commands run in their own small lane, not the user's. */
333
export const BackgroundGitWork = Context.Reference<boolean>("t3/vcs/BackgroundGitWork", {
334
defaultValue: () => false,
apps/server/src/vcs/GitVcsDriverCore.test.ts
+43
@@ -33,7 +33,9 @@ import * as Tracer from "effect/Tracer";
33
import { ChildProcess, ChildProcessSpawner, CommandLine } from "effect/process";
34
35
import {
36
+ DEFAULT_SERVER_SETTINGS,
37
GitCommandError,
38
+ ProjectId,
39
ReviewDiffPreviewInput,
40
VcsRef,
41
VcsListRefsResult,
@@ -50,6 +52,7 @@ import {
52
splitNullSeparatedGitStdoutPaths,
53
windowsLongPathConfigEnv,
54
} from "./GitVcsDriverCore.ts";
55
+import { autoPullProjects } from "../serverRuntimeStartup.ts";
56
import * as GitVcsDriver from "./GitVcsDriver.ts";
57
import { VcsAutomaticFetchInterval } from "./VcsAutomaticFetchInterval.ts";
58
import { gitConfigEnv } from "./VcsProcess.ts";
@@ -1235,6 +1238,46 @@ describe("pullCurrentBranch", () => {
1238
).pipe(Effect.provide(layerTest)),
1239
);
1240
1241
+ it.effect("the startup pull waits for a status fetch that runs past five seconds", () =>
1242
+ Effect.scoped(
1243
+ Effect.gen(function* () {
1244
+ const { cwd, remoteHead } = yield* cloneBehindRemote;
1245
+ const targetPath = NodeFS.realpathSync.native(cwd);
1246
+ const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
1247
+ const fetchHeld = yield* Deferred.make<void>();
1248
+ const release = yield* Deferred.make<void>();
1249
+ let held = false;
1250
+ const spawner = ChildProcessSpawner.make((command) =>
1251
+ Effect.gen(function* () {
1252
+ if (
1253
+ !held &&
1254
+ ChildProcess.isStandardCommand(command) &&
1255
+ command.args.includes("fetch") &&
1256
+ String(command.options.cwd) === targetPath
1257
+ ) {
1258
+ held = true;
1259
+ yield* Deferred.succeed(fetchHeld, undefined);
1260
+ yield* Deferred.await(release);
1261
+ }
1262
+ return yield* delegate.spawn(command);
1263
+ }),
1264
+ );
1265
+ const driver = yield* makeGitVcsDriverCore().pipe(
1266
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
1267
+ );
1268
+ const startup = yield* autoPullProjects(
1269
+ [{ id: ProjectId.make("behind"), workspaceRoot: cwd, autoPull: true }],
1270
+ { ...DEFAULT_SERVER_SETTINGS, defaultAutoPull: true },
1271
+ ).pipe(Effect.provideService(GitVcsDriver.GitVcsDriver, driver), Effect.forkChild);
1272
+ yield* Deferred.await(fetchHeld);
1273
+ yield* TestClock.adjust("6 seconds");
1274
+ yield* Deferred.succeed(release, undefined);
1275
+ yield* Fiber.join(startup);
1276
+ assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), remoteHead);
1277
+ }),
1278
+ ).pipe(Effect.provide(layerTest)),
1279
+ );
1280
+
1281
const claimedFetchFallbacks = ["diverged", "interrupted", "upstream-only"] as const;
1282
1283
it.effect.each(claimedFetchFallbacks)(
apps/server/src/vcs/GitVcsDriverCore.ts
+4
@@ -1971,6 +1971,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1971
statusRemoteRefreshCache,
1972
new StatusRemoteRefreshCacheKey({ gitCommonDir, remoteName }),
1973
).pipe(Effect.ignore);
1974
+ if (!(yield* GitVcsDriver.AwaitStatusFetch)) return;
1975
+ // The cache returns after five seconds while the fetch keeps running.
1976
+ const pending = statusFetches.get(`${gitCommonDir}\0${remoteName}`);
1977
+ if (pending) yield* Fiber.await(pending.fiber);
1978
});
1979
1980
const resolveDefaultBranchName = (