The best way to control Claude Code, Codex and more from any computer or phone
fix(server): pull request sync leaves a forge CLI slot for other reads (#38856)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Navid Nadali committed
Nov 19, 2026 at 04:54 UTC
3e35e7e17c9f6d2d45baaf88c6cfe082430dea16
3 files changed
+87
-2
apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+71
@@ -32,14 +32,18 @@ import * as DateTime from "effect/DateTime";
32
import * as Deferred from "effect/Deferred";
33
import * as Duration from "effect/Duration";
34
import * as Effect from "effect/Effect";
35
+import * as Fiber from "effect/Fiber";
36
import * as Layer from "effect/Layer";
37
import * as Queue from "effect/Queue";
38
import * as Ref from "effect/Ref";
39
+import { ChildProcessSpawner } from "effect/process";
40
import { TestClock } from "effect/testing";
41
42
import * as GitManager from "../git/GitManager.ts";
43
+import * as ProcessRunner from "../processRunner.ts";
44
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
45
import * as ServerActivation from "../serverActivation.ts";
46
+import * as VcsProcess from "../vcs/VcsProcess.ts";
47
import * as Orchestrator from "./Orchestrator.ts";
48
import * as ProjectionStore from "./ProjectionStore.ts";
49
import * as PullRequestSyncReactor from "./PullRequestSyncReactor.ts";
@@ -1293,6 +1297,73 @@ describe("PullRequestSyncReactor", () => {
1297
}),
1298
);
1299
1300
+ it.effect("leaves a forge CLI slot for reads outside the sweep", () =>
1301
+ Effect.gen(function* () {
1302
+ yield* TestClock.setTime(Date.parse(NOW));
1303
+ const asked = yield* Queue.unbounded<void>();
1304
+ const started = yield* Queue.unbounded<string>();
1305
+ const release = yield* Deferred.make<void>();
1306
+ const vcs = yield* VcsProcess.make.pipe(
1307
+ Effect.provideService(
1308
+ ProcessRunner.ProcessRunner,
1309
+ ProcessRunner.ProcessRunner.of({
1310
+ run: (input) =>
1311
+ Queue.offer(started, input.args.at(-1)!).pipe(
1312
+ Effect.andThen(Deferred.await(release)),
1313
+ Effect.as({
1314
+ stdout: "",
1315
+ stderr: "",
1316
+ code: ChildProcessSpawner.ExitCode(0),
1317
+ timedOut: false,
1318
+ stdoutTruncated: false,
1319
+ stderrTruncated: false,
1320
+ stdoutInvalidUtf8: false,
1321
+ stderrInvalidUtf8: false,
1322
+ }),
1323
+ ),
1324
+ }),
1325
+ ),
1326
+ );
1327
+ const glab = (number: string) =>
1328
+ vcs.run({
1329
+ operation: "synthetic.glab.view",
1330
+ command: "glab",
1331
+ args: ["mr", "view", number],
1332
+ cwd: "/workspace",
1333
+ });
1334
+ const numbers = Array.from({ length: 6 }, (_, index) => index + 1);
1335
+ const fixture = yield* makeHarness({
1336
+ snapshot: makeSnapshot(
1337
+ numbers.map((number) =>
1338
+ makeThread(`thread-${number}`, {
1339
+ pullRequests: [makeLink(number, null, { host: "gitlab.example.com" })],
1340
+ }),
1341
+ ),
1342
+ ),
1343
+ batchesReads: () => false,
1344
+ summary: (input) =>
1345
+ Queue.offer(asked, undefined).pipe(
1346
+ Effect.andThen(glab(String(input.number))),
1347
+ Effect.orDie,
1348
+ Effect.as(makeSummary(input)),
1349
+ ),
1350
+ });
1351
+ yield* Effect.gen(function* () {
1352
+ const reactor = yield* PullRequestSyncReactor.PullRequestSyncReactor;
1353
+ yield* reactor.start();
1354
+ yield* Deferred.succeed(fixture.activation, undefined);
1355
+ yield* Queue.takeN(asked, numbers.length);
1356
+ yield* Queue.takeN(started, 3);
1357
+ const panel = yield* glab("panel").pipe(Effect.forkChild({ startImmediately: true }));
1358
+ assert.strictEqual(yield* Queue.take(started), "panel");
1359
+ yield* Deferred.succeed(release, undefined);
1360
+ yield* Fiber.join(panel);
1361
+ yield* reactor.drain;
1362
+ assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, numbers.length);
1363
+ }).pipe(Effect.provide(fixture.layer));
1364
+ }),
1365
+ );
1366
+
1367
it.effect("reads a member a sibling flags while the sweep is full", () =>
1368
Effect.gen(function* () {
1369
yield* TestClock.setTime(Date.parse(NOW));
apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+5
-1
@@ -35,6 +35,7 @@ import * as GitManager from "../git/GitManager.ts";
35
import { PullRequestProviderError } from "@t3tools/source-control-core/server/PullRequestProvider";
36
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
37
import { forkParked } from "../serverActivation.ts";
38
+import * as VcsProcess from "../vcs/VcsProcess.ts";
39
import * as Orchestrator from "./Orchestrator.ts";
40
import * as ProjectionStore from "./ProjectionStore.ts";
41
import { isTerminalRunStatus } from "./ThreadManagementService.ts";
@@ -716,7 +717,10 @@ export const make = Effect.gen(function* () {
717
Effect.suspend(() => {
718
if (scope === "requested") requestedSweepQueued = false;
719
return pullRequests.withSharedProjectReads(sweep(scope));
719
- }).pipe(Effect.catchCause(logSkipped("pull request sync sweep failed", {}))),
720
+ }).pipe(
721
+ Effect.provideService(VcsProcess.Background, true),
722
+ Effect.catchCause(logSkipped("pull request sync sweep failed", {})),
723
+ ),
724
);
725
726
// Threads that ran a close command this run, with the commands already read for.
apps/server/src/vcs/VcsProcess.ts
+11
-1
@@ -69,6 +69,11 @@ const VCS_PROCESS_CONCURRENCY = 8;
69
// Forge CLIs can take seconds per call; cap them together so git, checkpoints included, keeps slots.
70
const NON_GIT_PROCESS_CONCURRENCY = VCS_PROCESS_CONCURRENCY / 2;
71
72
+/** Background non-git calls, such as the pull request sync sweep's, leave one slot for the rest. */
73
+export const Background = Context.Reference<boolean>("t3/vcs/VcsProcess/Background", {
74
+ defaultValue: () => false,
75
+});
76
+
77
/** Shown to users when a Git command fails because another process holds the index lock. */
78
export const GIT_INDEX_LOCKED_DETAIL =
79
"Git's index is locked. Wait for other Git operations to finish, then try again.";
@@ -210,6 +215,7 @@ export const make = Effect.gen(function* () {
215
const hostPlatform = yield* HostProcess.Platform;
216
const vcsProcesses = yield* Semaphore.make(VCS_PROCESS_CONCURRENCY);
217
const nonGitProcesses = yield* Semaphore.make(NON_GIT_PROCESS_CONCURRENCY);
218
+ const backgroundProcesses = yield* Semaphore.make(NON_GIT_PROCESS_CONCURRENCY - 1);
219
const keyedProcesses = new Map<string, Semaphore.Semaphore>();
220
const keyedPermit = (concurrency: NonNullable<VcsProcessInput["concurrency"]>) => {
221
let semaphore = keyedProcesses.get(concurrency.key);
@@ -400,7 +406,11 @@ export const make = Effect.gen(function* () {
406
);
407
}
408
const shared = input.command === "git" ? bounded : nonGitProcesses.withPermits(1)(bounded);
403
- return yield* input.concurrency === undefined ? shared : keyedPermit(input.concurrency)(shared);
409
+ const keyed = input.concurrency === undefined ? shared : keyedPermit(input.concurrency)(shared);
410
+ // Taken first, so a background call still waiting holds no permit another call needs.
411
+ return yield* input.command !== "git" && (yield* Background)
412
+ ? backgroundProcesses.withPermits(1)(keyed)
413
+ : keyed;
414
});
415
416
return VcsProcess.of({ run });