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 22, 03:15 UTC
perf(server): background PR discovery no longer delays git status after a restart (#32162)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 6, 2026 at 12:11 UTC
bdb8d5dfc067134f460ea7757e62355fe5f9b2a7
5 files changed
+66
-1
apps/server/src/orchestration-v2/ThreadPullRequestService.ts
+2
@@ -20,6 +20,7 @@ import * as Stream from "effect/Stream";
20
21
import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
22
import * as GitManager from "../git/GitManager.ts";
23
+import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
24
import * as ProjectStore from "./ProjectStore.ts";
25
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
26
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
@@ -347,6 +348,7 @@ export const make = Effect.gen(function* () {
348
349
const worker = yield* makeDrainableWorker((request: RefreshRequest) =>
350
synchronize(request).pipe(
351
+ Effect.provideService(GitVcsDriver.BackgroundGitWork, true),
352
Effect.catchCauseIf(
353
(cause) => !Cause.hasInterruptsOnly(cause),
354
(cause) =>
apps/server/src/orchestration-v2/ThreadSettlementService.ts
+2
@@ -31,6 +31,7 @@ import * as PullRequestService from "../pullRequest/PullRequestService.ts";
31
import * as ServerSettings from "../serverSettings.ts";
32
import { forkParked } from "../serverActivation.ts";
33
import * as TerminalManager from "../terminal/Manager.ts";
34
+import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
35
import * as ProjectStore from "./ProjectStore.ts";
36
import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
37
import * as Orchestrator from "./Orchestrator.ts";
@@ -556,6 +557,7 @@ export const make = Effect.gen(function* () {
557
threadId?: ThreadId,
558
) =>
559
sweep(mergedPullRequest, threadId).pipe(
560
+ Effect.provideService(GitVcsDriver.BackgroundGitWork, true),
561
Effect.catchCauseIf(
562
(cause) => !Cause.hasInterruptsOnly(cause),
563
(cause) =>
apps/server/src/vcs/GitVcsDriver.ts
+5
@@ -301,6 +301,11 @@ export interface GitRemoteStatusOptions {
301
readonly refreshUpstream?: boolean;
302
}
303
304
+/** Set by background discovery so its Git commands run in their own small lane, not the user's. */
305
+export const BackgroundGitWork = Context.Reference<boolean>("t3/vcs/BackgroundGitWork", {
306
+ defaultValue: () => false,
307
+});
308
+
309
export class GitVcsDriver extends Context.Service<
310
GitVcsDriver,
311
{
apps/server/src/vcs/GitVcsDriverCore.test.ts
+50
@@ -14,6 +14,7 @@ import * as FileSystem from "effect/FileSystem";
14
import * as Fiber from "effect/Fiber";
15
import * as Layer from "effect/Layer";
16
import * as Path from "effect/Path";
17
+import * as Queue from "effect/Queue";
18
import * as PlatformError from "effect/PlatformError";
19
import * as Ref from "effect/Ref";
20
import * as Result from "effect/Result";
@@ -129,6 +130,55 @@ const makeDriverReleasingLock = (
130
return { driver, failures };
131
});
132
133
+it.effect("runs background Git in its own lane so user commands never queue behind it", () =>
134
+ Effect.gen(function* () {
135
+ const gate = yield* Deferred.make<void>();
136
+ const starts = yield* Queue.unbounded<string>();
137
+ const spawner = ChildProcessSpawner.make((command) =>
138
+ Effect.gen(function* () {
139
+ yield* Queue.offer(
140
+ starts,
141
+ ChildProcess.isStandardCommand(command) ? String(command.args[0]) : "",
142
+ );
143
+ return ChildProcessSpawner.makeHandle({
144
+ ...makeSuccessfulHandle("ok"),
145
+ exitCode: Deferred.await(gate).pipe(Effect.as(ChildProcessSpawner.ExitCode(0))),
146
+ });
147
+ }),
148
+ );
149
+ const driver = yield* makeGitVcsDriverCore().pipe(
150
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
151
+ Effect.provide(layerServerConfig),
152
+ );
153
+ const run = (args: ReadonlyArray<string>) =>
154
+ driver.execute({ operation: "test.gitLane", cwd: "/repo", args: [...args] });
155
+ const background = yield* Effect.forEach(
156
+ Array.from({ length: 12 }),
157
+ () => run(["background"]),
158
+ {
159
+ concurrency: "unbounded",
160
+ },
161
+ ).pipe(Effect.provideService(GitVcsDriver.BackgroundGitWork, true), Effect.forkChild);
162
+ const foreground = yield* Effect.forEach(Array.from({ length: 4 }), () => run(["foreground"]), {
163
+ concurrency: "unbounded",
164
+ }).pipe(Effect.forkChild);
165
+
166
+ yield* TestClock.adjust("2 seconds");
167
+ const started = yield* Queue.takeAll(starts);
168
+ assert.deepStrictEqual([...started].toSorted(), [
169
+ "background",
170
+ "background",
171
+ "foreground",
172
+ "foreground",
173
+ "foreground",
174
+ "foreground",
175
+ ]);
176
+ yield* Deferred.succeed(gate, undefined);
177
+ assert.equal((yield* Fiber.join(background)).length, 12);
178
+ assert.equal((yield* Fiber.join(foreground)).length, 4);
179
+ }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
180
+);
181
+
182
describe("Git output collection", () => {
183
// Git writes in arbitrary chunk sizes; one byte per chunk splits every
184
// multibyte character across reads.
apps/server/src/vcs/GitVcsDriverCore.ts
+7
-1
@@ -63,6 +63,7 @@ const branchBaseConfigKey = (branch: string) => `branch.${branch}.t3-merge-base`
63
*/
64
const legacyBranchBaseConfigKey = (branch: string) => `branch.${branch}.gh-merge-base`;
65
const gitProcesses = Semaphore.makeUnsafe(8);
66
+const backgroundGitProcesses = Semaphore.makeUnsafe(2);
67
const WORKTREE_REMOVE_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5));
68
const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
69
const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]";
@@ -1123,7 +1124,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1124
(execution) =>
1125
input.timeoutMs === null || (input.timeoutMs ?? DEFAULT_TIMEOUT_MS) > DEFAULT_TIMEOUT_MS
1126
? execution
1126
- : gitProcesses.withPermits(1)(execution),
1127
+ : Effect.gen(function* () {
1128
+ const lane = (yield* GitVcsDriver.BackgroundGitWork)
1129
+ ? backgroundGitProcesses
1130
+ : gitProcesses;
1131
+ return yield* lane.withPermits(1)(execution);
1132
+ }),
1133
Effect.withSpan(input.operation, {
1134
kind: "client",
1135
attributes: {