From d44017574419f44a25a12529eeeb9f4f219217d7 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Wed, 28 Oct 2026 20:11:17 -0500 Subject: [PATCH 1/3] fix(clients): stop loading thread families when opening chats --- .../src/features/threads/ThreadRouteScreen.tsx | 8 +------- apps/mobile/src/state/threads.ts | 13 ------------- apps/web/src/components/ChatView.tsx | 10 +--------- apps/web/src/state/threads.ts | 14 -------------- 4 files changed, 2 insertions(+), 43 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx index 737e1aff90ada..a7a10a8675122 100644 --- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx @@ -80,7 +80,7 @@ import { useSelectedThreadWorktree } from "../../state/use-selected-thread-workt import { useThreadComposerState } from "../../state/use-thread-composer-state"; import { resolveMergeBackTargetThreadId } from "@t3tools/client-runtime/state/thread-relationships"; import { resolveLatestMergeBackRun } from "@t3tools/client-runtime/state/thread-workflows"; -import { threadEnvironment, useThreadFamily } from "../../state/threads"; +import { threadEnvironment } from "../../state/threads"; import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/threads"; import { useProjects } from "../../state/entities"; import { projectThreadContentPresentation } from "./threadContentPresentation"; @@ -243,12 +243,6 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) { const connectionsReady = useConnectionsReady(); const { connectionState } = useRemoteConnectionStatus(); const { selectedThread } = useThreadSelection(); - // Subagent rows, the open child's own row and its ancestors come from the family when the - // shell leaves idle children out. - useThreadFamily( - selectedThread?.environmentId ?? null, - selectedThread?.lineage.rootThreadId ?? null, - ); const params = props.route.params ?? {}; const environmentIdRaw = firstRouteParam(params.environmentId); const threadIdRaw = firstRouteParam(params.threadId); diff --git a/apps/mobile/src/state/threads.ts b/apps/mobile/src/state/threads.ts index 4cb0f92b4ee83..6ba5c635685a3 100644 --- a/apps/mobile/src/state/threads.ts +++ b/apps/mobile/src/state/threads.ts @@ -11,7 +11,6 @@ import { } from "@t3tools/client-runtime/state/threads"; import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; import { AsyncResult, Atom } from "effect/reactivity"; -import { useEffect } from "react"; import { environmentCatalog } from "../connection/catalog"; import { connectionAtomRuntime } from "../connection/runtime"; @@ -45,18 +44,6 @@ export const environmentThreadShells = createEnvironmentThreadShellAtoms({ snapshotAtom: threadEnvironment.snapshotAtom, }); -/** Keeps the subagent tree under `rootThreadId` in the thread list while the caller shows it. */ -export function useThreadFamily( - environmentId: EnvironmentId | null, - rootThreadId: ThreadId | null, -): void { - // 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 - useEffect(() => { - if (environmentId === null || rootThreadId === null) return; - return threadFamilies.mount(appAtomRegistry, environmentId, rootThreadId); - }, [environmentId, rootThreadId]); -} - // Long enough for the opened screen to subscribe; its subscription keeps the thread after this. const OPENING_THREAD_HOLD_MS = 3_000; diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 253cc1ea2e84b..ec98a90717c34 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -229,7 +229,7 @@ import { primaryServerKeybindingsAtom, serverEnvironment, } from "../state/server"; -import { threadEnvironment, useThreadFamily } from "../state/threads"; +import { threadEnvironment } from "../state/threads"; import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills"; import { vcsEnvironment } from "../state/vcs"; import { @@ -469,14 +469,6 @@ export default function ChatView(props: ChatViewProps) { }); const serverThreadProjection = useQuietThreadProjection(routeThreadDetailRef); const serverProjection = serverThreadProjection?.projection ?? null; - // Subagent rows, an open child's own row and its ancestors come from the family when the shell - // leaves idle children out. Every source agrees on the root, so the key never flips. - useThreadFamily( - routeKind === "server" ? environmentId : null, - serverThreadShell?.lineage.rootThreadId ?? - serverProjection?.thread.lineage.rootThreadId ?? - null, - ); // Only the shell-less fallback needs these; with a shell, the shell carries them. const fallbackDetailRef = serverThreadShell === null ? routeThreadDetailRef : null; const fallbackUpdatedAt = useThreadUpdatedAt(fallbackDetailRef); diff --git a/apps/web/src/state/threads.ts b/apps/web/src/state/threads.ts index 07fffa97cfbe0..c7919d658ccf6 100644 --- a/apps/web/src/state/threads.ts +++ b/apps/web/src/state/threads.ts @@ -14,11 +14,9 @@ import { import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts"; import * as Option from "effect/Option"; import { AsyncResult, Atom } from "effect/reactivity"; -import { useEffect } from "react"; import { environmentCatalog } from "../connection/catalog"; import { connectionAtomRuntime } from "../connection/runtime"; -import { appAtomRegistry } from "../rpc/atomRegistry"; import { environmentShell } from "./shell"; export const threadFamilies = createThreadFamilyAtoms( @@ -42,18 +40,6 @@ export const environmentThreadShells = createEnvironmentThreadShellAtoms({ snapshotAtom: threadEnvironment.snapshotAtom, }); -/** Keeps the subagent tree under `rootThreadId` in the thread list while the caller shows it. */ -export function useThreadFamily( - environmentId: EnvironmentId | null, - rootThreadId: ThreadId | null, -): void { - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mounts the subagent tree into the thread family registry while the caller shows it - useEffect(() => { - if (environmentId === null || rootThreadId === null) return; - return threadFamilies.mount(appAtomRegistry, environmentId, rootThreadId); - }, [environmentId, rootThreadId]); -} - const EMPTY_THREAD_STATE_ATOM = Atom.make(AsyncResult.success(EMPTY_ENVIRONMENT_THREAD_STATE)).pipe( Atom.withLabel("web-environment-thread:empty"), ); From 571d9e5a18945d4535867da0c98c9194ccb23373 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Thu, 29 Oct 2026 14:42:34 -0500 Subject: [PATCH 2/3] fix(web): keep omitted Lineage children navigable --- .../chat/ThreadLineageWorkflowRow.tsx | 8 +- ...hreadRelationshipsControl.browser.test.tsx | 78 +++++++++++++++++++ .../chat/ThreadRelationshipsControl.tsx | 10 +-- 3 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx diff --git a/apps/web/src/components/chat/ThreadLineageWorkflowRow.tsx b/apps/web/src/components/chat/ThreadLineageWorkflowRow.tsx index f1df96dd92133..ae13f519e02fd 100644 --- a/apps/web/src/components/chat/ThreadLineageWorkflowRow.tsx +++ b/apps/web/src/components/chat/ThreadLineageWorkflowRow.tsx @@ -54,7 +54,6 @@ function WorkflowMemberRow({ providers, driver, onOpen, - isThreadAvailable, }: { member: RuntimeSubagent; providerInstanceId: ProviderInstanceId; @@ -62,10 +61,9 @@ function WorkflowMemberRow({ providers: ReadonlyArray | undefined; driver: ProviderDriverKind | undefined; onOpen: (threadId: string) => void; - isThreadAvailable: (threadId: string) => boolean; }) { const threadId = member.childThreadId; - const canOpen = threadId !== null && isThreadAvailable(threadId); + const canOpen = threadId !== null; return (
  • @@ -117,7 +115,6 @@ export function ThreadLineageWorkflowRow({ providers, driver, onOpenThread, - isThreadAvailable, onStop, stopping, stopDisabled, @@ -129,7 +126,6 @@ export function ThreadLineageWorkflowRow({ readonly providers: ReadonlyArray | undefined; readonly driver: ProviderDriverKind | undefined; readonly onOpenThread: (threadId: string) => void; - readonly isThreadAvailable: (threadId: string) => boolean; readonly onStop?: (() => void) | undefined; readonly stopping: boolean; readonly stopDisabled: boolean; @@ -227,7 +223,6 @@ export function ThreadLineageWorkflowRow({ providers={providers} driver={driver} onOpen={onOpenThread} - isThreadAvailable={isThreadAvailable} /> ))} @@ -244,7 +239,6 @@ export function ThreadLineageWorkflowRow({ providers={providers} driver={driver} onOpen={onOpenThread} - isThreadAvailable={isThreadAvailable} /> ))} {phases.length === 0 && group.unphasedMembers.length === 0 ? ( diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx new file mode 100644 index 0000000000000..91b7ea49c1c79 --- /dev/null +++ b/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx @@ -0,0 +1,78 @@ +import { EnvironmentId, NodeId, ThreadId } from "@t3tools/contracts"; +import { expect, it, vi } from "vite-plus/test"; +import { Atom } from "effect/reactivity"; +import { makeThreadProjectionFixture } from "../../test-fixtures"; +import { render } from "../../../test/render"; + +const state = vi.hoisted(() => ({ projection: null as unknown })); + +vi.mock(import("../../state/entities"), () => ({ + useProjects: () => [], + useQuietThreadShell: () => null, + useThreadProjection: ((ref: unknown) => + ref === null ? null : { projection: state.projection }) as never, + useThreadRelationshipShells: () => [], +})); +vi.mock(import("../../state/environments"), () => ({ + useEnvironment: () => null, + useEnvironmentProviders: () => new Map(), +})); +vi.mock(import("../../lib/archivedThreadsState"), () => ({ + useArchivedThreadSnapshots: (() => ({ snapshots: [] })) as never, +})); +vi.mock(import("../../state/use-atom-command"), () => ({ + useAtomCommand: (() => async () => undefined) as never, +})); +vi.mock(import("../../state/threads"), () => ({ + threadEnvironment: {} as never, +})); +vi.mock(import("../../state/orchestration"), () => ({ + orchestrationEnvironment: { + stopWorkflow: { permissionAtom: () => Atom.make(false) }, + } as never, +})); + +import "~/index.css"; +import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl"; + +it("opens an idle child from Lineage when its shell has not been loaded", async () => { + const projection = makeThreadProjectionFixture(); + const childId = ThreadId.make("omitted-child"); + const environmentId = EnvironmentId.make("local"); + state.projection = { + ...projection, + subagents: [ + { + id: NodeId.make("agent"), + threadId: projection.thread.id, + runId: null, + parentNodeId: NodeId.make("parent"), + origin: "app_owned", + createdBy: "agent", + driver: "codex", + providerInstanceId: projection.thread.providerInstanceId, + providerThreadId: null, + childThreadId: childId, + nativeTaskRef: null, + prompt: "Inspect the change", + title: "Idle child", + model: null, + status: "completed", + result: null, + startedAt: null, + completedAt: projection.thread.updatedAt, + updatedAt: projection.thread.updatedAt, + }, + ], + }; + await using screen = await render( + , + ); + await screen.getByRole("button", { name: /Previous agents/ }).click(); + const child = screen.getByRole("button", { name: /Idle child/ }); + await expect.element(child).toBeEnabled(); + await child.click(); + await vi.waitFor(() => + expect(screen.router?.state.location.pathname).toBe("/local/omitted-child"), + ); +}); diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.tsx index 69403392b5ce8..e07a7fedd0cfa 100644 --- a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx +++ b/apps/web/src/components/chat/ThreadRelationshipsControl.tsx @@ -483,6 +483,7 @@ export function ThreadRelationshipsPanel(props: { return null; } + // Idle children can be omitted from the shell; opening one loads its own detail. const openThread = (threadId: ThreadId) => { void navigate({ to: "/$environmentId/$threadId", @@ -658,9 +659,7 @@ export function ThreadRelationshipsPanel(props: { ? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0" : ""; const project = projects.find((project) => project.id === node?.thread?.projectId); - const relationshipHint = node?.missing - ? "This related thread is unavailable" - : `Open ${relationship.toLowerCase()} in this chat`; + const relationshipHint = `Open ${relationship.toLowerCase()} in this chat`; const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup; const relationshipTooltip = agent ? ( openThread(threadId)} /> } @@ -750,9 +748,6 @@ export function ThreadRelationshipsPanel(props: { providers={providers} driver={providerDriver} onOpenThread={(memberThreadId) => openThread(memberThreadId as ThreadId)} - isThreadAvailable={(memberThreadId) => - graph.nodes.get(memberThreadId as ThreadId)?.missing === false - } onStop={canStopWorkflow ? () => void stopWorkflow(agent.id) : undefined} stopping={stoppingId === agent.id} stopDisabled={stoppingId !== null} @@ -773,7 +768,6 @@ export function ThreadRelationshipsPanel(props: { variant="ghost" part="primary" aria-label={`${threadTitle} ${threadRelationshipStatusLabel(rowStatus)}`} - disabled={node?.missing === true} onClick={() => openThread(threadId)} /> } From e2cb33fe2c67cb5d8df33aefee3c94b2cec580a1 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Thu, 29 Oct 2026 14:53:07 -0500 Subject: [PATCH 3/3] fix(clients): derive omitted thread parent links from detail --- .../src/state/threadRelationships.test.ts | 34 +++++++++++++++++++ .../src/state/threadRelationships.ts | 7 +++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/client-runtime/src/state/threadRelationships.test.ts b/packages/client-runtime/src/state/threadRelationships.test.ts index 9070b7628af1d..90dc68c21dd82 100644 --- a/packages/client-runtime/src/state/threadRelationships.test.ts +++ b/packages/client-runtime/src/state/threadRelationships.test.ts @@ -59,6 +59,40 @@ describe("thread relationships", () => { ).toBeNull(); }); + it.each(["fork", "subagent"] as const)( + "keeps the parent edge of an opened %s omitted from the shell", + (relationshipToParent) => { + const parent = ThreadId.make("parent"); + const child = ThreadId.make("omitted-child"); + const projection = { + thread: { + id: child, + forkedFrom: + relationshipToParent === "fork" + ? { type: "run", threadId: parent, runId: "source-run" } + : null, + lineage: { rootThreadId: parent, parentThreadId: parent, relationshipToParent }, + }, + subagents: [], + contextTransfers: [], + } as never; + const graph = deriveThreadRelationshipGraph({ threads: [], projection }); + expect(immediateThreadRelationships(graph, child)).toEqual([ + expect.objectContaining({ + threadId: parent, + edge: expect.objectContaining({ + sourceThreadId: parent, + targetThreadId: child, + kind: relationshipToParent, + }), + }), + ]); + expect(resolveMergeBackTargetThreadId(projection)).toBe( + relationshipToParent === "fork" ? parent : null, + ); + }, + ); + it("keeps an older activity run visible over a newer cancelled run", () => { const parent = ThreadId.make("thread-parent"); const child = ThreadId.make("thread-child"); diff --git a/packages/client-runtime/src/state/threadRelationships.ts b/packages/client-runtime/src/state/threadRelationships.ts index a0c63adccaaca..2aecc93470c2f 100644 --- a/packages/client-runtime/src/state/threadRelationships.ts +++ b/packages/client-runtime/src/state/threadRelationships.ts @@ -80,7 +80,12 @@ export function deriveThreadRelationshipGraph(input: { ); }; - for (const thread of threads) { + const selectedThread = input.projection?.thread; + const lineageThreads = + selectedThread !== undefined && !threadsById.has(selectedThread.id) + ? [...threads, { ...selectedThread, activityRunStatus: null, status: null }] + : threads; + for (const thread of lineageThreads) { const parentThreadId = thread.forkedFrom?.type === "run" ? thread.forkedFrom.threadId