@@ -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,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31493162 return stdout . trim ( ) ;
31503163 } ) ;
31513164
3152- const prepareUntrackedReviewIndex = Effect . fn ( "prepareUntrackedReviewIndex" ) ( function * (
3165+ const prepareUntrackedReviewIndexOrReason = Effect . fn ( "prepareUntrackedReviewIndex" ) ( function * (
31533166 cwd : string ,
31543167 pathArgs : ReadonlyArray < string > ,
31553168 onlyPath ?: string ,
@@ -3159,15 +3172,21 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31593172 cwd ,
31603173 [ "ls-files" , "--others" , "--exclude-standard" , "-z" , "--" , ...pathArgs ] ,
31613174 { maxOutputBytes : REVIEW_METADATA_MAX_OUTPUT_BYTES } ,
3162- ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
3163- if ( untracked === null ) return null ;
3175+ ) . pipe (
3176+ Effect . catchTags ( {
3177+ GitCommandError : ( error ) =>
3178+ Effect . succeed ( { unavailable : `Could not list untracked files: ${ error . detail } ` } ) ,
3179+ } ) ,
3180+ ) ;
3181+ if ( "unavailable" in untracked ) return untracked ;
31643182 // ls-files lists a nested repository with a trailing slash; its diff path has none.
31653183 const paths = splitNullSeparatedGitStdoutPaths ( untracked ) . filter (
31663184 ( candidate ) =>
31673185 onlyPath === undefined || candidate === onlyPath || candidate === `${ onlyPath } /` ,
31683186 ) ;
31693187 if ( paths . length === 0 ) return { env : undefined } ;
3170- if ( paths . length > REVIEW_UNTRACKED_MAX_FILES ) return null ;
3188+ if ( paths . length > REVIEW_UNTRACKED_MAX_FILES )
3189+ return { unavailable : "Too many untracked files to count." } ;
31713190 const env = yield * prepareReviewIndex ( cwd , paths ) . pipe (
31723191 Effect . catchTags ( {
31733192 PlatformError : ( cause ) =>
@@ -3184,6 +3203,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31843203 ) ;
31853204 return { env } ;
31863205 } ) ;
3206+ const prepareUntrackedReviewIndex = (
3207+ cwd : string ,
3208+ pathArgs : ReadonlyArray < string > ,
3209+ onlyPath ?: string ,
3210+ ) =>
3211+ prepareUntrackedReviewIndexOrReason ( cwd , pathArgs , onlyPath ) . pipe (
3212+ Effect . map ( ( result ) => ( "unavailable" in result ? null : result ) ) ,
3213+ ) ;
31873214
31883215 const resolveReviewMergeBase = Effect . fn ( "resolveReviewMergeBase" ) ( function * (
31893216 cwd : string ,
@@ -3257,16 +3284,46 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
32573284 roots . length <= 128 && roots . reduce ( ( length , root ) => length + root . length + 16 , 0 ) < 8_000
32583285 ? roots . map ( ( root ) => `:(top,literal)${ root } ` )
32593286 : [ ] ;
3287+ // Changed untracked roots skip the backoff and scan again.
3288+ const rootsKey = roots . join ( "\0" ) ;
3289+ const remembered = untrackedTotalsFailures . get ( cwd ) ;
3290+ if (
3291+ remembered !== undefined &&
3292+ remembered . roots === rootsKey &&
3293+ ( yield * Clock . currentTimeMillis ) < remembered . retryAt
3294+ ) {
3295+ return yield * new GitCommandError ( {
3296+ operation : "GitVcsDriver.readBranchChangeTotals" ,
3297+ command : "git ls-files" ,
3298+ cwd,
3299+ detail : remembered . detail ,
3300+ } ) ;
3301+ }
32603302 // Empty status can mean untracked files are hidden; retain the full scan.
3261- const untracked = yield * prepareUntrackedReviewIndex ( cwd , pathspecs ) ;
3262- if ( untracked === null ) {
3303+ const untracked = yield * prepareUntrackedReviewIndexOrReason ( cwd , pathspecs ) ;
3304+ if ( "unavailable" in untracked ) {
3305+ const count = remembered ?. roots === rootsKey ? remembered . count + 1 : 1 ;
3306+ untrackedTotalsFailures . delete ( cwd ) ;
3307+ untrackedTotalsFailures . set ( cwd , {
3308+ roots : rootsKey ,
3309+ count,
3310+ retryAt :
3311+ ( yield * Clock . currentTimeMillis ) +
3312+ Math . min ( UNTRACKED_TOTALS_RETRY_MIN_MS * 2 ** ( count - 1 ) , UNTRACKED_TOTALS_RETRY_MAX_MS ) ,
3313+ detail : untracked . unavailable ,
3314+ } ) ;
3315+ if ( untrackedTotalsFailures . size > STATUS_UPSTREAM_REFRESH_CACHE_CAPACITY ) {
3316+ const oldestKey = untrackedTotalsFailures . keys ( ) . next ( ) . value ;
3317+ if ( oldestKey !== undefined ) untrackedTotalsFailures . delete ( oldestKey ) ;
3318+ }
32633319 return yield * new GitCommandError ( {
32643320 operation : "GitVcsDriver.readBranchChangeTotals" ,
32653321 command : "git ls-files" ,
32663322 cwd,
3267- detail : "Too many untracked files to count." ,
3323+ detail : untracked . unavailable ,
32683324 } ) ;
32693325 }
3326+ untrackedTotalsFailures . delete ( cwd ) ;
32703327 const readNumstat = ( ref : string ) =>
32713328 executeGit (
32723329 "GitVcsDriver.readBranchChangeTotals" ,
0 commit comments