From f8b9d79934bbf50b76173ee63dbfd097bc2779c5 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Thu, 23 Jul 2026 19:42:11 -0700 Subject: [PATCH] Make pre-run summary reflect the capped selection exactly The environment/model breakdown previously aggregated every sweep candidate, so with more than SWEEP_MAX_THREADS unsettled threads it could list environments whose threads would all be skipped and row totals exceeding the actual call count. The summary now sorts and caps candidates with the same helpers startReviewSweep uses, so the rows always describe exactly the calls a run would make. Co-Authored-By: Claude Fable 5 --- .../reviewSweep/ReviewSweepView.tsx | 31 +++++++++++++------ apps/web/src/reviewSweepStore.ts | 19 ++++++++---- 2 files changed, 34 insertions(+), 16 deletions(-) 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 {