Skip to content

Commit bff132f

Browse files
fix(mobile): keep follow-up and legacy outbox models as main sends them
Older builds stored explicit picks and cached thread models the same way, so dropping the model from a legacy follow-up could discard a real pick. The composer also needs to send the thread's model when the draft has no pick: a same-instance pick leaves the draft once the thread accepts it, and an unpicked queued message would run on the model queued ahead of it. Delivery still sends no model for messages that name none and releases a delivered pick from the draft. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 75d9034 commit bff132f

4 files changed

Lines changed: 10 additions & 40 deletions

File tree

‎apps/mobile/src/state/thread-outbox-model.ts‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ export const QueuedThreadMessageSchema = Schema.Struct({
5757
context: Schema.optional(OrchestrationMessageContext),
5858
attachments: Schema.Array(DraftComposerAttachmentSchema),
5959
modelSelection: Schema.optional(ModelSelection),
60-
// Written with every stored model since follow-ups carry only the user's pick. Entries without it
61-
// come from builds that stored this client's cached thread model on every follow-up.
62-
modelPicked: Schema.optional(Schema.Literal(true)),
6360
dispatchMode: Schema.optional(Schema.Literals(["auto", "queue", "steer", "restart"])),
6461
compactBeforeSend: Schema.optional(Schema.Boolean),
6562
freshContext: Schema.optional(Schema.Boolean),
@@ -158,16 +155,12 @@ export function encodeQueuedThreadMessage(message: QueuedThreadMessage): unknown
158155
return encodeStoredQueuedThreadMessage({
159156
schemaVersion: THREAD_OUTBOX_SCHEMA_VERSION,
160157
...message,
161-
...(message.modelSelection === undefined ? {} : { modelPicked: true as const }),
162158
});
163159
}
164160

165161
export function decodeQueuedThreadMessage(value: unknown): QueuedThreadMessage {
166-
const { schemaVersion: _, modelPicked, ...message } = decodeStoredQueuedThreadMessage(value);
167-
if (message.creation !== undefined || modelPicked === true) return message;
168-
// Possibly a stale cached model rather than a pick: let the server use the thread's own.
169-
const { modelSelection: _unconfirmed, ...followUp } = message;
170-
return followUp;
162+
const { schemaVersion: _, ...message } = decodeStoredQueuedThreadMessage(value);
163+
return message;
171164
}
172165

173166
export function groupQueuedThreadMessages(

‎apps/mobile/src/state/thread-outbox.test.ts‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ function queuedMessage(input: {
112112
}
113113

114114
describe("thread outbox", () => {
115-
it("retains structured context and a model pick through a persisted offline queue round trip", () => {
115+
it("retains structured context through a persisted offline queue round trip", () => {
116116
const message: QueuedThreadMessage = {
117117
...queuedMessage({ messageId: "context-message", createdAt: "2026-09-06T12:00:00.000Z" }),
118-
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
119118
text: "[Build](t3-context://v1/terminal/build-output)",
120119
context: {
121120
version: 1,
@@ -138,27 +137,6 @@ describe("thread outbox", () => {
138137
decodeQueuedThreadMessage(JSON.parse(JSON.stringify(encodeQueuedThreadMessage(message)))),
139138
).toEqual(message);
140139
});
141-
142-
it("drops the model an older build stored on a follow-up, so the server keeps the thread's own", () => {
143-
const stale = { instanceId: "claudeAgent", model: "claude-opus-5-5" };
144-
const base = queuedMessage({ messageId: "older-entry", createdAt: "2026-10-23T23:00:00.000Z" });
145-
const stored = { schemaVersion: 3, ...base, modelSelection: stale };
146-
147-
expect(decodeQueuedThreadMessage(stored)).toEqual(base);
148-
// A new thread needs its model, so an older creation entry keeps it.
149-
const creation = {
150-
projectId: ProjectId.make("project-1"),
151-
workspaceMode: "local" as const,
152-
branch: null,
153-
worktreePath: null,
154-
};
155-
expect(decodeQueuedThreadMessage({ ...stored, creation })).toEqual({
156-
...base,
157-
modelSelection: stale,
158-
creation,
159-
});
160-
});
161-
162140
it.each(["read", "json", "schema"] as const)(
163141
"recovers usable messages without permitting cleanup after a record %s failure",
164142
async (failure) => {

‎apps/mobile/src/state/thread-task-permissions.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,17 @@ describe("mobile task permissions", () => {
507507
});
508508

509509
describe("queued follow-up model", () => {
510-
it("queues a follow-up with no model when the user picked none", async () => {
510+
it("queues an unpicked follow-up on the thread's current model", async () => {
511511
state.grantedEnvironments.add("secondary");
512512
const composer = useThreadComposerState(NO_SIDE_CHATS);
513513

514514
expect(await composer.onSendMessage()).toBe("message");
515515

516-
// The outbox can deliver after the thread moved elsewhere; only the server knows its model then.
517-
expect(state.enqueue).toHaveBeenCalledOnce();
518-
const [queued] = state.enqueue.mock.calls[0] as unknown as [object];
519-
expect(queued).not.toHaveProperty("modelSelection");
516+
// A same-instance pick leaves the draft once the thread accepts it; without a model the
517+
// server would run this message on the model queued ahead of it instead.
518+
expect(state.enqueue).toHaveBeenCalledExactlyOnceWith(
519+
expect.objectContaining({ modelSelection: { instanceId: "codex", model: "gpt-5.4" } }),
520+
);
520521
});
521522
});
522523

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,7 @@ export function useThreadComposerState(input: {
803803
text,
804804
attachments,
805805
context: draft.context,
806-
// Only a pick travels with the message. The thread's model is read by the server when the
807-
// outbox delivers, because this client's copy of it can be stale by then.
808-
...(draft.modelSelection === undefined ? {} : { modelSelection: draft.modelSelection }),
806+
modelSelection,
809807
runtimeMode: draft.runtimeMode ?? thread.runtimeMode,
810808
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
811809
...(compactBeforeSend

0 commit comments

Comments
 (0)