The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): Back from a sub-agent opened from its delegator returns to the delegator (#23795)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Oct 24, 2026 at 18:16 UTC
d53873b6a4799e87afd63c8d288ef0089f5a3748
6 files changed
+77
-17
apps/mobile/src/components/ComposerEditor.tsx
+3
-3
@@ -3,7 +3,6 @@ import { ComposerContextId } from "@t3tools/contracts";
3
import { useAtomValue } from "@effect/atom-react";
4
import { AsyncResult } from "effect/reactivity";
5
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
6
-import { useNavigation } from "@react-navigation/native";
6
import { useEffect, useRef, useState } from "react";
7
import type { EnvironmentId } from "@t3tools/contracts";
8
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
@@ -24,6 +23,7 @@ import {
23
} from "../state/use-composer-drafts";
24
import { importComposerContextClipboard } from "../lib/composerContextClipboard";
25
import { mobilePreferencesAtom } from "../state/preferences";
26
+import { useOpenLinkedThread } from "../features/threads/useOpenLinkedThread";
27
import { ComposerContextSheet } from "./ComposerContextSheet";
28
import { AppText as Text } from "./ui/AppText";
29
import {
@@ -154,7 +154,7 @@ export function ComposerEditor({
154
}),
155
})
156
: "";
157
- const navigation = useNavigation();
157
+ const openLinkedThread = useOpenLinkedThread();
158
const selectedReference = selected
159
? collectComposerContextReferences(selected.source)[0]
160
: undefined;
@@ -236,7 +236,7 @@ export function ComposerEditor({
236
: {})}
237
onOpenThread={(thread) => {
238
setSelected(null);
239
- navigation.navigate("Thread", {
239
+ openLinkedThread({
240
environmentId: String(thread.environmentId),
241
threadId: String(thread.threadId),
242
});
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+5
-10
@@ -147,7 +147,6 @@ import {
147
pendingThreadMessageJump,
148
subscribeThreadMessageJump,
149
} from "./threadMessageJump";
150
-import { parentThreadIsBelow } from "../../lib/android-workspace-navigation";
150
import {
151
clearThreadComposerError,
152
threadComposerErrorsAtom,
@@ -191,6 +190,7 @@ import { ComposerQueuedEditBanner } from "./ComposerQueuedEdit";
190
import { useThreadQueuedCount } from "./ThreadQueueControl";
191
import type { ThreadContentPresentation } from "./threadContentPresentation";
192
import { resolveThreadFeedSubmissionAnchor } from "./thread-feed-live-follow";
193
+import { useOpenLinkedThread } from "./useOpenLinkedThread";
194
import { useGlobalVoiceInput } from "../voice-input/VoiceInputProvider";
195
196
export interface ThreadDetailScreenProps {
@@ -513,6 +513,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
513
const [composerOwnsKeyboard, setComposerOwnsKeyboard] = useState(false);
514
if (sidebarSearchActive && composerOwnsKeyboard) setComposerOwnsKeyboard(false);
515
const navigation = useNavigation();
516
+ const openLinkedThread = useOpenLinkedThread();
517
const { session: voiceInputSession } = useGlobalVoiceInput();
518
const reportedModelSelection = useThreadReportedModelSelection(props.selectedThreadDetailRef);
519
const deviceState = useEnvironmentQuery(
@@ -1747,17 +1748,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
1748
onOpenParent={
1749
props.selectedThread.lineage.parentThreadId === null
1750
? null
1750
- : () => {
1751
- const parent = {
1751
+ : () =>
1752
+ openLinkedThread({
1753
environmentId: String(props.environmentId),
1754
threadId: String(props.selectedThread.lineage.parentThreadId),
1754
- };
1755
- navigation.dispatch((state) =>
1756
- parentThreadIsBelow(state, parent)
1757
- ? StackActions.pop()
1758
- : StackActions.push("Thread", parent),
1759
- );
1760
- }
1755
+ })
1756
}
1757
/>
1758
</View>
apps/mobile/src/features/threads/ThreadFeed.tsx
+7
-4
@@ -270,6 +270,7 @@ import { waitForThreadShellReady } from "./threadForkNavigation";
270
import { resolveUserMessageIntentBadge } from "./userMessageIntentBadge";
271
import { fileChipClipboardPath, fileChipMenu, resolveFileChipTarget } from "./fileChipMenu";
272
import { useFileChipShare } from "./useFileChipShare";
273
+import { useOpenLinkedThread } from "./useOpenLinkedThread";
274
import {
275
MarkdownImageAvailableWidthContext,
276
ThreadMarkdownImage,
@@ -1055,13 +1056,13 @@ function OpenSenderThreadButton(props: {
1056
readonly environmentId: EnvironmentId;
1057
readonly senderThreadId: ThreadId;
1058
}) {
1058
- const navigation = useNavigation();
1059
+ const openLinkedThread = useOpenLinkedThread();
1060
return (
1061
<Pressable
1062
accessibilityRole="link"
1063
hitSlop={6}
1064
onPress={() =>
1064
- navigation.navigate("Thread", {
1065
+ openLinkedThread({
1066
environmentId: String(props.environmentId),
1067
threadId: String(props.senderThreadId),
1068
})
@@ -1797,6 +1798,7 @@ type UserMessageContentProps = {
1798
function UserMessageContent(props: UserMessageContentProps) {
1799
const [selected, setSelected] = useState<{ contextId: string; label: string } | null>(null);
1800
const navigation = useNavigation();
1801
+ const openLinkedThread = useOpenLinkedThread();
1802
const { selectedThread } = useThreadSelection();
1803
const liveText = useLiveThreadLinkLabels(props.text, props.environmentId);
1804
const threadIcons = useThreadChipIcons(props.environmentId, liveText, props.context?.records);
@@ -1815,7 +1817,7 @@ function UserMessageContent(props: UserMessageContentProps) {
1817
return;
1818
}
1819
if (record?.kind === "thread" && "threadId" in record) {
1818
- navigation.navigate("Thread", {
1820
+ openLinkedThread({
1821
environmentId: String(record.environmentId),
1822
threadId: String(record.threadId),
1823
});
@@ -2026,6 +2028,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2028
const duoColumns = useNativeWorkspaceColumnsSupported() && isDuoDevice(deviceType);
2029
const openPullRequest = useOpenPullRequest();
2030
const navigation = useNavigation();
2031
+ const openLinkedThread = useOpenLinkedThread();
2032
const onOpenTurnDiff = useCallback(
2033
(checkpoint: ThreadCheckpointSummary) => {
2034
setReviewSelectedSectionId(
@@ -2210,7 +2213,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2213
}
2214
const target = resolveLinkedThread(href);
2215
if (target) {
2213
- navigation.navigate("Thread", {
2216
+ openLinkedThread({
2217
environmentId: String(target.environmentId),
2218
threadId: String(target.threadId),
2219
});
apps/mobile/src/features/threads/useOpenLinkedThread.ts
new
+16
@@ -0,0 +1,16 @@
1
+import { StackActions, useNavigation } from "@react-navigation/native";
2
+import { useCallback } from "react";
3
+import { linkedThreadStep } from "../../lib/android-workspace-navigation";
4
+
5
+export function useOpenLinkedThread() {
6
+ const navigation = useNavigation();
7
+ return useCallback(
8
+ (target: { readonly environmentId: string; readonly threadId: string }) => {
9
+ const state = navigation.getState();
10
+ const step = state ? linkedThreadStep(state, target) : "push";
11
+ if (step === "pop") navigation.dispatch(StackActions.pop());
12
+ else if (step === "push") navigation.dispatch(StackActions.push("Thread", target));
13
+ },
14
+ [navigation],
15
+ );
16
+}
apps/mobile/src/lib/android-workspace-navigation.test.ts
+25
@@ -7,6 +7,7 @@ import {
7
} from "../features/workspace/android-workspace-tabs";
8
import {
9
androidWorkspaceNavigationState,
10
+ linkedThreadStep,
11
parentThreadIsBelow,
12
resetAndroidWorkspace,
13
returnToAndroidWorkspaceList,
@@ -202,6 +203,30 @@ describe("Android workspace navigation", () => {
203
});
204
});
205
206
+ it("opens a linked thread above the current one so Back returns to it", () => {
207
+ const parent = select(router.getInitialState(options), thread);
208
+ const child = { ...thread.params, threadId: "child-a" };
209
+ const open = (
210
+ state: ReturnType<typeof router.getInitialState>,
211
+ target: ReactNavigation.RootParamList["Thread"],
212
+ ) => {
213
+ const step = linkedThreadStep(state, target);
214
+ if (step === "stay") return state;
215
+ return apply(
216
+ state,
217
+ step === "pop" ? StackActions.pop() : StackActions.push("Thread", target),
218
+ );
219
+ };
220
+
221
+ const inChild = open(parent, child);
222
+ expect(inChild.routes.map((route) => route.params)).toEqual([undefined, thread.params, child]);
223
+ expect(open(inChild, child)).toBe(inChild);
224
+
225
+ const backInParent = open(inChild, thread.params);
226
+ expect(backInParent.routes).toEqual(parent.routes);
227
+ expect(backInParent.index).toBe(parent.index);
228
+ });
229
+
230
it("recognizes a parent only when its environment and thread are immediately below", () => {
231
const parent = select(router.getInitialState(options), thread);
232
const child = apply(
apps/mobile/src/lib/android-workspace-navigation.ts
+21
@@ -92,6 +92,27 @@ export function parentThreadIsBelow(
92
);
93
}
94
95
+/**
96
+ * How a thread link opened from inside a thread reaches its target. `navigate` would reuse the
97
+ * current Thread route, so Back would skip the thread the link was in and land on the list.
98
+ */
99
+export function linkedThreadStep(
100
+ state: NavigationState,
101
+ target: ReactNavigation.RootParamList["Thread"],
102
+): "stay" | "pop" | "push" {
103
+ const params = state.routes[state.index]?.params as
104
+ | ReactNavigation.RootParamList["Thread"]
105
+ | undefined;
106
+ if (
107
+ state.routes[state.index]?.name === "Thread" &&
108
+ params?.environmentId === target?.environmentId &&
109
+ params?.threadId === target?.threadId
110
+ ) {
111
+ return "stay";
112
+ }
113
+ return parentThreadIsBelow(state, target) ? "pop" : "push";
114
+}
115
+
116
export function returnToAndroidWorkspaceList(
117
navigation: WorkspaceNavigation & { readonly goBack: () => void },
118
selectTab: () => void,