Skip to content

Commit 4ca6cc9

Browse files
fix(server): omit oversized untracked files without dropping review totals
Raise the untracked review budget to 256 MiB total and leave files past it out of the temporary index instead of falling back to the >5,000-file path, so the per-file list, deferred patches and Changes totals stay available. AI-assisted; verified with the tests and tools listed above.
1 parent 889e7c0 commit 4ca6cc9

2 files changed

Lines changed: 29 additions & 66 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,38 +2645,33 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
26452645
}),
26462646
);
26472647

2648-
it.effect("bounds untracked review input without hiding ordinary edits", () =>
2648+
it.effect("leaves oversized untracked files out of review input", () =>
26492649
Effect.gen(function* () {
26502650
const cwd = yield* makeTmpDir();
26512651
yield* initRepoWithCommit(cwd);
26522652
const fileSystem = yield* FileSystem.FileSystem;
26532653
const pathService = yield* Path.Path;
2654+
const driver = yield* GitVcsDriver.GitVcsDriver;
26542655
yield* writeTextFile(cwd, "README.md", "# test\ntracked edit\n");
26552656
yield* writeTextFile(cwd, "ordinary.txt", "ordinary edit\n");
26562657
yield* writeTextFile(cwd, "large.data", "");
26572658
// Sparse fixture exercises logical size without allocating the input budget.
2658-
yield* fileSystem.truncate(pathService.join(cwd, "large.data"), 11 * 1024 * 1024);
2659+
yield* fileSystem.truncate(pathService.join(cwd, "large.data"), 257 * 1024 * 1024);
26592660
if (symlinksSupported) {
26602661
yield* fileSystem.symlink("large.data", pathService.join(cwd, "ordinary-link"));
26612662
}
2662-
const driver = yield* GitVcsDriver.GitVcsDriver;
2663+
26632664
const preview = yield* driver.getReviewDiffPreview({ cwd, metadataOnly: true });
26642665
const source = preview.sources.find((item) => item.kind === "working-tree")!;
26652666
assert.isTrue(source.truncated);
2666-
assert.isUndefined(source.files);
2667-
assert.include(source.diff, "+tracked edit");
2668-
assert.include(source.diff, "+ordinary edit");
2669-
assert.notInclude(source.diff, "b/large.data");
2670-
if (symlinksSupported) assert.include(source.diff, "b/ordinary-link");
2671-
assert.isUndefined(
2672-
(yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true })).branchChanges,
2667+
assert.deepStrictEqual(
2668+
source.files?.map((file) => file.path),
2669+
symlinksSupported
2670+
? ["README.md", "ordinary-link", "ordinary.txt"]
2671+
: ["README.md", "ordinary.txt"],
26732672
);
2674-
const selected = yield* driver.getReviewDiffPreview({
2675-
cwd,
2676-
file: { path: "ordinary.txt", previousPath: null, sourceKind: "working-tree" },
2677-
});
2678-
assert.isFalse(selected.sources[0]!.truncated);
2679-
assert.include(selected.sources[0]!.diff, "+ordinary edit");
2673+
const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
2674+
assert.strictEqual(status.branchChanges?.insertions, symlinksSupported ? 3 : 2);
26802675
const oversized = yield* driver.getReviewDiffPreview({
26812676
cwd,
26822677
file: { path: "large.data", previousPath: null, sourceKind: "working-tree" },
@@ -2686,28 +2681,6 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
26862681
}),
26872682
);
26882683

2689-
it.effect("bounds aggregate untracked input while keeping later small files", () =>
2690-
Effect.gen(function* () {
2691-
const cwd = yield* makeTmpDir();
2692-
yield* initRepoWithCommit(cwd);
2693-
const fileSystem = yield* FileSystem.FileSystem;
2694-
const pathService = yield* Path.Path;
2695-
for (let index = 0; index < 8; index++) {
2696-
const name = `large-${index}.data`;
2697-
yield* writeTextFile(cwd, name, "");
2698-
yield* fileSystem.truncate(pathService.join(cwd, name), 9 * 1024 * 1024);
2699-
}
2700-
yield* writeTextFile(cwd, "z-small.txt", "still reviewable\n");
2701-
const driver = yield* GitVcsDriver.GitVcsDriver;
2702-
const preview = yield* driver.getReviewDiffPreview({ cwd, metadataOnly: true });
2703-
const source = preview.sources.find((item) => item.kind === "working-tree")!;
2704-
assert.isTrue(source.truncated);
2705-
assert.isUndefined(source.files);
2706-
assert.notInclude(source.diff, "b/large-7.data");
2707-
assert.include(source.diff, "+still reviewable");
2708-
}),
2709-
);
2710-
27112684
it.effect("reviews untracked files outside the sparse-checkout cone", () =>
27122685
Effect.gen(function* () {
27132686
const cwd = yield* makeTmpDir();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ const REVIEW_DIFF_PATCH_MAX_OUTPUT_BYTES = 120_000;
7676
const REVIEW_METADATA_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
7777
// Temporary-index git add scales poorly (50k files took ~30 s); report incomplete totals above this cap.
7878
const REVIEW_UNTRACKED_MAX_FILES = 5_000;
79-
const REVIEW_UNTRACKED_MAX_FILE_BYTES = 10n * 1024n * 1024n;
80-
const REVIEW_UNTRACKED_MAX_TOTAL_BYTES = 64n * 1024n * 1024n;
79+
// git diff --numstat reads ~5 ms/MB of untracked text; larger files are left out of the review index.
80+
const REVIEW_UNTRACKED_MAX_TOTAL_BYTES = 256n * 1024n * 1024n;
8181
const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024;
8282
const REVIEW_BRANCH_COMMIT_LIMIT = 100;
8383
const REVIEW_BRANCH_SUBJECT_LIMIT = 300;
@@ -3171,34 +3171,22 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31713171
(candidate) =>
31723172
onlyPath === undefined || candidate === onlyPath || candidate === `${onlyPath}/`,
31733173
);
3174-
if (paths.length === 0) return { env: undefined, complete: true };
3174+
if (paths.length === 0) return { env: undefined, omitted: false };
31753175
if (paths.length > REVIEW_UNTRACKED_MAX_FILES) return null;
31763176
const boundedPaths: string[] = [];
31773177
let bytes = 0n;
3178-
let complete = true;
31793178
for (const relativePath of paths) {
3180-
// lstat bounds sparse files by logical size without reading symlink targets.
3179+
// lstat reads logical size without following symlinks.
31813180
const info = yield* fileSystem
31823181
.lstat(path.resolve(cwd, relativePath))
31833182
.pipe(Effect.orElseSucceed(() => undefined));
3184-
if (
3185-
info === undefined ||
3186-
(info.type !== "File" && info.type !== "Directory" && info.type !== "SymbolicLink")
3187-
) {
3188-
complete = false;
3189-
continue;
3190-
}
3191-
const size = info.type === "Directory" ? 0n : info.size;
3192-
if (
3193-
size > REVIEW_UNTRACKED_MAX_FILE_BYTES ||
3194-
bytes + size > REVIEW_UNTRACKED_MAX_TOTAL_BYTES
3195-
) {
3196-
complete = false;
3197-
continue;
3198-
}
3183+
const size = info?.type === "File" || info?.type === "SymbolicLink" ? info.size : 0n;
3184+
if (bytes + size > REVIEW_UNTRACKED_MAX_TOTAL_BYTES) continue;
31993185
bytes += size;
32003186
boundedPaths.push(relativePath);
32013187
}
3188+
const omitted = boundedPaths.length < paths.length;
3189+
if (boundedPaths.length === 0) return { env: undefined, omitted };
32023190
const env = yield* prepareReviewIndex(cwd, boundedPaths).pipe(
32033191
Effect.catchTags({
32043192
PlatformError: (cause) =>
@@ -3213,7 +3201,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
32133201
),
32143202
}),
32153203
);
3216-
return { env, complete };
3204+
return { env, omitted };
32173205
});
32183206

32193207
const resolveReviewMergeBase = Effect.fn("resolveReviewMergeBase")(function* (
@@ -3290,12 +3278,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
32903278
: [];
32913279
// Empty status can mean untracked files are hidden; retain the full scan.
32923280
const untracked = yield* prepareUntrackedReviewIndex(cwd, pathspecs);
3293-
if (untracked === null || !untracked.complete) {
3281+
if (untracked === null) {
32943282
return yield* new GitCommandError({
32953283
operation: "GitVcsDriver.readBranchChangeTotals",
32963284
command: "git ls-files",
32973285
cwd,
3298-
detail: "Untracked files exceed the review input limits.",
3286+
detail: "Too many untracked files to count.",
32993287
});
33003288
}
33013289
const readNumstat = (ref: string) =>
@@ -3624,10 +3612,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
36243612
});
36253613
const [dirtyTrackedResult, baseResult] = yield* Effect.gen(function* () {
36263614
const untracked = input.trackedOnly
3627-
? { env: undefined, complete: true }
3615+
? { env: undefined, omitted: false }
36283616
: yield* prepareUntrackedReviewIndex(cwd, pathArgs, input.file?.path);
3629-
const metadataOnly =
3630-
input.metadataOnly === true && !input.file && untracked?.complete === true;
3617+
const metadataOnly = input.metadataOnly === true && !input.file && untracked !== null;
36313618
const [dirty, base] =
36323619
review.mergeBase === dirtyRef
36333620
? yield* readTrackedDiff(dirtyRef, untracked?.env, metadataOnly).pipe(
@@ -3640,9 +3627,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
36403627
],
36413628
{ concurrency: 2 },
36423629
);
3643-
if (untracked?.complete) return [dirty, base] as const;
3630+
if (untracked?.omitted === false) return [dirty, base] as const;
3631+
// Too many untracked files drops per-file totals; omitted oversized files only mark it partial.
36443632
const incomplete = (ref: string | null, result: typeof dirty) =>
3645-
ref === null ? result : { ...result, files: undefined, stdoutTruncated: true };
3633+
ref === null
3634+
? result
3635+
: { ...result, stdoutTruncated: true, files: untracked ? result.files : undefined };
36463636
return [incomplete(dirtyRef, dirty), incomplete(review.mergeBase, base)] as const;
36473637
}).pipe(Effect.scoped);
36483638
const dirtyFiles = dirtyTrackedResult.files;

0 commit comments

Comments
 (0)