The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 09:45 UTC
fix(web): an open delegated task selects its parent's sidebar row (#37500)
Julius Marminge committed
Nov 15, 2026 at 21:43 UTC
45dedf29558eb129d2cf86cbf93a3f484ecf3abe
8 files changed
+140
-86
apps/mobile/src/features/home/HomeScreen.tsx
+3
-1
@@ -62,6 +62,7 @@ import { useThreadSearch } from "../../state/queries";
62
import { requestThreadMessageJump } from "../threads/threadMessageJump";
63
import { useThreadListSearchMatches } from "../threads/useThreadListSearchMatches";
64
import { useThreadListV2 } from "../threads/useThreadListV2";
65
+import { useSidebarRowThreadKey } from "../threads/useSidebarRowThreadKey";
66
import { useThreadListNow } from "../threads/use-thread-list-now";
67
import { useSearchScrollRestoration } from "../layout/workspace/useSearchScrollRestoration";
68
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
@@ -203,7 +204,8 @@ export function HomeScreen(props: HomeScreenProps) {
204
);
205
const columnMetrics = useNativeColumnLayoutMetrics();
206
const activeNewTask = useActiveNewTask();
206
- const selectedThreadKey = activeNewTask ? null : (primaryColumn?.selectedThreadKey ?? null);
207
+ const sidebarRowThreadKey = useSidebarRowThreadKey(primaryColumn?.selectedThreadKey ?? null);
208
+ const selectedThreadKey = activeNewTask ? null : sidebarRowThreadKey;
209
const fullSwipeWidth = primaryColumn && columnMetrics ? columnMetrics.width - 20 : undefined;
210
const queuedThreadKeys = useQueuedThreadKeys();
211
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+6
-4
@@ -40,6 +40,7 @@ import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
40
import { useWorkspaceState } from "../../state/workspace";
41
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
42
import { useThreadListV2 } from "./useThreadListV2";
43
+import { useSidebarRowThreadKey } from "./useSidebarRowThreadKey";
44
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
45
import { requestThreadMessageJump } from "./threadMessageJump";
46
import { useThreadListSearchMatches } from "./useThreadListSearchMatches";
@@ -127,6 +128,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
128
const { fabClearance, fabSize } = useAndroidControlSizing();
129
const projects = useProjects();
130
const threads = useAtomValue(steadyNavigationThreadShellsAtom);
131
+ const selectedThreadKey = useSidebarRowThreadKey(props.selectedThreadKey);
132
const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
133
const { savedConnectionsById } = useSavedRemoteConnections();
134
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
@@ -288,7 +290,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
290
workingShelfExpanded,
291
snoozedShelfExpanded,
292
settledShelfExpanded,
291
- selectedThreadKey: props.selectedThreadKey ?? null,
293
+ selectedThreadKey,
294
});
295
const listItems: readonly SidebarListItem[] =
296
settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0
@@ -351,7 +353,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
353
// Recycle equality needs project/search data for titles and favicons; keep the minute clock on items to limit updates.
354
const listExtraData = {
355
activeNewTask,
354
- selectedThreadKey: props.selectedThreadKey ?? "",
356
+ selectedThreadKey: selectedThreadKey ?? "",
357
projectByKey,
358
projectTitleByProjectKey,
359
savedConnectionsById,
@@ -385,7 +387,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
387
scopedThreadKey(
388
item.pendingTask.environmentId,
389
item.pendingTask.message.threadId,
388
- ) === props.selectedThreadKey)
390
+ ) === selectedThreadKey)
391
}
392
project={projectByKey.get(pendingScopeKey) ?? null}
393
environmentLabel={
@@ -446,7 +448,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
448
pane="sidebar"
449
selected={
450
!activeNewTask &&
449
- scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
451
+ scopedThreadKey(thread.environmentId, thread.id) === selectedThreadKey
452
}
453
fullSwipeWidth={props.width - 20}
454
onSelectThread={handleSelectThread}
apps/mobile/src/features/threads/useSidebarRowThreadKey.ts
new
+15
@@ -0,0 +1,15 @@
1
+import { useAtomValue } from "@effect/atom-react";
2
+import { parseScopedThreadKey } from "@t3tools/client-runtime/environment";
3
+import { resolveListedAncestorThreadRef } from "@t3tools/client-runtime/state/threads";
4
+
5
+import { scopedThreadKey } from "../../lib/scopedEntities";
6
+import { environmentThreadShells } from "../../state/threads";
7
+
8
+/** An open subagent, side chat or delegated task has no row; its listed ancestor's row is selected. */
9
+export function useSidebarRowThreadKey(openThreadKey: string | null): string | null {
10
+ const threads = useAtomValue(environmentThreadShells.quietThreadShellsAtom);
11
+ const openThreadRef = openThreadKey === null ? null : parseScopedThreadKey(openThreadKey);
12
+ if (openThreadRef === null) return openThreadKey;
13
+ const rowRef = resolveListedAncestorThreadRef(openThreadRef, threads);
14
+ return scopedThreadKey(rowRef.environmentId, rowRef.threadId);
15
+}
apps/web/src/components/Sidebar.logic.test.ts
-43
@@ -11,7 +11,6 @@ import {
11
deleteSelectedThreadEntries,
12
getFallbackThreadIdAfterDelete,
13
hasUnseenCompletion,
14
- resolveSidebarRowThreadId,
14
orderItemsByPreferredIds,
15
pinOrderKeyBetween,
16
resolveSidebarSweepKeys,
@@ -138,48 +137,6 @@ describe("deleteSelectedThreadEntries", () => {
137
});
138
});
139
141
-describe("sidebar thread lineage helpers", () => {
142
- it("maps an open subagent to its nearest visible ancestor's sidebar row", () => {
143
- const environmentId = EnvironmentId.make("environment-row");
144
- const otherEnvironmentId = EnvironmentId.make("environment-other");
145
- const subagentOf = (id: string, parentId: ThreadId, environment = environmentId) =>
146
- makeThreadFixture({
147
- id: ThreadId.make(id),
148
- environmentId: environment,
149
- lineage: {
150
- rootThreadId: parentId,
151
- parentThreadId: parentId,
152
- relationshipToParent: "subagent",
153
- },
154
- });
155
- const root = makeThreadFixture({ id: ThreadId.make("thread-root"), environmentId });
156
- const fork = makeThreadFixture({
157
- id: ThreadId.make("thread-fork"),
158
- environmentId,
159
- lineage: {
160
- rootThreadId: root.id,
161
- parentThreadId: root.id,
162
- relationshipToParent: "fork",
163
- },
164
- });
165
- const child = subagentOf("thread-child", root.id);
166
- const grandchild = subagentOf("thread-grandchild", child.id);
167
- const forkChild = subagentOf("thread-fork-child", fork.id);
168
- const orphan = subagentOf("thread-orphan", ThreadId.make("thread-missing"));
169
- const elsewhere = subagentOf("thread-elsewhere", root.id, otherEnvironmentId);
170
- const threads = [root, fork, child, grandchild, forkChild, orphan, elsewhere];
171
-
172
- expect(resolveSidebarRowThreadId(child.id, environmentId, threads)).toBe(root.id);
173
- expect(resolveSidebarRowThreadId(grandchild.id, environmentId, threads)).toBe(root.id);
174
- expect(resolveSidebarRowThreadId(forkChild.id, environmentId, threads)).toBe(fork.id);
175
- expect(resolveSidebarRowThreadId(elsewhere.id, otherEnvironmentId, threads)).toBe(elsewhere.id);
176
- expect(resolveSidebarRowThreadId(orphan.id, environmentId, threads)).toBe(orphan.id);
177
- const loopA = subagentOf("thread-loop-a", ThreadId.make("thread-loop-b"));
178
- const loopB = subagentOf("thread-loop-b", loopA.id);
179
- expect(resolveSidebarRowThreadId(loopA.id, environmentId, [loopA, loopB])).toBe(loopA.id);
180
- });
181
-});
182
-
140
function makeLatestRun(overrides?: {
141
completedAt?: string | null;
142
startedAt?: string | null;
apps/web/src/components/Sidebar.logic.ts
-25
@@ -17,7 +17,6 @@ import {
17
} from "@t3tools/client-runtime/state/thread-search";
18
import { foldSearchQuery, rankSearchItems, scoreThreadSearch } from "@t3tools/shared/paletteSearch";
19
import {
20
- isListedThreadLineage,
20
type ContextMenuItem,
21
type EnvironmentId,
22
type ResolvedKeybindingsConfig,
@@ -582,30 +581,6 @@ export async function deleteSelectedThreadEntries<
581
return { deletedThreadKeys, firstFailure };
582
}
583
585
-function isSidebarHiddenThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
586
- return !isListedThreadLineage(thread.lineage);
587
-}
588
-
589
-// Subagent and side-chat threads have no sidebar row, so an open one is represented by
590
-// its nearest listed ancestor. A broken chain (missing parent, cycle,
591
-// other environment) resolves to the thread itself, which then matches no row.
592
-export function resolveSidebarRowThreadId(
593
- threadId: ThreadId,
594
- environmentId: EnvironmentId,
595
- threads: readonly Pick<SidebarThreadSummary, "id" | "environmentId" | "lineage">[],
596
-): ThreadId {
597
- const findThread = (id: ThreadId) =>
598
- threads.find((thread) => thread.id === id && thread.environmentId === environmentId);
599
- const visited = new Set<ThreadId>();
600
- let thread = findThread(threadId);
601
- while (thread !== undefined && isSidebarHiddenThread(thread)) {
602
- if (thread.lineage.parentThreadId === null || visited.has(thread.id)) return threadId;
603
- visited.add(thread.id);
604
- thread = findThread(thread.lineage.parentThreadId);
605
- }
606
- return thread?.id ?? threadId;
607
-}
608
-
584
/**
585
* `delegatedUnderParent` holds the tasks linked environments run for a thread
586
* the sidebar lists, by thread key; they show under that thread, as subagents do.
apps/web/src/components/Sidebar.tsx
+5
-12
@@ -59,7 +59,10 @@ import {
59
type ScopedThreadRef,
60
type ThreadId,
61
} from "@t3tools/contracts";
62
-import type { OlderSettledScope } from "@t3tools/client-runtime/state/threads";
62
+import {
63
+ resolveListedAncestorThreadRef,
64
+ type OlderSettledScope,
65
+} from "@t3tools/client-runtime/state/threads";
66
67
import {
68
CheckIcon,
@@ -208,7 +211,6 @@ import {
211
useThreadJumpHintsVisible,
212
type SidebarListItem,
213
type SidebarSection,
211
- resolveSidebarRowThreadId,
214
} from "./Sidebar.logic";
215
import {
216
createSidebarCollisionDetection,
@@ -1108,16 +1110,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1110
const routeRowThreadKey =
1111
routeThreadRef === null
1112
? null
1111
- : scopedThreadKey(
1112
- scopeThreadRef(
1113
- routeThreadRef.environmentId,
1114
- resolveSidebarRowThreadId(
1115
- routeThreadRef.threadId,
1116
- routeThreadRef.environmentId,
1117
- threads,
1118
- ),
1119
- ),
1120
- );
1113
+ : scopedThreadKey(resolveListedAncestorThreadRef(routeThreadRef, threads));
1114
const isSearchingThreads = threadSearchQuery.trim().length > 0;
1115
1116
// History, the palette and links can open a thread the scope hides or the list
packages/client-runtime/src/state/threadShell.test.ts
+71
-1
@@ -16,7 +16,11 @@ import { PrimaryConnectionTarget } from "../connection/model.ts";
16
import { v2Now, v2ShellSnapshot, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
17
import { applyShellStreamEvent } from "./shellReducer.ts";
18
import { isThreadWorking } from "./threadInbox.ts";
19
-import { childThreadInputsTitle, createEnvironmentThreadShellAtoms } from "./threadShell.ts";
19
+import {
20
+ childThreadInputsTitle,
21
+ createEnvironmentThreadShellAtoms,
22
+ resolveListedAncestorThreadRef,
23
+} from "./threadShell.ts";
24
25
const environmentId = EnvironmentId.make("environment-v2");
26
const remoteEnvironmentId = EnvironmentId.make("remote-environment-v2");
@@ -679,3 +683,69 @@ describe("v2 thread shell lists", () => {
683
}
684
});
685
});
686
+
687
+describe("resolveListedAncestorThreadRef", () => {
688
+ type Thread = Parameters<typeof resolveListedAncestorThreadRef>[1][number];
689
+ const otherEnvironmentId = EnvironmentId.make("environment-other");
690
+ const ref = (environment: EnvironmentId, threadId: ThreadId) => ({
691
+ environmentId: environment,
692
+ threadId,
693
+ });
694
+ const listed = (
695
+ id: string,
696
+ environment = environmentId,
697
+ overrides?: Partial<Thread>,
698
+ ): Thread => ({
699
+ id: ThreadId.make(id),
700
+ environmentId: environment,
701
+ lineage: { rootThreadId: ThreadId.make(id), parentThreadId: null, relationshipToParent: null },
702
+ archivedAt: null,
703
+ delegatedFrom: null,
704
+ ...overrides,
705
+ });
706
+ const subagentOf = (id: string, parentId: ThreadId, environment = environmentId) =>
707
+ listed(id, environment, {
708
+ lineage: {
709
+ rootThreadId: parentId,
710
+ parentThreadId: parentId,
711
+ relationshipToParent: "subagent",
712
+ },
713
+ });
714
+ const rowOf = (threadId: ThreadId, environment: EnvironmentId, threads: readonly Thread[]) =>
715
+ resolveListedAncestorThreadRef(ref(environment, threadId), threads);
716
+
717
+ it("maps an open subagent to its nearest listed ancestor", () => {
718
+ const root = listed("thread-root");
719
+ const fork = listed("thread-fork", environmentId, {
720
+ lineage: { rootThreadId: root.id, parentThreadId: root.id, relationshipToParent: "fork" },
721
+ });
722
+ const child = subagentOf("thread-child", root.id);
723
+ const grandchild = subagentOf("thread-grandchild", child.id);
724
+ const forkChild = subagentOf("thread-fork-child", fork.id);
725
+ const orphan = subagentOf("thread-orphan", ThreadId.make("thread-missing"));
726
+ const elsewhere = subagentOf("thread-elsewhere", root.id, otherEnvironmentId);
727
+ const threads = [root, fork, child, grandchild, forkChild, orphan, elsewhere];
728
+
729
+ expect(rowOf(child.id, environmentId, threads)).toEqual(ref(environmentId, root.id));
730
+ expect(rowOf(grandchild.id, environmentId, threads)).toEqual(ref(environmentId, root.id));
731
+ expect(rowOf(forkChild.id, environmentId, threads)).toEqual(ref(environmentId, fork.id));
732
+ expect(rowOf(elsewhere.id, otherEnvironmentId, threads)).toEqual(
733
+ ref(otherEnvironmentId, elsewhere.id),
734
+ );
735
+ expect(rowOf(orphan.id, environmentId, threads)).toEqual(ref(environmentId, orphan.id));
736
+ const loopA = subagentOf("thread-loop-a", ThreadId.make("thread-loop-b"));
737
+ const loopB = subagentOf("thread-loop-b", loopA.id);
738
+ expect(rowOf(loopA.id, environmentId, [loopA, loopB])).toEqual(ref(environmentId, loopA.id));
739
+ });
740
+
741
+ it("maps an open task a linked environment delegated to its listed parent", () => {
742
+ const parent = listed("thread-parent", remoteEnvironmentId);
743
+ const task = listed("thread-task", environmentId, {
744
+ delegatedFrom: { environmentId: remoteEnvironmentId, threadId: parent.id, title: "Parent" },
745
+ });
746
+
747
+ expect(rowOf(task.id, environmentId, [parent, task])).toEqual(
748
+ ref(remoteEnvironmentId, parent.id),
749
+ );
750
+ });
751
+});
packages/client-runtime/src/state/threadShell.ts
+40
@@ -69,6 +69,46 @@ export function isShownUnderParent(
69
return !isListedThreadLineage(lineage) || delegatedUnderParent.has(threadKey(ref));
70
}
71
72
+// Subagents, side chats and tasks delegated from a listed parent have no list row,
73
+// so an open one is represented by its nearest listed ancestor. A broken chain
74
+// (missing or archived parent, cycle) resolves to the thread itself, which then matches no row.
75
+export function resolveListedAncestorThreadRef(
76
+ ref: ScopedThreadRef,
77
+ threads: readonly Pick<
78
+ EnvironmentThreadShell,
79
+ "id" | "environmentId" | "lineage" | "delegatedFrom" | "archivedAt"
80
+ >[],
81
+): ScopedThreadRef {
82
+ const findThread = (target: ScopedThreadRef) =>
83
+ threads.find(
84
+ (thread) => thread.id === target.threadId && thread.environmentId === target.environmentId,
85
+ );
86
+ const visited = new Set<string>();
87
+ let current = ref;
88
+ let thread = findThread(current);
89
+ while (thread !== undefined) {
90
+ let parent: ScopedThreadRef;
91
+ if (!isListedThreadLineage(thread.lineage)) {
92
+ if (thread.lineage.parentThreadId === null) return ref;
93
+ parent = { environmentId: thread.environmentId, threadId: thread.lineage.parentThreadId };
94
+ } else if (thread.delegatedFrom != null) {
95
+ parent = {
96
+ environmentId: thread.delegatedFrom.environmentId,
97
+ threadId: thread.delegatedFrom.threadId,
98
+ };
99
+ // Mirrors delegatedUnderParent: a task whose parent is not listed keeps its own row.
100
+ if (findThread(parent)?.archivedAt !== null) return current;
101
+ } else {
102
+ return current;
103
+ }
104
+ if (visited.has(threadKey(current))) return ref;
105
+ visited.add(threadKey(current));
106
+ current = parent;
107
+ thread = findThread(current);
108
+ }
109
+ return ref;
110
+}
111
+
112
/** Provider-native
113
subagents ask on their parent, so they are skipped. */
114
function subagentRequest(thread: OrchestrationV2ThreadShell): PendingSubagentRequest | null {