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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ jobs:
app/tests/browse-apps-pages.test.tsx
app/tests/browse-steps-layout.test.tsx
app/tests/bug-reports-layout.test.tsx
app/tests/carry-on-carried-turn-browser.test.tsx
app/tests/chunk-recovery.test.tsx
app/tests/command-card-layout.test.tsx
app/tests/component-bots-layout.test.tsx
Expand Down
53 changes: 47 additions & 6 deletions app/src/components/channels/channel-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,8 @@ export function ChannelChat({
);
const carriedByServerRef = useRef(carriedByServer);
carriedByServerRef.current = carriedByServer;
// The last of the server's runs this conversation followed, which says how its carried turn ended.
const lastCarriedRun = useRef<string | null>(null);
useEffect(() => {
if (!carriedByServer || !isReady) return;
let current = true;
Expand All @@ -1975,7 +1977,10 @@ export function ChannelChat({
stopped: () =>
!current || !carriedByServerRef.current || turnsRef.current > 0,
});
if (followed !== null) continue;
if (followed !== null) {
lastCarriedRun.current = followed;
continue;
}
// Nothing going yet: asked again when the conversation's work next changes, or after a while.
await nextRosterChange(quietRunPeriod.ms);
}
Expand All @@ -1986,6 +1991,30 @@ export function ChannelChat({
current = false;
};
}, [carriedByServer, isReady, channel.id, copilotkit, joinedPromise]);
/*
* A TURN CUT OFF HERE THAT THE SERVER CARRIED TO ITS ANSWER NO LONGER SAYS IT STOPPED. Its notice
* is put away while the server works (`stoppedTurn`), and comes back once the server is done only
* when the last of its runs followed here did not finish, with its Carry on.
*/
const wasCarriedByServer = useRef(carriedByServer);
useEffect(() => {
const was = wasCarriedByServer.current;
wasCarriedByServer.current = carriedByServer;
if (!was || carriedByServer) return;
const last = lastCarriedRun.current;
lastCarriedRun.current = null;
if (last === null) return;
let current = true;
void askRunEnding(channel.id, last).then((ending) => {
if (current && ending === "finished")
setRunError((shown) =>
shown !== null && carriesOn(shown.message) ? null : shown,
);
});
return () => {
current = false;
};
}, [carriedByServer, channel.id]);

/**
* Tell the roster what was just said. Failures here must not block the conversation.
Expand Down Expand Up @@ -3101,7 +3130,7 @@ export function ChannelChat({
* is still holding, and the failed turn is already reported by `runError` under the transcript.
*/
const askFromComponent = useCallback((text: string) => {
// Carry on, or a button a Bot drew: Bots can't run until a card is added, and the dialog says why.
// A button a Bot drew: Bots can't run until a card is added, and the dialog says why.
if (stopIfNeedsCard()) return;
void sayRef.current(text).catch(() => undefined);
}, []);
Expand Down Expand Up @@ -3186,8 +3215,19 @@ export function ChannelChat({
* Why the last turn stopped: what ended a run of it, or, with nothing going and nothing said since,
* the server having given up carrying it on after a decision (`leftCalls`).
*/
/*
* NOT A TURN CUT OFF HERE WHILE THE SERVER CARRIES IT ON. Found on OpenBot Cloud: the server
* running a turn went away, this page said "The Bot stopped before it finished because OpenBot's
* backend stopped answering", and another server took the turn up. The notice stayed over the
* working conversation, and its Carry on, sent while the server had the turn, did nothing. So
* while the server works the conversation reads as working, with no Carry on, and the notice comes
* back only if the turn ends without finishing (`lastCarriedRun`). Any other notice stays: a Stop
* the server refused is about this moment.
*/
const cutOffWhileCarried =
runError !== null && carriedByServer && carriesOn(runError.message);
const stoppedTurn =
runError ??
(cutOffWhileCarried ? null : runError) ??
(!workingRef.current && stoppedOnLeft(shown.messages, leftCalls)
? LEFT_STOPPED
: null);
Expand Down Expand Up @@ -3503,11 +3543,12 @@ export function ChannelChat({
* stream broke, or the server says its reply came back incomplete or its model's
* connection dropped and asks for the Bot to carry on) is carried on with one press: a
* short message, as the person, so the Bot picks the work up with everything it did in
* front of it.
* front of it. Sent as a message typed here is, so one pressed while the Bot still has
* the turn waits, drawn as queued, and goes once the turn is over.
*/
onCarryOn={
carryOn={
stoppedTurn !== null && carriesOn(stoppedTurn.message)
? () => askFromComponent(CARRY_ON)
? CARRY_ON
: undefined
}
stoppedDismissed={stoppedDismissal.dismissed}
Expand Down
67 changes: 63 additions & 4 deletions app/src/components/channels/conversation-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { idempotencyKey, organizationId } from "@/lib/api/request";
import type { ComposerAttachmentLimits } from "@/lib/deployment/queries";
import type { Failure } from "@/lib/load-failure";
import { useNotificationPermission } from "@/lib/notifications/permission";
import { stopIfNeedsCard } from "@/lib/plan/queries";
import { newId } from "../../lib/new-id";

/** How soon a drain the Bot was still too busy for goes again. Nothing is sent while it waits. */
Expand All @@ -58,7 +59,7 @@ export function ConversationView({
stopped,
refusals,
stoppedNotice,
onCarryOn,
carryOn,
stoppedDismissed,
onDismissStopped,
working,
Expand Down Expand Up @@ -130,8 +131,12 @@ export function ConversationView({
refusals?: ReadonlyMap<string, string>;
/** Drawn under `stopped`, or else the latest refusal (the transcript's `stoppedNotice`). */
stoppedNotice?: ReactNode;
/** Carry on with a turn that was cut off part way; a button beside `stopped`. */
onCarryOn?: () => void;
/**
* What Carry on says for the person, for a turn that was cut off part way: a button beside
* `stopped`. Sent as a message from the composer is, so one pressed while a turn is in flight is
* parked, drawn as queued, and sent once that turn is over.
*/
carryOn?: string;
/** `stopped` was dismissed for this turn: see the transcript's `stoppedDismissed`. */
stoppedDismissed?: boolean;
/** Dismiss `stopped`; see the transcript's `onDismissStopped`. */
Expand Down Expand Up @@ -482,6 +487,58 @@ export function ConversationView({
}
}, [canStop, inFlight, onStop]);

/**
* CARRY ON IS SENT AS A MESSAGE TYPED HERE IS: at once while the conversation is free, parked
* while a turn is in flight, and sent once that turn is over, by the drain below.
*
* Found on OpenBot Cloud: the server carried a cut-off turn on by itself, and Carry on, pressed
* then, was refused because the Bot still had the turn. The refusal was dropped, so the press did
* nothing at all: no message, no run, nothing on screen. A send refused that way here is parked
* the same way (`StillWorkingError`), and goes again as soon as the Bot is free. Any other failure
* is put back as a failed drain is, and the turn says what went wrong under it.
*
* Offered once: not while its words are already waiting, nor while the send a press started is
* going, so two presses never become two turns. Only that send: a turn the person typed that is
* cut off says so with its Carry on at once, while its stream is still closing, as it always has.
* Pressed then, it waits as queued like anything sent while a turn is in flight.
*/
const [carryOnSending, setCarryOnSending] = useState(false);
const carryOnWaits =
carryOn !== undefined && queued.some((message) => message.text === carryOn);
const pressCarryOn =
carryOn === undefined || carryOnWaits || carryOnSending
? undefined
: () => {
if (stopIfNeedsCard()) return;
const started = submit(
{
agentId: null,
attachments: [],
commandIds: [],
isEmpty: false,
text: carryOn,
},
inFlight,
);
if (!started) return;
setCarryOnSending(true);
void started
.catch((error: unknown) => {
restoreFailedRun(
[
{
attachments: [],
commandIds: [],
id: newId(),
text: carryOn,
},
],
error,
);
})
.finally(() => setCarryOnSending(false));
};

/**
* The turn ended. Whatever was waiting for it goes now, as one message.
*
Expand Down Expand Up @@ -590,7 +647,9 @@ export function ConversationView({
{...(stopped ? { stopped } : {})}
{...(refusals ? { refusals } : {})}
{...((stopped || refusals) && stoppedNotice ? { stoppedNotice } : {})}
{...(stopped && onCarryOn && !disabled ? { onCarryOn } : {})}
{...(stopped && pressCarryOn && !disabled
? { onCarryOn: pressCarryOn }
: {})}
{...(stopped && stoppedDismissed ? { stoppedDismissed } : {})}
{...(stopped && onDismissStopped ? { onDismissStopped } : {})}
working={working}
Expand Down
170 changes: 170 additions & 0 deletions app/tests/carried-turn.fixture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import { CopilotKitProvider, useFrontendTool } from "@copilotkit/react-core/v2";
import {
type InfiniteData,
QueryClientProvider,
useQuery,
} from "@tanstack/react-query";
import {
createBrowserHistory,
createRootRoute,
createRoute,
createRouter,
RouterProvider,
} from "@tanstack/react-router";
import { useEffect } from "react";
import { createRoot } from "react-dom/client";
import { z } from "zod";
import { AppSidebar } from "@/components/app-sidebar/app-sidebar";
import { ChannelChat } from "@/components/channels/channel-chat";
import { SidebarShell } from "@/components/layout/sidebar-shell";
import { SidebarInset } from "@/components/ui/sidebar";
import { TooltipProvider } from "@/components/ui/tooltip";
import { approvalKeys } from "@/lib/approvals";
import {
type AgentChannel,
type ChannelPage,
type ChannelWork,
channelKeys,
} from "@/lib/channels/queries";
import { ActiveBotProvider } from "@/lib/copilot/active-bot";
import { BotOffers } from "@/lib/copilot/bot-offer";
import { ComputerTools } from "@/lib/copilot/computer-tools";
import { quietRunPeriod } from "@/lib/copilot/quiet-run";
import { setCurrentOrganization } from "@/lib/organizations/current";
import { queryClient } from "@/query-client";

/**
* A conversation whose turn the server can carry on by itself, as a page of its own for
* carry-on-carried-turn-browser.test.tsx to bundle and load in a browser: the real conversation in
* the app's real frame, as run-ended-unheard.fixture.tsx draws it.
*
* The one thing it adds is what the app's socket does. The test's server says what the
* conversation's work is now and when the person's approvals changed, at `/fixture/live`, and this
* page puts that where the socket's busy event and its `approvals` hint put it: on the
* conversation's row in the roster, and by reading the approvals again. Everything else is the app's.
*
* The quiet period is the test's (`?quietMs=`), as in run-ended-unheard.fixture.tsx.
*/
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-11-25T18:00:00.000Z",
};

queryClient.setQueryDefaults(channelKeys.list(), { staleTime: Infinity });
queryClient.setQueryData<InfiniteData<ChannelPage>>(channelKeys.list(), {
pages: [
{
channels: [
{
...CONVERSATION,
summary: "Launch plan",
lastMessage: null,
lastMessageAgentId: null,
createdAt: "2026-11-25T18:00:00.000Z",
pinned: false,
lastReadAt: "2026-11-25T18:00:00.000Z",
},
],
nextCursor: null,
},
],
pageParams: [""],
});

/** A step the Bot asks this browser to take, answered here as a step on the computer is. */
function BrowserStep() {
useFrontendTool({
name: "fixture_step",
description: "A step the browser carries out.",
parameters: z.object({}).passthrough(),
handler: async () => ({ ok: true }),
});
return null;
}

type Live = { work: ChannelWork[]; approvals: number };
const NO_WORK: ChannelWork[] = [];

/** The conversation, with its work as the socket last said it. */
function Conversation() {
const live = useQuery({
queryKey: ["fixture", "live"],
queryFn: async (): Promise<Live> =>
(await fetch("/fixture/live")).json() as Promise<Live>,
refetchInterval: 150,
}).data;
const work = live?.work ?? NO_WORK;
const approvals = live?.approvals ?? 0;
useEffect(() => {
queryClient.setQueryData<InfiniteData<ChannelPage>>(
channelKeys.list(),
(list) =>
list && {
...list,
pages: list.pages.map((page) => ({
...page,
channels: page.channels.map((row) =>
row.id === CONVERSATION.id ? { ...row, work } : row,
),
})),
},
);
}, [work]);
useEffect(() => {
if (approvals > 0)
void queryClient.invalidateQueries({ queryKey: approvalKeys.all });
}, [approvals]);
return (
<ChannelChat
channel={work.length > 0 ? { ...CONVERSATION, work } : CONVERSATION}
runtimeAgentId="general-assistant"
/>
);
}

const rootRoute = createRootRoute({
component: () => (
<SidebarShell className="h-svh overflow-hidden">
<AppSidebar />
<SidebarInset className="min-h-0 overflow-hidden">
<ActiveBotProvider>
<BotOffers />
<ComputerTools />
<BrowserStep />
<Conversation />
</ActiveBotProvider>
</SidebarInset>
</SidebarShell>
),
});
const router = createRouter({
history: createBrowserHistory(),
routeTree: rootRoute.addChildren([
createRoute({
getParentRoute: () => rootRoute,
path: "$",
component: () => null,
}),
]),
});

const root = document.getElementById("root");
if (root)
createRoot(root).render(
<QueryClientProvider client={queryClient}>
<CopilotKitProvider credentials="include" runtimeUrl="/api/copilotkit">
<TooltipProvider>
<RouterProvider router={router as never} />
</TooltipProvider>
</CopilotKitProvider>
</QueryClientProvider>,
);
Loading