Skip to content

Commit e07f70d

Browse files
braulioboclaude
andcommitted
fix(server): status refresh no longer indexes thousands of untracked files
The Changes totals copy the git index and run `git add --intent-to-add` over every untracked file on each local status refresh (end of every agent turn, client subscribe). In a repo with ~50k untracked files this pinned a CPU core for seconds per refresh. Past 5,000 untracked files the totals are now reported incomplete, reusing the existing "too many untracked" path. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent efecd3c commit e07f70d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,27 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
18861886
}),
18871887
);
18881888

1889+
it.effect("skips Changes totals instead of indexing thousands of untracked files", () =>
1890+
Effect.gen(function* () {
1891+
const cwd = yield* makeTmpDir();
1892+
yield* initRepoWithCommit(cwd);
1893+
const driver = yield* GitVcsDriver.GitVcsDriver;
1894+
yield* Effect.forEach(
1895+
Array.from({ length: 5_001 }, (_, index) => `bulk/${index}.txt`),
1896+
(file) => writeTextFile(cwd, file, "x\n"),
1897+
{ concurrency: 32, discard: true },
1898+
);
1899+
yield* writeTextFile(cwd, "README.md", "changed\n");
1900+
1901+
const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
1902+
assert.isTrue(status.hasWorkingTreeChanges);
1903+
assert.isUndefined(status.branchChanges);
1904+
1905+
const preview = yield* driver.getReviewDiffPreview({ cwd });
1906+
assert.isTrue(preview.sources.every((source) => source.truncated));
1907+
}),
1908+
);
1909+
18891910
it.effect("Changes does not show newer base commits as deletions", () =>
18901911
Effect.gen(function* () {
18911912
const cwd = yield* makeTmpDir();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const RANGE_DIFF_SUMMARY_MAX_OUTPUT_BYTES = 19_000;
5757
const RANGE_DIFF_PATCH_MAX_OUTPUT_BYTES = 59_000;
5858
const REVIEW_DIFF_PATCH_MAX_OUTPUT_BYTES = 120_000;
5959
const REVIEW_METADATA_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
60+
// Counting untracked files copies the index and stats every one of them on each status refresh.
61+
// Past this many, the cost is a CPU spike per agent turn, so the totals are reported incomplete.
62+
const REVIEW_UNTRACKED_MAX_FILES = 5_000;
6063
const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024;
6164
// Patches the clients render are parsed against git's default a/ and b/ path
6265
// prefixes. A repository or global diff.noprefix or diff.mnemonicPrefix would
@@ -2545,7 +2548,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
25452548
});
25462549

25472550
// Lists untracked files and adds them to a temporary index, so a diff against any commit
2548-
// shows them as new. Returns null when the list is too big to read. Needs a Scope.
2551+
// shows them as new. Returns null when the list is too big to read or to index. Needs a Scope.
25492552
const prepareUntrackedReviewIndex = Effect.fn("prepareUntrackedReviewIndex")(function* (
25502553
cwd: string,
25512554
pathArgs: ReadonlyArray<string>,
@@ -2567,6 +2570,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
25672570
(candidate) => onlyPath === undefined || candidate === onlyPath,
25682571
);
25692572
if (paths.length === 0) return { env: undefined };
2573+
if (paths.length > REVIEW_UNTRACKED_MAX_FILES) return null;
25702574
const env = yield* prepareReviewIndex(cwd, paths).pipe(
25712575
Effect.catchTags({
25722576
PlatformError: (cause) =>

0 commit comments

Comments
 (0)