Repository navigation
fix(server): branch totals stop relisting untracked files after a failed listing #34460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1601077
143edca
39d90e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,10 @@ const REVIEW_DIFF_PATCH_MAX_OUTPUT_BYTES = 120_000; | |
| const REVIEW_METADATA_MAX_OUTPUT_BYTES = 16 * 1024 * 1024; | ||
| // Temporary-index git add scales poorly (50k files took ~30 s); report incomplete totals above this cap. | ||
| const REVIEW_UNTRACKED_MAX_FILES = 5_000; | ||
| // The listing walks the whole untracked tree before the cap applies, so a folder whose listing | ||
| // failed (too many files, output limit, timeout) is not listed again on every status poll. | ||
| const UNTRACKED_TOTALS_RETRY_MIN_MS = 60_000; | ||
| const UNTRACKED_TOTALS_RETRY_MAX_MS = 30 * 60_000; | ||
| const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024; | ||
| const REVIEW_BRANCH_COMMIT_LIMIT = 100; | ||
| const REVIEW_BRANCH_SUBJECT_LIMIT = 300; | ||
|
|
@@ -1623,6 +1627,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | |
| }); | ||
|
|
||
| const statusRemoteRefreshFailures = new Map<string, { count: number; retryAt: number }>(); | ||
| const untrackedTotalsFailures = new Map< | ||
| string, | ||
| { | ||
| readonly roots: string; | ||
| readonly count: number; | ||
| readonly retryAt: number; | ||
| readonly detail: string; | ||
| } | ||
| >(); | ||
| const statusRemoteRefreshFailureKey = (cacheKey: StatusRemoteRefreshCacheKey) => | ||
| `${cacheKey.gitCommonDir}\0${cacheKey.remoteName}`; | ||
| const recordStatusRemoteRefreshFailure = Effect.fn( | ||
|
|
@@ -3149,7 +3162,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | |
| return stdout.trim(); | ||
| }); | ||
|
|
||
| const prepareUntrackedReviewIndex = Effect.fn("prepareUntrackedReviewIndex")(function* ( | ||
| const prepareUntrackedReviewIndexOrReason = Effect.fn("prepareUntrackedReviewIndex")(function* ( | ||
| cwd: string, | ||
| pathArgs: ReadonlyArray<string>, | ||
| onlyPath?: string, | ||
|
|
@@ -3159,15 +3172,21 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | |
| cwd, | ||
| ["ls-files", "--others", "--exclude-standard", "-z", "--", ...pathArgs], | ||
| { maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES }, | ||
| ).pipe(Effect.orElseSucceed(() => null)); | ||
| if (untracked === null) return null; | ||
| ).pipe( | ||
| Effect.catchTags({ | ||
| GitCommandError: (error) => | ||
| Effect.succeed({ unavailable: `Could not list untracked files: ${error.detail}` }), | ||
| }), | ||
| ); | ||
| if ("unavailable" in untracked) return untracked; | ||
| // ls-files lists a nested repository with a trailing slash; its diff path has none. | ||
| const paths = splitNullSeparatedGitStdoutPaths(untracked).filter( | ||
| (candidate) => | ||
| onlyPath === undefined || candidate === onlyPath || candidate === `${onlyPath}/`, | ||
| ); | ||
| if (paths.length === 0) return { env: undefined }; | ||
| if (paths.length > REVIEW_UNTRACKED_MAX_FILES) return null; | ||
| if (paths.length > REVIEW_UNTRACKED_MAX_FILES) | ||
| return { unavailable: "Too many untracked files to count." }; | ||
| const env = yield* prepareReviewIndex(cwd, paths).pipe( | ||
| Effect.catchTags({ | ||
| PlatformError: (cause) => | ||
|
|
@@ -3184,6 +3203,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | |
| ); | ||
| return { env }; | ||
| }); | ||
| const prepareUntrackedReviewIndex = ( | ||
| cwd: string, | ||
| pathArgs: ReadonlyArray<string>, | ||
| onlyPath?: string, | ||
| ) => | ||
| prepareUntrackedReviewIndexOrReason(cwd, pathArgs, onlyPath).pipe( | ||
| Effect.map((result) => ("unavailable" in result ? null : result)), | ||
| ); | ||
|
|
||
| const resolveReviewMergeBase = Effect.fn("resolveReviewMergeBase")(function* ( | ||
| cwd: string, | ||
|
|
@@ -3257,16 +3284,46 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | |
| roots.length <= 128 && roots.reduce((length, root) => length + root.length + 16, 0) < 8_000 | ||
| ? roots.map((root) => `:(top,literal)${root}`) | ||
| : []; | ||
| // Changed untracked roots skip the backoff and scan again. | ||
| const rootsKey = roots.join("\0"); | ||
| const remembered = untrackedTotalsFailures.get(cwd); | ||
| if ( | ||
| remembered !== undefined && | ||
| remembered.roots === rootsKey && | ||
| (yield* Clock.currentTimeMillis) < remembered.retryAt | ||
| ) { | ||
| return yield* new GitCommandError({ | ||
| operation: "GitVcsDriver.readBranchChangeTotals", | ||
| command: "git ls-files", | ||
| cwd, | ||
| detail: remembered.detail, | ||
| }); | ||
| } | ||
| // Empty status can mean untracked files are hidden; retain the full scan. | ||
| const untracked = yield* prepareUntrackedReviewIndex(cwd, pathspecs); | ||
| if (untracked === null) { | ||
| const untracked = yield* prepareUntrackedReviewIndexOrReason(cwd, pathspecs); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if ("unavailable" in untracked) { | ||
| const count = remembered?.roots === rootsKey ? remembered.count + 1 : 1; | ||
| untrackedTotalsFailures.delete(cwd); | ||
| untrackedTotalsFailures.set(cwd, { | ||
| roots: rootsKey, | ||
| count, | ||
| retryAt: | ||
| (yield* Clock.currentTimeMillis) + | ||
| Math.min(UNTRACKED_TOTALS_RETRY_MIN_MS * 2 ** (count - 1), UNTRACKED_TOTALS_RETRY_MAX_MS), | ||
| detail: untracked.unavailable, | ||
| }); | ||
| if (untrackedTotalsFailures.size > STATUS_UPSTREAM_REFRESH_CACHE_CAPACITY) { | ||
| const oldestKey = untrackedTotalsFailures.keys().next().value; | ||
| if (oldestKey !== undefined) untrackedTotalsFailures.delete(oldestKey); | ||
| } | ||
| return yield* new GitCommandError({ | ||
| operation: "GitVcsDriver.readBranchChangeTotals", | ||
| command: "git ls-files", | ||
| cwd, | ||
| detail: "Too many untracked files to count.", | ||
| detail: untracked.unavailable, | ||
| }); | ||
| } | ||
| untrackedTotalsFailures.delete(cwd); | ||
| const readNumstat = (ref: string) => | ||
| executeGit( | ||
| "GitVcsDriver.readBranchChangeTotals", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve the listing error as
cause.This conversion discards the original
GitCommandError. The errors constructed at Line 3297 and Line 3322 retain only its detail text. They lose structured diagnostics such asoutputLength,exitCode, and the underlying platform failure.Carry the original error through the unavailable result and remembered failure. Set it as
causewhen constructing the branch-total error. The file-count rejection needs no cause.As per coding guidelines, “An error that wraps a failure keeps the immediate underlying error as
cause.”Source: Coding guidelines