Skip to content

Commit 61c4f2d

Browse files
t3dotggclaude
andcommitted
fix(web): keep the Work locally resend across the bootstrap thread rotation
A cancelled bootstrap deletes its thread and the draft gets a new thread id. The pending resend was cleared by the thread-change effect before it could fire. It is now keyed by draft id, so it survives the rotation and drops on its own when the composer moves to another draft. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent d4b9f9f commit 61c4f2d

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,9 +1644,11 @@ export default function ChatView(props: ChatViewProps) {
16441644
ownerKey: string;
16451645
} | null>(null);
16461646
const [heldWorktreeSetup, setHeldWorktreeSetup] = useState<WorktreeSetupSnapshot | null>(null);
1647-
// Set by "Work locally": resend the restored draft once the cancelled
1648-
// dispatch has settled and the draft is in local mode.
1649-
const [workLocallyResendPending, setWorkLocallyResendPending] = useState(false);
1647+
// Set by "Work locally": the draft whose restored message should be resent
1648+
// once the cancelled dispatch has settled and the draft is in local mode.
1649+
// Keyed by draft id so a bootstrap rotating the thread id keeps it, while
1650+
// moving to another draft drops it without an effect.
1651+
const [workLocallyResendDraftId, setWorkLocallyResendDraftId] = useState<DraftId | null>(null);
16501652
const [feedbackSubmissionsByThreadKey, setFeedbackSubmissionsByThreadKey] = useState<
16511653
Record<string, ReadonlyArray<CodexFeedbackSubmission>>
16521654
>({});
@@ -5510,7 +5512,6 @@ export default function ChatView(props: ChatViewProps) {
55105512
return [];
55115513
});
55125514
resetLocalDispatch();
5513-
setWorkLocallyResendPending(false);
55145515
setExpandedImage(null);
55155516
}, [draftId, resetLocalDispatch, threadId]);
55165517

@@ -8292,7 +8293,8 @@ export default function ChatView(props: ChatViewProps) {
82928293
!worktreeSetup ||
82938294
!worktreeSetupRef ||
82948295
worktreeSetup.phase !== "running" ||
8295-
!isLocalDraftThread
8296+
!isLocalDraftThread ||
8297+
!draftId
82968298
) {
82978299
return;
82988300
}
@@ -8304,9 +8306,16 @@ export default function ChatView(props: ChatViewProps) {
83048306
const result = await cancelWorktreeSetup(target);
83058307
if (result._tag !== "Success" || !result.value.cancelled) return;
83068308
onEnvModeChange("local");
8307-
setWorkLocallyResendPending(true);
8309+
setWorkLocallyResendDraftId(draftId);
83088310
})();
8309-
}, [cancelWorktreeSetup, isLocalDraftThread, onEnvModeChange, worktreeSetup, worktreeSetupRef]);
8311+
}, [
8312+
cancelWorktreeSetup,
8313+
draftId,
8314+
isLocalDraftThread,
8315+
onEnvModeChange,
8316+
worktreeSetup,
8317+
worktreeSetupRef,
8318+
]);
83108319
const onSendRef = useRef(onSend);
83118320
onSendRef.current = onSend;
83128321
// Resend once the cancelled dispatch has settled and the composer is free.
@@ -8315,7 +8324,8 @@ export default function ChatView(props: ChatViewProps) {
83158324
// feedback upload in between. What remains inside `onSend` are the checks
83168325
// that need the user to change something, and those should not auto retry.
83178326
const workLocallyResendReady =
8318-
workLocallyResendPending &&
8327+
workLocallyResendDraftId !== null &&
8328+
workLocallyResendDraftId === draftId &&
83198329
activeThread !== null &&
83208330
!isSendBusy &&
83218331
!isConnecting &&
@@ -8335,7 +8345,7 @@ export default function ChatView(props: ChatViewProps) {
83358345
) {
83368346
return;
83378347
}
8338-
setWorkLocallyResendPending(false);
8348+
setWorkLocallyResendDraftId(null);
83398349
void onSendRef.current();
83408350
}, [routeThreadKey, workLocallyResendReady]);
83418351

0 commit comments

Comments
 (0)