@devries-cameron20 / t3code-1 / commits / 3f695422ae
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): a failed plan follow-up no longer overwrites the next draft (#24684)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Nov 1, 2026 at 16:01 UTC 3f695422ae21be7ce8537eb86c3abb63bfd94e03
3 files changed +72 -2
apps/web/src/components/ChatView.logic.test.ts
+56
@@ -3,6 +3,7 @@ import {
3 buildExpiredTerminalContextToastCopy,
4 mergeDirectPreviewAnnotation,
5 planComposerTurn,
6 + restorePlanFollowUpComposer,
7 snapshotComposerSend,
8 withMessageContext,
9 deriveAvailableRevertTurnCounts,
@@ -1129,6 +1130,61 @@ describe("planComposerTurn", () => {
1130 });
1131 });
1132
1133 +describe("restorePlanFollowUpComposer", () => {
1134 + // The draft is the failed follow-up's thread; the refs and cursor are whatever thread is on
1135 + // screen.
1136 + it.each([
1137 + {
1138 + name: "puts the follow-up back while its thread is open",
1139 + before: { draft: "", refs: "", cursor: null },
1140 + routeIsCurrent: true,
1141 + after: { draft: "Tighten step 2", refs: "Tighten step 2", cursor: "Tighten step 2" },
1142 + },
1143 + {
1144 + name: "keeps a draft typed while the follow-up was in flight",
1145 + before: { draft: "Next idea", refs: "Next idea", cursor: null },
1146 + routeIsCurrent: true,
1147 + after: { draft: "Next idea", refs: "Next idea", cursor: null },
1148 + },
1149 + {
1150 + name: "leaves another thread's composer alone after navigating away",
1151 + before: { draft: "", refs: "Other thread", cursor: null },
1152 + routeIsCurrent: false,
1153 + after: { draft: "Tighten step 2", refs: "Other thread", cursor: null },
1154 + },
1155 + ])("$name", ({ before, routeIsCurrent, after }) => {
1156 + const composer: { draft: string; refs: string; cursor: string | null } = { ...before };
1157 + restorePlanFollowUpComposer({
1158 + snapshot: {
1159 + prompt: "Tighten step 2",
1160 + environmentContexts: [],
1161 + terminalContexts: [],
1162 + reviewComments: [],
1163 + previewAnnotations: [],
1164 + threadContexts: [],
1165 + },
1166 + draftHasUserContent: composer.draft.trim().length > 0,
1167 + routeIsCurrent,
1168 + writeComposerRefs: (snapshot) => {
1169 + composer.refs = snapshot.prompt;
1170 + },
1171 + writePrompt: (prompt) => {
1172 + composer.draft = prompt;
1173 + },
1174 + writeTerminalContexts: () => undefined,
1175 + writeReviewComments: () => undefined,
1176 + writePreviewAnnotations: () => undefined,
1177 + writeThreadContexts: () => undefined,
1178 + writeEnvironmentContexts: () => undefined,
1179 + resetCursor: ({ prompt }) => {
1180 + composer.cursor = prompt;
1181 + },
1182 + });
1183 +
1184 + expect(composer).toEqual(after);
1185 + });
1186 +});
1187 +
1188 describe("withMessageContext", () => {
1189 const context = { records: [] } as unknown as NonNullable<
1190 Parameters<typeof withMessageContext>[0]["context"]
apps/web/src/components/ChatView.logic.ts
+8
@@ -1180,8 +1180,13 @@ export interface PlanFollowUpComposerSnapshot {
1180 readonly environmentContexts: ReadonlyArray<EnvironmentContextRecord>;
1181 }
1182
1183 +// A draft typed while the send was in flight is newer and stays. Composer refs and the cursor
1184 +// belong to the thread on screen, so they follow only while the follow-up's route is current.
1185 export function restorePlanFollowUpComposer(input: {
1186 readonly snapshot: PlanFollowUpComposerSnapshot;
1187 + readonly draftHasUserContent: boolean;
1188 + readonly routeIsCurrent: boolean;
1189 + readonly writeComposerRefs: (snapshot: PlanFollowUpComposerSnapshot) => void;
1190 readonly writePrompt: (prompt: string) => void;
1191 readonly writeTerminalContexts: (contexts: ReadonlyArray<TerminalContextDraft>) => void;
1192 readonly writeReviewComments: (comments: ReadonlyArray<ReviewCommentContext>) => void;
@@ -1194,12 +1199,15 @@ export function restorePlanFollowUpComposer(input: {
1199 detectTrigger: boolean;
1200 }) => void;
1201 }): void {
1202 + if (input.draftHasUserContent) return;
1203 + if (input.routeIsCurrent) input.writeComposerRefs(input.snapshot);
1204 input.writePrompt(input.snapshot.prompt);
1205 input.writeTerminalContexts(input.snapshot.terminalContexts);
1206 input.writeReviewComments(input.snapshot.reviewComments);
1207 input.writePreviewAnnotations(input.snapshot.previewAnnotations);
1208 input.writeThreadContexts(input.snapshot.threadContexts);
1209 input.writeEnvironmentContexts(input.snapshot.environmentContexts);
1210 + if (!input.routeIsCurrent) return;
1211 input.resetCursor({
1212 cursor: collapseExpandedComposerCursor(input.snapshot.prompt, input.snapshot.prompt.length),
1213 prompt: input.snapshot.prompt,
apps/web/src/components/chat/useComposerSend.ts
+8 -2
@@ -759,8 +759,6 @@ export function useComposerSend(input: ComposerSendInput) {
759 interactionMode: followUp.interactionMode,
760 });
761 if (!followUpSent) {
762 - promptRef.current = followUpPromptSnapshot;
763 - composerTerminalContextsRef.current = [...followUpTerminalContexts];
762 restorePlanFollowUpComposer({
763 snapshot: {
764 prompt: followUpPromptSnapshot,
@@ -770,6 +768,14 @@ export function useComposerSend(input: ComposerSendInput) {
768 threadContexts: followUpThreadContexts,
769 environmentContexts: followUpEnvironmentContexts,
770 },
771 + draftHasUserContent: composerDraftHasUserContent(
772 + useComposerDraftStore.getState().getComposerDraft(composerDraftTarget),
773 + ),
774 + routeIsCurrent: currentRouteThreadKeyRef.current === routeThreadKey,
775 + writeComposerRefs: (snapshot) => {
776 + promptRef.current = snapshot.prompt;
777 + composerTerminalContextsRef.current = [...snapshot.terminalContexts];
778 + },
779 writePrompt: (prompt) => setComposerDraftPrompt(composerDraftTarget, prompt),
780 writeTerminalContexts: (contexts) =>
781 setComposerDraftTerminalContexts(composerDraftTarget, [...contexts]),