Skip to content

Commit 5354496

Browse files
t3dotggclaude
andcommitted
Address PR #4026 review findings, round two
- Worktree-removal offer works after settle: archived threads leave the live shell store, so the orphan check re-includes the settled shell and click-time revalidation treats absence-from-live as still-settled - Un-settle is only offered when there is an archive to undo: auto-settled rows (inactivity / merged PR, archivedAt null) get Settle instead, on web (hover button + context menu) and mobile (swipe + long-press menu) - Mobile optimistic settled hold rolls back when the settle is blocked or fails (settleThread now reports success); web and mobile both drop holds on delete and un-settle so ghosts can't linger - Archived snapshot refreshes after delete too, clearing stale settled rows sourced from the snapshot - v2 mobile list renders queued offline tasks above the cards (they were dropped entirely, leaving a blank screen for pending-task-only projects) On the chat.new/settings finding: not fixed here — the shortcut routes to the v2 picker only inside chat routes by design; on /settings it falls back to contextual create, matching v1's behavior on those routes. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent af880a2 commit 5354496

5 files changed

Lines changed: 153 additions & 46 deletions

File tree

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ interface HomeScreenProps {
7676
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
7777
readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
7878
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
79-
readonly onSettleThread: (thread: EnvironmentThreadShell) => void;
79+
/** Resolves true iff the settle was dispatched and succeeded. */
80+
readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
8081
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
8182
readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
8283
readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
@@ -323,16 +324,52 @@ export function HomeScreen(props: HomeScreenProps) {
323324
);
324325
const handleSettleThread = useCallback(
325326
(thread: EnvironmentThreadShell) => {
327+
const threadKey = scopedThreadKey(thread.environmentId, thread.id);
326328
setSettledHolds((current) =>
327-
new Map(current).set(scopedThreadKey(thread.environmentId, thread.id), {
329+
new Map(current).set(threadKey, {
328330
...thread,
329331
archivedAt: thread.archivedAt ?? new Date().toISOString(),
330332
}),
331333
);
332-
props.onSettleThread(thread);
334+
void (async () => {
335+
// Roll the optimistic hold back if the settle was blocked or failed —
336+
// otherwise a never-archived thread would render settled forever.
337+
const succeeded = await props.onSettleThread(thread);
338+
if (!succeeded) {
339+
setSettledHolds((current) => {
340+
const next = new Map(current);
341+
next.delete(threadKey);
342+
return next;
343+
});
344+
}
345+
})();
333346
},
334347
[props.onSettleThread],
335348
);
349+
// Delete and un-settle both invalidate any hold for the thread.
350+
const dropSettledHold = useCallback((thread: EnvironmentThreadShell) => {
351+
setSettledHolds((current) => {
352+
const threadKey = scopedThreadKey(thread.environmentId, thread.id);
353+
if (!current.has(threadKey)) return current;
354+
const next = new Map(current);
355+
next.delete(threadKey);
356+
return next;
357+
});
358+
}, []);
359+
const handleDeleteThread = useCallback(
360+
(thread: EnvironmentThreadShell) => {
361+
dropSettledHold(thread);
362+
props.onDeleteThread(thread);
363+
},
364+
[dropSettledHold, props.onDeleteThread],
365+
);
366+
const handleUnsettleThread = useCallback(
367+
(thread: EnvironmentThreadShell) => {
368+
dropSettledHold(thread);
369+
props.onUnsettleThread(thread);
370+
},
371+
[dropSettledHold, props.onUnsettleThread],
372+
);
336373
useEffect(() => {
337374
if (settledHolds.size === 0) return;
338375
const covered = new Set<string>();
@@ -392,9 +429,9 @@ export function HomeScreen(props: HomeScreenProps) {
392429
}
393430
onSelectThread={props.onSelectThread}
394431
onArchiveThread={props.onArchiveThread}
395-
onDeleteThread={props.onDeleteThread}
432+
onDeleteThread={handleDeleteThread}
396433
onSettleThread={handleSettleThread}
397-
onUnsettleThread={props.onUnsettleThread}
434+
onUnsettleThread={handleUnsettleThread}
398435
onChangeRequestState={handleChangeRequestState}
399436
projectCwd={
400437
projectCwdByKey.get(scopedProjectKey(item.thread.environmentId, item.thread.projectId)) ??
@@ -406,15 +443,15 @@ export function HomeScreen(props: HomeScreenProps) {
406443
),
407444
[
408445
handleChangeRequestState,
446+
handleDeleteThread,
409447
handleSettleThread,
410448
handleSwipeableClose,
411449
handleSwipeableWillOpen,
450+
handleUnsettleThread,
412451
projectByKey,
413452
projectCwdByKey,
414453
props.onArchiveThread,
415-
props.onDeleteThread,
416454
props.onSelectThread,
417-
props.onUnsettleThread,
418455
],
419456
);
420457
const v2KeyExtractor = useCallback(
@@ -586,6 +623,28 @@ export function HomeScreen(props: HomeScreenProps) {
586623
</>
587624
);
588625

626+
// v2 renders queued offline tasks above the thread cards — they are not
627+
// thread shells, so the v2 item builder never sees them, but they must
628+
// stay visible and deletable while their environment is offline.
629+
const v2ListHeader = (
630+
<>
631+
{listHeader}
632+
{props.pendingTasks.map((pendingTask, index) => (
633+
<PendingTaskListRow
634+
key={pendingTask.message.messageId}
635+
variant="compact"
636+
pendingTask={pendingTask}
637+
environmentLabel={
638+
props.savedConnectionsById[pendingTask.message.environmentId]?.environmentLabel ?? null
639+
}
640+
isLast={index === props.pendingTasks.length - 1}
641+
onSelectPendingTask={props.onSelectPendingTask}
642+
onDeletePendingTask={props.onDeletePendingTask}
643+
/>
644+
))}
645+
</>
646+
);
647+
589648
const listEmpty = !hasResults ? (
590649
hasSearchQuery ? (
591650
<EmptyState title="No results" detail={`No threads matching "${props.searchQuery}".`} />
@@ -610,7 +669,7 @@ export function HomeScreen(props: HomeScreenProps) {
610669
drawDistance={500}
611670
estimatedItemSize={ESTIMATED_THREAD_ROW_HEIGHT}
612671
extraData={projectByKey}
613-
ListHeaderComponent={listHeader}
672+
ListHeaderComponent={v2ListHeader}
614673
ListEmptyComponent={listEmpty}
615674
style={{ flex: 1 }}
616675
automaticallyAdjustsScrollIndicatorInsets={Platform.OS === "ios"}

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function actionFailureTitle(action: ThreadListAction): string {
4040
return "Could not delete thread";
4141
}
4242

43+
/** Resolves to true iff the action was dispatched and succeeded. */
4344
function useThreadActionExecutor(
4445
onCompleted?: (action: ThreadListAction, thread: EnvironmentThreadShell) => void,
4546
) {
@@ -56,7 +57,7 @@ function useThreadActionExecutor(
5657
async (action: ThreadListAction, thread: EnvironmentThreadShell) => {
5758
const key = scopedThreadKey(thread.environmentId, thread.id);
5859
if (inFlightThreadKeys.current.has(key)) {
59-
return;
60+
return false;
6061
}
6162

6263
inFlightThreadKeys.current.add(key);
@@ -73,12 +74,12 @@ function useThreadActionExecutor(
7374
actionFailureTitle(action),
7475
"This thread is working. Interrupt it first, then try again.",
7576
);
76-
return;
77+
return false;
7778
}
7879
// Auto-settled rows (inactivity / merged PR) are not archived;
7980
// unarchiving them would be rejected. Nothing to undo — no-op.
8081
if (action === "unsettle" && thread.archivedAt === null) {
81-
return;
82+
return false;
8283
}
8384
const mutation =
8485
action === "settle"
@@ -96,15 +97,16 @@ function useThreadActionExecutor(
9697
});
9798
if (result._tag === "Failure") {
9899
Alert.alert(actionFailureTitle(action), actionFailureMessage(action, result.cause));
99-
return;
100-
}
101-
// Settle rides archive, and archiving drops the thread from the live
102-
// shell stream — refresh the archived snapshot so the v2 list can
103-
// show it as a settled row without waiting for a manual reload.
104-
if (action === "settle" || action === "unsettle" || action === "archive") {
105-
refreshArchivedThreadsForEnvironment(thread.environmentId);
100+
return false;
106101
}
102+
// Archived threads leave the live shell stream, and the v2 list
103+
// renders them from the archived snapshot — keep it fresh for every
104+
// action that changes what that snapshot should contain (delete
105+
// included, or a deleted settled row lingers until some later
106+
// refresh).
107+
refreshArchivedThreadsForEnvironment(thread.environmentId);
107108
onCompleted?.(action, thread);
109+
return true;
108110
} finally {
109111
inFlightThreadKeys.current.delete(key);
110112
}
@@ -123,7 +125,7 @@ function useThreadActionExecutor(
123125
}
124126

125127
function useConfirmDeleteThread(
126-
executeAction: (action: ThreadListAction, thread: EnvironmentThreadShell) => Promise<void>,
128+
executeAction: (action: ThreadListAction, thread: EnvironmentThreadShell) => Promise<boolean>,
127129
) {
128130
return useCallback(
129131
(thread: EnvironmentThreadShell) => {
@@ -159,7 +161,7 @@ function useConfirmDeleteThread(
159161
export function useThreadListActions(): {
160162
readonly archiveThread: (thread: EnvironmentThreadShell) => void;
161163
readonly confirmDeleteThread: (thread: EnvironmentThreadShell) => void;
162-
readonly settleThread: (thread: EnvironmentThreadShell) => void;
164+
readonly settleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
163165
readonly unsettleThread: (thread: EnvironmentThreadShell) => void;
164166
} {
165167
const executeAction = useThreadActionExecutor();
@@ -171,9 +173,7 @@ export function useThreadListActions(): {
171173
[executeAction],
172174
);
173175
const settleThread = useCallback(
174-
(thread: EnvironmentThreadShell) => {
175-
void executeAction("settle", thread);
176-
},
176+
async (thread: EnvironmentThreadShell) => (await executeAction("settle", thread)) === true,
177177
[executeAction],
178178
);
179179
const unsettleThread = useCallback(

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,27 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
189189
[handleArchive, handleDelete, handleSettle, handleUnsettle],
190190
);
191191

192-
// Swipe: the v2 primary action is Settle (cards) / Un-settle (slim) —
193-
// the lifecycle transition IS the organizing gesture of this list.
192+
// Swipe: the v2 primary action is the lifecycle transition. Un-settle only
193+
// exists when there is an archive to undo; an auto-settled slim row
194+
// (inactivity / merged PR, archivedAt null) offers Settle, which archives
195+
// it — the explicit "keep it settled" the row can actually deliver.
196+
const canUnsettle = variant === "slim" && thread.archivedAt !== null;
194197
const primaryAction = useMemo(
195198
() =>
196-
variant === "card"
199+
canUnsettle
197200
? {
198-
accessibilityLabel: `Settle ${thread.title}`,
199-
icon: "checkmark" as const,
200-
label: "Settle",
201-
onPress: handleSettle,
202-
}
203-
: {
204201
accessibilityLabel: `Un-settle ${thread.title}`,
205202
icon: "arrow.uturn.backward" as const,
206203
label: "Un-settle",
207204
onPress: handleUnsettle,
205+
}
206+
: {
207+
accessibilityLabel: `Settle ${thread.title}`,
208+
icon: "checkmark" as const,
209+
label: "Settle",
210+
onPress: handleSettle,
208211
},
209-
[handleSettle, handleUnsettle, thread.title, variant],
212+
[canUnsettle, handleSettle, handleUnsettle, thread.title],
210213
);
211214

212215
const rowContent = (close: () => void) =>
@@ -366,7 +369,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
366369
>
367370
{(close) => (
368371
<ControlPillMenu
369-
actions={variant === "card" ? CARD_MENU_ACTIONS : SLIM_MENU_ACTIONS}
372+
actions={canUnsettle ? SLIM_MENU_ACTIONS : CARD_MENU_ACTIONS}
370373
onPressAction={handleMenuAction}
371374
shouldOpenOnLongPress
372375
>

‎apps/web/src/components/SidebarV2.tsx‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,14 @@ export default function SidebarV2() {
979979
);
980980
return;
981981
}
982+
// Un-settling invalidates any optimistic settled hold for the thread.
983+
setSettledHolds((current) => {
984+
const threadKey = scopedThreadKey(threadRef);
985+
if (!current.has(threadKey)) return current;
986+
const next = new Map(current);
987+
next.delete(threadKey);
988+
return next;
989+
});
982990
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
983991
})();
984992
},
@@ -1053,6 +1061,15 @@ export default function SidebarV2() {
10531061
}
10541062
return;
10551063
}
1064+
// Deleted threads must not survive as settled holds or stale
1065+
// archived-snapshot rows.
1066+
setSettledHolds((current) => {
1067+
if (!current.has(threadKey)) return current;
1068+
const next = new Map(current);
1069+
next.delete(threadKey);
1070+
return next;
1071+
});
1072+
refreshArchivedThreadsForEnvironment(thread.environmentId);
10561073
}
10571074
removeFromSelection(threadKeys);
10581075
},
@@ -1079,9 +1096,9 @@ export default function SidebarV2() {
10791096
}
10801097
const thread = threadByKeyRef.current.get(threadKey);
10811098
if (!thread) return;
1082-
// Match what the user sees: a row renders slim iff it is in the
1083-
// settled partition, so the menu label mirrors that exact state.
1084-
const isSettled = settledThreadKeysRef.current.has(threadKey);
1099+
// Un-settle appears only when there is an archive to undo; an
1100+
// auto-settled (unarchived) slim row gets Settle, which archives it.
1101+
const isSettled = settledThreadKeysRef.current.has(threadKey) && thread.archivedAt !== null;
10851102
const clicked = await settlePromise(() =>
10861103
api.contextMenu.show(
10871104
[
@@ -1146,7 +1163,17 @@ export default function SidebarV2() {
11461163
description: error instanceof Error ? error.message : "An error occurred.",
11471164
}),
11481165
);
1166+
return;
11491167
}
1168+
// A deleted thread must not survive as a settled hold or a stale
1169+
// archived-snapshot row.
1170+
setSettledHolds((current) => {
1171+
if (!current.has(threadKey)) return current;
1172+
const next = new Map(current);
1173+
next.delete(threadKey);
1174+
return next;
1175+
});
1176+
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
11501177
return;
11511178
}
11521179
default:
@@ -1445,7 +1472,11 @@ export default function SidebarV2() {
14451472
key={threadKey}
14461473
thread={thread}
14471474
variant={isCard ? "card" : "slim"}
1448-
variantAction={isSettledRow ? "unsettle" : "settle"}
1475+
// Un-settle only when there is an archive to undo. An
1476+
// auto-settled row (inactivity / merged PR, archivedAt
1477+
// null) offers Settle: archiving is the explicit "keep it
1478+
// settled" the row can actually deliver.
1479+
variantAction={isSettledRow && thread.archivedAt !== null ? "unsettle" : "settle"}
14491480
isActive={routeThreadKey === threadKey}
14501481
jumpLabel={showJumpHints ? (jumpLabelByKey.get(threadKey) ?? null) : null}
14511482
currentEnvironmentId={primaryEnvironmentId}

‎apps/web/src/hooks/useThreadActions.ts‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,16 @@ export function useThreadActions() {
391391
if (thread.worktreePath === null) {
392392
return settleResult;
393393
}
394-
const threads = readEnvironmentThreadRefs(threadRef.environmentId).flatMap((ref) => {
394+
// Settle = archive drops the thread from the live shell store, so the
395+
// orphan computation must re-include the shell we just settled — the
396+
// live threads are only the OTHER worktree users.
397+
const liveThreads = readEnvironmentThreadRefs(threadRef.environmentId).flatMap((ref) => {
395398
const shell = readThreadShell(ref);
396399
return shell === null ? [] : [shell];
397400
});
401+
const threads = liveThreads.some((candidate) => candidate.id === threadRef.threadId)
402+
? liveThreads
403+
: [...liveThreads, thread];
398404
const orphanedWorktreePath = getOrphanedWorktreePathForThread(threads, threadRef.threadId);
399405
const threadProject = readProject({
400406
environmentId: threadRef.environmentId,
@@ -425,16 +431,24 @@ export function useThreadActions() {
425431
// thread can have woken up or another thread adopted the
426432
// worktree since the settle happened.
427433
const currentShell = readThreadShell(threadRef);
428-
const currentThreads = readEnvironmentThreadRefs(threadRef.environmentId).flatMap(
429-
(ref) => {
430-
const shell = readThreadShell(ref);
431-
return shell === null ? [] : [shell];
432-
},
433-
);
434+
const currentLiveThreads = readEnvironmentThreadRefs(
435+
threadRef.environmentId,
436+
).flatMap((ref) => {
437+
const shell = readThreadShell(ref);
438+
return shell === null ? [] : [shell];
439+
});
440+
// Archived threads leave the live store entirely, so absence
441+
// IS the settled state; a live shell means it woke back up
442+
// (unarchive puts it back in the stream).
443+
const stillSettled = currentShell === null || currentShell.archivedAt != null;
444+
const currentThreads = currentLiveThreads.some(
445+
(candidate) => candidate.id === threadRef.threadId,
446+
)
447+
? currentLiveThreads
448+
: [...currentLiveThreads, thread];
434449
const stillOrphaned =
435450
getOrphanedWorktreePathForThread(currentThreads, threadRef.threadId) ===
436451
orphanedWorktreePath;
437-
const stillSettled = currentShell?.archivedAt != null;
438452
if (!stillOrphaned || !stillSettled) {
439453
toastManager.add(
440454
stackedThreadToast({

0 commit comments

Comments
 (0)