Skip to content

Commit 504c35d

Browse files
fix(mobile): keep the sent model visible while new tasks close
1 parent 9f61ba6 commit 504c35d

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ export function NewTaskDraftScreen(props: {
438438
const contextImports = useAtomValue(composerContextImportsAtom);
439439
const isImportingContext = flow.draftKey ? contextImports[flow.draftKey] === true : false;
440440
const isComposerInteractionLocked =
441-
isIncomingShareTransferPending || flow.submitting || isImportingContext;
441+
isIncomingShareTransferPending ||
442+
flow.submitting ||
443+
submitNavigationAction !== null ||
444+
isImportingContext;
442445
// Hardware keyboard: step to the next machine, from the one a switch in
443446
// progress is heading to so repeated presses keep advancing.
444447
const { environments, selectedEnvironmentId, switchEnvironment, switchingToEnvironmentId } = flow;
@@ -1331,6 +1334,7 @@ export function NewTaskDraftScreen(props: {
13311334
flow.setSubmitting(false);
13321335
}
13331336
const draftSnapshot = getComposerDraftSnapshot(draftKey);
1337+
flow.setSubmittedModelSelection(message.modelSelection ?? modelSelection);
13341338
if (editingPendingTask) {
13351339
flow.finishEditingPendingTask();
13361340
} else {

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useAtomValue } from "@effect/atom-react";
2+
import { Atom } from "effect/reactivity";
13
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
24
import { Alert } from "react-native";
35

@@ -241,6 +243,7 @@ type NewTaskFlowContextValue = {
241243
readonly removeAttachment: (imageId: string) => void;
242244
readonly clearAttachments: () => void;
243245
readonly setSubmitting: (value: boolean) => void;
246+
readonly setSubmittedModelSelection: (value: ModelSelection) => void;
244247
readonly setBranchQuery: (value: string) => void;
245248
readonly loadBranches: () => void;
246249
readonly loadMoreBranches: () => void;
@@ -290,6 +293,13 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
290293
// chosen; each New Task entry mints its own, so a project can hold several.
291294
const [activeDraftKey, setActiveDraftKey] = useState<string | null>(null);
292295
const [submitting, setSubmitting] = useState(false);
296+
// Share the draft's synchronous store so cleanup cannot render ahead of this snapshot.
297+
const [submittedModelSelectionAtom] = useState(() => Atom.make<ModelSelection | null>(null));
298+
const submittedModelSelection = useAtomValue(submittedModelSelectionAtom);
299+
const setSubmittedModelSelection = useCallback(
300+
(value: ModelSelection | null) => appAtomRegistry.set(submittedModelSelectionAtom, value),
301+
[submittedModelSelectionAtom],
302+
);
293303
const [branchQuery, setBranchQuery] = useState("");
294304
const [expandedProvider, setExpandedProvider] = useState<string | null>(null);
295305
const [editingPendingTask, setEditingPendingTask] = useState<QueuedThreadMessage | null>(null);
@@ -306,6 +316,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
306316
setSelectedProjectKey(null);
307317
setActiveDraftKey(null);
308318
setSubmitting(false);
319+
setSubmittedModelSelection(null);
309320
setBranchQuery("");
310321
setExpandedProvider(null);
311322
pendingLocalBranchSyncDraftKeysRef.current.clear();
@@ -318,7 +329,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
318329
}
319330
releaseEditingQueuedMessage(editing.messageId);
320331
}
321-
}, []);
332+
}, [setSubmittedModelSelection]);
322333

323334
const projectsForEnvironment = useMemo(
324335
() =>
@@ -559,10 +570,14 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
559570
() =>
560571
buildModelOptions(
561572
selectedEnvironmentServerConfig,
562-
draftModelSelection ?? projectDefaultModelSelection ?? stickyModelSelection,
573+
submittedModelSelection ??
574+
draftModelSelection ??
575+
projectDefaultModelSelection ??
576+
stickyModelSelection,
563577
),
564578
[
565579
selectedEnvironmentServerConfig,
580+
submittedModelSelection,
566581
draftModelSelection,
567582
projectDefaultModelSelection,
568583
stickyModelSelection,
@@ -572,6 +587,9 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
572587
// An unsent draft keeps its explicit pick. Fresh drafts resolve the project
573588
// default before the last manual app-wide selection and provider default.
574589
const selectedModel = resolveNewTaskModelSelection({
590+
// Draft cleanup happens before the sheet finishes leaving. Keep showing
591+
// the model that was sent until this sheet and its provider unmount.
592+
submittedSelection: submittedModelSelection,
575593
draftSelection: draftModelSelection,
576594
projectDefaultSelection: projectDefaultModelSelection,
577595
stickySelection: stickyModelSelection,
@@ -1320,6 +1338,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
13201338
removeAttachment,
13211339
clearAttachments,
13221340
setSubmitting,
1341+
setSubmittedModelSelection,
13231342
setBranchQuery,
13241343
loadBranches,
13251344
loadMoreBranches,
@@ -1378,6 +1397,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
13781397
setPrompt,
13791398
setRuntimeMode,
13801399
setSelectedModelKey,
1400+
setSubmittedModelSelection,
13811401
setStartFromOrigin,
13821402
setWorkspaceMode,
13831403
startFromOrigin,

‎apps/mobile/src/lib/modelOptions.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,25 @@ describe("mobile model options", () => {
468468
expect(resolveDefaultableModelSelection(null, legacy)).toBe(legacy);
469469
});
470470

471+
it("prefers the submitted model over draft and defaults while a task leaves", () => {
472+
const submitted = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-6.1-sol" };
473+
const project = { ...submitted, model: "gpt-6-astra" };
474+
for (const draftSelection of [project, null]) {
475+
expect(
476+
resolveNewTaskModelSelection({
477+
submittedSelection: submitted,
478+
draftSelection,
479+
projectDefaultSelection: project,
480+
stickySelection: project,
481+
modelOptions: [],
482+
}),
483+
).toBe(submitted);
484+
}
485+
expect(buildModelOptions(null, submitted).map((option) => option.selection)).toContainEqual(
486+
submitted,
487+
);
488+
});
489+
471490
it("resolves new tasks from draft, project, sticky, then provider defaults", () => {
472491
const draft = { instanceId: ProviderInstanceId.make("codex"), model: "draft" };
473492
const project = { instanceId: ProviderInstanceId.make("codex"), model: "project" };

‎apps/mobile/src/lib/modelOptions.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ export function resolveDefaultableModelSelection(
140140
}
141141

142142
export function resolveNewTaskModelSelection(input: {
143+
readonly submittedSelection?: ModelSelection | null;
143144
readonly draftSelection: ModelSelection | null;
144145
readonly projectDefaultSelection: ModelSelection | null;
145146
readonly stickySelection: ModelSelection | null;
146147
readonly modelOptions: ReadonlyArray<ModelOption>;
147148
}): ModelSelection | null {
148149
return (
150+
input.submittedSelection ??
149151
input.draftSelection ??
150152
input.projectDefaultSelection ??
151153
input.stickySelection ??

0 commit comments

Comments
 (0)