The best way to control Claude Code, Codex and more from any computer or phone
fix(web): Stop shows a pending state and repeat clicks no longer resume (#20809)
Co-authored-by: Yannic Charlon <52761674+JustYannicc@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
voida6 committed
Nov 11, 2026 at 23:43 UTC
cbc68c9dc1de5d13fadc204188a431a61e157da4
4 files changed
+208
-12
apps/web/src/components/chat/ChatComposer.tsx
+3
@@ -3578,11 +3578,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3578
{composerControls}
3579
</div>
3580
<ComposerFooterPrimaryActions
3581
+ // Stop state belongs to one thread; the composer stays mounted across threads.
3582
+ key={`${environmentId}:${activeThreadId ?? "new"}`}
3583
compact={isComposerPrimaryActionsCompact}
3584
canOperateThread={canOperateThread}
3585
pendingAction={pendingPrimaryAction}
3586
isRunning={phase === "running"}
3587
canInterrupt={canInterrupt}
3588
+ runId={activeThread?.runtime?.activeRunId ?? null}
3589
followUpBehavior={followUpBehavior}
3590
canSteer={canSteer}
3591
alternateShortcutLabel={shortcutLabelForCommand(
apps/web/src/components/chat/ComposerFooterControls.tsx
+2
@@ -199,6 +199,7 @@ export const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryA
199
} | null;
200
isRunning: boolean;
201
canInterrupt: boolean;
202
+ runId: string | null;
203
followUpBehavior: "queue" | "steer";
204
canSteer: boolean;
205
alternateShortcutLabel: string | null;
@@ -226,6 +227,7 @@ export const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryA
227
pendingAction={props.pendingAction}
228
isRunning={props.isRunning}
229
canInterrupt={props.canInterrupt}
230
+ runId={props.runId}
231
followUpBehavior={props.followUpBehavior}
232
canSteer={props.canSteer}
233
alternateShortcutLabel={props.alternateShortcutLabel}
apps/web/src/components/chat/ComposerPrimaryActions.browser.test.tsx
new
+144
@@ -0,0 +1,144 @@
1
+import "~/index.css";
2
+
3
+import type { ComponentProps } from "react";
4
+import { expect, it, vi } from "vite-plus/test";
5
+import { act, fakeTimers, render } from "../../../test/render";
6
+
7
+vi.mock("~/hooks/useSettings", () => ({
8
+ useEnvironmentIdentificationMode: () => "none",
9
+ useClientSettings: () => false,
10
+}));
11
+vi.mock("../SidebarStageBackdrop", () => ({
12
+ StageBackdropButtonArt: () => null,
13
+ useSidebarStageBackdropVariant: () => null,
14
+}));
15
+
16
+import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
17
+
18
+function setup() {
19
+ return {
20
+ compact: true,
21
+ canOperateThread: true,
22
+ pendingAction: null,
23
+ isRunning: true,
24
+ canInterrupt: true,
25
+ canResume: false,
26
+ isSendBusy: false,
27
+ sendDisabledReason: null,
28
+ isEnvironmentUnavailable: false,
29
+ isPreparingWorktree: false,
30
+ hasSendableContent: false,
31
+ onPreviousPendingQuestion: vi.fn(),
32
+ onInterrupt: vi.fn(),
33
+ onResume: vi.fn(),
34
+ onSubmitMessage: vi.fn(),
35
+ } satisfies ComponentProps<typeof ComposerPrimaryActions>;
36
+}
37
+
38
+it.each([false, true])(
39
+ "keeps repeat clicks away from Resume and Send (draft: %s)",
40
+ async (draft) => {
41
+ const props = setup();
42
+ const container = document.createElement("div");
43
+ Object.assign(container.style, { display: "flex", justifyContent: "flex-end", width: "400px" });
44
+ await using screen = await render(<ComposerPrimaryActions {...props} />, { container });
45
+ const stop = screen
46
+ .getByRole("button", { name: "Stop generation" })
47
+ .element() as HTMLButtonElement;
48
+ const { x, y, width, height } = stop.getBoundingClientRect();
49
+ const target = () =>
50
+ document.elementFromPoint(x + width / 2, y + height / 2)?.closest("button");
51
+ await act(() => stop.click());
52
+ await act(() =>
53
+ (
54
+ screen.getByRole("button", { name: "Stopping", exact: true }).element() as HTMLButtonElement
55
+ ).click(),
56
+ );
57
+ await expect
58
+ .element(screen.getByRole("button", { name: "Stopping", exact: true }))
59
+ .toBeDisabled();
60
+ expect(props.onInterrupt).toHaveBeenCalledTimes(1);
61
+ await screen.rerender(
62
+ <ComposerPrimaryActions
63
+ {...props}
64
+ isRunning={false}
65
+ canInterrupt={false}
66
+ canResume
67
+ hasSendableContent={draft}
68
+ />,
69
+ );
70
+ await expect
71
+ .element(screen.getByRole("button", { name: "Stopped", exact: true }))
72
+ .toBeDisabled();
73
+ expect(target()).toHaveAttribute("aria-label", "Stopped");
74
+ await act(() => {
75
+ for (let i = 0; i < 20; i++) target()?.click();
76
+ });
77
+ expect(props.onResume).not.toHaveBeenCalled();
78
+ expect(props.onSubmitMessage).not.toHaveBeenCalled();
79
+ const action = screen
80
+ .getByRole("button", { name: draft ? "Submit message" : "Resume thread" })
81
+ .element() as HTMLButtonElement;
82
+ await act(() => action.click());
83
+ expect(draft ? props.onSubmitMessage : props.onResume).toHaveBeenCalledTimes(1);
84
+ await screen.rerender(<ComposerPrimaryActions {...props} />);
85
+ await expect.element(screen.getByRole("button", { name: "Stop generation" })).toBeEnabled();
86
+ },
87
+);
88
+
89
+it("allows retry after ten seconds and protects a late stop", async () => {
90
+ const props = setup();
91
+ await using screen = await render(<ComposerPrimaryActions {...props} />);
92
+ using _timers = fakeTimers();
93
+ await act(() =>
94
+ (
95
+ screen.getByRole("button", { name: "Stop generation" }).element() as HTMLButtonElement
96
+ ).click(),
97
+ );
98
+ await act(() => vi.advanceTimersByTime(9_999));
99
+ expect(screen.getByRole("button", { name: "Stopping", exact: true }).element()).toBeDisabled();
100
+ await act(() => vi.advanceTimersByTime(1));
101
+ await act(() =>
102
+ (
103
+ screen.getByRole("button", { name: "Stop generation" }).element() as HTMLButtonElement
104
+ ).click(),
105
+ );
106
+ await screen.rerender(
107
+ <ComposerPrimaryActions {...props} isRunning={false} canInterrupt={false} canResume />,
108
+ );
109
+ expect(screen.getByRole("button", { name: "Stopped", exact: true }).element()).toBeDisabled();
110
+ expect(props.onInterrupt).toHaveBeenCalledTimes(2);
111
+ expect(props.onResume).not.toHaveBeenCalled();
112
+});
113
+
114
+it("keeps Stop pending across a permission failure", async () => {
115
+ const props = setup();
116
+ await using screen = await render(<ComposerPrimaryActions {...props} />);
117
+ await act(() =>
118
+ (
119
+ screen.getByRole("button", { name: "Stop generation" }).element() as HTMLButtonElement
120
+ ).click(),
121
+ );
122
+ await screen.rerender(
123
+ <ComposerPrimaryActions {...props} canOperateThread={false} canInterrupt={false} />,
124
+ );
125
+ await screen.rerender(<ComposerPrimaryActions {...props} />);
126
+ await expect
127
+ .element(screen.getByRole("button", { name: "Stopping", exact: true }))
128
+ .toBeDisabled();
129
+ expect(props.onInterrupt).toHaveBeenCalledTimes(1);
130
+});
131
+
132
+it("keeps a pending stop when the run id clears and resets it for a different run", async () => {
133
+ const props = setup();
134
+ await using screen = await render(<ComposerPrimaryActions {...props} runId="first" />);
135
+ await act(() =>
136
+ (
137
+ screen.getByRole("button", { name: "Stop generation" }).element() as HTMLButtonElement
138
+ ).click(),
139
+ );
140
+ await screen.rerender(<ComposerPrimaryActions {...props} runId={null} />);
141
+ expect(screen.getByRole("button", { name: "Stopping", exact: true }).element()).toBeDisabled();
142
+ await screen.rerender(<ComposerPrimaryActions {...props} runId="second" />);
143
+ expect(screen.getByRole("button", { name: "Stop generation" }).element()).toBeEnabled();
144
+});
apps/web/src/components/chat/ComposerPrimaryActions.tsx
+59
-12
@@ -1,4 +1,11 @@
1
-import { memo, type MouseEventHandler, type PointerEventHandler, type ReactNode } from "react";
1
+import {
2
+ memo,
3
+ useEffect,
4
+ useState,
5
+ type MouseEventHandler,
6
+ type PointerEventHandler,
7
+ type ReactNode,
8
+} from "react";
9
import {
10
CheckIcon,
11
ChevronLeftIcon,
@@ -36,6 +43,7 @@ interface ComposerPrimaryActionsProps {
43
pendingAction: PendingActionState | null;
44
isRunning: boolean;
45
canInterrupt: boolean;
46
+ runId?: string | null;
47
followUpBehavior?: "queue" | "steer";
48
canSteer?: boolean;
49
alternateShortcutLabel?: string | null;
@@ -76,6 +84,8 @@ const formatPendingPrimaryActionLabel = (input: {
84
return input.questionIndex > 0 ? "Submit answers" : "Submit answer";
85
};
86
87
+const STOP_PENDING_MAX_MS = 10_000;
88
+
89
const messageActionPillClassName =
90
"inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap rounded-full bg-message-action font-medium text-base text-message-action-foreground shadow-xs shadow-message-action/24 outline-none hover:bg-message-action-hover focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-64 disabled:shadow-none sm:text-sm";
91
@@ -90,6 +100,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
100
pendingAction,
101
isRunning,
102
canInterrupt,
103
+ runId = null,
104
followUpBehavior = "steer",
105
canSteer = true,
106
alternateShortcutLabel = null,
@@ -110,6 +121,26 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
121
keepFullHistory = false,
122
onToggleKeepFullHistory,
123
}: ComposerPrimaryActionsProps) {
124
+ const [stopPhase, setStopPhase] = useState<"pending" | "timedOut" | "landed" | null>(null);
125
+ const [stopRunId, setStopRunId] = useState(runId);
126
+ if (runId !== null && stopRunId !== runId) {
127
+ setStopRunId(runId);
128
+ setStopPhase(null);
129
+ } else if (canOperateThread) {
130
+ // Losing permission also clears canInterrupt; it does not acknowledge the stop.
131
+ if ((stopPhase === "pending" || stopPhase === "timedOut") && !canInterrupt)
132
+ setStopPhase("landed");
133
+ else if (stopPhase === "landed" && canInterrupt) setStopPhase(null);
134
+ }
135
+ const isStopDisabled = stopPhase === "pending" || stopPhase === "landed";
136
+ const stopLabel =
137
+ stopPhase === "landed" ? "Stopped" : stopPhase === "pending" ? "Stopping" : "Stop generation";
138
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- timer that re-enables Stop if the interrupt never settles
139
+ useEffect(() => {
140
+ if (stopPhase !== "pending") return;
141
+ const timeout = setTimeout(() => setStopPhase("timedOut"), STOP_PENDING_MAX_MS);
142
+ return () => clearTimeout(timeout);
143
+ }, [stopPhase]);
144
const pointerFocusProps = preserveComposerFocusOnPointerDown
145
? { onPointerDown: preventPointerFocus }
146
: undefined;
@@ -134,15 +165,17 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
165
<button
166
type="button"
167
className={cn(
137
- "flex shrink-0 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-control-highlight transition-colors duration-150 hover:bg-destructive active:inset-shadow-control-pressed active:shadow-none [&_svg]:pointer-events-none",
168
+ "flex shrink-0 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-control-highlight transition-colors duration-150 hover:bg-destructive active:inset-shadow-control-pressed active:shadow-none disabled:cursor-default disabled:opacity-64 disabled:hover:bg-destructive/90 [&_svg]:pointer-events-none",
169
insidePendingAction ? "size-8 sm:size-7" : "size-8 sm:h-8 sm:w-8",
170
)}
171
{...pointerFocusProps}
141
- disabled={!canOperateThread}
172
+ disabled={!canOperateThread || isStopDisabled}
173
onClick={() => {
143
- if (canOperateThread) onInterrupt();
174
+ if (!canOperateThread || isStopDisabled) return;
175
+ setStopPhase("pending");
176
+ onInterrupt();
177
}}
145
- aria-label="Stop generation"
178
+ aria-label={stopLabel}
179
/>
180
}
181
>
@@ -150,14 +183,23 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
183
<rect x="2" y="2" width="8" height="8" rx="1.5" />
184
</svg>
185
</TooltipTrigger>
153
- <TooltipPopup>Interrupt</TooltipPopup>
186
+ <TooltipPopup>
187
+ {stopPhase === "pending" ? "Stopping…" : stopPhase === "landed" ? "Stopped" : "Interrupt"}
188
+ </TooltipPopup>
189
</Tooltip>
190
);
191
192
+ // Keep the clicked target at the right edge even if typing changes the primary action.
193
+ const withStopButton = (action: ReactNode) => (
194
+ <>
195
+ {action}
196
+ {stopPhase === null ? null : renderStopGenerationButton(false)}
197
+ </>
198
+ );
199
+
200
if (pendingAction) {
201
return (
202
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
160
- {canInterrupt ? renderStopGenerationButton(true) : null}
203
{pendingAction.questionIndex > 0 ? (
204
compact ? (
205
<Button
@@ -205,11 +247,16 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
247
questionIndex: pendingAction.questionIndex,
248
})}
249
</button>
250
+ {canInterrupt || stopPhase !== null ? renderStopGenerationButton(true) : null}
251
</div>
252
);
253
}
254
212
- if (canInterrupt && !hasSendableContent && !isEditingQueuedMessage) {
255
+ if (
256
+ (canInterrupt || stopPhase === "pending" || stopPhase === "timedOut") &&
257
+ !hasSendableContent &&
258
+ !isEditingQueuedMessage
259
+ ) {
260
return (
261
<>
262
{children}
@@ -310,15 +357,15 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
357
</Tooltip>
358
);
359
if (compactTokens === null) {
313
- return (
360
+ return withStopButton(
361
<>
362
{children}
363
{submit}
317
- </>
364
+ </>,
365
);
366
}
367
321
- return (
368
+ return withStopButton(
369
<div data-chat-composer-compact-send="true" className="flex items-center gap-2">
370
<Tooltip>
371
<TooltipTrigger
@@ -351,6 +398,6 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
398
</Tooltip>
399
{children}
400
{submit}
354
- </div>
401
+ </div>,
402
);
403
});