Skip to content

Commit 32788c5

Browse files
committed
Fix suggestion simulation cleanup
1 parent d75c214 commit 32788c5

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

apps/code/src/renderer/features/setup/hooks/useSetupDiscovery.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ export function useSetupDiscovery() {
2222
// Enricher runs per repo on every selection (gated on per-repo status
2323
// inside the service).
2424
useEffect(() => {
25-
if (!selectedDirectory) return;
25+
if (!selectedDirectory) return undefined;
2626
const service = get<SetupRunService>(RENDERER_TOKENS.SetupRunService);
2727
if (shouldSimulateSuggestions()) {
28-
service.startSuggestionSimulation(selectedDirectory);
29-
return;
28+
service.startSuggestionSimulation(
29+
selectedDirectory,
30+
shouldSimulateSuggestions,
31+
);
32+
return () => service.stopSuggestionSimulation(selectedDirectory);
3033
}
3134

35+
service.stopSuggestionSimulation();
3236
const discoveryEverStarted = Object.values(
3337
useSetupStore.getState().discoveryByRepo,
3438
).some((d) => d.status !== "idle");
@@ -37,5 +41,6 @@ export function useSetupDiscovery() {
3741
} else {
3842
service.startSetup(selectedDirectory);
3943
}
44+
return undefined;
4045
}, [selectedDirectory]);
4146
}

apps/code/src/renderer/features/setup/services/setupRunService.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const SIMULATED_SUGGESTION_CATEGORIES: DiscoveredTask["category"][] = [
3838
];
3939

4040
const SIMULATED_SUGGESTION_INTERVAL_MS = 2500;
41+
const SIMULATED_SUGGESTION_LIMIT = 12;
4142

4243
function buildSimulatedSuggestion(
4344
repoPath: string,
@@ -295,7 +296,10 @@ export class SetupRunService {
295296
this.injectEnricherSuggestions(directory);
296297
}
297298

298-
startSuggestionSimulation(directory: string): void {
299+
startSuggestionSimulation(
300+
directory: string,
301+
shouldContinue: () => boolean = () => true,
302+
): void {
299303
if (!directory) return;
300304
if (this.simulatedSuggestionsRepo === directory) return;
301305

@@ -305,11 +309,16 @@ export class SetupRunService {
305309

306310
this.simulatedSuggestionsRepo = directory;
307311
this.simulatedSuggestionsCount = 0;
308-
useSetupStore
309-
.getState()
310-
.startDiscovery(directory, "simulated-discovery", "simulated-run");
311312

312313
const addNextSuggestion = () => {
314+
if (
315+
!shouldContinue() ||
316+
this.simulatedSuggestionsCount >= SIMULATED_SUGGESTION_LIMIT
317+
) {
318+
this.stopSuggestionSimulation(directory);
319+
return;
320+
}
321+
313322
useSetupStore
314323
.getState()
315324
.addDiscoveredTaskIfMissing(
@@ -325,6 +334,16 @@ export class SetupRunService {
325334
);
326335
}
327336

337+
stopSuggestionSimulation(directory?: string): void {
338+
if (directory && this.simulatedSuggestionsRepo !== directory) return;
339+
if (this.simulatedSuggestionsTimer !== null) {
340+
window.clearInterval(this.simulatedSuggestionsTimer);
341+
}
342+
this.simulatedSuggestionsTimer = null;
343+
this.simulatedSuggestionsRepo = null;
344+
this.simulatedSuggestionsCount = 0;
345+
}
346+
328347
startDiscovery(directory: string): void {
329348
if (!directory) return;
330349
if (this.anyDiscoveryEverLaunched) return;

apps/code/src/renderer/features/task-detail/components/SuggestedTasksPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export function SuggestedTasksPanel() {
121121

122122
const hasTasks = discoveredTasks.length > 0;
123123
const showEnricherFeed = !hasTasks && enricherStatus === "running";
124-
const showDiscoveryFeed = !hasTasks && discoveryStatus === "running";
124+
const showDiscoveryFeed = discoveryStatus === "running";
125125

126126
if (!hasTasks && !showEnricherFeed && !showDiscoveryFeed) return null;
127127

0 commit comments

Comments
 (0)