fix: handle large workspace cleanup comment lists

This commit is contained in:
Neil
2026-05-30 05:13:25 -07:00
parent 2dd317cbbd
commit de74155358
2 changed files with 37 additions and 1 deletions
+28
View File
@@ -344,6 +344,34 @@ describe('workspace cleanup scan', () => {
})
})
it('handles persisted diff note lists larger than the JavaScript argument limit', async () => {
const diffComments = Array.from({ length: 130_000 }, (_, index): DiffComment => {
return {
id: `comment-${index}`,
worktreeId: 'repo-1::/repo-feature',
filePath: 'src/file.ts',
lineNumber: 12,
body: 'Follow up before deleting',
createdAt: NOW - index,
side: 'modified'
}
})
const result = await scanWorkspaceCleanup(
makeStore({
baseRef: undefined,
diffComments
})
)
expect(result.candidates[0]).toMatchObject({
localContext: {
diffCommentCount: diffComments.length,
newestDiffCommentAt: NOW
}
})
})
it('does not expose PR cache state in inactivity cleanup results', async () => {
const result = await scanWorkspaceCleanup(
makeStore({
+9 -1
View File
@@ -582,7 +582,15 @@ function getNewestDiffCommentAt(diffComments: Worktree['diffComments'] | undefin
if (!diffComments || diffComments.length === 0) {
return null
}
return Math.max(...diffComments.map((comment) => comment.createdAt))
// Why: persisted review notes can exceed V8's argument limit if expanded
// into Math.max(), and cleanup must still show the workspace safely.
let newest = Number.NEGATIVE_INFINITY
for (const comment of diffComments) {
if (comment.createdAt > newest) {
newest = comment.createdAt
}
}
return newest
}
function createEmptyGitEvidence(): GitEvidence {