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 22, 02:00 UTC
fix: side chats start with the parent's permission mode and reasoning level (#32315)
Abdullah Al Zawad committed
Nov 7, 2026 at 18:43 UTC
e455200077ce60806a01c8f28435b58860dcfc74
6 files changed
+127
-26
apps/mobile/src/features/threads/useStartSideChat.ts
+32
-4
@@ -5,7 +5,13 @@ import {
5
squashAtomCommandFailure,
6
type AtomCommandResult,
7
} from "@t3tools/client-runtime/state/runtime";
8
-import { MessageId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
8
+import {
9
+ MessageId,
10
+ ThreadId,
11
+ type ModelSelection,
12
+ type RuntimeMode,
13
+ type ScopedThreadRef,
14
+} from "@t3tools/contracts";
15
16
import * as Dialog from "../../components/ui/Dialog";
17
import { uuidv4 } from "../../lib/uuid";
@@ -17,11 +23,13 @@ import { useOpenLinkedThread } from "./useOpenLinkedThread";
23
24
/**
25
* Forks `source` at its latest stable point into a side chat, sends `prompt` there, and opens
20
- * it like any linked thread. Resolves false when the side chat did not start.
26
+ * it like any linked thread. Resolves false when the side chat did not start. `settings` are
27
+ * what the parent's composer would send, which its thread gets only on its next send.
28
*/
29
export function useStartSideChat() {
30
const forkSideChat = useAtomCommand(threadEnvironment.forkSideChat, { reportFailure: false });
31
const deleteThread = useAtomCommand(threadEnvironment.delete, { reportFailure: false });
32
+ const setRuntimeMode = useAtomCommand(threadEnvironment.setRuntimeMode, { reportFailure: false });
33
const startTurn = useAtomCommand(threadEnvironment.startTurn, { reportFailure: false });
34
const openLinkedThread = useOpenLinkedThread();
35
@@ -34,7 +42,11 @@ export function useStartSideChat() {
42
Dialog.alert("Side chat not started", error instanceof Error ? error.message : fallback);
43
};
44
37
- return async (source: ScopedThreadRef, prompt: string): Promise<boolean> => {
45
+ return async (
46
+ source: ScopedThreadRef,
47
+ prompt: string,
48
+ settings: { readonly runtimeMode: RuntimeMode; readonly modelSelection: ModelSelection },
49
+ ): Promise<boolean> => {
50
const targetThreadId = ThreadId.make(uuidv4());
51
const fork = await forkSideChat({
52
environmentId: source.environmentId,
@@ -70,6 +82,21 @@ export function useStartSideChat() {
82
discard();
83
return false;
84
}
85
+ if (settings.runtimeMode !== sideChat.runtimeMode) {
86
+ const mode = await setRuntimeMode({
87
+ environmentId: source.environmentId,
88
+ input: {
89
+ threadId: targetThreadId,
90
+ runtimeMode: settings.runtimeMode,
91
+ createdAt: new Date().toISOString(),
92
+ },
93
+ });
94
+ if (mode._tag === "Failure") {
95
+ alertFailure(mode, "Could not set the side chat's permission mode.");
96
+ discard();
97
+ return false;
98
+ }
99
+ }
100
const turn = await startTurn({
101
environmentId: source.environmentId,
102
input: {
@@ -80,8 +107,9 @@ export function useStartSideChat() {
107
text: prompt,
108
attachments: [],
109
},
110
+ modelSelection: settings.modelSelection,
111
titleSeed: deriveThreadTitleSeed({ text: prompt, attachments: [] }),
84
- runtimeMode: sideChat.runtimeMode,
112
+ runtimeMode: settings.runtimeMode,
113
interactionMode: "default",
114
createdAt: new Date().toISOString(),
115
},
apps/mobile/src/state/thread-task-permissions.test.ts
+32
-2
@@ -10,6 +10,7 @@ import {
10
TurnItemId,
11
type ModelSelection,
12
type OrchestrationV2ThreadProjection,
13
+ type RuntimeMode,
14
type ServerConfig,
15
} from "@t3tools/contracts";
16
import {
@@ -30,6 +31,7 @@ const state = vi.hoisted(() => ({
31
text: "Keep my draft",
32
attachments: [] as DraftComposerImageAttachment[],
33
modelSelection: undefined as ModelSelection | undefined,
34
+ runtimeMode: undefined as RuntimeMode | undefined,
35
},
36
serverConfig: null as ServerConfig | null,
37
projection: null as OrchestrationV2ThreadProjection | null,
@@ -185,6 +187,7 @@ vi.mock("../lib/commandMetadata", () => ({
187
vi.mock("../lib/copyTextWithHaptic", () => ({ copyTextWithHaptic: vi.fn() }));
188
vi.mock("./use-remote-environment-registry", () => ({ setPendingConnectionError: vi.fn() }));
189
190
+import { Alert } from "react-native";
191
import { useThreadComposerState } from "./use-thread-composer-state";
192
import { useSelectedThreadRequests } from "./use-selected-thread-requests";
193
@@ -193,7 +196,12 @@ const NO_SIDE_CHATS = { startSideChat: async () => false };
196
beforeEach(() => {
197
state.grantedEnvironments = new Set(["primary"]);
198
state.connectionState = "connected";
196
- state.draft = { text: "Keep my draft", attachments: [], modelSelection: undefined };
199
+ state.draft = {
200
+ text: "Keep my draft",
201
+ attachments: [],
202
+ modelSelection: undefined,
203
+ runtimeMode: undefined,
204
+ };
205
state.freshPending = false;
206
state.compactDue = false;
207
state.thread.latestRun = null;
@@ -345,7 +353,18 @@ describe("mobile task permissions", () => {
353
...state.serverConfig,
354
environment: { capabilities: { sideChats: true } },
355
} as ServerConfig;
348
- state.draft = { ...state.draft, text: "/side why does this fail?" };
356
+ // The thread gets the composer's mode and model only on its next send.
357
+ const selection: ModelSelection = {
358
+ instanceId: ProviderInstanceId.make("codex"),
359
+ model: "gpt-5.4",
360
+ options: [{ id: "reasoningEffort", value: "xhigh" }],
361
+ };
362
+ state.draft = {
363
+ ...state.draft,
364
+ text: "/side why does this fail?",
365
+ modelSelection: selection,
366
+ runtimeMode: "approval-required",
367
+ };
368
const startSideChat = vi.fn(async () => true);
369
const composer = useThreadComposerState({ startSideChat });
370
expect(composer.sideChatUnavailableReason).toBeNull();
@@ -353,6 +372,7 @@ describe("mobile task permissions", () => {
372
expect(startSideChat).toHaveBeenCalledExactlyOnceWith(
373
{ environmentId: "secondary", threadId: "thread" },
374
"why does this fail?",
375
+ { runtimeMode: "approval-required", modelSelection: selection },
376
);
377
expect(state.enqueue).not.toHaveBeenCalled();
378
expect(state.clearDraft).toHaveBeenCalled();
@@ -370,6 +390,16 @@ describe("mobile task permissions", () => {
390
expect(await useThreadComposerState({ startSideChat }).onSendMessage()).toBeNull();
391
expect(startSideChat).toHaveBeenCalledOnce();
392
expect(state.clearDraft).not.toHaveBeenCalled();
393
+ // A model the send would refuse does not start a side chat either.
394
+ vi.clearAllMocks();
395
+ state.serverConfig = {
396
+ ...state.serverConfig,
397
+ providers: [{ instanceId: "codex", driver: "codex", enabled: false }],
398
+ } as unknown as ServerConfig;
399
+ state.draft = { ...state.draft, attachments: [] };
400
+ expect(await useThreadComposerState({ startSideChat }).onSendMessage()).toBeNull();
401
+ expect(startSideChat).not.toHaveBeenCalled();
402
+ expect(Alert.alert).toHaveBeenCalledOnce();
403
});
404
405
it("rechecks a retained send callback before clearing or queueing the draft", async () => {
apps/mobile/src/state/use-thread-composer-state.ts
+27
-13
@@ -27,6 +27,7 @@ import {
27
type EnvironmentId,
28
type ModelSelection,
29
type ProviderInteractionMode,
30
+ type RuntimeMode,
31
type ScopedThreadRef,
32
type ServerProvider,
33
type ThreadId,
@@ -197,7 +198,11 @@ export function updateThreadDraftModelSelection(
198
199
export function useThreadComposerState(input: {
200
/** Forks the thread into a side chat that gets `prompt`; resolves false when it did not start. */
200
- readonly startSideChat: (source: ScopedThreadRef, prompt: string) => Promise<boolean>;
201
+ readonly startSideChat: (
202
+ source: ScopedThreadRef,
203
+ prompt: string,
204
+ settings: { readonly runtimeMode: RuntimeMode; readonly modelSelection: ModelSelection },
205
+ ) => Promise<boolean>;
206
}) {
207
const {
208
selectedThread: selectedThreadShell,
@@ -564,6 +569,19 @@ export function useThreadComposerState(input: {
569
if (text.length === 0 && attachments.length === 0) {
570
return null;
571
}
572
+ const modelSelection = draft.modelSelection ?? thread.modelSelection;
573
+ const serverConfig = selectedEnvironmentRuntime?.serverConfig;
574
+ const modelUnavailable =
575
+ selectedEnvironmentRuntime?.connectionState === "connected" &&
576
+ isModelSelectionUnavailable(serverConfig, modelSelection, thread.projectId);
577
+ const alertModelUnavailable = () => {
578
+ const { title, detail } = describeUnavailableModelSelection(
579
+ serverConfig,
580
+ modelSelection,
581
+ thread.projectId,
582
+ );
583
+ Dialog.alert(title, detail);
584
+ };
585
// A redirect's text answers its approval, so `/side` there is that text, not the command.
586
const sideChatCommand = beforeDispatch === undefined ? parseSideChatCommand(text) : null;
587
if (sideChatCommand) {
@@ -576,12 +594,18 @@ export function useThreadComposerState(input: {
594
);
595
} else if (sideChatCommand.prompt.length === 0) {
596
Dialog.alert("Ask a side question", "Type the question after /side, then send it.");
597
+ } else if (modelUnavailable) {
598
+ alertModelUnavailable();
599
} else if (!startingSideChatRef.current) {
600
startingSideChatRef.current = true;
601
const started = await input
602
.startSideChat(
603
{ environmentId: thread.environmentId, threadId: thread.id },
604
sideChatCommand.prompt,
605
+ {
606
+ runtimeMode: draft.runtimeMode ?? thread.runtimeMode,
607
+ modelSelection,
608
+ },
609
)
610
.finally(() => {
611
startingSideChatRef.current = false;
@@ -627,18 +651,8 @@ export function useThreadComposerState(input: {
651
return null;
652
}
653
630
- const modelSelection = draft.modelSelection ?? thread.modelSelection;
631
- const serverConfig = selectedEnvironmentRuntime?.serverConfig;
632
- if (
633
- selectedEnvironmentRuntime?.connectionState === "connected" &&
634
- isModelSelectionUnavailable(serverConfig, modelSelection, thread.projectId)
635
- ) {
636
- const { title, detail } = describeUnavailableModelSelection(
637
- serverConfig,
638
- modelSelection,
639
- thread.projectId,
640
- );
641
- Dialog.alert(title, detail);
654
+ if (modelUnavailable) {
655
+ alertModelUnavailable();
656
return null;
657
}
658
const provider = serverConfig?.providers.find(
apps/web/src/components/ChatView.tsx
+4
@@ -2794,6 +2794,10 @@ export default function ChatView(props: ChatViewProps) {
2794
serverConfig?.environment.capabilities.sideChats === true;
2795
const sideChat = useSideChat({
2796
threadRef: sideChatsOffered && isServerThread ? activeThreadRef : null,
2797
+ readSettings: () => ({
2798
+ runtimeMode,
2799
+ modelSelection: composerRef.current?.getSendContext().selectedModelSelection,
2800
+ }),
2801
onError: (message) => {
2802
if (activeThread) setThreadError(activeThread.id, message);
2803
},
apps/web/src/components/chat/useSideChat.ts
+28
-4
@@ -1,4 +1,4 @@
1
-import type { ScopedThreadRef } from "@t3tools/contracts";
1
+import type { ModelSelection, RuntimeMode, ScopedThreadRef } from "@t3tools/contracts";
2
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3
import { deriveThreadTitleSeed } from "@t3tools/client-runtime/operations";
4
import {
@@ -9,6 +9,7 @@ import {
9
import { useRef } from "react";
10
11
import { newMessageId, newThreadId } from "~/lib/utils";
12
+import { useComposerDraftStore } from "../../composerDraftStore";
13
import { useStableCallback } from "../../hooks/useStableCallback";
14
import { useRightPanelStore } from "../../rightPanelStore";
15
import { readThreadShell, waitForThreadShell } from "../../state/entities";
@@ -18,16 +19,24 @@ import { useOrchestrationCommand } from "../../state/use-orchestration-command";
19
20
/**
21
* Starts side chats from `threadRef`, or offers none when it is null. `open` forks the
21
- * thread's latest stable point, sends `prompt` there, and shows the side chat's tab. It
22
- * resolves false when the side chat did not start, or another one is still starting.
22
+ * thread's latest stable point, sends `prompt` there with `readSettings()`, the parent
23
+ * composer's settings, and shows the tab. It resolves false when the side chat did not
24
+ * start, or another one is still starting.
25
*/
26
export function useSideChat(input: {
27
readonly threadRef: ScopedThreadRef | null;
28
+ readonly readSettings: () => {
29
+ readonly runtimeMode: RuntimeMode;
30
+ readonly modelSelection: ModelSelection | undefined;
31
+ };
32
readonly onError: (message: string) => void;
33
}) {
34
const pendingRef = useRef(false);
35
const forkSideChat = useAtomCommand(threadEnvironment.forkSideChat, { reportFailure: false });
36
const deleteThread = useAtomCommand(threadEnvironment.delete, { reportFailure: false });
37
+ const setThreadRuntimeMode = useOrchestrationCommand(threadEnvironment.setRuntimeMode, {
38
+ reportFailure: false,
39
+ });
40
const startThreadTurn = useOrchestrationCommand(threadEnvironment.startTurn, {
41
reportFailure: false,
42
});
@@ -40,6 +49,7 @@ export function useSideChat(input: {
49
input.onError(error instanceof Error ? error.message : fallback);
50
};
51
const start = async (threadRef: ScopedThreadRef, prompt: string | undefined) => {
52
+ const { runtimeMode, modelSelection } = input.readSettings();
53
const targetThreadId = newThreadId();
54
const fork = await forkSideChat({
55
environmentId: threadRef.environmentId,
@@ -67,6 +77,17 @@ export function useSideChat(input: {
77
discard();
78
return false;
79
}
80
+ if (runtimeMode !== sideChat.runtimeMode) {
81
+ const mode = await setThreadRuntimeMode({
82
+ environmentId: threadRef.environmentId,
83
+ input: { threadId: targetThreadId, runtimeMode, createdAt: new Date().toISOString() },
84
+ });
85
+ if (mode._tag === "Failure") {
86
+ reportFailure(mode, "Could not set the side chat's permission mode.");
87
+ discard();
88
+ return false;
89
+ }
90
+ }
91
const text = prompt?.trim();
92
// Send before showing the tab: closing a tab whose side chat has no run deletes it.
93
if (text) {
@@ -75,8 +96,9 @@ export function useSideChat(input: {
96
input: {
97
threadId: targetThreadId,
98
message: { messageId: newMessageId(), role: "user", text, attachments: [] },
99
+ ...(modelSelection === undefined ? {} : { modelSelection }),
100
titleSeed: deriveThreadTitleSeed({ text, attachments: [] }),
79
- runtimeMode: sideChat.runtimeMode,
101
+ runtimeMode,
102
interactionMode: "default",
103
createdAt: new Date().toISOString(),
104
},
@@ -86,6 +108,8 @@ export function useSideChat(input: {
108
discard();
109
return false;
110
}
111
+ } else if (modelSelection !== undefined) {
112
+ useComposerDraftStore.getState().setModelSelection(targetRef, modelSelection);
113
}
114
useRightPanelStore.getState().openSideChat(threadRef, targetThreadId);
115
return true;
docs/user/thread-sidebar.md
+4
-3
@@ -304,9 +304,10 @@ You can also choose **Side chat** from the **+** menu in the right panel. The si
304
chat opens as a tab there, with its own composer. Side chats do not show in the
305
sidebar. Find one again under **Side chats** in thread details.
306
307
-A side chat works in the same folder as the thread and inherits its permissions
308
-when created, including for its first reply. Change permissions for an individual
309
-side chat in its composer. Later changes to the parent do not change existing side chats.
307
+A side chat works in the same folder as the thread and starts with the permissions,
308
+model, and reasoning level shown in the thread's composer, including for its first
309
+reply. Change them for an individual side chat in its composer. Later changes to the
310
+parent do not change existing side chats.
311
312
To use what you learned, choose **Bring back**. The thread gets the side chat with
313
your next message there. Bring back is available while the thread is idle.