Skip to content

Commit d0fb38b

Browse files
fix(mobile): stabilize sent model snapshot cleanup
1 parent eb0b7e1 commit d0fb38b

3 files changed

Lines changed: 22 additions & 23 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,8 @@ export function NewTaskDraftScreen(props: {
523523
});
524524
return () => cancelAnimationFrame(frame);
525525
}, [navigation, preventRemove, submitNavigationAction]);
526-
// The sent model stands in only while this draft leaves. If the screen goes
527-
// before its closing navigation runs, the sheet's next draft resolves its
528-
// model normally.
529526
const { setSubmittedModelSelection } = flow;
527+
// An interrupted close can remove this screen while its flow provider survives.
530528
useEffect(() => () => setSubmittedModelSelection(null), [setSubmittedModelSelection]);
531529
const hasImportedIncomingShare = Boolean(
532530
props.incomingShareId &&

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useAtomValue } from "@effect/atom-react";
1+
import { useAtom } from "@effect/atom-react";
22
import { Atom } from "effect/reactivity";
33
import * as Dialog from "../../components/ui/Dialog";
44
import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/filesystem";
@@ -286,9 +286,9 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
286286
const [submitting, setSubmitting] = useState(false);
287287
// Share the draft's synchronous store so cleanup cannot render ahead of this snapshot.
288288
const [submittedModelSelectionAtom] = useState(() => Atom.make<ModelSelection | null>(null));
289-
const submittedModelSelection = useAtomValue(submittedModelSelectionAtom);
290-
const setSubmittedModelSelection = (value: ModelSelection | null) =>
291-
appAtomRegistry.set(submittedModelSelectionAtom, value);
289+
const [submittedModelSelection, setSubmittedModelSelection] = useAtom(
290+
submittedModelSelectionAtom,
291+
);
292292
const [branchQuery, setBranchQuery] = useState("");
293293
const [expandedProvider, setExpandedProvider] = useState<string | null>(null);
294294
const [editingPendingTask, setEditingPendingTask] = useState<QueuedThreadMessage | null>(null);
@@ -546,8 +546,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
546546
);
547547

548548
const selectedModel = resolveNewTaskModelSelection({
549-
// Draft cleanup happens before the sheet finishes leaving. Keep showing
550-
// the model that was sent until this sheet and its provider unmount.
551549
submittedSelection: submittedModelSelection,
552550
draftSelection: draftModelSelection,
553551
projectDefaultSelection: projectDefaultModelSelection,

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -495,23 +495,26 @@ describe("mobile model options", () => {
495495
expect(resolveDefaultableModelSelection(null, legacy, null)).toBe(legacy);
496496
});
497497

498-
it("prefers the submitted model over draft and defaults while a task leaves", () => {
498+
it("retains the submitted model through draft cleanup until the snapshot is cleared", () => {
499499
const submitted = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-6.1-sol" };
500500
const project = { ...submitted, model: "gpt-6-astra" };
501-
for (const draftSelection of [project, null]) {
502-
expect(
503-
resolveNewTaskModelSelection({
504-
submittedSelection: submitted,
505-
draftSelection,
506-
projectDefaultSelection: project,
507-
stickySelection: project,
508-
modelOptions: [],
509-
}),
510-
).toBe(submitted);
511-
}
501+
const input = {
502+
submittedSelection: submitted,
503+
draftSelection: project,
504+
projectDefaultSelection: project,
505+
stickySelection: null,
506+
modelOptions: [],
507+
};
508+
509+
expect(resolveNewTaskModelSelection(input)).toBe(submitted);
510+
expect(resolveNewTaskModelSelection({ ...input, draftSelection: null })).toBe(submitted);
512511
expect(
513-
buildModelOptions(null, submitted, undefined, null).map((option) => option.selection),
514-
).toContainEqual(submitted);
512+
resolveNewTaskModelSelection({
513+
...input,
514+
draftSelection: null,
515+
submittedSelection: null,
516+
}),
517+
).toBe(project);
515518
});
516519

517520
it("resolves new tasks from draft, project, sticky, then provider defaults", () => {

0 commit comments

Comments
 (0)