From de7415535856689f393d26211c864859ba5bc112 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 05:13:25 -0700 Subject: [PATCH] fix: handle large workspace cleanup comment lists --- src/main/ipc/workspace-cleanup.test.ts | 28 ++++++++++++++++++++++++++ src/main/ipc/workspace-cleanup.ts | 10 ++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/ipc/workspace-cleanup.test.ts b/src/main/ipc/workspace-cleanup.test.ts index 2a1e5072183..67c17879a53 100644 --- a/src/main/ipc/workspace-cleanup.test.ts +++ b/src/main/ipc/workspace-cleanup.test.ts @@ -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({ diff --git a/src/main/ipc/workspace-cleanup.ts b/src/main/ipc/workspace-cleanup.ts index 21c7e26819a..18473dc5bf8 100644 --- a/src/main/ipc/workspace-cleanup.ts +++ b/src/main/ipc/workspace-cleanup.ts @@ -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 {