@@ -77,6 +77,10 @@ const REVIEW_DIFF_PATCH_MAX_OUTPUT_BYTES = 120_000;
7777const REVIEW_METADATA_MAX_OUTPUT_BYTES = 16 * 1024 * 1024 ;
7878// Temporary-index git add scales poorly (50k files took ~30 s); report incomplete totals above this cap.
7979const REVIEW_UNTRACKED_MAX_FILES = 5_000 ;
80+ // The listing walks the whole untracked tree before the cap applies, so a folder whose listing
81+ // failed (too many files, output limit, timeout) is not listed again on every status poll.
82+ const UNTRACKED_TOTALS_RETRY_MIN_MS = 60_000 ;
83+ const UNTRACKED_TOTALS_RETRY_MAX_MS = 30 * 60_000 ;
8084const REVIEW_DIFF_FILE_MAX_OUTPUT_BYTES = 1024 * 1024 ;
8185const REVIEW_BRANCH_COMMIT_LIMIT = 100 ;
8286const REVIEW_BRANCH_SUBJECT_LIMIT = 300 ;
@@ -1623,6 +1627,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
16231627 } ) ;
16241628
16251629 const statusRemoteRefreshFailures = new Map < string , { count : number ; retryAt : number } > ( ) ;
1630+ const untrackedTotalsFailures = new Map <
1631+ string ,
1632+ {
1633+ readonly roots : string ;
1634+ readonly count : number ;
1635+ readonly retryAt : number ;
1636+ readonly detail : string ;
1637+ }
1638+ > ( ) ;
16261639 const statusRemoteRefreshFailureKey = ( cacheKey : StatusRemoteRefreshCacheKey ) =>
16271640 `${ cacheKey . gitCommonDir } \0${ cacheKey . remoteName } ` ;
16281641 const recordStatusRemoteRefreshFailure = Effect . fn (
@@ -3149,7 +3162,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31493162 return stdout . trim ( ) ;
31503163 } ) ;
31513164
3152- const prepareUntrackedReviewIndex = Effect . fn ( "prepareUntrackedReviewIndex" ) ( function * (
3165+ // `unavailable` says why the untracked files could not be indexed.
3166+ const prepareUntrackedReviewIndexOrReason = Effect . fn ( "prepareUntrackedReviewIndex" ) ( function * (
31533167 cwd : string ,
31543168 pathArgs : ReadonlyArray < string > ,
31553169 onlyPath ?: string ,
@@ -3159,15 +3173,21 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31593173 cwd ,
31603174 [ "ls-files" , "--others" , "--exclude-standard" , "-z" , "--" , ...pathArgs ] ,
31613175 { maxOutputBytes : REVIEW_METADATA_MAX_OUTPUT_BYTES } ,
3162- ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
3163- if ( untracked === null ) return null ;
3176+ ) . pipe (
3177+ Effect . catchTags ( {
3178+ GitCommandError : ( error ) =>
3179+ Effect . succeed ( { unavailable : `Could not list untracked files: ${ error . detail } ` } ) ,
3180+ } ) ,
3181+ ) ;
3182+ if ( "unavailable" in untracked ) return untracked ;
31643183 // ls-files lists a nested repository with a trailing slash; its diff path has none.
31653184 const paths = splitNullSeparatedGitStdoutPaths ( untracked ) . filter (
31663185 ( candidate ) =>
31673186 onlyPath === undefined || candidate === onlyPath || candidate === `${ onlyPath } /` ,
31683187 ) ;
31693188 if ( paths . length === 0 ) return { env : undefined } ;
3170- if ( paths . length > REVIEW_UNTRACKED_MAX_FILES ) return null ;
3189+ if ( paths . length > REVIEW_UNTRACKED_MAX_FILES )
3190+ return { unavailable : "Too many untracked files to count." } ;
31713191 const env = yield * prepareReviewIndex ( cwd , paths ) . pipe (
31723192 Effect . catchTags ( {
31733193 PlatformError : ( cause ) =>
@@ -3184,6 +3204,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31843204 ) ;
31853205 return { env } ;
31863206 } ) ;
3207+ const prepareUntrackedReviewIndex = (
3208+ cwd : string ,
3209+ pathArgs : ReadonlyArray < string > ,
3210+ onlyPath ?: string ,
3211+ ) =>
3212+ prepareUntrackedReviewIndexOrReason ( cwd , pathArgs , onlyPath ) . pipe (
3213+ Effect . map ( ( result ) => ( "unavailable" in result ? null : result ) ) ,
3214+ ) ;
31873215
31883216 const resolveReviewMergeBase = Effect . fn ( "resolveReviewMergeBase" ) ( function * (
31893217 cwd : string ,
@@ -3257,16 +3285,48 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
32573285 roots . length <= 128 && roots . reduce ( ( length , root ) => length + root . length + 16 , 0 ) < 8_000
32583286 ? roots . map ( ( root ) => `:(top,literal)${ root } ` )
32593287 : [ ] ;
3288+ // Until the retry time, the same untracked roots get the remembered failure without a scan;
3289+ // different roots (files added or removed at status level) scan again at once.
3290+ const rootsKey = roots . join ( "\0" ) ;
3291+ const remembered = untrackedTotalsFailures . get ( cwd ) ;
3292+ if (
3293+ remembered !== undefined &&
3294+ remembered . roots === rootsKey &&
3295+ ( yield * Clock . currentTimeMillis ) < remembered . retryAt
3296+ ) {
3297+ return yield * new GitCommandError ( {
3298+ operation : "GitVcsDriver.readBranchChangeTotals" ,
3299+ command : "git ls-files" ,
3300+ cwd,
3301+ detail : remembered . detail ,
3302+ } ) ;
3303+ }
32603304 // Empty status can mean untracked files are hidden; retain the full scan.
3261- const untracked = yield * prepareUntrackedReviewIndex ( cwd , pathspecs ) ;
3262- if ( untracked === null ) {
3305+ const untracked = yield * prepareUntrackedReviewIndexOrReason ( cwd , pathspecs ) ;
3306+ if ( "unavailable" in untracked ) {
3307+ const count = remembered ?. roots === rootsKey ? remembered . count + 1 : 1 ;
3308+ // Bounded like the remote refresh failures: the oldest folder is forgotten first.
3309+ untrackedTotalsFailures . delete ( cwd ) ;
3310+ untrackedTotalsFailures . set ( cwd , {
3311+ roots : rootsKey ,
3312+ count,
3313+ retryAt :
3314+ ( yield * Clock . currentTimeMillis ) +
3315+ Math . min ( UNTRACKED_TOTALS_RETRY_MIN_MS * 2 ** ( count - 1 ) , UNTRACKED_TOTALS_RETRY_MAX_MS ) ,
3316+ detail : untracked . unavailable ,
3317+ } ) ;
3318+ if ( untrackedTotalsFailures . size > STATUS_UPSTREAM_REFRESH_CACHE_CAPACITY ) {
3319+ const oldestKey = untrackedTotalsFailures . keys ( ) . next ( ) . value ;
3320+ if ( oldestKey !== undefined ) untrackedTotalsFailures . delete ( oldestKey ) ;
3321+ }
32633322 return yield * new GitCommandError ( {
32643323 operation : "GitVcsDriver.readBranchChangeTotals" ,
32653324 command : "git ls-files" ,
32663325 cwd,
3267- detail : "Too many untracked files to count." ,
3326+ detail : untracked . unavailable ,
32683327 } ) ;
32693328 }
3329+ untrackedTotalsFailures . delete ( cwd ) ;
32703330 const readNumstat = ( ref : string ) =>
32713331 executeGit (
32723332 "GitVcsDriver.readBranchChangeTotals" ,
0 commit comments