TypeScript
fix(chat): surface pending subagent questions on parents (#16634)
mariaed4ea1083d47
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsxindex 9229c117d8d..a3d7a6f4e0c 100644--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx@@ -1,5 +1,5 @@import { useAtomValue } from "@effect/atom-react";-import { useThreadReportedModelSelection } from "../../state/entities";+import { useChildThreadInputs, useThreadReportedModelSelection } from "../../state/entities";import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";import { useNavigation } from "@react-navigation/native";import type { WorktreeSetupCardProps } from "./worktree-setup-card";@@ -400,6 +400,10 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Threadconst controlInsets = deriveBottomControlInsets(nativeMetrics);const agentLabel = `${props.selectedThread.modelSelection.instanceId} agent`;const selectedThreadKey = scopedThreadKey(props.environmentId, props.selectedThread.id);+ const childThreadInputs = useChildThreadInputs({+ environmentId: props.environmentId,+ threadId: props.selectedThread.id,+ });const composerError = useAtomValue(threadComposerErrorsAtom)[selectedThreadKey]?.message ?? null;const queuedCount = useThreadQueuedCount({environmentId: props.environmentId,@@ -507,6 +511,24 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Threadif (threadSyncLabel !== null) {return { kind: "syncing", label: threadSyncLabel };}+ const childInput = childThreadInputs[0];+ if (childInput && contentPresentationKind === "ready") {+ return {+ kind: "child-input",+ label:+ childThreadInputs.length === 1+ ? "Subagent needs input"+ : `${childThreadInputs.length} subagents need input`,+ accessibilityLabel: `Open question from ${childInput.title}`,+ onPress: () => {+ Keyboard.dismiss();+ navigation.navigate("Thread", {+ environmentId: props.environmentId,+ threadId: childInput.id,+ });+ },+ };+ }if (props.isCompacting && contentPresentationKind === "ready") {return { kind: "compacting" };}diff --git a/apps/mobile/src/features/threads/floating-working-control.tsx b/apps/mobile/src/features/threads/floating-working-control.tsxindex f21a83f09a1..1fb87ce1c72 100644--- a/apps/mobile/src/features/threads/floating-working-control.tsx+++ b/apps/mobile/src/features/threads/floating-working-control.tsx@@ -160,15 +160,16 @@ export function FloatingWorkingControl(props: {hasAgents ||hasQueue ||(props.devicePreview !== null && props.browserPreview !== null);- // The queue, agents, and reconnect labels have separate tap targets.- const statusInteractive = props.status?.kind === "connection";+ // The queue, agents, questions, and reconnect labels have separate tap targets.+ const statusInteractive =+ props.status?.kind === "connection" || props.status?.kind === "child-input";const capsuleInteractive = statusInteractive || hasQueue || hasAgents || hasPreview;// The host stays centered on the capsule, but its measurement constraint// comes from the overlay, independent of the capsule's current width.const statusContent =props.status !== null ? (<View- pointerEvents={props.status.kind === "connection" ? "box-none" : "none"}+ pointerEvents={statusInteractive ? "box-none" : "none"}className="h-11 items-center justify-center"><Animated.View className="h-11" style={capsuleSizerStyle} />@@ -372,6 +373,23 @@ function FloatingStatusLabel(props: {if (props.status.kind === "compacting") {return <CompactingLabel key="compacting" onLayout={props.onLayout} />;}+ if (props.status.kind === "child-input") {+ return (+ <StatusLabelRow+ key="child-input"+ accessibilityLabel={props.status.accessibilityLabel}+ accessibilityRole="button"+ className="gap-2"+ onLayout={props.onLayout}+ onPress={props.status.onPress}+ >+ <SymbolView name="text.bubble" size={13} tintColorClassName="foreground" />+ <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>+ {props.status.label}+ </Text>+ </StatusLabelRow>+ );+ }if (props.status.kind === "connection") {return (<StatusLabelRowdiff --git a/apps/mobile/src/features/threads/floating-working-status.ts b/apps/mobile/src/features/threads/floating-working-status.tsindex f5c463842b0..9315f3ffb34 100644--- a/apps/mobile/src/features/threads/floating-working-status.ts+++ b/apps/mobile/src/features/threads/floating-working-status.ts@@ -9,6 +9,12 @@ export type FloatingWorkingStatus =| { readonly kind: "working"; readonly startedAt: string }| { readonly kind: "syncing"; readonly label: string }| { readonly kind: "compacting" }+ | {+ readonly kind: "child-input";+ readonly label: string;+ readonly accessibilityLabel: string;+ readonly onPress: () => void;+ }// The turn settled while background work it started still runs. `waiting`// is false when only commands remain, such as a dev server: the agent is done.| {diff --git a/apps/mobile/src/state/entities.ts b/apps/mobile/src/state/entities.tsindex 0d3b33d582d..b8e42b0cb99 100644--- a/apps/mobile/src/state/entities.ts+++ b/apps/mobile/src/state/entities.ts@@ -98,6 +98,10 @@ export function useThreadShell(ref: ScopedThreadRef | null): EnvironmentThreadSh);}+export function useChildThreadInputs(ref: ScopedThreadRef) {+ return useAtomValue(environmentThreadShells.childThreadInputsAtom(ref));+}+/** `markdown` with each thread link labeled by the thread's current title in `environmentId`. */export function useLiveThreadLinkLabels(markdown: string, environmentId: EnvironmentId): string {const titles = useAtomValue(diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex a80fc56c57e..06a6bacaf48 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -300,6 +300,7 @@ import ThreadTerminalDrawer from "./ThreadTerminalDrawer";import {AlarmClockIcon,CheckCircle2Icon,+ MessageCircleIcon,PaperclipIcon,ChevronDownIcon,DownloadIcon,@@ -427,6 +428,7 @@ import {useThreadStatus,useThreadHistory,useThreadShell,+ useChildThreadInputs,useThreadRefs,useThreadVisibleTurnItems,waitForThreadShell,@@ -7414,6 +7416,42 @@ export default function ChatView(props: ChatViewProps) {},[environmentId, navigate],);+ const childThreadInputs = useChildThreadInputs(activeThreadRef);+ const childInputBannerItem = useMemo<ComposerBannerStackItem | null>(() => {+ const first = childThreadInputs[0];+ const parentAwaitingUser =+ activePendingApproval || activePendingUserInput || activeThreadShell?.hasPendingUserInput;+ if (!first || parentAwaitingUser) return null;+ return {+ id: `child-input:${first.id}`,+ variant: "info",+ priority: "activity",+ icon: <MessageCircleIcon />,+ title:+ childThreadInputs.length === 1+ ? "Subagent needs input"+ : `${childThreadInputs.length} subagents need input`,+ description: childThreadInputs.map((child, index) => (+ <Fragment key={child.id}>+ {index > 0 ? ", " : null}+ <InlineButton tone="muted" onClick={() => onOpenRelatedThread(child.id)}>+ {child.title}+ </InlineButton>+ </Fragment>+ )),+ actions: (+ <Button size="xs" variant="ghost" onClick={() => onOpenRelatedThread(first.id)}>+ Open question+ </Button>+ ),+ };+ }, [+ childThreadInputs,+ activePendingApproval,+ activePendingUserInput,+ activeThreadShell?.hasPendingUserInput,+ onOpenRelatedThread,+ ]);// Commands such as /compact and /goal clear run as their own turn. The draft// and its attachments stay local.@@ -7774,9 +7812,11 @@ export default function ChatView(props: ChatViewProps) {: null;const composerBannerItems = useMemo<ComposerBannerStackItem[]>(() => {const limitRecoveryItems = limitRecoveryBanner === null ? [] : [limitRecoveryBanner];- const backgroundWorkItems = [goalBannerItem, backgroundWorkBannerItem].filter(- (item) => item !== null,- );+ const backgroundWorkItems = [+ childInputBannerItem,+ goalBannerItem,+ backgroundWorkBannerItem,+ ].filter((item) => item !== null);// The user asked for this one, so it leads the notice tier instead of trailing it.const usageLimitsItems = usageLimitsBanner === null ? [] : [usageLimitsBanner];const projectCloneItems = projectCloneBannerItem === null ? [] : [projectCloneBannerItem];@@ -7847,6 +7887,7 @@ export default function ChatView(props: ChatViewProps) {handleRestoreThreadBranch,isRestoringThreadBranch,backgroundWorkBannerItem,+ childInputBannerItem,goalBannerItem,localCheckoutBranchMismatch,projectCloneBannerItem,diff --git a/apps/web/src/state/entities.ts b/apps/web/src/state/entities.tsindex aa9b650fb5b..ebf62f01be6 100644--- a/apps/web/src/state/entities.ts+++ b/apps/web/src/state/entities.ts@@ -117,6 +117,12 @@ export function useThreadShell(ref: ScopedThreadRef | null): EnvironmentThreadSh);}+export function useChildThreadInputs(ref: ScopedThreadRef | null) {+ return useAtomValue(+ ref === null ? EMPTY_THREAD_SHELLS_ATOM : environmentThreadShells.childThreadInputsAtom(ref),+ );+}+export function useThreadProjection(ref: ScopedThreadRef | null): EnvironmentThread | null {return useAtomValue(ref === null ? EMPTY_THREAD_PROJECTION_ATOM : environmentThreadDetails.threadAtom(ref),diff --git a/packages/client-runtime/src/state/threadShell.ts b/packages/client-runtime/src/state/threadShell.tsindex bc6d444f471..3cb54087ac1 100644--- a/packages/client-runtime/src/state/threadShell.ts+++ b/packages/client-runtime/src/state/threadShell.ts@@ -7,6 +7,7 @@ import type {ScopedThreadRef,ThreadId,} from "@t3tools/contracts";+import { isProviderNativeSubagentThread } from "@t3tools/contracts";import { Atom } from "effect/reactivity";import type { EnvironmentThreadShell } from "./models.ts";@@ -138,6 +139,50 @@ export function createEnvironmentThreadShellAtoms(input: {}).pipe(Atom.withLabel(`environment-thread-shell:${key}`));});+ // Child questions are hidden with their sidebar rows. Read their shell summaries,+ // without subscribing to every child transcript.+ const childThreadInputsAtomFamily = Atom.family((key: string) => {+ const ref = parseThreadKey(key);+ let previous: ReadonlyArray<EnvironmentThreadShell> = [];+ return Atom.make((get) => {+ const children = new Map<ThreadId, OrchestrationV2ThreadShell[]>();+ for (const thread of get(environmentThreadsAtom(ref.environmentId))) {+ const parent = thread.lineage.parentThreadId;+ if (parent === null || thread.lineage.relationshipToParent !== "subagent") continue;+ const siblings = children.get(parent);+ if (siblings) siblings.push(thread);+ else children.set(parent, [thread]);+ }+ const seen = new Set<ThreadId>([ref.threadId]);+ const pending = [ref.threadId];+ const next: EnvironmentThreadShell[] = [];+ for (const parent of pending) {+ for (const child of children.get(parent) ?? []) {+ if (seen.has(child.id)) continue;+ seen.add(child.id);+ pending.push(child.id);+ if (+ child.pendingRuntimeRequest?.kind === "user_input" &&+ !isProviderNativeSubagentThread(child)+ ) {+ next.push(scopedThread(ref.environmentId, child));+ }+ }+ }+ // Indicators read only ids and titles, so other shell updates keep the old array.+ if (+ previous.length === next.length &&+ previous.every(+ (thread, index) => thread.id === next[index]?.id && thread.title === next[index]?.title,+ )+ ) {+ return previous;+ }+ previous = next;+ return next;+ }).pipe(Atom.withLabel(`environment-child-thread-inputs:${key}`));+ });+const threadShellsForProjectRefsAtomFamily = Atom.family((key: string) => {const projectRefs = parseProjectRefCollectionKey(key);let previous: ReadonlyArray<EnvironmentThreadShell> = [];@@ -225,5 +270,6 @@ export function createEnvironmentThreadShellAtoms(input: {threadShellsForProjectRefsAtom: (refs: ReadonlyArray<ScopedProjectRef>) =>threadShellsForProjectRefsAtomFamily(projectRefCollectionKey(refs)),threadShellAtom: (ref: ScopedThreadRef) => threadShellAtomFamily(threadKey(ref)),+ childThreadInputsAtom: (ref: ScopedThreadRef) => childThreadInputsAtomFamily(threadKey(ref)),};}