From 069f271b1cb4bfabcac8a9572ffba4eb876a747d Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Tue, 14 Jul 2026 04:20:29 -0700 Subject: [PATCH] Address PR #3960 review findings and CI failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI: add settledOverride/settledAt + new client settings to desktop and mobile test fixtures and the mobile threadDetailToShell mapping. Review fixes (cursor bugbot + macroscope): - failed status now requires session.status === "error" instead of any lingering lastError on a stopped/ready session - effectiveSettled: pending approvals or user input always win — blocked work can never collapse into the settled tail, even manually settled - decider unsettle-on-activity guards check settledOverride === "settled" so activity no longer erases a user's explicit keep-active override - repeat thread.settle re-emits with updatedAt = original settledAt, so double-settles no longer bump recency ordering - sidebarAutoSettleAfterDays bounded 1..90 in schema and patch - approval wait sort/label use shell.updatedAt (bumped by the approval activity in the projection pipeline) instead of latestUserMessageAt / turn start, with the approximation documented - v2 rows: Enter/Space keyboard activation; double-click inline rename ported from v1 plus a context-menu Rename entry - new-thread picker: cross-project creation no longer inherits the active thread's branch/worktree; preselection consults the active draft via resolveThreadActionProjectRef; stale project scope resets to All - settle worktree prompt: vcs status checked before offering (and again at click time) — dirty or ahead worktrees are never offered Co-Authored-By: Claude Fable 5 --- .../settings/DesktopClientSettings.test.ts | 2 + .../archive/archivedThreadList.test.ts | 2 + .../src/features/home/homeListItems.test.ts | 2 + .../src/features/home/homeThreadList.test.ts | 2 + apps/mobile/src/lib/repositoryGroups.test.ts | 2 + apps/mobile/src/lib/threadActivity.test.ts | 2 + apps/mobile/src/state/use-thread-selection.ts | 2 + .../src/orchestration/decider.settled.test.ts | 52 ++++- apps/server/src/orchestration/decider.ts | 8 +- apps/web/src/components/Sidebar.logic.test.ts | 21 +- apps/web/src/components/Sidebar.logic.ts | 15 +- apps/web/src/components/SidebarV2.tsx | 193 +++++++++++++++--- apps/web/src/hooks/useThreadActions.ts | 37 +++- apps/web/src/lib/chatThreadActions.test.ts | 21 ++ apps/web/src/lib/chatThreadActions.ts | 8 + apps/web/src/worktreeCleanup.test.ts | 14 +- apps/web/src/worktreeCleanup.ts | 7 + .../src/state/threadSettled.test.ts | 39 ++-- .../client-runtime/src/state/threadSettled.ts | 2 + packages/contracts/src/settings.test.ts | 7 + packages/contracts/src/settings.ts | 16 +- 21 files changed, 386 insertions(+), 68 deletions(-) diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts index ea7ec6e151..47800f3192 100644 --- a/apps/desktop/src/settings/DesktopClientSettings.test.ts +++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts @@ -20,6 +20,7 @@ const clientSettings: ClientSettings = { diffIgnoreWhitespace: true, favorites: [], providerModelPreferences: {}, + sidebarAutoSettleAfterDays: 3, sidebarProjectGroupingMode: "repository_path", sidebarProjectGroupingOverrides: { "environment-1:/tmp/project-a": "separate", @@ -27,6 +28,7 @@ const clientSettings: ClientSettings = { sidebarProjectSortOrder: "manual", sidebarThreadSortOrder: "created_at", sidebarThreadPreviewCount: 6, + sidebarV2Enabled: false, timestampFormat: "24-hour", wordWrap: true, }; diff --git a/apps/mobile/src/features/archive/archivedThreadList.test.ts b/apps/mobile/src/features/archive/archivedThreadList.test.ts index 6cd530ab37..697d13e7c4 100644 --- a/apps/mobile/src/features/archive/archivedThreadList.test.ts +++ b/apps/mobile/src/features/archive/archivedThreadList.test.ts @@ -41,6 +41,8 @@ function makeThread( hasPendingUserInput: false, hasActionableProposedPlan: false, ...input, + settledOverride: input.settledOverride ?? null, + settledAt: input.settledAt ?? null, }; } diff --git a/apps/mobile/src/features/home/homeListItems.test.ts b/apps/mobile/src/features/home/homeListItems.test.ts index 36e98ef129..c5a9f2c6bb 100644 --- a/apps/mobile/src/features/home/homeListItems.test.ts +++ b/apps/mobile/src/features/home/homeListItems.test.ts @@ -47,6 +47,8 @@ function makeThread(id: string, projectId: ProjectId): EnvironmentThreadShell { createdAt: "2026-06-01T00:00:00.000Z", updatedAt: "2026-06-01T00:00:00.000Z", archivedAt: null, + settledOverride: null, + settledAt: null, session: null, latestUserMessageAt: null, hasPendingApprovals: false, diff --git a/apps/mobile/src/features/home/homeThreadList.test.ts b/apps/mobile/src/features/home/homeThreadList.test.ts index 8f13000b9e..46d1173b0d 100644 --- a/apps/mobile/src/features/home/homeThreadList.test.ts +++ b/apps/mobile/src/features/home/homeThreadList.test.ts @@ -41,6 +41,8 @@ function makeThread( hasPendingUserInput: false, hasActionableProposedPlan: false, ...input, + settledOverride: input.settledOverride ?? null, + settledAt: input.settledAt ?? null, }; } diff --git a/apps/mobile/src/lib/repositoryGroups.test.ts b/apps/mobile/src/lib/repositoryGroups.test.ts index 8cea5df230..ab4311524c 100644 --- a/apps/mobile/src/lib/repositoryGroups.test.ts +++ b/apps/mobile/src/lib/repositoryGroups.test.ts @@ -38,6 +38,8 @@ function makeThread( hasPendingUserInput: false, hasActionableProposedPlan: false, ...input, + settledOverride: input.settledOverride ?? null, + settledAt: input.settledAt ?? null, }; } diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts index 23b47fc625..5f9f099a46 100644 --- a/apps/mobile/src/lib/threadActivity.test.ts +++ b/apps/mobile/src/lib/threadActivity.test.ts @@ -50,6 +50,8 @@ function makeThread( checkpoints: [], session: null, ...input, + settledOverride: input.settledOverride ?? null, + settledAt: input.settledAt ?? null, }; } diff --git a/apps/mobile/src/state/use-thread-selection.ts b/apps/mobile/src/state/use-thread-selection.ts index d369fbc437..80bc1916b1 100644 --- a/apps/mobile/src/state/use-thread-selection.ts +++ b/apps/mobile/src/state/use-thread-selection.ts @@ -58,6 +58,8 @@ function threadDetailToShell( createdAt: thread.createdAt, updatedAt: thread.updatedAt, archivedAt: thread.archivedAt, + settledOverride: thread.settledOverride, + settledAt: thread.settledAt, session: thread.session, latestUserMessageAt: latestUserMessageAt(thread), hasPendingApprovals: false, diff --git a/apps/server/src/orchestration/decider.settled.test.ts b/apps/server/src/orchestration/decider.settled.test.ts index dca1100e28..d4ecfba6a4 100644 --- a/apps/server/src/orchestration/decider.settled.test.ts +++ b/apps/server/src/orchestration/decider.settled.test.ts @@ -98,6 +98,7 @@ it.layer(NodeServices.layer)("settled thread decider", (it) => { expect(reEmitEvents[0]?.type).toBe("thread.settled"); if (reEmitEvents[0]?.type === "thread.settled") { expect(reEmitEvents[0].payload.settledAt).toBe(SETTLED_AT); + expect(reEmitEvents[0].payload.updatedAt).toBe(SETTLED_AT); } }), ); @@ -199,10 +200,55 @@ it.layer(NodeServices.layer)("settled thread decider", (it) => { readModel: makeReadModel("active"), }); const sessionEvents = Array.isArray(sessionResult) ? sessionResult : [sessionResult]; - expect(sessionEvents.map((event) => event.type)).toEqual([ - "thread.unsettled", - "thread.session-set", + expect(sessionEvents.map((event) => event.type)).toEqual(["thread.session-set"]); + }), + ); + + it.effect("preserves an explicit active override during activity", () => + Effect.gen(function* () { + const turnResult = yield* decideOrchestrationCommand({ + command: { + type: "thread.turn.start", + commandId: CommandId.make("cmd-active-turn-start"), + threadId: ThreadId.make("thread-1"), + message: { + messageId: MessageId.make("message-active"), + role: "user", + text: "Continue", + attachments: [], + }, + runtimeMode: "full-access", + interactionMode: "default", + createdAt: NOW, + }, + readModel: makeReadModel("active"), + }); + const turnEvents = Array.isArray(turnResult) ? turnResult : [turnResult]; + expect(turnEvents.map((event) => event.type)).toEqual([ + "thread.message-sent", + "thread.turn-start-requested", ]); + + const activityResult = yield* decideOrchestrationCommand({ + command: { + type: "thread.activity.append", + commandId: CommandId.make("cmd-active-approval"), + threadId: ThreadId.make("thread-1"), + activity: { + id: EventId.make("activity-active"), + tone: "approval", + kind: "approval.requested", + summary: "Command approval requested", + payload: null, + turnId: null, + createdAt: NOW, + }, + createdAt: NOW, + }, + readModel: makeReadModel("active"), + }); + const activityEvents = Array.isArray(activityResult) ? activityResult : [activityResult]; + expect(activityEvents.map((event) => event.type)).toEqual(["thread.activity-appended"]); }), ); diff --git a/apps/server/src/orchestration/decider.ts b/apps/server/src/orchestration/decider.ts index ad84090da7..1f9cc311ce 100644 --- a/apps/server/src/orchestration/decider.ts +++ b/apps/server/src/orchestration/decider.ts @@ -337,7 +337,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" payload: { threadId: command.threadId, settledAt, - updatedAt: occurredAt, + updatedAt: settledAt, }, }; } @@ -519,7 +519,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" createdAt: command.createdAt, }, }; - if (targetThread.settledOverride === null) { + if (targetThread.settledOverride !== "settled") { return [userMessageEvent, turnStartRequestedEvent]; } const unsettledEvent: Omit = { @@ -681,7 +681,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" // must not fight a user's explicit settle. const isSessionActivity = command.session.status === "starting" || command.session.status === "running"; - if (thread.settledOverride === null || !isSessionActivity) { + if (thread.settledOverride !== "settled" || !isSessionActivity) { return sessionSetEvent; } const unsettledEvent: Omit = { @@ -857,7 +857,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" const wakesSettledThread = command.activity.kind === "approval.requested" || command.activity.kind === "user-input.requested"; - if (thread.settledOverride === null || !wakesSettledThread) { + if (thread.settledOverride !== "settled" || !wakesSettledThread) { return activityAppendedEvent; } const unsettledEvent: Omit = { diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts index 5348aa67cb..6a1a2da2b0 100644 --- a/apps/web/src/components/Sidebar.logic.test.ts +++ b/apps/web/src/components/Sidebar.logic.test.ts @@ -592,17 +592,23 @@ describe("resolveSidebarV2Status", () => { ).toBe("working"); }); - it("reports failed only for stopped sessions with an error", () => { + it("reports failed only while the session status is error", () => { expect( resolveSidebarV2Status({ hasPendingApprovals: false, - session: { ...session, status: "stopped" as const, lastError: "boom" }, + session: { ...session, status: "error" as const, lastError: "boom" }, }), ).toBe("failed"); expect( resolveSidebarV2Status({ hasPendingApprovals: false, - session: { ...session, status: "stopped" as const }, + session: { ...session, status: "stopped" as const, lastError: "persisted" }, + }), + ).toBe("ready"); + expect( + resolveSidebarV2Status({ + hasPendingApprovals: false, + session: { ...session, status: "ready" as const, lastError: "persisted" }, }), ).toBe("ready"); }); @@ -617,12 +623,13 @@ describe("sortThreadsForSidebarV2", () => { id: string; hasPendingApprovals?: boolean; latestUserMessageAt: string; + updatedAt?: string; }) => ({ id: input.id, hasPendingApprovals: input.hasPendingApprovals ?? false, session: null, createdAt: "2026-03-09T10:00:00.000Z", - updatedAt: input.latestUserMessageAt, + updatedAt: input.updatedAt ?? input.latestUserMessageAt, latestUserMessageAt: input.latestUserMessageAt, }); @@ -632,12 +639,14 @@ describe("sortThreadsForSidebarV2", () => { sortable({ id: "approval-new", hasPendingApprovals: true, - latestUserMessageAt: "2026-03-09T11:00:00.000Z", + latestUserMessageAt: "2026-03-09T08:00:00.000Z", + updatedAt: "2026-03-09T11:00:00.000Z", }), sortable({ id: "approval-old", hasPendingApprovals: true, - latestUserMessageAt: "2026-03-09T09:00:00.000Z", + latestUserMessageAt: "2026-03-09T11:30:00.000Z", + updatedAt: "2026-03-09T09:00:00.000Z", }), sortable({ id: "stale", latestUserMessageAt: "2026-03-09T08:00:00.000Z" }), ]); diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index 40e9e89fbf..bce7c48be0 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -373,7 +373,7 @@ export function resolveSidebarV2Status(thread: SidebarV2StatusInput): SidebarV2S if (thread.session?.status === "running" || thread.session?.status === "starting") { return "working"; } - if (thread.session != null && thread.session.lastError !== null) { + if (thread.session?.status === "error") { return "failed"; } return "ready"; @@ -390,13 +390,16 @@ export function sortThreadsForSidebarV2< if (leftApproval !== rightApproval) { return leftApproval ? -1 : 1; } + // Approval activities update the shell's updatedAt in the projection + // pipeline, making it the best available request-time proxy. Oldest waits + // pin first. (The shell does not expose the approval request timestamp.) + if (leftApproval && rightApproval) { + return ( + Date.parse(left.updatedAt) - Date.parse(right.updatedAt) || left.id.localeCompare(right.id) + ); + } const byRecency = getThreadSortTimestamp(right, "updated_at") - getThreadSortTimestamp(left, "updated_at"); - // Approval wait time is "how long you've been the bottleneck", which is - // oldest-activity-first — the inverse of recency. - if (leftApproval && rightApproval) { - return -byRecency || left.id.localeCompare(right.id); - } return byRecency || left.id.localeCompare(right.id); }); } diff --git a/apps/web/src/components/SidebarV2.tsx b/apps/web/src/components/SidebarV2.tsx index c46cb39fc9..b00abee5b8 100644 --- a/apps/web/src/components/SidebarV2.tsx +++ b/apps/web/src/components/SidebarV2.tsx @@ -16,6 +16,7 @@ import { useMemo, useRef, useState, + type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent, } from "react"; import { useParams, useRouter } from "@tanstack/react-router"; @@ -47,6 +48,7 @@ import { useOpenAddProjectCommandPalette } from "../commandPaletteContext"; import { onOpenNewThreadPicker } from "../newThreadPickerBus"; import { Dialog, DialogHeader, DialogPopup, DialogTitle } from "./ui/dialog"; import { + resolveThreadActionProjectRef, startNewThreadFromContext, startNewThreadInProjectFromContext, } from "../lib/chatThreadActions"; @@ -55,7 +57,9 @@ import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments" import { useProjects, useThreadShells } from "../state/entities"; import { primaryServerKeybindingsAtom } from "../state/server"; import { vcsEnvironment } from "../state/vcs"; +import { threadEnvironment } from "../state/threads"; import { useEnvironmentQuery } from "../state/query"; +import { useAtomCommand } from "../state/use-atom-command"; import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes"; import { formatElapsedDurationLabel, formatRelativeTimeLabel } from "../timestampFormat"; import type { SidebarThreadSummary } from "../types"; @@ -128,8 +132,10 @@ function threadTimeLabel(thread: SidebarThreadSummary, status: SidebarV2Status): return formatElapsedDurationLabel(thread.latestTurn.startedAt); } if (status === "approval") { - const waitingSince = thread.latestTurn?.startedAt ?? thread.updatedAt; - return `waiting ${formatElapsedDurationLabel(waitingSince)}`; + // Approval activities bump shell.updatedAt in the projection pipeline. + // The shell has no dedicated request timestamp, so this is the closest + // accurate wait-start signal shared by the label and approval ordering. + return `waiting ${formatElapsedDurationLabel(thread.updatedAt)}`; } const timestamp = thread.latestUserMessageAt ?? thread.updatedAt; return formatRelativeTimeLabel(timestamp); @@ -152,17 +158,31 @@ const SidebarV2Row = memo(function SidebarV2Row(props: { projectCwd: string | null; providerEntryByInstanceId: ReadonlyMap; onThreadClick: (event: ReactMouseEvent, threadRef: ScopedThreadRef) => void; + onThreadActivate: (threadRef: ScopedThreadRef) => void; + onStartRename: (threadRef: ScopedThreadRef, title: string) => void; + onRenameTitleChange: (title: string) => void; + onCommitRename: (threadRef: ScopedThreadRef, title: string, originalTitle: string) => void; + onCancelRename: () => void; + isRenaming: boolean; + renamingTitle: string; onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void; onSettle: (threadRef: ScopedThreadRef) => void; onUnsettle: (threadRef: ScopedThreadRef) => void; onChangeRequestState: (threadKey: string, state: "open" | "closed" | "merged" | null) => void; }) { const { + isRenaming, onChangeRequestState, + onCancelRename, + onCommitRename, onContextMenu, + onRenameTitleChange, onSettle, + onStartRename, + onThreadActivate, onThreadClick, onUnsettle, + renamingTitle, thread, variant, variantAction, @@ -221,6 +241,50 @@ const SidebarV2Row = memo(function SidebarV2Row(props: { }, [onContextMenu, threadRef], ); + const handleKeyDown = useCallback( + (event: ReactKeyboardEvent) => { + if (event.target !== event.currentTarget) return; + if (event.key !== "Enter" && event.key !== " ") return; + event.preventDefault(); + onThreadActivate(threadRef); + }, + [onThreadActivate, threadRef], + ); + const handleDoubleClick = useCallback( + (event: ReactMouseEvent) => { + if (isRenaming || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { + return; + } + if ((event.target as HTMLElement).closest("button, a, input")) return; + event.preventDefault(); + onStartRename(threadRef, thread.title); + }, + [isRenaming, onStartRename, thread.title, threadRef], + ); + const renameCommittedRef = useRef(false); + useEffect(() => { + if (isRenaming) renameCommittedRef.current = false; + }, [isRenaming]); + const handleRenameKeyDown = useCallback( + (event: ReactKeyboardEvent) => { + event.stopPropagation(); + if (event.key === "Enter") { + event.preventDefault(); + renameCommittedRef.current = true; + onCommitRename(threadRef, renamingTitle, thread.title); + } else if (event.key === "Escape") { + event.preventDefault(); + renameCommittedRef.current = true; + onCancelRename(); + } + }, + [onCancelRename, onCommitRename, renamingTitle, thread.title, threadRef], + ); + const handleRenameBlur = useCallback(() => { + if (!renameCommittedRef.current) { + onCommitRename(threadRef, renamingTitle, thread.title); + } + }, [onCommitRename, renamingTitle, thread.title, threadRef]); const handleSettleClick = useCallback( (event: ReactMouseEvent) => { event.preventDefault(); @@ -261,6 +325,36 @@ const SidebarV2Row = memo(function SidebarV2Row(props: { /> ); + const title = isRenaming ? ( + onRenameTitleChange(event.target.value)} + onFocus={(event) => event.currentTarget.select()} + onKeyDown={handleRenameKeyDown} + onBlur={handleRenameBlur} + onClick={(event) => event.stopPropagation()} + onDoubleClick={(event) => event.stopPropagation()} + className="min-w-0 flex-1 rounded border border-border bg-background px-1 text-[13px] text-foreground outline-none focus:border-ring" + /> + ) : ( + + {thread.title} + + ); + const prBadge = prStatus && pr ? (