The best way to control Claude Code, Codex and more from any computer or phone
fix(server): PR sync backs off links on hosts it cannot read (#36901)
Julius Marminge committed
Nov 14, 2026 at 12:12 UTC
ea05ea5e2af272f07e8253786bc418baa4d00cf1
3 files changed
+52
-5
apps/server/src/git/GitManager.ts
+6
-1
@@ -18,6 +18,7 @@ import * as PubSub from "effect/PubSub";
18
import * as Ref from "effect/Ref";
19
import * as Schema from "effect/Schema";
20
import * as Scope from "effect/Scope";
21
+import * as Semaphore from "effect/Semaphore";
22
import * as Stream from "effect/Stream";
23
import {
24
GitActionProgressEvent,
@@ -189,6 +190,9 @@ const PR_LOOKUP_FAILURE_MAX_TTL = Duration.minutes(15);
190
const PR_LOOKUP_CACHE_CAPACITY = 2_048;
191
const PR_LOOKUP_GIT_STATE_TTL = Duration.minutes(5);
192
const SETTLED_PR_LOOKUP_RECHECK_INTERVAL = Duration.minutes(15);
193
+// Shared by every background caller (backfill, settlement, cleanup), so startup discovery
194
+// cannot fill the git and forge process slots that foreground work also needs.
195
+const BRANCH_PR_LOOKUP_CONCURRENCY = 4;
196
const PR_THREAD_CONTEXT_BYTES = 16_000;
197
const PR_THREAD_COMMAND_OUTPUT_CHARS = 2_000;
198
const isSourceControlProviderError = Schema.is(SourceControlProviderError);
@@ -2579,6 +2583,7 @@ export const make = Effect.gen(function* () {
2583
prLookupGitStateByKey.set(entryKey, { readAtMs, value });
2584
return value;
2585
});
2586
+ const branchPrLookups = yield* Semaphore.make(BRANCH_PR_LOOKUP_CONCURRENCY);
2587
const settledPrLookupByBranchKey = new Map<
2588
string,
2589
{ readonly url: string; readonly fingerprint: string; readonly confirmedAtMs: number }
@@ -2879,7 +2884,7 @@ export const make = Effect.gen(function* () {
2884
});
2885
}
2886
return confirmed;
2882
- });
2887
+ }, branchPrLookups.withPermits(1));
2888
2889
const checkedOutPullRequest: GitManager["Service"]["checkedOutPullRequest"] = Effect.fn(
2890
"checkedOutPullRequest",
apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+41
-1
@@ -8,6 +8,7 @@ import {
8
ProjectId,
9
ProviderInstanceId,
10
PullRequestOperationError,
11
+ PullRequestUnavailableError,
12
RunId,
13
ThreadId,
14
TurnItemId,
@@ -180,7 +181,7 @@ interface HarnessOptions {
181
readonly snapshot: TestShellSnapshot;
182
readonly summary?: (
183
input: PullRequestRef,
183
- ) => Effect.Effect<PullRequestSummary, PullRequestOperationError>;
184
+ ) => Effect.Effect<PullRequestSummary, PullRequestService.PullRequestError>;
185
readonly stack?: (
186
input: PullRequestRef,
187
) => Effect.Effect<PullRequestStack | null, PullRequestOperationError>;
@@ -1674,6 +1675,45 @@ describe("PullRequestSyncReactor", () => {
1675
}),
1676
);
1677
1678
+ it.effect("stops reading a pull request on a host it cannot browse each sweep", () =>
1679
+ Effect.gen(function* () {
1680
+ yield* TestClock.setTime(Date.parse(NOW));
1681
+ const fixture = yield* makeHarness({
1682
+ snapshot: makeSnapshot([
1683
+ makeThread("unsupported", { pullRequests: [makeLink(9, { state: "open" })] }),
1684
+ makeThread("fine", { pullRequests: [makeLink(8, { state: "open" })] }),
1685
+ ]),
1686
+ summary: (input) =>
1687
+ input.number === 9
1688
+ ? Effect.fail(new PullRequestUnavailableError({ reason: "provider-unsupported" }))
1689
+ : Effect.succeed(makeSummary(input)),
1690
+ });
1691
+ const unsupportedReads = Ref.get(fixture.summaryCalls).pipe(
1692
+ Effect.map((calls) => calls.filter((call) => call.number === 9).length),
1693
+ );
1694
+ yield* Effect.gen(function* () {
1695
+ const reactor = yield* startAndSweep(fixture);
1696
+ for (let index = 0; index < 5; index += 1) yield* sweepAgain(fixture, reactor);
1697
+ const afterSweeps = yield* unsupportedReads;
1698
+
1699
+ // A refresh another link asks for must not re-read the unsupported one as well.
1700
+ yield* reactor.requestSync(makeLink(9));
1701
+ yield* Queue.take(fixture.snapshotReads);
1702
+ yield* reactor.drain;
1703
+ const afterItsRefresh = yield* unsupportedReads;
1704
+ for (let index = 0; index < 3; index += 1) {
1705
+ yield* reactor.requestSync(makeLink(8));
1706
+ yield* Queue.take(fixture.snapshotReads);
1707
+ yield* reactor.drain;
1708
+ }
1709
+ assert.deepStrictEqual(
1710
+ { afterSweeps, afterItsRefresh, afterOtherRefreshes: yield* unsupportedReads },
1711
+ { afterSweeps: 1, afterItsRefresh: 2, afterOtherRefreshes: 2 },
1712
+ );
1713
+ }).pipe(Effect.provide(fixture.layer));
1714
+ }),
1715
+ );
1716
+
1717
it.effect(
1718
"holds missing links through sibling and link updates but honors a reader refresh",
1719
() =>
apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+5
-3
@@ -366,7 +366,8 @@ export const make = Effect.gen(function* () {
366
// linking dozens of pull requests) is read together and shares the summary batches.
367
let requestedSweepQueued = false;
368
const retryStacks = new Set<string>();
369
- // Group keys the host answered not-found for; they are read on the slow cadence until found.
369
+ // Group keys the host answered not-found for, or this server cannot read (no CLI, signed out,
370
+ // unsupported host); they are read on the slow cadence until a read succeeds.
371
const missing = new Set<string>();
372
// Pause per project and host because credentials are project-specific; leave paused PRs due until reset.
373
const pausedUntil = new Map<string, number>();
@@ -510,9 +511,10 @@ export const make = Effect.gen(function* () {
511
if (invalidated) yield* pullRequests.invalidate({ reference: ref });
512
const summary = yield* pullRequests.summary(ref, { recoverTransientFailure: false }).pipe(
513
Effect.tapError((error) =>
513
- error.reason === "not-found"
514
+ error.reason === "not-found" || error._tag === "PullRequestUnavailableError"
515
? Effect.sync(() => {
515
- // Not-found is a host answer: it consumes the refresh and starts the backoff.
516
+ // Not-found, or a host this server cannot read, won't change by asking again
517
+ // next sweep: it consumes the refresh and starts the backoff.
518
missing.add(key);
519
lastSyncedAt.set(key, nowMs);
520
requested.delete(key);