diff --git a/apps/web/src/components/reviewSweep/ReviewSweepView.tsx b/apps/web/src/components/reviewSweep/ReviewSweepView.tsx index 0986e3b882..4c74b04a19 100644 --- a/apps/web/src/components/reviewSweep/ReviewSweepView.tsx +++ b/apps/web/src/components/reviewSweep/ReviewSweepView.tsx @@ -13,6 +13,7 @@ import { dismissSweepItem, isSweepCandidate, retrySweepItem, + sortSweepCandidates, startReviewSweep, SWEEP_MAX_THREADS, useReviewSweepStore, @@ -156,20 +157,28 @@ function SweepPreRunSummary() { const serverConfigs = useServerConfigs(); const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays); - const { candidateCount, modelsByEnvironment } = useMemo(() => { + const { candidateCount, reviewedCount, modelsByEnvironment } = useMemo(() => { const now = new Date().toISOString(); - let count = 0; + const candidates = sortSweepCandidates( + shells.filter((shell) => + isSweepCandidate(shell, serverConfigs.get(shell.environmentId)?.environment.capabilities, { + now, + autoSettleAfterDays, + }), + ), + ); + // Aggregate only what a run would actually review: the cap is applied + // here, in the same most-recently-active order startReviewSweep uses, + // so the environment/model rows never overstate the calls. + const reviewed = candidates.slice(0, SWEEP_MAX_THREADS); const models = new Map(); - for (const shell of shells) { + for (const shell of reviewed) { const config = serverConfigs.get(shell.environmentId); - if (!isSweepCandidate(shell, config?.environment.capabilities, { now, autoSettleAfterDays })) - continue; - count += 1; - const selection = config?.settings.textGenerationModelSelection; const entry = models.get(shell.environmentId); if (entry) { entry.threads += 1; } else { + const selection = config?.settings.textGenerationModelSelection; models.set(shell.environmentId, { label: config?.environment.label ?? shell.environmentId, model: selection ? `${selection.model}` : "server default", @@ -177,11 +186,13 @@ function SweepPreRunSummary() { }); } } - return { candidateCount: count, modelsByEnvironment: [...models.values()] }; + return { + candidateCount: candidates.length, + reviewedCount: reviewed.length, + modelsByEnvironment: [...models.values()], + }; }, [autoSettleAfterDays, serverConfigs, shells]); - const reviewedCount = Math.min(candidateCount, SWEEP_MAX_THREADS); - if (candidateCount === 0) { return ( diff --git a/apps/web/src/reviewSweepStore.ts b/apps/web/src/reviewSweepStore.ts index d543ab1089..548b9f7632 100644 --- a/apps/web/src/reviewSweepStore.ts +++ b/apps/web/src/reviewSweepStore.ts @@ -112,8 +112,9 @@ export function isSweepCandidate( } /** All unsettled, unarchived threads across every connected environment that - supports the sweep. */ -function collectSweepCandidates(): EnvironmentThreadShell[] { + supports the sweep, most recently active first — the exact order the + SWEEP_MAX_THREADS cap is applied in. */ +export function collectSweepCandidates(): EnvironmentThreadShell[] { const now = new Date().toISOString(); const autoSettleAfterDays = getClientSettings().sidebarAutoSettleAfterDays; const candidates: EnvironmentThreadShell[] = []; @@ -124,14 +125,20 @@ function collectSweepCandidates(): EnvironmentThreadShell[] { if (!isSweepCandidate(shell, capabilities, { now, autoSettleAfterDays })) continue; candidates.push(shell); } - // Most recently active first, so the SWEEP_MAX_THREADS cap drops the - // longest-idle threads rather than the oldest-created ones. + return sortSweepCandidates(candidates); +} + +/** Most recently active first, so the SWEEP_MAX_THREADS cap drops the + longest-idle threads rather than the oldest-created ones. Exported so + the pre-run summary previews the exact capped selection. */ +export function sortSweepCandidates( + candidates: ReadonlyArray, +): EnvironmentThreadShell[] { const activityMs = (shell: EnvironmentThreadShell): number => toSortableTimestamp(threadLastActivityAt(shell) ?? undefined) ?? toSortableTimestamp(shell.createdAt) ?? 0; - candidates.sort((a, b) => activityMs(b) - activityMs(a)); - return candidates; + return [...candidates].sort((a, b) => activityMs(b) - activityMs(a)); } async function reviewOne(runId: number, item: SweepItem): Promise {