Skip to content

Commit 3946d97

Browse files
fix(azure-devops): pull request Code tab loads when the pull request changes many files
A diff page read up to 300 files, two az processes each, before answering, so pull requests with many files outran the client's 60s diff timeout and the Code tab never rendered. Close a page once 15s have passed after a batch of reads; the existing cursor loads the rest as the user scrolls. Claude Opus 5.5 in T3 Code (Claude Code harness)
1 parent 8970a32 commit 3946d97

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { describe, expect, it } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
33
import * as Layer from "effect/Layer";
4+
import * as TestClock from "effect/testing/TestClock";
45

56
import * as AzureDevOpsPullRequestCli from "./AzureDevOpsPullRequestCli.ts";
67
import {
8+
DIFF_SLICE_READ_BUDGET_MILLIS,
79
LOCATION_CACHE_CAPACITY,
810
make,
911
MAX_DIFF_SPAWNS,
@@ -58,6 +60,7 @@ const readSlice = (input: {
5860
readonly refused?: ReadonlyArray<string>;
5961
readonly created?: ReadonlyArray<string>;
6062
readonly cursor?: string;
63+
readonly millisPerRead?: number;
6164
}) =>
6265
Effect.gen(function* () {
6366
const reads: string[] = [];
@@ -87,6 +90,7 @@ const readSlice = (input: {
8790
const answersAfter = input.paths.length - input.paths.indexOf(item.path);
8891
for (let turn = 0; turn < answersAfter; turn += 1) yield* Effect.yieldNow;
8992
inFlight -= 1;
93+
if (input.millisPerRead !== undefined) yield* TestClock.adjust(input.millisPerRead);
9094
if (refused.has(item.path)) {
9195
return yield* new AzureDevOpsPullRequestCli.AzureDevOpsPullRequestReadError({
9296
command: "az",
@@ -299,6 +303,24 @@ describe("what one diff slice spends", () => {
299303
}),
300304
);
301305

306+
it.effect(
307+
"stops starting reads once the slice has run long enough to risk the client giving up",
308+
() =>
309+
Effect.gen(function* () {
310+
const paths = Array.from({ length: 12 }, (_, file) => `file-${file}.ts`);
311+
// Two reads per file and four files a batch: the second batch crosses the budget.
312+
const read = yield* readSlice({
313+
paths,
314+
lines: 2,
315+
width: 4,
316+
millisPerRead: DIFF_SLICE_READ_BUDGET_MILLIS / 15,
317+
});
318+
319+
expect(patchedPaths(read.slice.patch)).toEqual(paths.slice(0, 8));
320+
expect(read.slice.nextCursor).toBe(`${ITERATION.id}:8`);
321+
}),
322+
);
323+
302324
it.effect("carries on from where the last slice stopped", () =>
303325
Effect.gen(function* () {
304326
const paths = ["a.ts", "b.ts", "c.ts", "d.ts", "e.ts", "f.ts"];

‎packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolvePullRequestAuthorFilter, SourceControlProviderKind } from "@t3tools/contracts";
2+
import * as Clock from "effect/Clock";
23
import * as Effect from "effect/Effect";
34
import * as Semaphore from "effect/Semaphore";
45
import type { PullRequestCapabilities, PullRequestViewerPermissions } from "@t3tools/contracts";
@@ -43,6 +44,12 @@ export const MAX_DIFF_SPAWNS = 2 * DIFF_FILE_CONCURRENCY;
4344

4445
export const LOCATION_CACHE_CAPACITY = 128;
4546

47+
/**
48+
* Stop starting file reads once a slice has run this long. The client abandons a diff page after
49+
* 60 seconds, and each `az` read can take several seconds on a busy machine.
50+
*/
51+
export const DIFF_SLICE_READ_BUDGET_MILLIS = 15_000;
52+
4653
const CAPABILITIES: PullRequestCapabilities = {
4754
diff: true,
4855
comment: false,
@@ -386,6 +393,7 @@ export const make = Effect.gen(function* () {
386393
// the Code tab has nothing to scope itself to and always asks for the whole change.
387394
getDiff: Effect.fn("AzureDevOpsPullRequestProvider.getDiff")(
388395
function* (input) {
396+
const startedAt = yield* Clock.currentTimeMillis;
389397
const scope = yield* diffScope(input);
390398
if (scope === null) return EMPTY_DIFF_SLICE;
391399
const cursor = parseAzureDevOpsDiffCursor(input.cursor);
@@ -462,6 +470,12 @@ export const make = Effect.gen(function* () {
462470
break;
463471
}
464472
}
473+
if (
474+
!full &&
475+
(yield* Clock.currentTimeMillis) - startedAt >= DIFF_SLICE_READ_BUDGET_MILLIS
476+
) {
477+
full = true;
478+
}
465479
}
466480

467481
const slice: ProviderDiffSlice = {

0 commit comments

Comments
 (0)