Skip to content

Commit 60d547a

Browse files
committed
fix(web): treat a stop that lands after the timeout as landed
A stop that landed after the 10 s fallback reset the slot to a plain Resume button, so repeat Stop clicks could resume the thread. The timeout now moves to a timed-out phase that keeps Stop retryable and still transitions to landed when the run stops.
1 parent cd049fc commit 60d547a

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,24 @@ describe("ComposerPrimaryActions stop pending state", () => {
191191
act(() => vi.advanceTimersByTime(10_000));
192192
expect(slot()).toMatchObject({ ariaLabel: "Stop generation", disabled: false });
193193
});
194+
195+
it("keeps repeat Stop clicks away from Resume when the stop lands after the timeout", () => {
196+
clickStop();
197+
act(() => vi.advanceTimersByTime(10_000));
198+
199+
render(false);
200+
for (let i = 0; i < 20; i++) clickStop();
201+
expect(onInterrupt).toHaveBeenCalledTimes(1);
202+
expect(onResume).not.toHaveBeenCalled();
203+
expect(slot()).toMatchObject({ ariaLabel: "Stopped", disabled: true });
204+
});
205+
206+
it("sends Stop again after the timeout and waits for it to land", () => {
207+
clickStop();
208+
act(() => vi.advanceTimersByTime(10_000));
209+
210+
clickStop();
211+
expect(onInterrupt).toHaveBeenCalledTimes(2);
212+
expect(slot()).toMatchObject({ ariaLabel: "Stopping", disabled: true });
213+
});
194214
});

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

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

76-
// A stop can take seconds to land. Stop re-enables if it never lands.
76+
// A stop can take seconds to land. Stop re-enables if it never lands, but a late
77+
// landing still counts as landed so Resume does not take the Stop slot.
7778
const STOP_PENDING_MAX_MS = 10_000;
7879

7980
const messageActionPillClassName =
@@ -112,14 +113,15 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
112113
keepFullHistory = false,
113114
onToggleKeepFullHistory,
114115
}: ComposerPrimaryActionsProps) {
115-
const [stopPhase, setStopPhase] = useState<"pending" | "landed" | null>(null);
116+
const [stopPhase, setStopPhase] = useState<"pending" | "timedOut" | "landed" | null>(null);
116117
// Once the stop has landed, interruptible again means a new run started.
117-
if (stopPhase === "pending" && !canInterrupt) setStopPhase("landed");
118+
if ((stopPhase === "pending" || stopPhase === "timedOut") && !canInterrupt)
119+
setStopPhase("landed");
118120
else if (stopPhase === "landed" && canInterrupt) setStopPhase(null);
119-
const isStopping = stopPhase !== null;
121+
const isStopping = stopPhase === "pending" || stopPhase === "landed";
120122
useEffect(() => {
121123
if (stopPhase !== "pending") return;
122-
const timeout = setTimeout(() => setStopPhase(null), STOP_PENDING_MAX_MS);
124+
const timeout = setTimeout(() => setStopPhase("timedOut"), STOP_PENDING_MAX_MS);
123125
return () => clearTimeout(timeout);
124126
}, [stopPhase]);
125127
const pointerFocusProps = preserveComposerFocusOnPointerDown

0 commit comments

Comments
 (0)