@devries-cameron20 / t3code-1 / commits / eef35b0262
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(clients): stop loading thread families when opening chats (#26762)

Yash Singh committed Oct 31, 2026 at 05:39 UTC eef35b0262f24e83ef09cd4d2a59b4baed1c2581
9 files changed +95 -60
apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+1 -7
@@ -80,7 +80,7 @@ import { useSelectedThreadWorktree } from "../../state/use-selected-thread-workt
80 import { useThreadComposerState } from "../../state/use-thread-composer-state";
81 import { resolveMergeBackTargetThreadId } from "@t3tools/client-runtime/state/thread-relationships";
82 import { resolveLatestMergeBackRun } from "@t3tools/client-runtime/state/thread-workflows";
83 -import { threadEnvironment, useThreadFamily } from "../../state/threads";
83 +import { threadEnvironment } from "../../state/threads";
84 import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/threads";
85 import { useProjects } from "../../state/entities";
86 import { projectThreadContentPresentation } from "./threadContentPresentation";
@@ -243,12 +243,6 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
243 const connectionsReady = useConnectionsReady();
244 const { connectionState } = useRemoteConnectionStatus();
245 const { selectedThread } = useThreadSelection();
246 - // Subagent rows, the open child's own row and its ancestors come from the family when the
247 - // shell leaves idle children out.
248 - useThreadFamily(
249 - selectedThread?.environmentId ?? null,
250 - selectedThread?.lineage.rootThreadId ?? null,
251 - );
246 const params = props.route.params ?? {};
247 const environmentIdRaw = firstRouteParam(params.environmentId);
248 const threadIdRaw = firstRouteParam(params.threadId);
apps/mobile/src/state/threads.ts
-13
@@ -11,7 +11,6 @@ import {
11 } from "@t3tools/client-runtime/state/threads";
12 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
13 import { AsyncResult, Atom } from "effect/reactivity";
14 -import { useEffect } from "react";
14
15 import { environmentCatalog } from "../connection/catalog";
16 import { connectionAtomRuntime } from "../connection/runtime";
@@ -45,18 +44,6 @@ export const environmentThreadShells = createEnvironmentThreadShellAtoms({
44 snapshotAtom: threadEnvironment.snapshotAtom,
45 });
46
48 -/** Keeps the subagent tree under `rootThreadId` in the thread list while the caller shows it. */
49 -export function useThreadFamily(
50 - environmentId: EnvironmentId | null,
51 - rootThreadId: ThreadId | null,
52 -): void {
53 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mounts the subagent tree under the root thread into the shared thread registry while the caller shows it
54 - useEffect(() => {
55 - if (environmentId === null || rootThreadId === null) return;
56 - return threadFamilies.mount(appAtomRegistry, environmentId, rootThreadId);
57 - }, [environmentId, rootThreadId]);
58 -}
59 -
47 // Long enough for the opened screen to subscribe; its subscription keeps the thread after this.
48 const OPENING_THREAD_HOLD_MS = 3_000;
49
apps/web/src/components/ChatView.tsx
+1 -9
@@ -234,7 +234,7 @@ import {
234 primaryServerKeybindingsAtom,
235 serverEnvironment,
236 } from "../state/server";
237 -import { threadEnvironment, useThreadFamily } from "../state/threads";
237 +import { threadEnvironment } from "../state/threads";
238 import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills";
239 import { vcsEnvironment } from "../state/vcs";
240 import {
@@ -483,14 +483,6 @@ export default function ChatView(props: ChatViewProps) {
483 });
484 const serverThreadProjection = useQuietThreadProjection(routeThreadDetailRef);
485 const serverProjection = serverThreadProjection?.projection ?? null;
486 - // Subagent rows, an open child's own row and its ancestors come from the family when the shell
487 - // leaves idle children out. Every source agrees on the root, so the key never flips.
488 - useThreadFamily(
489 - routeKind === "server" ? environmentId : null,
490 - serverThreadShell?.lineage.rootThreadId ??
491 - serverProjection?.thread.lineage.rootThreadId ??
492 - null,
493 - );
486 // Only the shell-less fallback needs these; with a shell, the shell carries them.
487 const fallbackDetailRef = serverThreadShell === null ? routeThreadDetailRef : null;
488 const fallbackUpdatedAt = useThreadUpdatedAt(fallbackDetailRef);
apps/web/src/components/chat/ThreadLineageWorkflowRow.tsx
+1 -7
@@ -54,7 +54,6 @@ function WorkflowMemberRow({
54 providers,
55 driver,
56 onOpen,
57 - isThreadAvailable,
57 }: {
58 member: RuntimeSubagent;
59 providerInstanceId: ProviderInstanceId;
@@ -62,10 +61,9 @@ function WorkflowMemberRow({
61 providers: ReadonlyArray<ServerProvider> | undefined;
62 driver: ProviderDriverKind | undefined;
63 onOpen: (threadId: string) => void;
65 - isThreadAvailable: (threadId: string) => boolean;
64 }) {
65 const threadId = member.childThreadId;
68 - const canOpen = threadId !== null && isThreadAvailable(threadId);
66 + const canOpen = threadId !== null;
67 return (
68 <li>
69 <Tooltip>
@@ -117,7 +115,6 @@ export function ThreadLineageWorkflowRow({
115 providers,
116 driver,
117 onOpenThread,
120 - isThreadAvailable,
118 onStop,
119 stopping,
120 stopDisabled,
@@ -129,7 +126,6 @@ export function ThreadLineageWorkflowRow({
126 readonly providers: ReadonlyArray<ServerProvider> | undefined;
127 readonly driver: ProviderDriverKind | undefined;
128 readonly onOpenThread: (threadId: string) => void;
132 - readonly isThreadAvailable: (threadId: string) => boolean;
129 readonly onStop?: (() => void) | undefined;
130 readonly stopping: boolean;
131 readonly stopDisabled: boolean;
@@ -227,7 +223,6 @@ export function ThreadLineageWorkflowRow({
223 providers={providers}
224 driver={driver}
225 onOpen={onOpenThread}
230 - isThreadAvailable={isThreadAvailable}
226 />
227 ))}
228 </ul>
@@ -244,7 +239,6 @@ export function ThreadLineageWorkflowRow({
239 providers={providers}
240 driver={driver}
241 onOpen={onOpenThread}
247 - isThreadAvailable={isThreadAvailable}
242 />
243 ))}
244 {phases.length === 0 && group.unphasedMembers.length === 0 ? (
apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx
+50 -1
@@ -1,4 +1,4 @@
1 -import { EnvironmentId, ThreadId } from "@t3tools/contracts";
1 +import { EnvironmentId, NodeId, ThreadId } from "@t3tools/contracts";
2 import * as Cause from "effect/Cause";
3 import { AsyncResult } from "effect/reactivity";
4 import { expect, it, vi } from "vite-plus/test";
@@ -34,6 +34,7 @@ vi.mock(import("../../state/use-atom-command"), () => ({
34 }));
35
36 import { render } from "../../../test/render";
37 +import { makeThreadProjectionFixture } from "../../test-fixtures";
38 import { ToastProvider } from "../ui/toast";
39 import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
40
@@ -134,3 +135,51 @@ it.each([
135 await expect.element(screen.getByRole("button", { name: "More thread actions" })).toBeEnabled();
136 }
137 });
138 +
139 +it("opens an idle child from Lineage when its shell has not been loaded", async () => {
140 + setup();
141 + const projection = makeThreadProjectionFixture();
142 + const childId = ThreadId.make("omitted-child");
143 + const environmentId = EnvironmentId.make("local");
144 + state.projection = {
145 + ...projection,
146 + subagents: [
147 + {
148 + id: NodeId.make("agent"),
149 + threadId: projection.thread.id,
150 + runId: null,
151 + parentNodeId: NodeId.make("parent"),
152 + origin: "app_owned",
153 + createdBy: "agent",
154 + driver: "codex",
155 + providerInstanceId: projection.thread.providerInstanceId,
156 + providerThreadId: null,
157 + childThreadId: childId,
158 + nativeTaskRef: null,
159 + prompt: "Inspect the change",
160 + title: "Idle child",
161 + model: null,
162 + status: "completed",
163 + result: null,
164 + startedAt: null,
165 + completedAt: projection.thread.updatedAt,
166 + updatedAt: projection.thread.updatedAt,
167 + },
168 + ],
169 + };
170 + await using screen = await render(
171 + <ThreadRelationshipsPanel
172 + environmentId={environmentId}
173 + threadId={projection.thread.id}
174 + showLineage
175 + showSideChats
176 + />,
177 + );
178 + await screen.getByRole("button", { name: /Previous agents/ }).click();
179 + const child = screen.getByRole("button", { name: /Idle child/ });
180 + await expect.element(child).toBeEnabled();
181 + await child.click();
182 + await vi.waitFor(() =>
183 + expect(screen.router?.state.location.pathname).toBe("/local/omitted-child"),
184 + );
185 +});
apps/web/src/components/chat/ThreadRelationshipsControl.tsx
+2 -8
@@ -500,6 +500,7 @@ export function ThreadRelationshipsPanel(props: {
500 return null;
501 }
502
503 + // Idle children can be omitted from the shell; opening one loads its own detail.
504 const openThread = (threadId: ThreadId) => {
505 if (openSideChatTab(ref, graph.nodes.get(threadId)?.thread ?? null)) return;
506 void navigate({
@@ -643,9 +644,7 @@ export function ThreadRelationshipsPanel(props: {
644 ? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0"
645 : "";
646 const project = projects.find((project) => project.id === node?.thread?.projectId);
646 - const relationshipHint = node?.missing
647 - ? "This related thread is unavailable"
648 - : `Open ${relationship.toLowerCase()} in this chat`;
647 + const relationshipHint = `Open ${relationship.toLowerCase()} in this chat`;
648 const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup;
649 const relationshipTooltip = agent ? (
650 <SubagentTooltipContent
@@ -713,7 +712,6 @@ export function ThreadRelationshipsPanel(props: {
712 size="sm"
713 variant="ghost"
714 part={workflowGroup ? "primary" : "row"}
716 - disabled={node?.missing === true}
715 onClick={() => openThread(threadId)}
716 />
717 }
@@ -733,9 +731,6 @@ export function ThreadRelationshipsPanel(props: {
731 providers={providers}
732 driver={providerDriver}
733 onOpenThread={(memberThreadId) => openThread(memberThreadId as ThreadId)}
736 - isThreadAvailable={(memberThreadId) =>
737 - graph.nodes.get(memberThreadId as ThreadId)?.missing === false
738 - }
734 onStop={canStopWorkflow ? () => void stopWorkflow(agent.id) : undefined}
735 stopping={stoppingId === agent.id}
736 stopDisabled={stoppingId !== null}
@@ -756,7 +751,6 @@ export function ThreadRelationshipsPanel(props: {
751 variant="ghost"
752 part="primary"
753 aria-label={`${threadTitle} ${threadRelationshipStatusLabel(rowStatus)}`}
759 - disabled={node?.missing === true}
754 onClick={() => openThread(threadId)}
755 />
756 }
apps/web/src/state/threads.ts
-14
@@ -14,11 +14,9 @@ import {
14 import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts";
15 import * as Option from "effect/Option";
16 import { AsyncResult, Atom } from "effect/reactivity";
17 -import { useEffect } from "react";
17
18 import { environmentCatalog } from "../connection/catalog";
19 import { connectionAtomRuntime } from "../connection/runtime";
21 -import { appAtomRegistry } from "../rpc/atomRegistry";
20 import { environmentShell } from "./shell";
21
22 export const threadFamilies = createThreadFamilyAtoms(
@@ -42,18 +40,6 @@ export const environmentThreadShells = createEnvironmentThreadShellAtoms({
40 snapshotAtom: threadEnvironment.snapshotAtom,
41 });
42
45 -/** Keeps the subagent tree under `rootThreadId` in the thread list while the caller shows it. */
46 -export function useThreadFamily(
47 - environmentId: EnvironmentId | null,
48 - rootThreadId: ThreadId | null,
49 -): void {
50 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mounts the subagent tree into the thread family registry while the caller shows it
51 - useEffect(() => {
52 - if (environmentId === null || rootThreadId === null) return;
53 - return threadFamilies.mount(appAtomRegistry, environmentId, rootThreadId);
54 - }, [environmentId, rootThreadId]);
55 -}
56 -
43 const EMPTY_THREAD_STATE_ATOM = Atom.make(AsyncResult.success(EMPTY_ENVIRONMENT_THREAD_STATE)).pipe(
44 Atom.withLabel("web-environment-thread:empty"),
45 );
packages/client-runtime/src/state/threadRelationships.test.ts
+34
@@ -59,6 +59,40 @@ describe("thread relationships", () => {
59 ).toBeNull();
60 });
61
62 + it.each(["fork", "subagent"] as const)(
63 + "keeps the parent edge of an opened %s omitted from the shell",
64 + (relationshipToParent) => {
65 + const parent = ThreadId.make("parent");
66 + const child = ThreadId.make("omitted-child");
67 + const projection = {
68 + thread: {
69 + id: child,
70 + forkedFrom:
71 + relationshipToParent === "fork"
72 + ? { type: "run", threadId: parent, runId: "source-run" }
73 + : null,
74 + lineage: { rootThreadId: parent, parentThreadId: parent, relationshipToParent },
75 + },
76 + subagents: [],
77 + contextTransfers: [],
78 + } as never;
79 + const graph = deriveThreadRelationshipGraph({ threads: [], projection });
80 + expect(immediateThreadRelationships(graph, child)).toEqual([
81 + expect.objectContaining({
82 + threadId: parent,
83 + edge: expect.objectContaining({
84 + sourceThreadId: parent,
85 + targetThreadId: child,
86 + kind: relationshipToParent,
87 + }),
88 + }),
89 + ]);
90 + expect(resolveMergeBackTargetThreadId(projection)).toBe(
91 + relationshipToParent === "fork" ? parent : null,
92 + );
93 + },
94 + );
95 +
96 it("keeps an older activity run visible over a newer cancelled run", () => {
97 const parent = ThreadId.make("thread-parent");
98 const child = ThreadId.make("thread-child");
packages/client-runtime/src/state/threadRelationships.ts
+6 -1
@@ -80,7 +80,12 @@ export function deriveThreadRelationshipGraph(input: {
80 );
81 };
82
83 - for (const thread of threads) {
83 + const selectedThread = input.projection?.thread;
84 + const lineageThreads =
85 + selectedThread !== undefined && !threadsById.has(selectedThread.id)
86 + ? [...threads, { ...selectedThread, activityRunStatus: null, status: null }]
87 + : threads;
88 + for (const thread of lineageThreads) {
89 const parentThreadId =
90 thread.forkedFrom?.type === "run"
91 ? thread.forkedFrom.threadId