diff --git a/agent-langgraph-agui/src/tool_runtime.py b/agent-langgraph-agui/src/tool_runtime.py index 73356cb6d8..42f74142c3 100644 --- a/agent-langgraph-agui/src/tool_runtime.py +++ b/agent-langgraph-agui/src/tool_runtime.py @@ -292,7 +292,13 @@ def model_unreachable(error: BaseException) -> bool: The SDKs' own classes, and httpx's for an SDK that lets them through (Google's). A tool's call never raises one here: `_call_tool` answers its own transport errors. + + Not a connection that broke part way: the OpenAI SDK raises the same `APIConnectionError` + ("Connection error.") for a stream reset while it reads, from httpx's `ReadError`, and the + person was told OpenBot couldn't reach a model that had already answered part way. """ + if dropped_connection(error): + return False unreached = [] for module, names in ( ("openai", ("APIConnectionError",)), # `APITimeoutError` is one. @@ -332,6 +338,50 @@ def model_address(error: BaseException) -> str | None: return None +def dropped_connection(error: BaseException) -> str | None: + """The code of a connection to the model that broke part way through its answer, or None. + + The answer had begun, so somebody was there: not a model nothing answered at, and not a + provider's refusal, since nobody said anything. httpx raises `ReadError` ("[Errno 54] Connection + reset by peer") or `RemoteProtocolError` ("peer closed connection without sending complete + message body") from inside the stream the SDK is reading. Before, the run ended with + `RUN_FAILED`. Found on OpenBot Cloud with the TypeScript engine, 2026-12-03: OpenAI's stream + broke while a Bot was writing a Google Slides deck into a call, and the person read "The Bot + stopped before it finished answering" with no way on. + + A tool's call never raises one here: `_call_tool` answers its own transport errors. + """ + cut = [] + for module, names in ( + ("httpx", ("ReadError", "RemoteProtocolError", "WriteError")), + ("httpx2", ("ReadError", "RemoteProtocolError", "WriteError")), + ): + try: + loaded = __import__(module) + except ImportError: + continue + cut.extend(getattr(loaded, name) for name in names if hasattr(loaded, name)) + links = list(_links(error)) + broken = next((link for link in links if isinstance(link, tuple(cut))), None) + if broken is None: + return None + reset = any(isinstance(link, ConnectionResetError) for link in links) or ( + "reset by peer" in str(broken).lower() + ) + return "ECONNRESET" if reset else type(broken).__name__ + + +def dropped_message(code: str, provider: str) -> str: + """The words a dropped connection ends the run with. + + The server reads "Connection dropped" as one (`connection_dropped` in provider-refusal.ts), as it + reads Claude Code's "API Error: Connection dropped (ECONNRESET)", and tells the person the + connection to their model dropped, with Carry on: the turn may already have done work. + """ + who = "your model provider" if provider == "Your model provider" else provider + return f"Connection dropped ({code}) before {who} finished answering." + + # What the run ends with when nothing answered at the model's address, coded so the server can put # the step that fits its edition in place of the second sentence (it reads the address back out of # the first). The step here is right wherever the model is set. @@ -432,6 +482,17 @@ async def run(self, input: RunAgentInput): message=unreachable_message(address), code=MODEL_UNREACHABLE, ) + elif dropped := dropped_connection(error): + # Coded as a refusal so the server reads the words, which say the connection + # dropped. Not `server_error`: behind OpenBot's sign-in proxy the server lets that + # category decide, and the person would read that the provider is having problems. + logger.warning("The connection to the model dropped part way: %r", error) + yield RunErrorEvent( + type=EventType.RUN_ERROR, + message=dropped_message(dropped, provider_name()), + code="OPENBOT_MODEL_REFUSED", + metadata={"errorCategory": "unknown"}, + ) elif provider_refusal(error): # Raised, it ended the response stream after RUN_STARTED with no terminal event, # and the provider's reason never reached anyone. Coded as a refusal, so the server diff --git a/agent-langgraph-agui/tests/test_tool_protocol.py b/agent-langgraph-agui/tests/test_tool_protocol.py index d9d9eb4c6b..dc32f6583a 100644 --- a/agent-langgraph-agui/tests/test_tool_protocol.py +++ b/agent-langgraph-agui/tests/test_tool_protocol.py @@ -6,6 +6,8 @@ import asyncio import json +import socket +import struct import sys import time from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer @@ -206,7 +208,11 @@ def do_POST(self): ) if captured.get("text_with_tools"): parts[0]["content"] = "Using the computer." - for part, reason in [*((part, None) for part in parts), ({}, finish)]: + cut = captured.get("cut") + frames = [*((part, None) for part in parts)] + if not cut: + frames.append(({}, finish)) + for part, reason in frames: chunk = { "id": "response-proof", "object": "chat.completion.chunk", @@ -215,8 +221,25 @@ def do_POST(self): "choices": [{"index": 0, "delta": part, "finish_reason": reason}], } self.wfile.write(("data: " + json.dumps(chunk) + "\n\n").encode()) + if cut: + # The provider's stream breaks part way, after the call's arguments began: a TCP + # reset, as OpenBot Cloud's engine read one (`ECONNRESET`). No finish, no [DONE]. + self.wfile.flush() + time.sleep(0.05) + self.connection.setsockopt( + socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0) + ) + self.connection.close() + self.close_connection = True + return self.wfile.write(b"data: [DONE]\n\n") + def finish(self): + try: + super().finish() + except OSError: + pass # A connection this handler reset on purpose (`cut`). + def log_message(self, *_args): pass @@ -495,6 +518,35 @@ async def test_a_model_host_that_does_not_exist_is_told_the_same_way(boundary, m ) +@pytest.mark.asyncio +async def test_a_stream_that_breaks_part_way_through_a_call_says_the_connection_dropped(boundary): + """Found on OpenBot Cloud, 2026-12-03: a Bot said a line and was writing a Google Slides deck + into a call's arguments when the provider's stream broke. The person read "The Bot stopped + before it finished answering. Try again." with no way on. The connection dropped, and the run + says so in the words the server tells as one, with Carry on (provider-refusal.ts).""" + boundary.update(text_with_tools=True, shape="interleaved", cut=True) + events = await run_protocol( + run_input(["GOOGLESLIDES_CREATE_SLIDES_MARKDOWN"]), allow_error=True + ) + types = [event["type"] for event in events] + # What the person saw before it broke stays: the line and the call it was making. + assert "TEXT_MESSAGE_CONTENT" in types and "TOOL_CALL_START" in types, types + assert types.count("RUN_ERROR") == 1 and types[-1] == "RUN_ERROR", events[-1] + assert events[-1]["code"] == "OPENBOT_MODEL_REFUSED" + assert events[-1]["metadata"] == {"errorCategory": "unknown"} + # An OpenAI-compatible base URL that is not OpenAI's names nobody. + assert events[-1]["message"] == ( + "Connection dropped (ECONNRESET) before your model provider finished answering." + ) + # Nothing ran: the call never finished, so it never reached OpenBot. + assert not boundary["callback"] + + # Carry on: the next run answers. + boundary["cut"] = False + events = await run_protocol(run_input([])) + assert events[-1]["type"] == "RUN_FINISHED" + + def test_a_model_that_never_answers_in_time_is_unreachable_too(): """A timeout is the third way an address can't be reached, and is told the same way.""" import openai diff --git a/agent-langgraph-ts/src/errors.ts b/agent-langgraph-ts/src/errors.ts index 0fe5b09fd8..b9a0ebbb9d 100644 --- a/agent-langgraph-ts/src/errors.ts +++ b/agent-langgraph-ts/src/errors.ts @@ -108,6 +108,15 @@ const NOT_CONNECTED = new Set([ "EAI_AGAIN", ]); +/** + * A connection that broke after the model's answer began, by the codes and words Node's and + * undici's fetch give it: undici's "terminated" around a socket's `ECONNRESET`, "other side closed" + * (`UND_ERR_SOCKET`), Node's "socket hang up". The same as the server's `BROKEN_SOCKET`. + */ +const CUT_CODES = new Set(["ECONNRESET", "EPIPE", "UND_ERR_SOCKET"]); +const CUT_WORDS = + /^terminated$|other side closed|socket hang up|socket connection was closed unexpectedly/i; + type Link = Record & { message?: unknown; name?: unknown }; /** The error and every error it was raised from. */ @@ -300,6 +309,44 @@ export function unreached(error: unknown): boolean { }); } +/** + * The code of a connection to the model that broke part way through its answer, or undefined. + * + * FOUND ON OPENBOT CLOUD, 2026-12-03. A Bot on GPT-6.1 Terra had said a line and was writing a + * Google Slides deck into a call's arguments when OpenAI's stream broke 44 seconds in. The model + * gateway's answer broke with it, and this engine's fetch threw undici's `TypeError: terminated`, + * caused by `read ECONNRESET`. That has no status and is not a connection that never opened, so the + * run ended with `RUN_FAILED`, and the person read "The Bot stopped before it finished answering" + * with no way on. + * + * Inside a run the only connection is the model's: OpenBot's tools go back to the caller as + * pending calls, and the one tool answered here (recall) reads memory. A stop the caller asked for + * aborts, and is the caller's, not the connection's. + */ +export function droppedConnection(error: unknown): string | undefined { + const chain = links(error); + if (chain.some((link) => link.name === "AbortError")) return undefined; + for (const link of chain) + if (typeof link.code === "string" && CUT_CODES.has(link.code)) + return link.code; + for (const link of chain) + if (typeof link.message === "string" && CUT_WORDS.test(link.message.trim())) + return link.message.trim(); + return undefined; +} + +/** + * The words a dropped connection ends the run with. The server reads "Connection dropped" as one + * (`connection_dropped` in provider-refusal.ts), as it reads Claude Code's "API Error: Connection + * dropped (ECONNRESET)", and tells the person the connection to their model dropped, with Carry + * on: the turn may already have done work, so it is carried on rather than sent again. + */ +export function droppedMessage(code: string, provider: string): string { + const who = + provider === "Your model provider" ? "your model provider" : provider; + return `Connection dropped (${code}) before ${who} finished answering.`; +} + /** * Where the model was dialled, as host and port only: a base URL can carry a user and password, * and some gateways put a key in the path. Nothing for OpenBot's own sign-in proxy, whose address @@ -406,5 +453,16 @@ export function runFailure( }; } + const dropped = droppedConnection(error); + if (dropped) { + return { + message: droppedMessage(dropped, context.provider), + code: MODEL_REFUSED, + // Not `server_error`: behind OpenBot's sign-in proxy the server lets that category decide + // (`PROXY_DECIDES`), and the person would read that the provider is having problems. + category: "unknown", + }; + } + return { message: RUN_FAILED }; } diff --git a/agent-langgraph-ts/src/run.ts b/agent-langgraph-ts/src/run.ts index d81411a428..4612d62c0c 100644 --- a/agent-langgraph-ts/src/run.ts +++ b/agent-langgraph-ts/src/run.ts @@ -75,7 +75,9 @@ import { withRecall, } from "./context-room.ts"; import { + droppedConnection, MessageTooLongError, + MODEL_REFUSED, ModelDeclinedError, runFailure, } from "./errors.ts"; @@ -739,7 +741,10 @@ export async function runAgent( } catch (error) { if (options.signal?.aborted) return; const failure = runFailure(error, failureContext(env, choice)); - if (failure.code) + // Not a refusal: nobody said anything, and the error is what shows where it broke. + if (droppedConnection(error) && failure.code === MODEL_REFUSED) + log.warn("The connection to the model dropped part way", error); + else if (failure.code) log.warn(`The model provider refused the run: ${failure.message}`); else log.error("The run failed before it finished", error); emit({ diff --git a/agent-langgraph-ts/test/errors.test.ts b/agent-langgraph-ts/test/errors.test.ts index 988a5048b8..c4ab1767b0 100644 --- a/agent-langgraph-ts/test/errors.test.ts +++ b/agent-langgraph-ts/test/errors.test.ts @@ -435,3 +435,44 @@ test("Nothing answering at the model's address says where it was dialled, and no `OpenBot couldn't reach the AI model at 127.0.0.1:${port}. Check that it's running and the address is right.`, ); }); + +/* + * A provider's stream that breaks part way: the answer had begun, a line said and a call's + * arguments under way, and then the connection was reset. Not a refusal and not a model nothing + * answered at: the connection dropped, in the words the server tells as one, with Carry on. Before, + * every wire ended with "The Bot stopped before it finished answering. Try again." + */ +const CUT: { name: string; provider: Provider; who: string }[] = [ + // An OpenAI-compatible base URL that is not OpenAI's names nobody. + { + name: "OpenAI Chat Completions", + provider: "openai", + who: "your model provider", + }, + { name: "Anthropic Messages", provider: "anthropic", who: "Anthropic" }, + { name: "Gemini", provider: "google", who: "Google" }, +]; + +for (const each of CUT) { + test(`${each.name}: a connection reset part way through a call ends the run saying the connection dropped`, async () => { + const error = await runError(each.provider, { + text: "I'll make the deck now.", + calls: [ + { + id: "call_deck", + name: "get_weather", + args: { city: "A long argument ".repeat(200) }, + }, + ], + cut: true, + }); + assert.equal(error.code, "OPENBOT_MODEL_REFUSED"); + assert.equal(error.metadata?.errorCategory, "unknown"); + assert.match( + error.message, + new RegExp( + `^Connection dropped \\((ECONNRESET|terminated|other side closed|UND_ERR_SOCKET)\\) before ${each.who} finished answering\\.$`, + ), + ); + }); +} diff --git a/agent-langgraph-ts/test/fake-provider.ts b/agent-langgraph-ts/test/fake-provider.ts index e83874f53e..ff211960de 100644 --- a/agent-langgraph-ts/test/fake-provider.ts +++ b/agent-langgraph-ts/test/fake-provider.ts @@ -35,7 +35,19 @@ export type Call = { */ export type Thinking = { thinking: string; signature: string }; export type Turn = - | { text?: string; calls?: Call[]; stop?: string; thinking?: Thinking[] } + | { + text?: string; + calls?: Call[]; + stop?: string; + thinking?: Thinking[]; + /** + * The connection is reset part way (a TCP RST, so the engine's fetch reads `ECONNRESET`, as on + * OpenBot Cloud when a provider's stream broke under a call): the stream is sent up to and + * including the first frame that carries a call's arguments, or half its frames where there + * is no call, and then the socket is reset. Nothing after it, not even the stream's end. + */ + cut?: true; + } | { status: number; body: unknown } /** * A 200 whose stream begins, says `text` if there is any, and then carries the provider's error @@ -57,11 +69,26 @@ export type FakeProvider = { close: () => Promise; }; -function sse(response: ServerResponse, frames: string[]) { +/** Where a cut stream stops: after the first frame with a call's arguments in it. */ +const ARGUMENTS_FRAME = + /function_call_arguments\.delta|input_json_delta|"arguments":"(?!")/; + +function sse(response: ServerResponse, frames: string[], cut?: true) { response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", }); + if (cut) { + const at = frames.findIndex((frame) => ARGUMENTS_FRAME.test(frame)); + const sent = frames.slice( + 0, + at >= 0 ? at + 1 : Math.ceil(frames.length / 2), + ); + for (const frame of sent) response.write(frame); + // Let what was sent reach the reader before the reset, which would throw away anything unsent. + setTimeout(() => response.socket?.resetAndDestroy(), 50); + return; + } for (const frame of frames) response.write(frame); response.end(); } @@ -73,7 +100,7 @@ const named = (name: string, value: unknown) => function chatCompletions( response: ServerResponse, body: Record, - turn: { text?: string; calls?: Call[] }, + turn: { text?: string; calls?: Call[]; cut?: true }, ) { const model = String(body.model ?? "model"); const base = { @@ -189,13 +216,13 @@ function chatCompletions( }), ); frames.push("data: [DONE]\n\n"); - sse(response, frames); + sse(response, frames, turn.cut); } function responses( response: ServerResponse, body: Record, - turn: { text?: string; calls?: Call[] }, + turn: { text?: string; calls?: Call[]; cut?: true }, ) { const model = String(body.model ?? "model"); const output: Record[] = []; @@ -305,13 +332,20 @@ function responses( events.map((event, index) => named(String(event.type), { ...event, sequence_number: index }), ), + turn.cut, ); } function anthropic( response: ServerResponse, body: Record, - turn: { text?: string; calls?: Call[]; stop?: string; thinking?: Thinking[] }, + turn: { + text?: string; + calls?: Call[]; + stop?: string; + thinking?: Thinking[]; + cut?: true; + }, ) { const message = { id: "msg_fake", @@ -419,12 +453,12 @@ function anthropic( }), ); frames.push(named("message_stop", { type: "message_stop" })); - sse(response, frames); + sse(response, frames, turn.cut); } function gemini( response: ServerResponse, - turn: { text?: string; calls?: Call[]; stop?: string }, + turn: { text?: string; calls?: Call[]; stop?: string; cut?: true }, ) { const frames: string[] = []; if (turn.text) { @@ -480,7 +514,7 @@ function gemini( modelVersion: "gemini-fake", }), ); - sse(response, frames); + sse(response, frames, turn.cut); } /** diff --git a/agent-langgraph-ts/test/model-gateway.ts b/agent-langgraph-ts/test/model-gateway.ts index 55eaacb59d..8b93f6c8f8 100644 --- a/agent-langgraph-ts/test/model-gateway.ts +++ b/agent-langgraph-ts/test/model-gateway.ts @@ -7,7 +7,7 @@ * - Auth: `Authorization: Bearer ` or `x-api-key: `, `` one of the run tokens it minted. * - Per request: the connection as it stands now, the caller's auth headers stripped, the * connection's key added, sent to the connection's upstream (never one the request names) with - * `redirect: "error"`, and the answer streamed back as it came. + * `redirect: "error"`, and the answer streamed back as it came, broken where the provider's broke. * - A wire the connection can't serve: 409 with a plain sentence, in that wire's error shape, and * `x-should-retry: false` so neither SDK asks again. * @@ -196,7 +196,15 @@ export async function modelGateway( } response.writeHead(reply.status, passed); if (!reply.body) return response.end(); - Readable.fromWeb(reply.body as never).pipe(response); + const body = Readable.fromWeb(reply.body as never); + /* + * A provider's stream that breaks part way breaks the answer with it, as the server's gateway + * errors its body (`watched` in gateway.ts). Seen on OpenBot Cloud: the gateway logged the + * stream ended by the provider, and 4 ms later the engine's fetch read `ECONNRESET`. `pipe` + * alone would leave the engine waiting on an answer that never ends. + */ + body.on("error", () => response.socket?.resetAndDestroy()); + body.pipe(response); }); await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); const { port } = server.address() as AddressInfo; diff --git a/agent-langgraph-ts/test/model-route.test.ts b/agent-langgraph-ts/test/model-route.test.ts index 17da22fe11..9922b27efc 100644 --- a/agent-langgraph-ts/test/model-route.test.ts +++ b/agent-langgraph-ts/test/model-route.test.ts @@ -637,3 +637,111 @@ test("Neither the run's token nor its forwardedProps reach the log, whatever fai "forwardedProps are never logged", ); }); + +/* + * FOUND ON OPENBOT CLOUD, 2026-12-03. A Bot on GPT-6.1 Terra, on the gateway's /v1/responses, said + * "I'll make a short call deck…" and was writing the deck into a Google Slides call's arguments + * when OpenAI's stream broke, 44 seconds in. The engine's fetch read `TypeError: terminated` (read + * ECONNRESET), and the person read "The Bot stopped before it finished answering. Try again.", with + * no way on. The server tells a dropped connection as one, with Carry on, when the engine says so. + */ +const SLIDES_TOOL = { + name: "GOOGLESLIDES_CREATE_SLIDES_MARKDOWN", + description: "Create a Google Slides presentation from Markdown.", + parameters: { + type: "object", + properties: { title: { type: "string" }, markdown: { type: "string" } }, + required: ["title", "markdown"], + }, +}; + +const DECK = Array.from( + { length: 40 }, + (_, slide) => + `## Slide ${slide + 1}\n\n- Spotify's use case\n- The Java/ADK POC\n- Open question ${slide + 1}`, +).join("\n\n---\n\n"); + +test("A model's stream that breaks part way through a call on the gateway's /v1/responses ends the run saying the connection dropped, and carrying on answers", async () => { + if (live) return; // A broken stream is the fake provider's to script. + const cut: Responder = (request, index) => + index === 0 + ? { + text: "I'll make a short call deck around Spotify's use case and the Java/ADK POC.", + calls: [ + { + id: "call_slides", + name: SLIDES_TOOL.name, + args: { title: "Spotify call", markdown: DECK }, + }, + ], + cut: true, + } + : pineapple(request, index); + await withGateway( + "openai", + async (gateway) => { + gateway.mint("run-token-cut"); + const forwardedProps = { + openbotModel: { model: RESPONSES_MODEL, reasoningEffort: "low" }, + openbotModelRoute: { via: "openai", token: "run-token-cut" }, + }; + const first = await withEngine({ env: engineEnv(gateway.url) }, (base) => + run(base, ask({ tools: [SLIDES_TOOL], forwardedProps })), + ); + assert.equal( + gateway.requests[0]!.path, + "/api/model-provider/v1/responses", + ); + // What the person saw before it broke stays: the line and the call it was making. + assert.match(words(first.events), /short call deck/); + assert.ok( + first.events.some( + (event) => + event.type === "TOOL_CALL_START" && + (event as { toolCallName?: string }).toolCallName === + SLIDES_TOOL.name, + ), + "the call it was writing was shown", + ); + const errors = first.events.filter((event) => event.type === "RUN_ERROR"); + assert.equal(errors.length, 1, inspect(first.events.at(-1))); + const error = first.events.at(-1) as unknown as { + type: string; + message: string; + code?: string; + metadata?: { errorCategory?: string }; + }; + assert.equal(error.type, "RUN_ERROR"); + assert.equal(error.code, "OPENBOT_MODEL_REFUSED"); + assert.equal(error.metadata?.errorCategory, "unknown"); + // Behind the gateway the engine can't tell which OpenAI-compatible provider answers; the + // server, which can, names it in the sentence the person reads. + assert.equal( + error.message, + "Connection dropped (ECONNRESET) before your model provider finished answering.", + ); + + // Carry on: the next run on the same engine is answered. + gateway.mint("run-token-on"); + const next = await withEngine({ env: engineEnv(gateway.url) }, (base) => + run( + base, + ask({ + runId: "run-2", + forwardedProps: { + ...forwardedProps, + openbotModelRoute: { via: "openai", token: "run-token-on" }, + }, + }), + ), + ); + assert.equal( + next.events.at(-1)?.type, + "RUN_FINISHED", + inspect(next.events.at(-1)), + ); + assert.match(words(next.events), /pineapple/i); + }, + cut, + ); +}); diff --git a/app/src/lib/copilot/stopped-turn.ts b/app/src/lib/copilot/stopped-turn.ts index 9ed82a3b02..a12c9dd7d1 100644 --- a/app/src/lib/copilot/stopped-turn.ts +++ b/app/src/lib/copilot/stopped-turn.ts @@ -53,7 +53,10 @@ export function stoppedReason(reported: unknown): string { console.warn("A Bot's event stream broke AG-UI's rules.", said); return UNREADABLE_REPLY; } - if (CONNECTION_CUT.test(said.trim())) { + if ( + CONNECTION_CUT.test(said.trim()) || + BOT_CONNECTION_CUT.test(said.trim()) + ) { console.warn("A Bot's connection was cut part way through a turn.", said); return CONNECTION_CUT_OFF; } @@ -71,6 +74,20 @@ export function stoppedReason(reported: unknown): string { const CONNECTION_CUT = /ECONNRESET|socket connection was closed unexpectedly|^socket hang up$|^other side closed$|^terminated$/i; +/** + * Python's words for a connection cut part way, as a Bot in Python passes them on: the socket's + * "[Errno 54] Connection reset by peer" (httpx's `ReadError`, which the OpenAI and Anthropic SDKs + * read with), h11's "peer closed connection without sending complete message body (incomplete + * chunked read)" and "Server disconnected without sending a response.", and the OpenAI SDK's own + * "Connection error.", which it raises around the first of them. Never this browser's own, so only + * ever the Bot's connection, and never read as the backend's (`laterRunFailure`). + * + * FOUND ON OPENBOT CLOUD, 2026-12-03: a Bot's connection to its model was cut while it wrote a + * Google Slides deck. A Bot in Python whose connection is cut the same way showed these words. + */ +const BOT_CONNECTION_CUT = + /connection reset by peer|peer closed connection without sending complete message body|^server disconnected without sending a response\.?$|^connection error\.?$/i; + /** * Whether the server ended the turn asking the person to have the Bot carry on: a reply that came * back incomplete, or the connection to the Bot's model dropping part way ("The connection to Claude diff --git a/app/tests/stopped-turn.test.ts b/app/tests/stopped-turn.test.ts index 527a2edb79..426ef5033d 100644 --- a/app/tests/stopped-turn.test.ts +++ b/app/tests/stopped-turn.test.ts @@ -69,6 +69,26 @@ describe("a later run of a turn that fails", () => { ]); } expect(CONNECTION_CUT_OFF).not.toContain("backend"); + /* + * FOUND ON OPENBOT CLOUD, 2026-12-03: a Bot's connection to its model was cut while it wrote a + * Google Slides deck. A Bot in Python cut the same way passes on Python's words, exactly as + * httpx, h11 and the OpenAI SDK raise them (the OpenAI SDK's "Connection error." around httpx's + * ReadError, read from a stream reset part way). Only ever the Bot's: never this browser's. + */ + for (const said of [ + "[Errno 54] Connection reset by peer", + "[Errno 104] Connection reset by peer", + "peer closed connection without sending complete message body (incomplete chunked read)", + "peer closed connection without sending complete message body (received 120 bytes, expected 4096)", + "Server disconnected without sending a response.", + "Connection error.", + ]) { + expect([said, stoppedReason(said)]).toEqual([said, CONNECTION_CUT_OFF]); + expect([said, laterRunFailure(new Error(said))]).toEqual([ + said, + CONNECTION_CUT_OFF, + ]); + } // A sentence that only mentions a connection is still passed on in its own words. expect( stoppedReason(