feat(code): suggested task cleanup#2273
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
4dec6f5 to
0b04c91
Compare
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/features/task-detail/components/SuggestedTasksPanel.tsx:57-59
`pageStart` is local state that persists across repo changes. When the user switches from repo A (was on page 2) to repo B that also has ≥`visibleCount` tasks, `effectivePageStart` stays at the previous offset and the user lands on an arbitrary page of the new repo's suggestions. A `useEffect` that resets `pageStart` to 0 whenever `selectedDirectory` changes would fix this.
```suggestion
const [detailTask, setDetailTask] = useState<DiscoveredTask | null>(null);
const [pageStart, setPageStart] = useState(0);
const [pageDirection, setPageDirection] = useState<1 | -1>(1);
// Reset pagination whenever the active repo changes so the user always
// lands on page 1 of the new repo's suggestions.
useEffect(() => {
setPageStart(0);
}, [selectedDirectory]);
```
### Issue 2 of 2
apps/code/src/renderer/features/setup/hooks/useSetupDiscovery.ts:19-27
**Effect fires twice on first-ever repo selection**
When a brand-new user selects their first repo, the effect runs with `discoveryEverStarted=false` and calls `startSetup(dir)`. Inside `startSetup`, `injectEnricherSuggestions` + `startDiscovery` are both kicked off. `startDiscovery` eventually calls `useSetupStore.getState().startDiscovery(dir, ...)` (after the async API task creation), which flips `discoveryByRepo[dir].status` to `"running"`. This makes `discoveryEverStarted` become `true`, re-running the effect with the same `selectedDirectory` and now calling `startEnricherForRepo(dir)` — even though `startSetup` already invoked `injectEnricherSuggestions`.
The in-process and store guards (`enricherSuggestionsRunningByRepo.has(dir)` / `enricherStatus === "done"|"running"`) prevent an actual double-run, so there is no visible breakage. But if the enricher finishes with an error in the narrow window between the two effect firings, it would be retried unexpectedly on the same selection. Consider removing `discoveryEverStarted` from the deps and capturing the branch decision in a `useRef` keyed to `selectedDirectory`.
Reviews (1): Last reviewed commit: "feat(code): remove suggested tasks from ..." | Re-trigger Greptile |
| const [detailTask, setDetailTask] = useState<DiscoveredTask | null>(null); | ||
| const [pageStart, setPageStart] = useState(0); | ||
| const [pageDirection, setPageDirection] = useState<1 | -1>(1); |
There was a problem hiding this comment.
pageStart is local state that persists across repo changes. When the user switches from repo A (was on page 2) to repo B that also has ≥visibleCount tasks, effectivePageStart stays at the previous offset and the user lands on an arbitrary page of the new repo's suggestions. A useEffect that resets pageStart to 0 whenever selectedDirectory changes would fix this.
| const [detailTask, setDetailTask] = useState<DiscoveredTask | null>(null); | |
| const [pageStart, setPageStart] = useState(0); | |
| const [pageDirection, setPageDirection] = useState<1 | -1>(1); | |
| const [detailTask, setDetailTask] = useState<DiscoveredTask | null>(null); | |
| const [pageStart, setPageStart] = useState(0); | |
| const [pageDirection, setPageDirection] = useState<1 | -1>(1); | |
| // Reset pagination whenever the active repo changes so the user always | |
| // lands on page 1 of the new repo's suggestions. | |
| useEffect(() => { | |
| setPageStart(0); | |
| }, [selectedDirectory]); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/task-detail/components/SuggestedTasksPanel.tsx
Line: 57-59
Comment:
`pageStart` is local state that persists across repo changes. When the user switches from repo A (was on page 2) to repo B that also has ≥`visibleCount` tasks, `effectivePageStart` stays at the previous offset and the user lands on an arbitrary page of the new repo's suggestions. A `useEffect` that resets `pageStart` to 0 whenever `selectedDirectory` changes would fix this.
```suggestion
const [detailTask, setDetailTask] = useState<DiscoveredTask | null>(null);
const [pageStart, setPageStart] = useState(0);
const [pageDirection, setPageDirection] = useState<1 | -1>(1);
// Reset pagination whenever the active repo changes so the user always
// lands on page 1 of the new repo's suggestions.
useEffect(() => {
setPageStart(0);
}, [selectedDirectory]);
```
How can I resolve this? If you propose a fix, please make it concise.| useEffect(() => { | ||
| if (startedRef.current) return; | ||
| // Only auto-fire from a clean "idle" state. "done" needs no rerun, and | ||
| // "error" (which now includes interrupted runs persisted across boots — | ||
| // see setupStore partialize) requires an explicit user retry to recover. | ||
| if (discoveryStatus !== "idle") return; | ||
| if (!selectedDirectory) return; | ||
|
|
||
| startedRef.current = true; | ||
| get<SetupRunService>(RENDERER_TOKENS.SetupRunService).startSetup( | ||
| selectedDirectory, | ||
| ); | ||
| }, [discoveryStatus, selectedDirectory]); | ||
| const service = get<SetupRunService>(RENDERER_TOKENS.SetupRunService); | ||
| if (discoveryEverStarted) { | ||
| service.startEnricherForRepo(selectedDirectory); | ||
| } else { | ||
| service.startSetup(selectedDirectory); | ||
| } | ||
| }, [discoveryEverStarted, selectedDirectory]); |
There was a problem hiding this comment.
Effect fires twice on first-ever repo selection
When a brand-new user selects their first repo, the effect runs with discoveryEverStarted=false and calls startSetup(dir). Inside startSetup, injectEnricherSuggestions + startDiscovery are both kicked off. startDiscovery eventually calls useSetupStore.getState().startDiscovery(dir, ...) (after the async API task creation), which flips discoveryByRepo[dir].status to "running". This makes discoveryEverStarted become true, re-running the effect with the same selectedDirectory and now calling startEnricherForRepo(dir) — even though startSetup already invoked injectEnricherSuggestions.
The in-process and store guards (enricherSuggestionsRunningByRepo.has(dir) / enricherStatus === "done"|"running") prevent an actual double-run, so there is no visible breakage. But if the enricher finishes with an error in the narrow window between the two effect firings, it would be retried unexpectedly on the same selection. Consider removing discoveryEverStarted from the deps and capturing the branch decision in a useRef keyed to selectedDirectory.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/setup/hooks/useSetupDiscovery.ts
Line: 19-27
Comment:
**Effect fires twice on first-ever repo selection**
When a brand-new user selects their first repo, the effect runs with `discoveryEverStarted=false` and calls `startSetup(dir)`. Inside `startSetup`, `injectEnricherSuggestions` + `startDiscovery` are both kicked off. `startDiscovery` eventually calls `useSetupStore.getState().startDiscovery(dir, ...)` (after the async API task creation), which flips `discoveryByRepo[dir].status` to `"running"`. This makes `discoveryEverStarted` become `true`, re-running the effect with the same `selectedDirectory` and now calling `startEnricherForRepo(dir)` — even though `startSetup` already invoked `injectEnricherSuggestions`.
The in-process and store guards (`enricherSuggestionsRunningByRepo.has(dir)` / `enricherStatus === "done"|"running"`) prevent an actual double-run, so there is no visible breakage. But if the enricher finishes with an error in the narrow window between the two effect firings, it would be retried unexpectedly on the same selection. Consider removing `discoveryEverStarted` from the deps and capturing the branch decision in a `useRef` keyed to `selectedDirectory`.
How can I resolve this? If you propose a fix, please make it concise.0b04c91 to
67260f4
Compare

Problem
Changes
suggestions-update.mp4 (uploaded via Graphite)
makes all task suggestions (enricher + discovery) scoped to a repo
runs enricher on any new repo selected
removes suggestions from inbox
clicking a suggestion now opens a modal w/ task details and options to implement or dismiss
"see N more in inbox" is gone, suggestions are paginated inline
How did you test this?
manually
Publish to changelog?
no