Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ jobs:
app/tests/roster-working.test.tsx
app/tests/routine-run-now-layout.test.tsx
app/tests/run-ended-unheard-layout.test.tsx
app/tests/run-refused-browser.test.tsx
app/tests/section-strip-routines.test.tsx
app/tests/select-long-names-layout.test.tsx
app/tests/select-scrolls-layout.test.tsx
Expand Down
17 changes: 8 additions & 9 deletions app/src/lib/agents/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
} from "@/lib/api/generated/model";
import { idempotencyKey, organizationId } from "@/lib/api/request";
import { ClientError } from "@/lib/client";
import { type Failure, failureOf, isHeld } from "@/lib/load-failure";
import { type Failure, failureOf } from "@/lib/load-failure";

export type AgentVisibility = BotVisibility;

Expand Down Expand Up @@ -136,20 +136,19 @@ export function agentQueryOptions(agentId: string) {
/**
* Whether a Bot is, right now, not one this person can use: the read of it answers "not found".
*
* A verdict about this moment, asked when a message to the Bot was refused, so it is not cached and
* it fails closed: only the API's own 404 says the Bot is gone. A read that could not be made, or a
* server that broke, says nothing about the Bot, and answers false.
*
* Except OpenBot holding off (a move, or the organization's database briefly out of reach): that
* refusal is thrown as it came, so the caller can say the server's sentence calmly (`failedRunReason`).
* A verdict about this moment, asked when a message to the Bot was refused, so it is not cached:
* only the API's own 404 says the Bot is gone, and only a read that answered says it is still there.
* A read that could not be made, or a server that broke, says nothing about the Bot, and is thrown
* as it came, so the caller claims neither (`failedRunReason`). OpenBot holding off (a move, or the
* organization's database briefly out of reach) is thrown the same way, and said calmly.
*/
export async function botNoLongerUsable(agentId: string): Promise<boolean> {
try {
await getBot(organizationId(), agentId);
return false;
} catch (error) {
if (isHeld(error)) throw error;
return error instanceof ClientError && error.status === 404;
if (error instanceof ClientError && error.status === 404) return true;
throw error;
}
}

Expand Down
121 changes: 110 additions & 11 deletions app/src/lib/copilot/stopped-turn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export function stoppedReason(reported: unknown): string {
if (busy) return busy.message;
const refused = refusalForPerson(said);
if (refused) return refused;
const notStarted = backEndRefused(said);
if (notStarted) return notStarted;
const unreachable = backEndUnreachable(said);
if (unreachable) return unreachable;
if (RUNNER_DROPPED.test(said.trim())) return TURN_INTERRUPTED;
Expand Down Expand Up @@ -108,6 +110,37 @@ export const UNREADABLE_REPLY =
export const TURN_CUT_OFF =
"The Bot stopped before it finished because OpenBot's backend stopped answering. What it saved is shown here.";

/**
* Said under a turn whose later run the backend answered and refused, with no sentence of its own
* for the person. It was answering, so it is not said to have stopped. Its work stands.
*/
export const TURN_REFUSED =
"OpenBot's backend couldn't carry on this turn, so the Bot stopped before it finished. What it saved is shown here.";

/**
* Said when the backend answered a first run, or a join, and refused it with no sentence of its own
* for the person: the runtime's own `{ "error": … }`, or a fault on the server. The backend was
* reached, so "couldn't reach" would be false, and the raw body is nothing the person can act on.
*/
export const RUN_NOT_STARTED =
"OpenBot's backend couldn't start this turn, so your message wasn't sent. Try again, or ask an admin if it keeps happening.";
export const CONNECT_NOT_OPENED =
"OpenBot's backend couldn't open this conversation. Try again, or ask an admin if it keeps happening.";

/**
* Said when the backend can't build the Bot a run names, though the Bot is still the person's: the
* runtime answers "Agent not found" for a Bot whose setup it can't run on (no instructions, or an
* address it can't use), while the API still lists the Bot and reads it back.
*
* FOUND ON OPENBOT CLOUD, 2026-12-03. A public Bot moved in from somebody's OpenBot Desktop had no
* instructions. Each run of it was answered 404 "Agent not found", and the person was told OpenBot
* couldn't reach its backend and to quit and reopen it, while the backend answered every time.
*/
export const BOT_CANNOT_RUN_MESSAGE_NOT_SENT =
"This Bot can't run because its setup isn't finished, so your message wasn't sent. Its owner or an admin can finish it in Setup.";
export const BOT_CANNOT_RUN =
"This Bot can't run because its setup isn't finished. Its owner or an admin can finish it in Setup.";

/**
* Said under a turn whose run went away under it: the server running it stopped part way, and the
* backend ended the run for it ("Runner connection dropped"). Its work stands, and Carry on picks it
Expand Down Expand Up @@ -170,6 +203,11 @@ export function laterRunFailure(reported: unknown): string | null {
: "";
if (refusalForPerson(said) || tooManyRuns(reported))
return stoppedReason(reported);
// Answered and refused: the backend was reached, so it is not said to have stopped answering.
if (backendAnswered(said)) {
console.warn("OpenBot's backend refused a later run of a turn.", said);
return TURN_REFUSED;
}
// Thrown here, a cut connection is this browser's own, to OpenBot's backend: not the Bot's.
if (
REST_REQUEST_FAILED.test(said.trim()) ||
Expand All @@ -186,12 +224,13 @@ export function laterRunFailure(reported: unknown): string | null {
}

/**
* The one reason that is NOT passed on in its own words: the browser couldn't reach the runtime.
* A request to the runtime that failed, NOT passed on in its own words.
*
* CopilotKit's Intelligence agent writes it as `REST <mode> request failed: <whatever came back>`,
* and what came back is the server's raw body, JSON included (`{"error":"Failed to resolve Learning
* Container"}`). Nothing in it is the person's to act on, so they are told what happened in their
* terms and the original goes to the console for whoever is debugging.
* Container"}`), or the fetch's own words when nothing came back. Nothing in it is the person's to
* act on, so they are told what happened in their terms (`backEndRefused` when the backend answered,
* `backEndUnreachable` when it didn't) and the original goes to the console for whoever is debugging.
*/
const REST_REQUEST_FAILED = /^REST (\w+) request failed\b:?\s*/;

Expand Down Expand Up @@ -318,6 +357,41 @@ export function tooManyRuns(reported: unknown): ClientError | undefined {
);
}

/**
* Whether a REST failure is the backend's own answer.
*
* The client throws what came back after its prefix: the body of the answer, else its status text,
* else the fetch's own words. The backend answers in JSON, its refusals and its faults alike. A
* fetch that failed ("Failed to fetch", Safari's "Load failed"), a proxy's page in front of a backend
* that is down, or a status text alone is the backend not answering.
*/
function backendAnswered(said: string): boolean {
const body = refusedBody(said);
return typeof body === "object" && body !== null && !Array.isArray(body);
}

/** Whether a REST failure is the runtime's answer for a Bot it has not built for this person. */
function agentNotFound(said: string): boolean {
const body = refusedBody(said);
return (
typeof body === "object" &&
body !== null &&
(body as { error?: unknown }).error === "Agent not found"
);
}

/**
* A REST failure the backend answered, said in the person's terms: it was reached, and it could not
* start what was asked. The body goes to the console for whoever is debugging. Null when the backend
* did not answer, which `backEndUnreachable` says.
*/
function backEndRefused(said: string): string | null {
const match = REST_REQUEST_FAILED.exec(said.trim());
if (!match || !backendAnswered(said)) return null;
console.warn("OpenBot's backend refused the request.", said);
return match[1] === "run" ? RUN_NOT_STARTED : CONNECT_NOT_OPENED;
}

function backEndUnreachable(said: string): string | null {
const match = REST_REQUEST_FAILED.exec(said.trim());
if (!match) return null;
Expand Down Expand Up @@ -394,11 +468,31 @@ export async function failedRunReason(
if (!request) return said;
const asked = await askAboutBot(botId, noLongerUsable);
if (asked.held) return asked.held;
if (!asked.gone) return said;
return {
message:
request === "run" ? BOT_NOT_SHARED_MESSAGE_NOT_SENT : BOT_NOT_SHARED,
};
if (asked.gone)
return {
message:
request === "run" ? BOT_NOT_SHARED_MESSAGE_NOT_SENT : BOT_NOT_SHARED,
};
/*
* Still theirs, the server says, and the runtime has no such Bot to run: it can't build it from the
* setup it has. Said only when the server answered both, so a read that failed keeps the sentence
* it had.
*/
if (asked.known && agentNotFound(errorText(reported)))
return {
message:
request === "run" ? BOT_CANNOT_RUN_MESSAGE_NOT_SENT : BOT_CANNOT_RUN,
};
return said;
}

/** What a reported failure says, as `stoppedReason` reads it. */
function errorText(reported: unknown): string {
return reported instanceof Error
? reported.message
: typeof reported === "string"
? reported
: "";
}

/**
Expand Down Expand Up @@ -433,11 +527,16 @@ export async function laterRunReason(
async function askAboutBot(
botId: string,
noLongerUsable: (botId: string) => Promise<boolean>,
): Promise<{ gone: boolean; held?: undefined } | { held: Failure }> {
): Promise<
| { gone: boolean; known: boolean; held?: undefined }
| { held: Failure; gone?: undefined; known?: undefined }
> {
try {
return { gone: await noLongerUsable(botId) };
return { gone: await noLongerUsable(botId), known: true };
} catch (error) {
return isHeld(error) ? { held: error as Failure } : { gone: false };
return isHeld(error)
? { held: error as Failure }
: { gone: false, known: false };
}
}

Expand Down
44 changes: 37 additions & 7 deletions app/tests/channel-failed-run-restore.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {
UNANSWERED_RETRY_MS,
} from "@/lib/copilot/quiet-run";
import {
BOT_CANNOT_RUN_MESSAGE_NOT_SENT,
CONNECTION_CUT_OFF,
RUN_NOT_STARTED,
TURN_CUT_OFF,
TURN_INTERRUPTED,
UNREADABLE_REPLY,
Expand Down Expand Up @@ -1055,21 +1057,49 @@ test.each(["intelligence", "sse"] as const)(
},
);

/*
* FOUND ON OPENBOT CLOUD, 2026-12-03 (Desktop 1.2.0-rc.5 connected to Cloud 1.2.9). A new
* conversation with a public Bot the runtime couldn't build: each run was answered 404 "Agent not
* found" while the Bot was still listed and read back, and the conversation said OpenBot couldn't
* reach its backend and to quit and reopen it. Only a backend that didn't answer is out of reach.
*/
test.each([
["the back end cannot be reached at all", "unreachable", "found"],
["the back end answers with a server error", "breaks", "breaks"],
["the run is refused but the Bot is still theirs", "refused", "found"],
["the run is refused and the Bot cannot be read", "refused", "breaks"],
[
"the back end cannot be reached at all",
"unreachable",
"found",
UNREACHABLE,
],
[
"the back end answers with a server error",
"breaks",
"breaks",
RUN_NOT_STARTED,
],
[
"the run is refused but the Bot is still theirs",
"refused",
"found",
BOT_CANNOT_RUN_MESSAGE_NOT_SENT,
],
[
"the run is refused and the Bot cannot be read",
"refused",
"breaks",
RUN_NOT_STARTED,
],
] as const)(
"a message that is not sent because %s still says the back end couldn't be reached",
async (_why, kind, read) => {
"a message that is not sent because %s says what happened",
async (_why, kind, read, sentence) => {
transport = "intelligence";
plans = [{ kind }];
botRead = read;
const live = open();
await send(live, "Summarise my inbox");
const shown = await live.findByTestId("transcript-stopped");
expect(shown.textContent).toBe(UNREACHABLE);
expect(shown.textContent).toBe(sentence);
if (kind !== "unreachable")
expect(live.queryByText(/couldn't reach|quit and reopen/)).toBeNull();
},
);

Expand Down
5 changes: 3 additions & 2 deletions app/tests/desktop-problems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,9 @@ test("a run whose request the server refused is handed over with the request id
await bot.runAgent().catch(() => undefined);
await waitFor(() => expect(recorded()).toHaveLength(1));
stop();
// The backend answered (a 500 problem): it was reached, and is not said to be out of reach.
const sentence =
"OpenBot couldn't reach its backend, so your message wasn't sent. Try again, or quit and reopen OpenBot.";
"OpenBot's backend couldn't start this turn, so your message wasn't sent. Try again, or ask an admin if it keeps happening.";
expect(shown.at(-1)).toBe(sentence);
expect(recorded()).toEqual([
{
Expand Down Expand Up @@ -522,7 +523,7 @@ test("in a browser, the same failures are kept in the page for the troubleshooti
{
kind: "run",
message:
"OpenBot couldn't reach its backend, so your message wasn't sent. Try again, or quit and reopen OpenBot.",
"OpenBot's backend couldn't start this turn, so your message wasn't sent. Try again, or ask an admin if it keeps happening.",
requestId: "req_run500",
appVersion: VERSION,
},
Expand Down
12 changes: 8 additions & 4 deletions app/tests/organization-unavailable-chat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ afterAll(async () => {
await stop();
});

const BACKEND_UNREACHABLE =
"OpenBot couldn't reach its backend, so your message wasn't sent. Try again, or quit and reopen OpenBot.";
/**
* A run the server answered with a fault (500): the backend was reached, so it says the backend
* couldn't start the turn, never that it couldn't be reached (stopped-turn.ts `RUN_NOT_STARTED`).
*/
const SERVER_FAULT =
"OpenBot's backend couldn't start this turn, so your message wasn't sent. Try again, or ask an admin if it keeps happening.";
const CHOICES_FAILED = "Couldn't load the choices. Try again in a moment.";
/** The server's sentence for a person over its limit (429). */
const TOO_MANY = "Too many call attempts. Try again in a moment.";
Expand Down Expand Up @@ -471,7 +475,7 @@ describe.skipIf(!asked)(
.getByTestId("transcript-stopped")
.waitFor({ timeout: 15_000 });
await style(page);
seen.conversation = await drawn(page, BACKEND_UNREACHABLE);
seen.conversation = await drawn(page, SERVER_FAULT);
} finally {
await page.close();
}
Expand All @@ -496,7 +500,7 @@ describe.skipIf(!asked)(
.getByTestId("bot-chat-stopped")
.waitFor({ timeout: 15_000 });
await style(page);
seen.botPage = await drawn(page, BACKEND_UNREACHABLE);
seen.botPage = await drawn(page, SERVER_FAULT);
} finally {
await page.close();
}
Expand Down
Loading