Skip to content

Commit cd049fc

Browse files
voida6JustYannicc
andcommitted
fix(web): keep repeat Stop clicks away from Resume
The one-second Resume guard still resumed the run when repeat Stop clicks outlasted it. Keep the stopped button disabled in its slot and show Resume beside it, so no amount of clicking on the old target resumes. Key the footer actions by thread so a pending stop does not carry over to another thread, since the composer stays mounted across threads. Co-authored-by: Yannic Charlon <[email protected]>
1 parent b8a4ef6 commit cd049fc

3 files changed

Lines changed: 39 additions & 18 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7262,6 +7262,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
72627262
</>
72637263
) : null}
72647264
<ComposerFooterPrimaryActions
7265+
// Stop state belongs to one thread; the composer stays mounted across threads.
7266+
key={activeThreadId ?? "new"}
72657267
compact={isComposerResting || isComposerPrimaryActionsCompact}
72667268
canOperateThread={canOperateThread}
72677269
activeContextWindow={

‎apps/web/src/components/chat/ComposerPrimaryActions.test.tsx‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ describe("ComposerPrimaryActions", () => {
111111
});
112112

113113
describe("ComposerPrimaryActions stop pending state", () => {
114+
const onInterrupt = vi.fn();
115+
const onResume = vi.fn();
114116
function runningProps(canInterrupt: boolean) {
115117
return {
116118
compact: true,
@@ -128,8 +130,8 @@ describe("ComposerPrimaryActions stop pending state", () => {
128130
isPreparingWorktree: false,
129131
hasSendableContent: false,
130132
onPreviousPendingQuestion: () => {},
131-
onInterrupt: () => {},
132-
onResume: () => {},
133+
onInterrupt,
134+
onResume,
133135
onImplementPlanInNewThread: () => {},
134136
};
135137
}
@@ -142,6 +144,8 @@ describe("ComposerPrimaryActions stop pending state", () => {
142144
const clickStop = () => act(() => slot().click());
143145

144146
beforeEach(() => {
147+
onInterrupt.mockClear();
148+
onResume.mockClear();
145149
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
146150
vi.useFakeTimers();
147151
container = document.createElement("div");
@@ -156,15 +160,21 @@ describe("ComposerPrimaryActions stop pending state", () => {
156160
vi.unstubAllGlobals();
157161
});
158162

159-
it("blocks Resume briefly after a stop lands so repeat clicks do not resume", () => {
163+
it("keeps repeat Stop clicks inert after the stop lands, with a separate Resume target", () => {
160164
clickStop();
161165
expect(slot()).toMatchObject({ ariaLabel: "Stopping", disabled: true });
162166

163167
render(false);
164-
expect(slot()).toMatchObject({ ariaLabel: "Resume thread", disabled: true });
165-
166-
act(() => vi.advanceTimersByTime(1_000));
167-
expect(slot().disabled).toBe(false);
168+
act(() => vi.advanceTimersByTime(1_100));
169+
for (let i = 0; i < 20; i++) clickStop();
170+
expect(onInterrupt).toHaveBeenCalledTimes(1);
171+
expect(onResume).not.toHaveBeenCalled();
172+
expect(slot()).toMatchObject({ ariaLabel: "Stopped", disabled: true });
173+
174+
const resume = container.querySelector<HTMLButtonElement>('button[aria-label="Resume thread"]');
175+
expect(resume?.disabled).toBe(false);
176+
act(() => resume?.click());
177+
expect(onResume).toHaveBeenCalledTimes(1);
168178
});
169179

170180
it("enables Stop at once for a new run started after the stop lands", () => {

‎apps/web/src/components/chat/ComposerPrimaryActions.tsx‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ const formatPendingPrimaryActionLabel = (input: {
7373
return input.questionIndex > 0 ? "Submit answers" : "Submit answer";
7474
};
7575

76-
// A stop can take seconds to land, and then this slot becomes Resume, so
77-
// repeat Stop clicks would resume the run. Stop re-enables if it never lands.
76+
// A stop can take seconds to land. Stop re-enables if it never lands.
7877
const STOP_PENDING_MAX_MS = 10_000;
79-
const RESUME_AFTER_STOP_GUARD_MS = 1_000;
8078

8179
const messageActionPillClassName =
8280
"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";
@@ -120,11 +118,8 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
120118
else if (stopPhase === "landed" && canInterrupt) setStopPhase(null);
121119
const isStopping = stopPhase !== null;
122120
useEffect(() => {
123-
if (stopPhase === null) return;
124-
const timeout = setTimeout(
125-
() => setStopPhase(null),
126-
stopPhase === "pending" ? STOP_PENDING_MAX_MS : RESUME_AFTER_STOP_GUARD_MS,
127-
);
121+
if (stopPhase !== "pending") return;
122+
const timeout = setTimeout(() => setStopPhase(null), STOP_PENDING_MAX_MS);
128123
return () => clearTimeout(timeout);
129124
}, [stopPhase]);
130125
const pointerFocusProps = preserveComposerFocusOnPointerDown
@@ -163,15 +158,19 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
163158
setStopPhase("pending");
164159
onInterrupt();
165160
}}
166-
aria-label={isStopping ? "Stopping" : "Stop generation"}
161+
aria-label={
162+
stopPhase === "landed" ? "Stopped" : isStopping ? "Stopping" : "Stop generation"
163+
}
167164
/>
168165
}
169166
>
170167
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
171168
<rect x="2" y="2" width="8" height="8" rx="1.5" />
172169
</svg>
173170
</TooltipTrigger>
174-
<TooltipPopup>{isStopping ? "Stopping…" : "Interrupt"}</TooltipPopup>
171+
<TooltipPopup>
172+
{stopPhase === "landed" ? "Stopped" : isStopping ? "Stopping…" : "Interrupt"}
173+
</TooltipPopup>
175174
</Tooltip>
176175
);
177176

@@ -340,7 +339,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
340339
isSendDisabled ||
341340
isConnecting ||
342341
isEnvironmentUnavailable ||
343-
(showResume && isStopping) ||
342+
(showResume && stopPhase === "pending") ||
344343
(!hasSendableContent && !showResume)
345344
}
346345
aria-label={submitStatus ?? submitLabel}
@@ -378,6 +377,16 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
378377
<TooltipPopup>{submitTooltip}</TooltipPopup>
379378
</Tooltip>
380379
);
380+
// Repeat Stop clicks can outlast any cooldown, so the stopped button keeps its slot
381+
// and Resume appears beside it.
382+
if (showResume && stopPhase === "landed") {
383+
return (
384+
<div className="flex items-center gap-2">
385+
{submit}
386+
{renderStopGenerationButton(false)}
387+
</div>
388+
);
389+
}
381390
if (compactTokens === null) return submit;
382391

383392
return (

0 commit comments

Comments
 (0)