Skip to content

Commit 1d87beb

Browse files
t3dotggclaude
andcommitted
fix(mobile): re-check busy/editing guards after outbox write confirmation
The drain's threadBusy and editing-state guards were evaluated before awaiting write confirmation, so a thread going busy or the user opening the message in the editor during a slow write could still dispatch a stale payload. Re-read both from the registry after the await and defer to the next drain pass instead. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 712ab01 commit 1d87beb

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎apps/mobile/src/state/use-thread-outbox-drain.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
type QueuedThreadMessage,
3838
type ThreadOutboxCommandStage,
3939
} from "./thread-outbox-model";
40-
import { threadEnvironment } from "./threads";
40+
import { environmentThreadShells, threadEnvironment } from "./threads";
4141
import { useAtomCommand } from "./use-atom-command";
4242
import {
4343
editingQueuedMessageIdsAtom,
@@ -361,6 +361,23 @@ export function useThreadOutboxDrain(): void {
361361
// Rolled back by a failed write; nothing to deliver or retry.
362362
return true;
363363
}
364+
// The guards evaluated before the confirmation await are stale by now:
365+
// the thread may have gone busy, or the user may have opened this
366+
// message in the editor. Re-read both and defer to the next drain pass
367+
// (returning true skips the failure/backoff path) rather than sending
368+
// a payload the user is editing or racing an active turn.
369+
if (appAtomRegistry.get(editingQueuedMessageIdsAtom)[nextQueuedMessage.messageId]) {
370+
return true;
371+
}
372+
const freshThread = findThread(
373+
appAtomRegistry.get(environmentThreadShells.threadShellsAtom),
374+
nextQueuedMessage,
375+
);
376+
const freshThreadBusy =
377+
freshThread?.session?.status === "running" || freshThread?.session?.status === "starting";
378+
if (deliveryAction === "send" && creation === undefined && freshThreadBusy) {
379+
return true;
380+
}
364381
return deliveryAction === "remove"
365382
? removeQueuedMessage("[thread-outbox] failed to remove message for a missing thread")
366383
: creation !== undefined

0 commit comments

Comments
 (0)