Skip to content
Merged
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 api/accepted-live-breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Once the change is on the base branch, the check no longer reports it and its li
- 2026-11-26 `add /components/schemas/ConversationWork/properties/kind/x-extensible-enum`: the same change, its open list.
- 2026-11-26 `remove /components/schemas/ConversationActivity/properties/work/items/properties/kind/enum`: the same change, where the message's work is resolved.
- 2026-11-26 `add /components/schemas/ConversationActivity/properties/work/items/properties/kind/x-extensible-enum`: the same change, its open list there.
- 2026-12-02 `add /channels/conversationEvents/bindings/ws/query/properties/client`: the socket gains a second optional query parameter, `client`, naming the app that opens it as the OpenBot-Client header does. The server only writes it into its log when it refuses the socket; a socket opened without it is answered the same, so no client loses anything.
10 changes: 10 additions & 0 deletions api/asyncapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ channels:
can name the person's own turn (ConversationWork);
data-changed, the socket is sent dataChanged; and
artifact-activity, the socket is sent artifactActivity.
client:
type: string
maxLength: 200
description: >-
The app that opens the socket, as the OpenBot-Client header
names it on a request (`<kind>/<version>`, such as
`web/1.2.8`), since a browser can't set a header on a
WebSocket. Optional, and used only to name the app in the
server's log when it refuses the socket: nothing is refused
for it, and a socket opened without it is answered the same.
bindingVersion: 0.1.0
messages:
conversationActivity:
Expand Down
21 changes: 21 additions & 0 deletions app/src/components/auth/signed-out-watch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useRouter } from "@tanstack/react-router";
import { useEffect } from "react";
import { onSignedOutFound } from "@/lib/auth/session-check";

/**
* Found out, while the app is open, that nobody is signed in any more (lib/auth/session-check.ts):
* the signed-in gate runs again (`_authed`), and does what it does on a load. The sign-in screen,
* bringing the person back to this page; inside OpenBot Desktop, Desktop's own renewal; embedded,
* the host's. Draws nothing.
*/
export function SignedOutWatch() {
const router = useRouter();
useEffect(
() =>
onSignedOutFound(() => {
void router.invalidate();
}),
[router],
);
return null;
}
62 changes: 62 additions & 0 deletions app/src/lib/auth/session-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { QueryClient } from "@tanstack/react-query";
import { currentUserQueryOptions } from "./queries";

/**
* What OpenBot said when asked again who is signed in: somebody, nobody, or no answer (the network,
* a 5xx, a page that is not OpenBot's), which is never read as signed out (lib/auth/signed-out.ts).
*/
export type SessionAnswer = "signed-in" | "signed-out" | "unknown";

/*
* A SIGNED-OUT TAB MUST STOP ASKING. Some of what the app keeps open never sees a 401 it can read: a
* browser hides the status of a WebSocket upgrade it was refused, and only tells the page the socket
* closed. A tab signed out elsewhere (in another tab, by an admin, by the session running out) went
* on reconnecting every 30 seconds and reading a computer's wheel every second or two, for hours,
* and never told the person (Cloud alert, 2 Dec 2026: conversation-events refused 401 at 25%).
*
* So what was refused that way asks here, once, who is signed in, with the app's own question
* (`getPerson`, the one the `_authed` gate asks). Nobody: whatever asked stops, and the app is told
* (`onSignedOutFound`), which runs the gate again (`SignedOutWatch`): the sign-in screen, or inside
* OpenBot Desktop and embedded, their own ways of signing in again.
*/
const listeners = new Set<() => void>();
let asking: Promise<SessionAnswer> | undefined;

/**
* Ask OpenBot again whether anybody is signed in, past the cached answer. One question at a time,
* however many sockets and reads ask together. Nobody signed in is told to `onSignedOutFound`.
*/
export function askWhoIsSignedIn(
queryClient: QueryClient,
): Promise<SessionAnswer> {
if (asking) return asking;
const question = queryClient
.fetchQuery({ ...currentUserQueryOptions(), staleTime: 0 })
.then(
(user): SessionAnswer => (user ? "signed-in" : "signed-out"),
(): SessionAnswer => "unknown",
)
.then((answer) => {
if (answer === "signed-out")
for (const listener of [...listeners]) listener();
return answer;
})
.finally(() => {
if (asking === question) asking = undefined;
});
asking = question;
return question;
}

/** Hear that OpenBot answered nobody is signed in. Returns how to stop hearing. */
export function onSignedOutFound(listener: () => void): () => void {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}

/** Whether the cached answer to who is signed in is somebody: a sign-in again, after nobody. */
export function signedInNow(queryClient: QueryClient): boolean {
return Boolean(queryClient.getQueryData(currentUserQueryOptions().queryKey));
}
62 changes: 58 additions & 4 deletions app/src/lib/channels/use-channel-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
resyncArtifacts,
} from "@/lib/artifacts/activity";
import { HELD_OUT_NOW, holdOut, SSO_REQUIRED_CLOSE } from "@/lib/auth/held-out";
import { CAPABILITIES } from "@/lib/client";
import { askWhoIsSignedIn, signedInNow } from "@/lib/auth/session-check";
import { CAPABILITIES, CLIENT_NAME } from "@/lib/client";
import { deploymentCapabilitiesQueryOptions } from "@/lib/deployment/queries";
import { embedSocketRenewal } from "@/lib/embed/session";
import {
Expand Down Expand Up @@ -664,12 +665,23 @@ export function recoveryReadDelayMs(random: number = Math.random()): number {
/**
* The socket names the newer messages this app understands in its query, as every request does in
* its OpenBot-Capabilities header (`lib/client.ts`): a browser can't set a header on a WebSocket.
* It names this app too (`client`), as the OpenBot-Client header does, so a socket OpenBot refuses
* is logged with the app that asked.
*/
function socketUrl() {
const query = new URLSearchParams({ [CAPABILITIES_QUERY]: CAPABILITIES });
const query = new URLSearchParams({
[CAPABILITIES_QUERY]: CAPABILITIES,
client: CLIENT_NAME,
});
return `${buildSocketUrl(apiSocketPath("/conversation-events"))}?${query}`;
}

/**
* How seldom a socket that goes on being refused before it opens asks again who is signed in, once
* OpenBot said somebody is: as seldom as the slowest reconnect.
*/
const ASK_AGAIN_MS = MAX_RETRY_MS;

export function useChannelEvents() {
const queryClient = useQueryClient();
const router = useRouter();
Expand Down Expand Up @@ -697,13 +709,53 @@ export function useChannelEvents() {
let stopped = false;
// Embedded, a socket refused for want of a session renews it once and opens again at once.
const renewal = embedSocketRenewal();
/** When this socket last asked who is signed in, after being refused before it opened. */
let askedAt: number | undefined;
/** Waiting for somebody to be signed in again, after OpenBot said nobody is. */
let stopWaiting: (() => void) | undefined;

const retryLater = () => {
if (stopped) return;
retryTimer = window.setTimeout(connect, reconnectDelayMs(attempts));
attempts += 1;
};

/*
* Nobody signed in: not reconnected. The app runs its gate again (`SignedOutWatch`), which takes
* the tab to signing in, and this screen goes with it. Should the gate keep the tab (OpenBot
* Desktop renewed its sign-in), the socket opens again once somebody is signed in.
*/
const waitForSignIn = () => {
if (stopped || stopWaiting) return;
const stop = queryClient.getQueryCache().subscribe(() => {
if (!signedInNow(queryClient)) return;
stop();
stopWaiting = undefined;
attempts = 0;
connect();
});
stopWaiting = stop;
};

/**
* Refused before it opened. A browser never shows the page why, so OpenBot is asked who is
* signed in (`askWhoIsSignedIn`): on the first refusal since the socket was last open, and then
* no more often than {@link ASK_AGAIN_MS}. Nobody: wait for a sign-in; anything else: as before.
*/
const refusedBeforeOpening = () => {
const now = Date.now();
if (askedAt !== undefined && now - askedAt < ASK_AGAIN_MS) {
retryLater();
return;
}
askedAt = now;
askWhoIsSignedIn(queryClient).then((answer) => {
if (stopped) return;
if (answer === "signed-out") waitForSignIn();
else retryLater();
}, retryLater);
};

/** Read the lists, as nothing patched while the socket was not heard can be trusted. */
const readLists = () => {
// An artifact open on screen reads its comments and viewers again, as the roster does.
Expand Down Expand Up @@ -741,6 +793,7 @@ export function useChannelEvents() {
opened = true;
renewal.opened();
attempts = 0;
askedAt = undefined;
/*
* A turn's end said while the socket was down was never heard, so what it said before is
* let go of: the read below is the best word there is. This tab's own turns stay held.
Expand Down Expand Up @@ -876,8 +929,8 @@ export function useChannelEvents() {
renewal.closedBeforeOpening().then((renewed) => {
if (stopped) return;
if (renewed) connect();
else retryLater();
}, retryLater);
else refusedBeforeOpening();
}, refusedBeforeOpening);
return;
}
retryLater();
Expand All @@ -888,6 +941,7 @@ export function useChannelEvents() {

return () => {
stopped = true;
stopWaiting?.();
if (retryTimer !== undefined) window.clearTimeout(retryTimer);
if (readTimer !== undefined) window.clearTimeout(readTimer);
// Cleared first: the close below must not schedule a reconnect for a screen that is gone.
Expand Down
23 changes: 16 additions & 7 deletions app/src/lib/computers/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
takeComputerControl,
} from "@/lib/api/generated/computers/computers";
import { idempotencyKey, organizationId } from "@/lib/api/request";
import { refusedAsSignedOut } from "@/lib/auth/signed-out";
import { ClientError } from "@/lib/client";
import type { Failure } from "@/lib/load-failure";

Expand Down Expand Up @@ -103,30 +104,38 @@ export function readControl(
/** A read of the wheel that answered "not found": the Bot is not one this person can use. */
export const BOT_GONE = "gone";

/** A read of the wheel that OpenBot refused with its own 401: nobody is signed in. */
export const SIGNED_OUT = "signed-out";

/**
* Who is driving, for the poll: as `readControl`, and saying when the Bot itself is not there.
* Who is driving, for the poll: as `readControl`, and saying when the Bot itself is not there, or
* when nobody is signed in.
*
* The API answers the read 404 when the Bot does not exist or is not this person's any more (a Bot
* shared with a team they were taken out of). That is an answer and not a hiccup: asking again a
* second later gets it again, for as long as the screen stays open.
* shared with a team they were taken out of), and 401 when the person was signed out (elsewhere, by
* an admin, or their session ran out). Both are answers and not hiccups: asking again a second later
* gets them again, for as long as the screen stays open. Only OpenBot's own 401 is signed out
* (`refusedAsSignedOut`): a proxy's, or a hosted sign-in that needs renewing, is no answer.
*/
export async function readControlOrGone(
computerId: string,
signal?: AbortSignal,
): Promise<ControlState | typeof BOT_GONE | null> {
let gone = false;
): Promise<ControlState | typeof BOT_GONE | typeof SIGNED_OUT | null> {
let refusal: typeof BOT_GONE | typeof SIGNED_OUT | undefined;
const control = await controlFrom(
getComputerControl(
organizationId(),
computerId,
undefined,
signal ? { signal } : {},
).catch((error: unknown) => {
gone = error instanceof ClientError && error.status === 404;
if (error instanceof ClientError && error.status === 404)
refusal = BOT_GONE;
else if (refusedAsSignedOut(error)) refusal = SIGNED_OUT;
throw error;
}),
);
return gone ? BOT_GONE : control;
return refusal ?? control;
}

export async function takeControl(computerId: string, requestId?: string) {
Expand Down
16 changes: 13 additions & 3 deletions app/src/lib/computers/use-control.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery } from "@tanstack/react-query";
import { useSyncExternalStore } from "react";
import { currentUserQueryOptions } from "@/lib/auth/queries";
import { askWhoIsSignedIn } from "@/lib/auth/session-check";
import {
type WindowAttention,
watchWindowAttention,
Expand All @@ -14,6 +15,7 @@ import {
cancelControl,
readControlOrGone,
releaseControl,
SIGNED_OUT,
takeControl,
} from "./control";
import { nextReadIn, STEADY_READS } from "./poll-pace";
Expand Down Expand Up @@ -47,7 +49,7 @@ function createControlStore(computerId: string): ControlStore {
let failures = 0;
/** Reads in a row that answered what the one before did, which slows the next (`nextReadIn`). */
let unchanged = 0;
/** The last read answered that the Bot is not this person's to use. See `refresh`. */
/** The last read answered that the Bot is not this person's to use, or that nobody is signed in. See `read`. */
let gone = false;
let stopWatching: (() => void) | undefined;
const listeners = new Set<() => void>();
Expand Down Expand Up @@ -111,14 +113,22 @@ function createControlStore(computerId: string): ControlStore {
* the read is not asked again every second (it was, 55 times in one capture of an open
* conversation). Coming back to the tab asks once more, in case the Bot is theirs again.
*/
gone = answer === BOT_GONE;
/*
* Nobody is signed in any more: signed out elsewhere, by an admin, or the session ran out. The
* same as a Bot that is gone, the read stops (it went on every second or two for hours, in a tab
* signed out since the afternoon), and the app is asked to find out who is signed in, which
* takes the tab to signing in again (`askWhoIsSignedIn`).
*/
gone = answer === BOT_GONE || answer === SIGNED_OUT;
if (gone) {
failures = 0;
if (answer === SIGNED_OUT) void askWhoIsSignedIn(queryClient);
if (snapshot.control || snapshot.problem)
publish({ ...snapshot, control: null, problem: null });
return;
}
const control = answer === BOT_GONE ? null : answer;
const control =
answer === BOT_GONE || answer === SIGNED_OUT ? null : answer;
/*
* One read that did not come back is not news. It used to blank the control state at once, which
* took the wheel off a person mid-sentence: their keyboard stopped being forwarded and every key
Expand Down
9 changes: 6 additions & 3 deletions app/src/routes/_authed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ReactNode } from "react";
import { BotLookProvider } from "../components/agents/bot-look";
import { BeingDeletedGate } from "../components/auth/being-deleted-page";
import { HeldOutGate } from "../components/auth/company-sign-in-page";
import { SignedOutWatch } from "../components/auth/signed-out-watch";
import { WebPushKeeper } from "../components/delivery/web-push-keeper";
import { OpenFromApp } from "../components/desktop/open-from-app";
import { TeamFeaturesDialog } from "../components/edition/team-features-dialog";
Expand Down Expand Up @@ -32,6 +33,9 @@ import {
import { signInReturnPath } from "../lib/auth/resume";
import { fittedReturnPath } from "../lib/auth/return-address";
import { forgetSignedIn, rememberSignedIn } from "../lib/auth/was-signed-in";
import { CopilotProvider } from "../lib/copilot/provider";
import { whenConnectionBack } from "../lib/desktop/connection-lost";
import { noteUnreachable } from "../lib/desktop/reachability";
import { embedConfig } from "../lib/embed/config";
import {
EMBED_REFUSED_DEFAULT_MESSAGE,
Expand All @@ -41,9 +45,6 @@ import {
SIGNED_OUT,
withoutEmbedRenewal,
} from "../lib/embed/session";
import { CopilotProvider } from "../lib/copilot/provider";
import { whenConnectionBack } from "../lib/desktop/connection-lost";
import { noteUnreachable } from "../lib/desktop/reachability";
import { ReportedErrorComponent } from "../lib/error-reporting";
import { AppHotkeys } from "../lib/hotkeys/app-hotkeys";
import { standingInWhileLoadingAgain } from "../lib/load-again";
Expand Down Expand Up @@ -342,6 +343,8 @@ function AuthedApp() {
*/}
<SkinBotLook>
<AppHotkeys />
{/* Nobody signed in any more, found out by a socket or a read refused: the gate again, so the tab signs in. */}
<SignedOutWatch />
{/* This browser's push subscription, saved again in each organization OpenBot starts in. */}
<WebPushKeeper />
{/* For an admin: requests for apps kept counted, and a notice for a new one while OpenBot is out of sight. */}
Expand Down
Loading