From 3429cd88891ea4bb47694106da33491bfbc28f99 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 4 Dec 2026 03:15:07 -0800 Subject: [PATCH] Say a turn's failure again after coming back to it on a slow join A person who left a conversation while its Bot worked, and came back after the run failed, saw the Bot's last line with no notice and no Carry on: the kept agent had heard the RUN_ERROR, but a failure was said again only from a join that finished inside its 1.5 s deadline. Now a join that didn't finish asks the server about the last run the kept agent heard, and says its failure again when no run is going and that run didn't finish. The kept story's failure code goes with it. Browser test in Chromium and WebKit: red without the fix, green with it. --- .github/workflows/ci.yml | 1 + app/src/components/channels/channel-chat.tsx | 39 +- .../stopped-turn-return-browser.test.tsx | 561 ++++++++++++++++++ app/tests/stopped-turn-return.fixture.tsx | 122 ++++ 4 files changed, 722 insertions(+), 1 deletion(-) create mode 100644 app/tests/stopped-turn-return-browser.test.tsx create mode 100644 app/tests/stopped-turn-return.fixture.tsx diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bd5bd0497..5b1eacd283 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -801,6 +801,7 @@ jobs: app/tests/step-rows-layout.test.tsx app/tests/stopped-command-layout.test.tsx app/tests/stopped-turn-dismiss-browser.test.tsx + app/tests/stopped-turn-return-browser.test.tsx app/tests/strip-version-layout.test.tsx app/tests/table-export-browser.test.tsx app/tests/team-connections-directory-layout.test.tsx diff --git a/app/src/components/channels/channel-chat.tsx b/app/src/components/channels/channel-chat.tsx index 34604d17e2..d6ebae3fa8 100644 --- a/app/src/components/channels/channel-chat.tsx +++ b/app/src/components/channels/channel-chat.tsx @@ -1297,7 +1297,7 @@ export function ChannelChat({ */ const failed = joined === "connected" ? story().failure() : null; if (failed !== null && current && turnsRef.current === 0) { - const code = lastRun.failureCode(); + const code = story().failureCode(); setRunError( (shown) => shown ?? { message: failed, ...(code ? { code } : {}) }, ); @@ -1410,6 +1410,43 @@ export function ChannelChat({ openJoinGate.current(); } if (askAgain && current) pullHistoryRef.current?.({ opening: true }); + /* + * A FAILURE THIS PAGE HEARD ITSELF IS NOT FORGOTTEN BECAUSE THE JOIN WAS SLOW. FOUND ON OPENBOT + * CLOUD, 2026-12-04: a person left a conversation on his phone while its Bot worked, the + * Bot's model connection dropped two minutes in and the run ended in a RUN_ERROR, and he came + * back to the Bot's last line, "I'll check options for both days so the drafts are clear.", + * with no notice, no Carry on and nothing working. The agent kept for the conversation had + * heard that RUN_ERROR, but the join that resumed the thread took longer than its deadline, + * and a failure is said above only from a join that finished. + * + * So when the join did not finish and heard no run of its own, the last run the kept agent + * heard is asked about: said again if the server has no run going and says that run did not + * finish. Asked after the history is in, so the conversation is never held for it. + */ + const keptStory = heardRuns(agent); + const keptFailure = keptStory?.failure() ?? null; + const keptFailedRun = keptStory?.runId() ?? null; + if ( + joined !== "connected" && + lastRun.runId() === null && + keptFailure !== null && + keptFailedRun !== null && + current && + turnsRef.current === 0 + ) { + const going = await askRunGoing(channel.id); + const ended = + going.liveness === "over" + ? await askRunEnding(channel.id, keptFailedRun) + : null; + if (ended === "stopped" && current && turnsRef.current === 0) { + const code = keptStory?.failureCode(); + setRunError( + (shown) => + shown ?? { message: keptFailure, ...(code ? { code } : {}) }, + ); + } + } /* * A TURN THE SERVER IS STILL CARRYING ON IS FOLLOWED FROM HERE. The join above streams the run * going when the conversation opened, and ends with it; the server then carries the turn on in diff --git a/app/tests/stopped-turn-return-browser.test.tsx b/app/tests/stopped-turn-return-browser.test.tsx new file mode 100644 index 0000000000..3b1dc1f698 --- /dev/null +++ b/app/tests/stopped-turn-return-browser.test.tsx @@ -0,0 +1,561 @@ +import { afterAll, beforeAll, describe, expect } from "bun:test"; +import { existsSync, mkdirSync, readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import type { Server } from "bun"; +import type { Browser, BrowserType, Page } from "playwright-core"; +import { compile } from "tailwindcss"; +import { getGetBotDelegationResponseMock } from "@/lib/api/generated/agents/agents.msw"; +import { getGetBotResponseMock } from "@/lib/api/generated/bots/bots.msw"; +import { personBody } from "./accounts-api"; +import { botGrantsBody } from "./bot-grants-api"; +import { still } from "./page-still"; +import { test } from "./renderer-crash"; + +/** + * A turn that ended in an error says so, with Carry on, however the person comes back to it: in a + * real browser, with the real conversation, against a real HTTP server on this machine that answers + * at the API's and the runtime's addresses. + * + * FOUND ON OPENBOT CLOUD, 2026-12-04. A person asked a Bot on GPT-6.2 Sol to check his calendar and + * draft two messages. It said what it would do, took fifteen steps, said "I'll check options for + * both days so the drafts are clear.", took five more, and then its model's stream broke: the run + * ended with a RUN_ERROR two minutes in. He had gone to start another conversation meanwhile, on + * his phone. When he came back the conversation ended on the Bot's promise, with no notice, no + * Carry on and nothing working: "bot says it will do additional work, but actually, it stopped + * doing work. It just got stuck there." He typed "Still running?" to find out. + * + * The RUN_ERROR is not in the thread's stored messages, only in the run's events. The agent kept for + * the conversation heard it, but a failure was said again only from a join that finished, and the + * join that resumed the thread took longer than its deadline (1.5 s, on a phone), so the + * conversation came back with nothing said. + * + * OPENBOT_APP_BROWSER=1 bun test app/tests/stopped-turn-return-browser.test.tsx + * + * Chromium by default. OPENBOT_APP_ENGINES=chromium,webkit adds WebKit. With OPENBOT_APP_SHOTS= + * each step is saved as stopped-turn-return-----.png. + */ +const asked = process.env.OPENBOT_APP_BROWSER === "1"; +const shots = process.env.OPENBOT_APP_SHOTS; +const engines = (process.env.OPENBOT_APP_ENGINES ?? "chromium") + .split(",") + .map((engine) => engine.trim()) + .filter((engine) => engine === "chromium" || engine === "webkit") as ( + | "chromium" + | "webkit" +)[]; + +const APP = join(import.meta.dir, ".."); +const ORGANIZATION = "/api/v2/organizations/default"; +const BOT_ID = "general-assistant"; +const CONVERSATION = "launch-conversation"; +const BOT_PATH = `${ORGANIZATION}/bots/${BOT_ID}`; +const HERE = `/channel/${CONVERSATION}`; + +const ASKED = + "Do I have any time to speak to Eli tomorrow? Draft the messages here first; don't send anything."; +const PROMISE = + "I found the Ely invite and the flight conflict. I'll check options for both days so the drafts are clear."; +const TOOL = "GOOGLECALENDAR_FREE_BUSY_QUERY"; + +/** The server's sentence for a model connection that dropped part way (provider-refusal.ts). */ +const DROPPED = "The connection to OpenAI dropped. Ask the Bot to carry on."; + +const BOT = { + ...getGetBotResponseMock().bot, + id: BOT_ID, + name: "General Assistant", + mine: true, + canManage: true, + systemOwned: false, + visibility: "private" as const, +}; +const DELEGATION = { ...getGetBotDelegationResponseMock(), botId: BOT_ID }; + +/** + * What the runtime keeps of the thread (every run's events, and the messages said), the sentence + * the next run ends with, how long a join waits before its replay starts, and how long a run works + * before its model's stream breaks. + */ +type Scene = { + runs: number; + recorded: unknown[]; + stored: unknown[]; + ending: string; + replayAfterMs: number; + breaksAfterMs: number; +}; +const fresh = (over: Partial = {}): Scene => ({ + runs: 0, + recorded: [], + stored: [], + ending: DROPPED, + replayAfterMs: 0, + breaksAfterMs: 0, + ...over, +}); +let scene: Scene = fresh(); + +const json = (body: unknown, status = 200) => + Response.json(body, { + status, + headers: { "cache-control": "private, no-store" }, + }); +const frame = (event: unknown) => `data: ${JSON.stringify(event)}\n\n`; +const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); + +/** A stream of events, the first `at` of them at once and the rest after `ms`. */ +function stream(events: unknown[], at: number, ms: number): Response { + const encoder = new TextEncoder(); + return new Response( + new ReadableStream({ + async start(controller) { + controller.enqueue( + encoder.encode(events.slice(0, at).map(frame).join("")), + ); + if (ms > 0) await sleep(ms); + controller.enqueue( + encoder.encode(events.slice(at).map(frame).join("")), + ); + controller.close(); + }, + }), + { headers: { "content-type": "text/event-stream" } }, + ); +} + +/** + * The Bot's run: it says what it will do, takes a step, says what it found and what it will do + * next, starts its next step, and its model's stream breaks, so the run ends in the scene's + * sentence. Recorded as the runtime records it, for the join to replay. + */ +function run(input: { + threadId: string; + runId: string; + messages: { id: string; role: string }[]; +}): Response { + scene.runs += 1; + const { threadId, runId } = input; + const opening = `opening-${runId}`; + const promise = `promise-${runId}`; + const step = `step-${runId}`; + const call = `call-${runId}`; + const next = `call-next-${runId}`; + const events = [ + { type: "RUN_STARTED", threadId, runId }, + { type: "TEXT_MESSAGE_START", messageId: opening, role: "assistant" }, + { + type: "TEXT_MESSAGE_CONTENT", + messageId: opening, + delta: "I'll check your calendar, then draft the messages here.", + }, + { type: "TEXT_MESSAGE_END", messageId: opening }, + { + type: "TOOL_CALL_START", + toolCallId: call, + toolCallName: TOOL, + parentMessageId: step, + }, + { type: "TOOL_CALL_ARGS", toolCallId: call, delta: '{"day":"Friday"}' }, + { type: "TOOL_CALL_END", toolCallId: call }, + { + type: "TOOL_CALL_RESULT", + messageId: `result-${runId}`, + toolCallId: call, + content: "Busy 14:00-15:00 (Ely), flight 14:03.", + }, + { type: "TEXT_MESSAGE_START", messageId: promise, role: "assistant" }, + { type: "TEXT_MESSAGE_CONTENT", messageId: promise, delta: PROMISE }, + { type: "TEXT_MESSAGE_END", messageId: promise }, + { + type: "TOOL_CALL_START", + toolCallId: next, + toolCallName: TOOL, + parentMessageId: `next-${runId}`, + }, + { type: "TOOL_CALL_ARGS", toolCallId: next, delta: '{"day":"Saturday"}' }, + { type: "TOOL_CALL_END", toolCallId: next }, + { + type: "TOOL_CALL_RESULT", + messageId: `result-next-${runId}`, + toolCallId: next, + content: "Free 10:00-10:30 and 13:00-13:30.", + }, + { type: "RUN_ERROR", message: scene.ending }, + ]; + scene.recorded.push(...events); + const known = new Set( + scene.stored.map((message) => (message as { id: string }).id), + ); + scene.stored = [ + ...scene.stored, + ...input.messages.filter( + (message) => message.role === "user" && !known.has(message.id), + ), + { + id: opening, + role: "assistant", + content: "I'll check your calendar, then draft the messages here.", + }, + { + id: step, + role: "assistant", + content: "", + toolCalls: [ + { + id: call, + type: "function", + function: { name: TOOL, arguments: '{"day":"Friday"}' }, + }, + ], + }, + { + id: `result-${runId}`, + role: "tool", + toolCallId: call, + content: "Busy 14:00-15:00 (Ely), flight 14:03.", + }, + { id: promise, role: "assistant", content: PROMISE }, + { + id: `next-${runId}`, + role: "assistant", + content: "", + toolCalls: [ + { + id: next, + type: "function", + function: { name: TOOL, arguments: '{"day":"Saturday"}' }, + }, + ], + }, + { + id: `result-next-${runId}`, + role: "tool", + toolCallId: next, + content: "Free 10:00-10:30 and 13:00-13:30.", + }, + ]; + // Everything up to the promise at once; the rest, and the break, once the run has worked a while. + return stream(events, 11, scene.breaksAfterMs); +} + +/** What the server answers at the API's and the runtime's addresses. */ +async function answer(request: Request): Promise { + const path = new URL(request.url).pathname; + if (path === "/api/copilotkit/info") + return json({ + version: "fixture", + agents: { [BOT_ID]: { description: "Fixture", capabilities: {} } }, + mode: "sse", + telemetryDisabled: true, + }); + // Joining the thread replays every run's events, as the runtime's runners do: here as slowly + // as the scene says, as a long thread's replay reaches a phone. + if (path.endsWith("/connect")) { + if (scene.replayAfterMs > 0) await sleep(scene.replayAfterMs); + return stream(scene.recorded, scene.recorded.length, 0); + } + if (path.endsWith("/run")) return run(await request.json()); + if (path.startsWith(`${ORGANIZATION}/people/me/approval-modes/`)) + return json({ asksEveryStep: false }); + if (/\/agent\/[^/]+\/stop\//.test(path)) return json({ stopped: true }); + if (path === `${BOT_PATH}/delegation`) return json(DELEGATION); + if (path === BOT_PATH) return json({ bot: BOT }); + if (path === `${ORGANIZATION}/bots`) + return json({ bots: [BOT], nextCursor: null }); + if (path === `${BOT_PATH}/grants`) return json(botGrantsBody()); + if (path === `${BOT_PATH}/components`) + return json({ components: [], nextCursor: null }); + if (path === `${ORGANIZATION}/people/me/capabilities`) + return json({ capabilities: {}, enforced: false }); + if (path === `${ORGANIZATION}/people/me`) + return json({ + person: personBody({ + id: "atlas", + name: "Ari Atlas", + email: "ari.atlas@northwind.example", + role: "member", + }), + openbotVersion: "v1.2.11", + }); + if (path === `${ORGANIZATION}/deployment`) + return json({ + generativeUi: true, + selfHostBanner: false, + localEvaluation: false, + edition: "team", + authProviders: [], + ssoConfigured: false, + ssoRequired: false, + }); + if (/\/conversations\/[^/]+\/(activity|signal-busy|mark-read)$/.test(path)) + return new Response(null, { status: 204 }); + if (/\/conversations\/[^/]+\/voice-sessions$/.test(path)) + return json({ sessions: [], nextCursor: null }); + if (/\/conversations\/[^/]+\/refused-turns$/.test(path)) + return json({ refusedTurns: [], nextCursor: null }); + if (/\/conversations\/[^/]+\/work$/.test(path)) return json({ work: [] }); + // No run going in the conversation. + if (path === `${ORGANIZATION}/conversations/${CONVERSATION}/join-tokens`) + return json( + { + joinToken: "jt", + expiresAt: new Date(Date.now() + 30_000).toISOString(), + threadId: "launch-thread", + runId: null, + realtime: { clientUrl: "ws://127.0.0.1/client", topic: "thread" }, + }, + 201, + ); + // How each run ended, as the server keeps it: failed. + const ran = path.match( + new RegExp(`^${ORGANIZATION}/conversations/${CONVERSATION}/runs/([^/]+)$`), + ); + if (ran) + return json({ + run: { + id: decodeURIComponent(ran[1] ?? ""), + outcome: "failed", + endedAt: new Date().toISOString(), + }, + }); + if (/\/threads\/[^/]+\/messages$/.test(path)) + return json({ messages: scene.stored }); + return undefined; +} + +async function bundle(): Promise { + const built = await Bun.build({ + entrypoints: [join(import.meta.dir, "stopped-turn-return.fixture.tsx")], + target: "browser", + define: { "process.env.NODE_ENV": JSON.stringify("production") }, + plugins: [ + { + name: "no-marks", + setup(build) { + build.onResolve({ filter: /^@\/lib\/marks$/ }, () => ({ + path: "marks", + namespace: "no-marks", + })); + build.onLoad({ filter: /.*/, namespace: "no-marks" }, () => ({ + contents: "export const markFor = () => null;", + loader: "js", + })); + }, + }, + ], + }); + if (!built.success) throw new AggregateError(built.logs, "bundle failed"); + const script = built.outputs.find((output) => output.kind === "entry-point"); + if (!script) throw new Error("bundle has no entry point"); + return script.text(); +} + +function packageDir(name: string): string { + const dir = [ + join(APP, "node_modules", name), + join(APP, "..", "node_modules", name), + ].find(existsSync); + if (!dir) throw new Error(`no package ${name}`); + return dir; +} + +function packageStylesheet(id: string): string { + const parts = id.split("/"); + const name = id.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]; + const dir = packageDir(name); + const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")); + const subpath = `.${id.slice(name.length)}`; + const entry = pkg.exports?.[subpath]; + const file = + typeof entry === "string" + ? entry + : (entry?.style ?? entry?.default ?? pkg.main ?? "index.css"); + return join(dir, file); +} + +/** The app's stylesheet, built by Tailwind for these classes, as the app's build does. */ +async function stylesheet(classes: string[]): Promise { + const tailwind = dirname(Bun.resolveSync("tailwindcss/package.json", APP)); + const entry = join(APP, "src", "styles.css"); + const compiler = await compile(readFileSync(entry, "utf8"), { + base: dirname(entry), + loadStylesheet: async (id, base) => { + const path = + id === "tailwindcss" + ? join(tailwind, "index.css") + : id.startsWith(".") + ? join(base, id) + : packageStylesheet(id); + return { path, base: dirname(path), content: readFileSync(path, "utf8") }; + }, + }); + return compiler.build(classes); +} + +const browsers = new Map(); +let server: Server | undefined; +let origin = ""; + +beforeAll(async () => { + if (!asked) return; + const script = await bundle(); + const figtree = join(packageDir("@fontsource-variable/figtree"), "files"); + server = Bun.serve({ + hostname: "127.0.0.1", + port: 0, + idleTimeout: 0, + async fetch(request) { + const path = new URL(request.url).pathname; + if (path === "/conversation.js") + return new Response(script, { + headers: { "content-type": "text/javascript" }, + }); + const font = join(figtree, path.split("/").pop() ?? ""); + if (path.startsWith("/files/") && existsSync(font)) + return new Response(Bun.file(font)); + if (path.startsWith("/api/")) + return (await answer(request)) ?? json({ detail: "Not found." }, 404); + const theme = new URL(request.url).searchParams.get("theme") ?? "light"; + return new Response( + `
`, + { headers: { "content-type": "text/html" } }, + ); + }, + }); + origin = `http://127.0.0.1:${server.port}`; + const playwright = await import("playwright-core"); + for (const engine of engines) { + const type: BrowserType = playwright[engine]; + browsers.set( + engine, + // The CI job installs full Chromium without the headless shell. + await type.launch(engine === "chromium" ? { channel: "chromium" } : {}), + ); + } +}, 120_000); + +afterAll(async () => { + for (const browser of browsers.values()) await browser.close(); + await server?.stop(true); +}); + +async function shoot(page: Page, name: string) { + const classes = await page.evaluate(() => + [...document.querySelectorAll("[class]")].flatMap((element) => [ + ...element.classList, + ]), + ); + await page.addStyleTag({ content: await stylesheet([...new Set(classes)]) }); + await still(page); + if (!shots) return; + mkdirSync(shots, { recursive: true }); + await page.screenshot({ path: join(shots, `${name}.png`) }); +} + +/** The message box, once the conversation is open and has stopped working. */ +async function composer(page: Page) { + const box = page.getByRole("textbox", { name: "Message" }); + await box.waitFor({ timeout: 15_000 }); + await page + .getByRole("button", { name: "Stop the Bot" }) + .waitFor({ state: "detached", timeout: 15_000 }); + return box; +} + +async function send(page: Page, text: string) { + const box = await composer(page); + await box.click(); + await page.keyboard.type(text); + await page.getByRole("button", { name: "Send message" }).click(); +} + +const go = (page: Page, to: string) => + page.evaluate( + (path) => + (window as unknown as { go: (to: string) => Promise }).go(path), + to, + ); + +/** + * The conversation, opened and settled: its history is in, nothing is working, and a notice that + * was coming has come (a join's replay and the reads after it are over). + */ +async function settled(page: Page) { + await composer(page); + await page.getByText(PROMISE).waitFor({ timeout: 15_000 }); + // Past the join's deadline, its replay, the history read and the server's answer on the run. + await sleep(4_000); +} + +/** The notice under the turn, and its Carry on. */ +async function notice(page: Page) { + const stopped = page.getByTestId("transcript-stopped"); + return { + count: await stopped.count(), + said: + (await stopped.count()) > 0 + ? await stopped.getByRole("alert").textContent() + : null, + carryOn: + (await stopped.count()) > 0 + ? await stopped.getByRole("button", { name: "Carry on" }).count() + : 0, + }; +} + +describe.skipIf(!asked)("a turn that ended in an error", () => { + for (const engine of engines) + for (const theme of ["light", "dark"] as const) + for (const window of [ + { width: 390, height: 844 }, + { width: 1280, height: 800 }, + ]) + test(`says so with Carry on when the person comes back after it failed, the join slow, and after a reload, in ${engine}, ${theme}, ${window.width}px`, async () => { + // The model's stream breaks three seconds into the run, while the person is elsewhere. + scene = fresh({ breaksAfterMs: 3_000 }); + const browser = browsers.get(engine); + if (!browser) throw new Error(`no ${engine}`); + const page = await browser.newPage({ + viewport: window, + colorScheme: theme, + reducedMotion: "reduce", + }); + page.on("pageerror", (error) => console.error(error)); + const name = (step: string) => + `stopped-turn-return-${step}-${engine}-${theme}-${window.width}`; + try { + await page.goto(`${origin}${HERE}?quietMs=400&theme=${theme}`); + await send(page, ASKED); + await page.getByText(PROMISE).waitFor({ timeout: 15_000 }); + + // The person goes to start another conversation while the Bot works. + await go(page, "/channel/new"); + await page.getByText("Somewhere else in OpenBot").waitFor(); + await sleep(4_500); + + // And comes back once the run has failed: the long thread replays slowly. + scene.replayAfterMs = 2_500; + await go(page, HERE); + await settled(page); + await shoot(page, name("1-came-back")); + expect(await notice(page)).toEqual({ + count: 1, + said: DROPPED, + carryOn: 1, + }); + + // Opened again from nothing: the join replays the run's end, and it says the same. + scene.replayAfterMs = 0; + await page.goto(`${origin}${HERE}?quietMs=400&theme=${theme}`); + await settled(page); + await shoot(page, name("2-reloaded")); + expect(await notice(page)).toEqual({ + count: 1, + said: DROPPED, + carryOn: 1, + }); + } finally { + await page.close(); + } + }, 120_000); +}); diff --git a/app/tests/stopped-turn-return.fixture.tsx b/app/tests/stopped-turn-return.fixture.tsx new file mode 100644 index 0000000000..44412a2400 --- /dev/null +++ b/app/tests/stopped-turn-return.fixture.tsx @@ -0,0 +1,122 @@ +import { CopilotKitProvider } from "@copilotkit/react-core/v2"; +import { type InfiniteData, QueryClientProvider } from "@tanstack/react-query"; +import { + createBrowserHistory, + createRootRoute, + createRoute, + createRouter, + Outlet, + RouterProvider, +} from "@tanstack/react-router"; +import { createRoot } from "react-dom/client"; +import { ChannelChat } from "@/components/channels/channel-chat"; +import { TooltipProvider } from "@/components/ui/tooltip"; +import { + type AuthenticatedUser, + currentUserQueryOptions, +} from "@/lib/auth/queries"; +import { + type AgentChannel, + type ChannelPage, + channelKeys, +} from "@/lib/channels/queries"; +import { ActiveBotProvider } from "@/lib/copilot/active-bot"; +import { BotOffers } from "@/lib/copilot/bot-offer"; +import { quietRunPeriod } from "@/lib/copilot/quiet-run"; +import { setCurrentOrganization } from "@/lib/organizations/current"; +import { queryClient } from "@/query-client"; + +/** + * A conversation that can be left and come back to, for stopped-turn-return-browser.test.tsx to + * bundle and load in a browser. `/channel/launch-conversation` is the real conversation; any other + * address is somewhere else in the app, so going there closes the conversation, as opening another + * one or New conversation does, and coming back opens it again in the same page. The test moves + * between them with `window.go(path)`, as the sidebar's links do. What the server and the runtime + * answer comes from the test's server. + */ +setCurrentOrganization("default"); +quietRunPeriod.ms = Number( + new URLSearchParams(location.search).get("quietMs") ?? quietRunPeriod.ms, +); + +const CONVERSATION: AgentChannel = { + id: "launch-conversation", + name: "General Assistant", + agentIds: ["general-assistant"], + threadId: "launch-thread", + active: true, + lastMessageAt: "2026-12-04T10:36:27.000Z", +}; + +// Signed in, as every page of the app is by the time a conversation opens. +const ARI: AuthenticatedUser = { + id: "atlas", + email: "ari.atlas@northwind.example", + name: "Ari Atlas", + role: "member", + onboarding: null, + openbotVersion: "v1.2.11", + providers: [], +}; +queryClient.setQueryData(currentUserQueryOptions().queryKey, ARI); +queryClient.setQueryDefaults(channelKeys.list(), { staleTime: Infinity }); +queryClient.setQueryData>(channelKeys.list(), { + pages: [ + { + channels: [ + { + ...CONVERSATION, + summary: "Calendar sanity", + lastMessage: null, + lastMessageAgentId: null, + createdAt: "2026-12-04T10:36:27.000Z", + pinned: false, + lastReadAt: "2026-12-04T10:36:27.000Z", + }, + ], + nextCursor: null, + }, + ], + pageParams: [""], +}); + +const rootRoute = createRootRoute({ + component: () => ( +
+ + + + +
+ ), +}); +const conversation = createRoute({ + getParentRoute: () => rootRoute, + path: "/channel/launch-conversation", + component: () => ( + + ), +}); +const elsewhere = createRoute({ + getParentRoute: () => rootRoute, + path: "$", + component: () =>

Somewhere else in OpenBot

, +}); +const router = createRouter({ + history: createBrowserHistory(), + routeTree: rootRoute.addChildren([conversation, elsewhere]), +}); +(window as unknown as { go: (to: string) => Promise }).go = (to) => + router.navigate({ to } as never); + +const root = document.getElementById("root"); +if (root) + createRoot(root).render( + + + + + + + , + );