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]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-07-15 22:42:33 -07:00
1 parent af880a2740
commit 535449600a
5 files changed
+153 -46

No files matched your search

+67 -8
View File
@@ -76,7 +76,8 @@ interface HomeScreenProps {
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
readonly onSettleThread: (thread: EnvironmentThreadShell) => void;
/** Resolves true iff the settle was dispatched and succeeded. */
readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
@@ -323,16 +324,52 @@ export function HomeScreen(props: HomeScreenProps) {
);
const handleSettleThread = useCallback(
(thread: EnvironmentThreadShell) => {
const threadKey = scopedThreadKey(thread.environmentId, thread.id);
setSettledHolds((current) =>
new Map(current).set(scopedThreadKey(thread.environmentId, thread.id), {
new Map(current).set(threadKey, {
...thread,
archivedAt: thread.archivedAt ?? new Date().toISOString(),
}),
);
props.onSettleThread(thread);
void (async () => {
// Roll the optimistic hold back if the settle was blocked or failed —
// otherwise a never-archived thread would render settled forever.
const succeeded = await props.onSettleThread(thread);
if (!succeeded) {
setSettledHolds((current) => {
const next = new Map(current);
next.delete(threadKey);
return next;
});
}
})();
},
[props.onSettleThread],
);
// Delete and un-settle both invalidate any hold for the thread.
const dropSettledHold = useCallback((thread: EnvironmentThreadShell) => {
setSettledHolds((current) => {
const threadKey = scopedThreadKey(thread.environmentId, thread.id);
if (!current.has(threadKey)) return current;
const next = new Map(current);
next.delete(threadKey);
return next;
});
}, []);
const handleDeleteThread = useCallback(
(thread: EnvironmentThreadShell) => {
dropSettledHold(thread);
props.onDeleteThread(thread);
},
[dropSettledHold, props.onDeleteThread],
);
const handleUnsettleThread = useCallback(
(thread: EnvironmentThreadShell) => {
dropSettledHold(thread);
props.onUnsettleThread(thread);
},
[dropSettledHold, props.onUnsettleThread],
);
useEffect(() => {
if (settledHolds.size === 0) return;
const covered = new Set<string>();
@@ -392,9 +429,9 @@ export function HomeScreen(props: HomeScreenProps) {
}
onSelectThread={props.onSelectThread}
onArchiveThread={props.onArchiveThread}
onDeleteThread={props.onDeleteThread}
onDeleteThread={handleDeleteThread}
onSettleThread={handleSettleThread}
onUnsettleThread={props.onUnsettleThread}
onUnsettleThread={handleUnsettleThread}
onChangeRequestState={handleChangeRequestState}
projectCwd={
projectCwdByKey.get(scopedProjectKey(item.thread.environmentId, item.thread.projectId)) ??
@@ -406,15 +443,15 @@ export function HomeScreen(props: HomeScreenProps) {
),
[
handleChangeRequestState,
handleDeleteThread,
handleSettleThread,
handleSwipeableClose,
handleSwipeableWillOpen,
handleUnsettleThread,
projectByKey,
projectCwdByKey,
props.onArchiveThread,
props.onDeleteThread,
props.onSelectThread,
props.onUnsettleThread,
],
);
const v2KeyExtractor = useCallback(
@@ -586,6 +623,28 @@ export function HomeScreen(props: HomeScreenProps) {
</>
);
// v2 renders queued offline tasks above the thread cards — they are not
// thread shells, so the v2 item builder never sees them, but they must
// stay visible and deletable while their environment is offline.
const v2ListHeader = (
<>
{listHeader}
{props.pendingTasks.map((pendingTask, index) => (
<PendingTaskListRow
key={pendingTask.message.messageId}
variant="compact"
pendingTask={pendingTask}
environmentLabel={
props.savedConnectionsById[pendingTask.message.environmentId]?.environmentLabel ?? null
}
isLast={index === props.pendingTasks.length - 1}
onSelectPendingTask={props.onSelectPendingTask}
onDeletePendingTask={props.onDeletePendingTask}
/>
))}
</>
);
const listEmpty = !hasResults ? (
hasSearchQuery ? (
<EmptyState title="No results" detail={`No threads matching "${props.searchQuery}".`} />
@@ -610,7 +669,7 @@ export function HomeScreen(props: HomeScreenProps) {
drawDistance={500}
estimatedItemSize={ESTIMATED_THREAD_ROW_HEIGHT}
extraData={projectByKey}
ListHeaderComponent={listHeader}
ListHeaderComponent={v2ListHeader}
ListEmptyComponent={listEmpty}
style={{ flex: 1 }}
automaticallyAdjustsScrollIndicatorInsets={Platform.OS === "ios"}
@@ -40,6 +40,7 @@ function actionFailureTitle(action: ThreadListAction): string {
return "Could not delete thread";
}
/** Resolves to true iff the action was dispatched and succeeded. */
function useThreadActionExecutor(
onCompleted?: (action: ThreadListAction, thread: EnvironmentThreadShell) => void,
) {
@@ -56,7 +57,7 @@ function useThreadActionExecutor(
async (action: ThreadListAction, thread: EnvironmentThreadShell) => {
const key = scopedThreadKey(thread.environmentId, thread.id);
if (inFlightThreadKeys.current.has(key)) {
return;
return false;
}
inFlightThreadKeys.current.add(key);
@@ -73,12 +74,12 @@ function useThreadActionExecutor(
actionFailureTitle(action),
"This thread is working. Interrupt it first, then try again.",
);
return;
return false;
}
// Auto-settled rows (inactivity / merged PR) are not archived;
// unarchiving them would be rejected. Nothing to undo — no-op.
if (action === "unsettle" && thread.archivedAt === null) {
return;
return false;
}
const mutation =
action === "settle"
@@ -96,15 +97,16 @@ function useThreadActionExecutor(
});
if (result._tag === "Failure") {
Alert.alert(actionFailureTitle(action), actionFailureMessage(action, result.cause));
return;
}
// Settle rides archive, and archiving drops the thread from the live
// shell stream — refresh the archived snapshot so the v2 list can
// show it as a settled row without waiting for a manual reload.
if (action === "settle" || action === "unsettle" || action === "archive") {
refreshArchivedThreadsForEnvironment(thread.environmentId);
return false;
}
// Archived threads leave the live shell stream, and the v2 list
// renders them from the archived snapshot — keep it fresh for every
// action that changes what that snapshot should contain (delete
// included, or a deleted settled row lingers until some later
// refresh).
refreshArchivedThreadsForEnvironment(thread.environmentId);
onCompleted?.(action, thread);
return true;
} finally {
inFlightThreadKeys.current.delete(key);
}
@@ -123,7 +125,7 @@ function useThreadActionExecutor(
}
function useConfirmDeleteThread(
executeAction: (action: ThreadListAction, thread: EnvironmentThreadShell) => Promise<void>,
executeAction: (action: ThreadListAction, thread: EnvironmentThreadShell) => Promise<boolean>,
) {
return useCallback(
(thread: EnvironmentThreadShell) => {
@@ -159,7 +161,7 @@ function useConfirmDeleteThread(
export function useThreadListActions(): {
readonly archiveThread: (thread: EnvironmentThreadShell) => void;
readonly confirmDeleteThread: (thread: EnvironmentThreadShell) => void;
readonly settleThread: (thread: EnvironmentThreadShell) => void;
readonly settleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
readonly unsettleThread: (thread: EnvironmentThreadShell) => void;
} {
const executeAction = useThreadActionExecutor();
@@ -171,9 +173,7 @@ export function useThreadListActions(): {
[executeAction],
);
const settleThread = useCallback(
(thread: EnvironmentThreadShell) => {
void executeAction("settle", thread);
},
async (thread: EnvironmentThreadShell) => (await executeAction("settle", thread)) === true,
[executeAction],
);
const unsettleThread = useCallback(
@@ -189,24 +189,27 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
[handleArchive, handleDelete, handleSettle, handleUnsettle],
);
// Swipe: the v2 primary action is Settle (cards) / Un-settle (slim) —
// the lifecycle transition IS the organizing gesture of this list.
// Swipe: the v2 primary action is the lifecycle transition. Un-settle only
// exists when there is an archive to undo; an auto-settled slim row
// (inactivity / merged PR, archivedAt null) offers Settle, which archives
// it — the explicit "keep it settled" the row can actually deliver.
const canUnsettle = variant === "slim" && thread.archivedAt !== null;
const primaryAction = useMemo(
() =>
variant === "card"
canUnsettle
? {
accessibilityLabel: `Settle ${thread.title}`,
icon: "checkmark" as const,
label: "Settle",
onPress: handleSettle,
}
: {
accessibilityLabel: `Un-settle ${thread.title}`,
icon: "arrow.uturn.backward" as const,
label: "Un-settle",
onPress: handleUnsettle,
}
: {
accessibilityLabel: `Settle ${thread.title}`,
icon: "checkmark" as const,
label: "Settle",
onPress: handleSettle,
},
[handleSettle, handleUnsettle, thread.title, variant],
[canUnsettle, handleSettle, handleUnsettle, thread.title],
);
const rowContent = (close: () => void) =>
@@ -366,7 +369,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
>
{(close) => (
<ControlPillMenu
actions={variant === "card" ? CARD_MENU_ACTIONS : SLIM_MENU_ACTIONS}
actions={canUnsettle ? SLIM_MENU_ACTIONS : CARD_MENU_ACTIONS}
onPressAction={handleMenuAction}
shouldOpenOnLongPress
>
+35 -4
View File
@@ -979,6 +979,14 @@ export default function SidebarV2() {
);
return;
}
// Un-settling invalidates any optimistic settled hold for the thread.
setSettledHolds((current) => {
const threadKey = scopedThreadKey(threadRef);
if (!current.has(threadKey)) return current;
const next = new Map(current);
next.delete(threadKey);
return next;
});
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
})();
},
@@ -1053,6 +1061,15 @@ export default function SidebarV2() {
}
return;
}
// Deleted threads must not survive as settled holds or stale
// archived-snapshot rows.
setSettledHolds((current) => {
if (!current.has(threadKey)) return current;
const next = new Map(current);
next.delete(threadKey);
return next;
});
refreshArchivedThreadsForEnvironment(thread.environmentId);
}
removeFromSelection(threadKeys);
},
@@ -1079,9 +1096,9 @@ export default function SidebarV2() {
}
const thread = threadByKeyRef.current.get(threadKey);
if (!thread) return;
// Match what the user sees: a row renders slim iff it is in the
// settled partition, so the menu label mirrors that exact state.
const isSettled = settledThreadKeysRef.current.has(threadKey);
// Un-settle appears only when there is an archive to undo; an
// auto-settled (unarchived) slim row gets Settle, which archives it.
const isSettled = settledThreadKeysRef.current.has(threadKey) && thread.archivedAt !== null;
const clicked = await settlePromise(() =>
api.contextMenu.show(
[
@@ -1146,7 +1163,17 @@ export default function SidebarV2() {
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
return;
}
// A deleted thread must not survive as a settled hold or a stale
// archived-snapshot row.
setSettledHolds((current) => {
if (!current.has(threadKey)) return current;
const next = new Map(current);
next.delete(threadKey);
return next;
});
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
return;
}
default:
@@ -1445,7 +1472,11 @@ export default function SidebarV2() {
key={threadKey}
thread={thread}
variant={isCard ? "card" : "slim"}
variantAction={isSettledRow ? "unsettle" : "settle"}
// Un-settle only when there is an archive to undo. An
// auto-settled row (inactivity / merged PR, archivedAt
// null) offers Settle: archiving is the explicit "keep it
// settled" the row can actually deliver.
variantAction={isSettledRow && thread.archivedAt !== null ? "unsettle" : "settle"}
isActive={routeThreadKey === threadKey}
jumpLabel={showJumpHints ? (jumpLabelByKey.get(threadKey) ?? null) : null}
currentEnvironmentId={primaryEnvironmentId}
+22 -8
View File
@@ -391,10 +391,16 @@ export function useThreadActions() {
if (thread.worktreePath === null) {
return settleResult;
}
const threads = readEnvironmentThreadRefs(threadRef.environmentId).flatMap((ref) => {
// Settle = archive drops the thread from the live shell store, so the
// orphan computation must re-include the shell we just settled — the
// live threads are only the OTHER worktree users.
const liveThreads = readEnvironmentThreadRefs(threadRef.environmentId).flatMap((ref) => {
const shell = readThreadShell(ref);
return shell === null ? [] : [shell];
});
const threads = liveThreads.some((candidate) => candidate.id === threadRef.threadId)
? liveThreads
: [...liveThreads, thread];
const orphanedWorktreePath = getOrphanedWorktreePathForThread(threads, threadRef.threadId);
const threadProject = readProject({
environmentId: threadRef.environmentId,
@@ -425,16 +431,24 @@ export function useThreadActions() {
// thread can have woken up or another thread adopted the
// worktree since the settle happened.
const currentShell = readThreadShell(threadRef);
const currentThreads = readEnvironmentThreadRefs(threadRef.environmentId).flatMap(
(ref) => {
const shell = readThreadShell(ref);
return shell === null ? [] : [shell];
},
);
const currentLiveThreads = readEnvironmentThreadRefs(
threadRef.environmentId,
).flatMap((ref) => {
const shell = readThreadShell(ref);
return shell === null ? [] : [shell];
});
// Archived threads leave the live store entirely, so absence
// IS the settled state; a live shell means it woke back up
// (unarchive puts it back in the stream).
const stillSettled = currentShell === null || currentShell.archivedAt != null;
const currentThreads = currentLiveThreads.some(
(candidate) => candidate.id === threadRef.threadId,
)
? currentLiveThreads
: [...currentLiveThreads, thread];
const stillOrphaned =
getOrphanedWorktreePathForThread(currentThreads, threadRef.threadId) ===
orphanedWorktreePath;
const stillSettled = currentShell?.archivedAt != null;
if (!stillOrphaned || !stillSettled) {
toastManager.add(
stackedThreadToast({