@@ -80,6 +80,11 @@ let stored: Message[];
8080let lastRunEnded : "dropped" | "finished" ;
8181/** Every run this page asked the runtime for. */
8282let 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 ;
8388let originalFetch : typeof fetch ;
8489
8590function 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