Skip to content

Commit 30ee64d

Browse files
committed
Carry on: hold it back only while its own send is going
Carry on was hidden while any send from this screen was going, so a typed turn that was cut off said it stopped with no Carry on until its stream had closed. WebKit in CI read the notice in that gap (stopped-turn-dismiss-browser). It is now held back only while the send a press of it started is going, which still keeps two presses from making two turns; pressed while a stream is closing, it waits as queued. A test holds a cut-off turn's stream open and checks Carry on is there.
1 parent b40521b commit 30ee64d

2 files changed

Lines changed: 110 additions & 14 deletions

File tree

‎app/src/components/channels/conversation-view.tsx‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,16 @@ export function ConversationView({
497497
* the same way (`StillWorkingError`), and goes again as soon as the Bot is free. Any other failure
498498
* is put back as a failed drain is, and the turn says what went wrong under it.
499499
*
500-
* Offered once: not while its words are already waiting, nor while this screen's own send is
501-
* starting, so two presses never become two turns.
500+
* Offered once: not while its words are already waiting, nor while the send a press started is
501+
* going, so two presses never become two turns. Only that send: a turn the person typed that is
502+
* cut off says so with its Carry on at once, while its stream is still closing, as it always has.
503+
* Pressed then, it waits as queued like anything sent while a turn is in flight.
502504
*/
505+
const [carryOnSending, setCarryOnSending] = useState(false);
503506
const carryOnWaits =
504507
carryOn !== undefined && queued.some((message) => message.text === carryOn);
505508
const pressCarryOn =
506-
carryOn === undefined || carryOnWaits || running
509+
carryOn === undefined || carryOnWaits || carryOnSending
507510
? undefined
508511
: () => {
509512
if (stopIfNeedsCard()) return;
@@ -517,12 +520,23 @@ export function ConversationView({
517520
},
518521
inFlight,
519522
);
520-
void started?.catch((error: unknown) => {
521-
restoreFailedRun(
522-
[{ attachments: [], commandIds: [], id: newId(), text: carryOn }],
523-
error,
524-
);
525-
});
523+
if (!started) return;
524+
setCarryOnSending(true);
525+
void started
526+
.catch((error: unknown) => {
527+
restoreFailedRun(
528+
[
529+
{
530+
attachments: [],
531+
commandIds: [],
532+
id: newId(),
533+
text: carryOn,
534+
},
535+
],
536+
error,
537+
);
538+
})
539+
.finally(() => setCarryOnSending(false));
526540
};
527541

528542
/**

‎app/tests/carry-on-while-busy.test.tsx‎

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ let stored: Message[];
8080
let lastRunEnded: "dropped" | "finished";
8181
/** Every run this page asked the runtime for. */
8282
let runs: RunAgentInput[] = [];
83+
/**
84+
* Set, the next run is cut off part way ("Runner connection dropped") and its stream stays open
85+
* until this settles, as a stream can for a moment after its RUN_ERROR.
86+
*/
87+
let cutOffHeldOpen: Promise<void> | null = null;
8388
let originalFetch: typeof fetch;
8489

8590
function inbox(): ApprovalQueueData & Partial<ApprovalSettingsData> {
@@ -193,6 +198,41 @@ beforeAll(() => {
193198
if (url.pathname.endsWith("/run")) {
194199
const body = (await request.json()) as RunAgentInput;
195200
runs.push(body);
201+
if (cutOffHeldOpen) {
202+
const held = cutOffHeldOpen;
203+
cutOffHeldOpen = null;
204+
const said = [
205+
{ type: "RUN_STARTED", threadId: body.threadId, runId: body.runId },
206+
{
207+
type: "TEXT_MESSAGE_START",
208+
messageId: `reply-${body.runId}`,
209+
role: "assistant",
210+
},
211+
{
212+
type: "TEXT_MESSAGE_CONTENT",
213+
messageId: `reply-${body.runId}`,
214+
delta: "Reading the second transcript now.",
215+
},
216+
{ type: "TEXT_MESSAGE_END", messageId: `reply-${body.runId}` },
217+
{ type: "RUN_ERROR", message: "Runner connection dropped" },
218+
];
219+
return new NativeResponse(
220+
new ReadableStream({
221+
async start(controller) {
222+
controller.enqueue(
223+
new TextEncoder().encode(
224+
said
225+
.map((event) => `data: ${JSON.stringify(event)}\n\n`)
226+
.join(""),
227+
),
228+
);
229+
await held;
230+
controller.close();
231+
},
232+
}),
233+
{ headers: { "content-type": "text/event-stream" } },
234+
);
235+
}
196236
return sse([
197237
{
198238
type: "RUN_STARTED",
@@ -284,12 +324,14 @@ afterAll(async () => {
284324
GlobalRegistrator.unregister();
285325
});
286326

287-
function mounting() {
288-
status = "pending";
289-
decidedAt = null;
290-
stored = [ask, send];
291-
lastRunEnded = "dropped";
327+
/** `idle`: the DM was sent and the thread's last run finished, so nothing waits and nothing stopped. */
328+
function mounting(idle = false) {
329+
status = idle ? "completed" : "pending";
330+
decidedAt = idle ? "2026-12-02T05:16:00.000Z" : null;
331+
stored = idle ? [ask, send, sent] : [ask, send];
332+
lastRunEnded = idle ? "finished" : "dropped";
292333
runs = [];
334+
cutOffHeldOpen = null;
293335
queryClient.setQueryData(channelKeys.list(), {
294336
pages: [
295337
{
@@ -379,3 +421,43 @@ test("Carry on pressed while the server still has the turn waits as a queued mes
379421
await act(() => Bun.sleep(1_000));
380422
expect(runs).toHaveLength(1);
381423
}, 30_000);
424+
425+
/*
426+
* FOUND IN CI, on this change before it was merged: Carry on was hidden for as long as any send from
427+
* this screen was going, so a turn the person typed that was cut off said it stopped with no Carry
428+
* on until its stream had closed. On a busy machine WebKit read the notice in that gap. Carry on is
429+
* held back only while the send a press of it started is going.
430+
*/
431+
test("a typed turn cut off part way says so with its Carry on at once, while its stream is still closing", async () => {
432+
const view = mounting(true);
433+
const user = userEvent.setup({ document: view.container.ownerDocument });
434+
await view.findByText(ask.content, {}, { timeout: 10_000 });
435+
await waitFor(() =>
436+
expect(view.queryByTestId("transcript-stopped")).toBeNull(),
437+
);
438+
439+
const closing = Promise.withResolvers<void>();
440+
cutOffHeldOpen = closing.promise;
441+
try {
442+
await user.type(
443+
await view.findByRole("textbox", { name: "Message" }),
444+
"Now the second transcript, please.",
445+
);
446+
await user.click(view.getByRole("button", { name: "Send message" }));
447+
448+
const stopped = await view.findByTestId(
449+
"transcript-stopped",
450+
{},
451+
{ timeout: 10_000 },
452+
);
453+
expect(stopped.textContent).toContain(TURN_INTERRUPTED);
454+
// Its run's stream is still open here, so this screen's send has not settled.
455+
expect(runs).toHaveLength(1);
456+
expect(
457+
within(stopped).queryByRole("button", { name: "Carry on" }),
458+
).not.toBeNull();
459+
} finally {
460+
closing.resolve();
461+
}
462+
await act(() => settleReactWork());
463+
}, 30_000);

0 commit comments

Comments
 (0)