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 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-07-23 19:42:11 -07:00
1 parent dc66ff1d5c
commit f8b9d79934
2 files changed
+34 -16

No files matched your search

@@ -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<string, { label: string; model: string; threads: number }>();
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 (
<Empty>
+13 -6
View File
@@ -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>,
): 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<void> {