Make sweep respect merged-PR auto-settle like the sidebar
Real-data testing surfaced the gap the plan had flagged: the sweep passed changeRequestState: null, so threads the sidebar auto-settles (merged/closed PR + idle) counted as unsettled — 18 candidates vs ~7 sidebar cards. SidebarV2 now mirrors its per-row PR-state map into the sweep store, isSweepCandidate consults it, and the pre-run summary subscribes to a version counter so its count tracks PR states as they stream in. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
c68e9fa23c
commit
4faf0e9418
3 files changed
+41
-5
No files matched your search
@@ -81,6 +81,7 @@ import {
|
||||
type SidebarProjectGroupMember,
|
||||
type SidebarProjectSnapshot,
|
||||
} from "../sidebarProjectGrouping";
|
||||
import { publishSweepChangeRequestStates } from "../reviewSweepStore";
|
||||
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
|
||||
import { useThreadSelectionStore } from "../threadSelectionStore";
|
||||
import { useThreadActions } from "../hooks/useThreadActions";
|
||||
@@ -1163,6 +1164,11 @@ export default function SidebarV2() {
|
||||
},
|
||||
[],
|
||||
);
|
||||
// Mirror PR states to the review-sweep store so its unsettled-candidate
|
||||
// predicate matches this sidebar's partition (merged-PR auto-settle).
|
||||
useEffect(() => {
|
||||
publishSweepChangeRequestStates(changeRequestStateByKey);
|
||||
}, [changeRequestStateByKey]);
|
||||
|
||||
// Project scope: one menu above the list. Scoping filters the list without
|
||||
// making the header width depend on the number or length of project names.
|
||||
|
||||
@@ -159,6 +159,9 @@ function SweepPreRunSummary() {
|
||||
const shells = useThreadShells();
|
||||
const serverConfigs = useServerConfigs();
|
||||
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
|
||||
// Recompute when the sidebar publishes fresh PR states — merged-PR
|
||||
// auto-settle changes which threads count as unsettled.
|
||||
const candidateVersion = useReviewSweepStore((state) => state.candidateVersion);
|
||||
|
||||
const { candidateCount, reviewedCount, modelsByEnvironment } = useMemo(() => {
|
||||
const now = new Date().toISOString();
|
||||
@@ -198,7 +201,7 @@ function SweepPreRunSummary() {
|
||||
reviewedCount: reviewed.length,
|
||||
modelsByEnvironment: [...models.values()],
|
||||
};
|
||||
}, [autoSettleAfterDays, serverConfigs, shells]);
|
||||
}, [autoSettleAfterDays, candidateVersion, serverConfigs, shells]);
|
||||
|
||||
if (candidateCount === 0) {
|
||||
return (
|
||||
|
||||
@@ -23,6 +23,22 @@ import { reviewEnvironment } from "./state/review";
|
||||
import { environmentServerConfigsAtom } from "./state/server";
|
||||
import { threadEnvironment } from "./state/threads";
|
||||
|
||||
/** PR states mirrored from SidebarV2's per-row VCS subscriptions (keyed by
|
||||
scoped thread key). The sidebar auto-settles merged/closed+idle threads
|
||||
using this data; the sweep must see the same states or it will count
|
||||
those threads as unsettled. Module-level because the sidebar is mounted
|
||||
for the app's lifetime and owns the subscriptions. */
|
||||
let changeRequestStateByKey: ReadonlyMap<string, "open" | "closed" | "merged"> = new Map();
|
||||
|
||||
export function publishSweepChangeRequestStates(
|
||||
states: ReadonlyMap<string, "open" | "closed" | "merged">,
|
||||
): void {
|
||||
changeRequestStateByKey = states;
|
||||
// Bump the store version so the pre-run summary recomputes its candidate
|
||||
// count as PR states stream in from the sidebar rows.
|
||||
useReviewSweepStore.getState().bumpCandidateVersion();
|
||||
}
|
||||
|
||||
const SWEEP_CONCURRENCY = 3;
|
||||
/** Soft cap so a giant backlog doesn't spawn an unbounded number of LLM
|
||||
generations in one click. */
|
||||
@@ -52,6 +68,9 @@ interface ReviewSweepState {
|
||||
items: Readonly<Record<string, SweepItem>>;
|
||||
/** Count of candidates dropped by SWEEP_MAX_THREADS (0 = full coverage). */
|
||||
truncatedCount: number;
|
||||
/** Bumped when sidebar-owned PR states change; the pre-run summary
|
||||
subscribes so its candidate count tracks the sidebar's partition. */
|
||||
candidateVersion: number;
|
||||
startRun: (input: {
|
||||
runId: number;
|
||||
items: ReadonlyArray<SweepItem>;
|
||||
@@ -59,6 +78,7 @@ interface ReviewSweepState {
|
||||
}) => void;
|
||||
patchItem: (key: string, patch: Partial<SweepItem>) => void;
|
||||
finishRun: (runId: number) => void;
|
||||
bumpCandidateVersion: () => void;
|
||||
reset: () => void;
|
||||
}
|
||||
|
||||
@@ -68,6 +88,7 @@ export const useReviewSweepStore = create<ReviewSweepState>((set) => ({
|
||||
order: [],
|
||||
items: {},
|
||||
truncatedCount: 0,
|
||||
candidateVersion: 0,
|
||||
startRun: ({ runId, items, truncatedCount }) =>
|
||||
set({
|
||||
phase: "running",
|
||||
@@ -83,6 +104,7 @@ export const useReviewSweepStore = create<ReviewSweepState>((set) => ({
|
||||
return { items: { ...state.items, [key]: { ...existing, ...patch } } };
|
||||
}),
|
||||
finishRun: (runId) => set((state) => (state.runId === runId ? { phase: "complete" } : state)),
|
||||
bumpCandidateVersion: () => set((state) => ({ candidateVersion: state.candidateVersion + 1 })),
|
||||
reset: () => set({ phase: "idle", order: [], items: {}, truncatedCount: 0 }),
|
||||
}));
|
||||
|
||||
@@ -101,13 +123,18 @@ export function isSweepCandidate(
|
||||
): boolean {
|
||||
if (shell.archivedAt !== null) return false;
|
||||
if (capabilities?.threadSettlement !== true || capabilities.reviewSweep !== true) return false;
|
||||
// PR state is owned by per-row VCS subscriptions in the sidebar and isn't
|
||||
// readable here; passing null may include a few threads the sidebar shows
|
||||
// as settled (merged PR + idle). Reviewing them is harmless.
|
||||
// PR state comes from SidebarV2's per-row subscriptions via
|
||||
// publishSweepChangeRequestStates, so merged-PR+idle threads classify as
|
||||
// settled here exactly like they do in the sidebar. Rows that haven't
|
||||
// reported yet fall back to null (treated as unsettled) — same as a
|
||||
// freshly mounted sidebar.
|
||||
const changeRequestState =
|
||||
changeRequestStateByKey.get(scopedThreadKey(scopeThreadRef(shell.environmentId, shell.id))) ??
|
||||
null;
|
||||
return !effectiveSettled(shell, {
|
||||
now: options.now,
|
||||
autoSettleAfterDays: options.autoSettleAfterDays,
|
||||
changeRequestState: null,
|
||||
changeRequestState,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user