Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ jobs:
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 --env OPENBOT_APP_ENGINES=chromium,webkit \
"$PLAYWRIGHT_IMAGE" \
bun test --parallel="$TEST_WORKERS" --timeout="$TEST_TIMEOUT_MS" app/tests/chunk-recovery.test.tsx app/tests/composer-dictation-language.test.tsx app/tests/sidebar-zoom-drag.test.tsx app/tests/service-terms.test.tsx app/tests/move-to-cloud-settings.test.tsx app/tests/moved-elsewhere.test.tsx app/tests/home-no-answer.test.tsx app/tests/section-strip-routines.test.tsx app/tests/organization-members-remove.test.tsx app/tests/settings-tool-cards-admin-layout.test.tsx app/tests/settings-tool-cards-personal.test.tsx app/tests/add-custom-mcp-card-layout.test.tsx app/tests/settings-tool-cards-core.test.tsx app/tests/one-press-connect-layout.test.tsx app/tests/sign-in-reconnect-layout.test.tsx app/tests/admin-notion-one-press-layout.test.tsx app/tests/team-connections-directory-layout.test.tsx app/tests/conversation-switch.test.tsx app/tests/conversation-kept-browser.test.tsx app/tests/conversation-resume.test.tsx app/tests/conversation-return-running.test.tsx app/tests/member-rows-long-names.test.tsx app/tests/people-lists.test.tsx app/tests/organization-moving.test.tsx app/tests/organization-removed.test.tsx app/tests/organization-held-reload.test.tsx app/tests/organization-unavailable-pages.test.tsx app/tests/organization-held-actions.test.tsx app/tests/organization-unavailable-admin-pages.test.tsx app/tests/organization-held-recovery.test.tsx app/tests/bot-screen-sharp.test.tsx app/tests/bots-panel-start-conversation.test.tsx app/tests/table-export-browser.test.tsx app/tests/organization-unavailable-chat.test.tsx app/tests/too-many-follow-ups.test.tsx app/tests/moved-apps-reconnect.test.tsx app/tests/composer-keeps-draft-browser.test.tsx app/tests/conversation-reply-toolbar-layout.test.tsx app/tests/roster-working.test.tsx app/tests/delete-account-layout.test.tsx app/tests/composer-touch-return.test.tsx app/tests/bot-long-instructions-layout.test.tsx app/tests/web-push-browser.test.tsx app/tests/computer-panel-phone-layout.test.tsx app/tests/computer-starting-browser.test.tsx app/tests/browse-apps-pages.test.tsx app/tests/hand-back-row-layout.test.tsx app/tests/first-message-thinking.test.tsx app/tests/group-conversation-gutter.test.tsx app/tests/new-conversation-picked-model.test.tsx app/tests/renderer-crash.test.ts app/tests/home-holds-still.test.tsx app/tests/app-frame-skeleton-still.test.tsx app/tests/step-rows-layout.test.tsx app/tests/sign-in-returns-there.test.tsx app/tests/sign-in-with-apple-layout.test.tsx app/tests/stopped-command-layout.test.tsx
bun test --parallel="$TEST_WORKERS" --timeout="$TEST_TIMEOUT_MS" app/tests/chunk-recovery.test.tsx app/tests/composer-dictation-language.test.tsx app/tests/sidebar-zoom-drag.test.tsx app/tests/service-terms.test.tsx app/tests/move-to-cloud-settings.test.tsx app/tests/moved-elsewhere.test.tsx app/tests/home-no-answer.test.tsx app/tests/section-strip-routines.test.tsx app/tests/organization-members-remove.test.tsx app/tests/settings-tool-cards-admin-layout.test.tsx app/tests/settings-tool-cards-personal.test.tsx app/tests/add-custom-mcp-card-layout.test.tsx app/tests/settings-tool-cards-core.test.tsx app/tests/one-press-connect-layout.test.tsx app/tests/sign-in-reconnect-layout.test.tsx app/tests/admin-notion-one-press-layout.test.tsx app/tests/team-connections-directory-layout.test.tsx app/tests/conversation-switch.test.tsx app/tests/conversation-kept-browser.test.tsx app/tests/conversation-resume.test.tsx app/tests/conversation-return-running.test.tsx app/tests/reload-keeps-answer-browser.test.tsx app/tests/member-rows-long-names.test.tsx app/tests/people-lists.test.tsx app/tests/organization-moving.test.tsx app/tests/organization-removed.test.tsx app/tests/organization-held-reload.test.tsx app/tests/organization-unavailable-pages.test.tsx app/tests/organization-held-actions.test.tsx app/tests/organization-unavailable-admin-pages.test.tsx app/tests/organization-held-recovery.test.tsx app/tests/bot-screen-sharp.test.tsx app/tests/bots-panel-start-conversation.test.tsx app/tests/table-export-browser.test.tsx app/tests/organization-unavailable-chat.test.tsx app/tests/too-many-follow-ups.test.tsx app/tests/moved-apps-reconnect.test.tsx app/tests/composer-keeps-draft-browser.test.tsx app/tests/conversation-reply-toolbar-layout.test.tsx app/tests/roster-working.test.tsx app/tests/delete-account-layout.test.tsx app/tests/composer-touch-return.test.tsx app/tests/bot-long-instructions-layout.test.tsx app/tests/web-push-browser.test.tsx app/tests/computer-panel-phone-layout.test.tsx app/tests/computer-starting-browser.test.tsx app/tests/browse-apps-pages.test.tsx app/tests/hand-back-row-layout.test.tsx app/tests/first-message-thinking.test.tsx app/tests/group-conversation-gutter.test.tsx app/tests/new-conversation-picked-model.test.tsx app/tests/renderer-crash.test.ts app/tests/home-holds-still.test.tsx app/tests/app-frame-skeleton-still.test.tsx app/tests/step-rows-layout.test.tsx app/tests/sign-in-returns-there.test.tsx app/tests/sign-in-with-apple-layout.test.tsx app/tests/stopped-command-layout.test.tsx
# Connect your AI's sign-in code, copied with one press and read back from WebKit's clipboard.
# Only that test: the rest of the file runs in Chromium in the job above.
- run: |
Expand Down
66 changes: 49 additions & 17 deletions app/src/components/channels/channel-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ import { newId } from "../../lib/new-id";
*/
const JOIN_DEADLINE_MS = 1500;

/** One join's gate (`joinSettled`): open once that join has replayed the thread, or given up. */
type JoinedGate = { promise: Promise<void>; open: () => void };

function joinedGate(): JoinedGate {
let open: () => void = () => {};
const promise = new Promise<void>((resolve) => {
open = resolve;
});
return { promise, open };
}

/**
* How long the runtime is given to say whether a turn the roster reports can still be heard, before
* the join is ended. Shorter than a quiet run's ask: the conversation shows nothing while it waits.
Expand Down Expand Up @@ -808,15 +819,30 @@ export function ChannelChat({
/**
* Opened once the join has replayed the thread, or given up, and before history is read. Every
* read of the store waits for it; see `pull` below.
*
* ONE GATE PER JOIN, AND THE WAIT IS FOR THE NEWEST. The join below can run more than once as
* the conversation opens: in development React runs it twice on mount (StrictMode, main.tsx), and
* the conversation's agent is kept and ready at once (`useKeptAgent`), so both runs join the
* thread; the agent changing, or OpenBot answering again (`joins`), runs it again too. The first
* join, given up for the second, is over at once, and a gate it opened let a read through before
* the second had replayed the thread. FOUND BY THE STOCK AG-UI APPROVAL JOURNEY, reloaded a moment
* after the Bot answered: the sidebar's list arrived and its read merged the whole stored history
* onto the agent; the second join's replay then rebuilt the agent from the thread's first run and
* was cut at its deadline before the second, which held the answer; and the opening's own read had
* been taken over by the list's, so nothing read the store again. The answer was on screen for half
* a second, then gone until the conversation was opened again. Each join now has a gate of its own,
* and `joinSettled` waits until the newest join's gate is open.
*/
const openJoined = useRef<() => void>(() => {});
const joinedGate = useRef<Promise<void> | null>(null);
if (joinedGate.current === null) {
joinedGate.current = new Promise<void>((resolve) => {
openJoined.current = resolve;
});
}
const joinedPromise = joinedGate.current;
const joined = useRef<JoinedGate | null>(null);
if (joined.current === null) joined.current = joinedGate();
const joinSettled = useCallback(async () => {
for (;;) {
const gate = joined.current;
if (!gate) return;
await gate.promise;
if (joined.current === gate) return;
}
}, []);

/** Promise gate so messages typed before runtime readiness wait instead of being discarded. */
const openReadyGate = useRef<() => void>(() => {});
Expand Down Expand Up @@ -961,7 +987,7 @@ export function ChannelChat({
// Just made here: nothing to join or read, and the first message is not held for it (`fresh`).
// Asked again when OpenBot answers again (`joins`), it is joined as any conversation is.
if (fresh && joins === 0) {
openJoined.current();
joined.current?.open();
openJoinGate.current();
return;
}
Expand All @@ -976,7 +1002,7 @@ export function ChannelChat({
*/
if (liveJoin(agent)) {
setRestoring(false);
openJoined.current();
joined.current?.open();
openJoinGate.current();
void joinsEnded(agent).then(() => {
if (current) setJoins((count) => count + 1);
Expand All @@ -986,6 +1012,12 @@ export function ChannelChat({
};
}
const version = ++historyReadVersion.current;
// This join's own gate: reads wait for this join, not one an earlier run of this effect made
// (`joinSettled`). Whoever waits on the earlier gate is let through once this one opens.
const previousGate = joined.current;
const gate = joinedGate();
joined.current = gate;
if (previousGate) void gate.promise.then(previousGate.open);
// Before the connect: it is handed the subscribers the agent has when it starts.
const lastRun = followLastRun(agent);
/*
Expand Down Expand Up @@ -1121,7 +1153,7 @@ export function ChannelChat({
joinOver = true;
// The stored copy stays up until the history below is on the agent: see `earlyHistory`.
if (current) setReplaying(false);
openJoined.current();
gate.open();
}
/*
* The turn the join was kept for had ended without a word reaching here: say so, unless the
Expand Down Expand Up @@ -1424,7 +1456,7 @@ export function ChannelChat({
* reload. The roster can announce a Bot's turn at any moment, the moment the conversation
* opens included, so every read waits for the join to be over.
*/
await joinedPromise;
await joinSettled();
// Nor while a run of a turn going on in a chat that closed is joined: see `rejoining`.
await rejoining.current;
if (!isCurrent()) return;
Expand Down Expand Up @@ -1569,7 +1601,7 @@ export function ChannelChat({
channel.id,
channel.threadId,
joinGatePromise,
joinedPromise,
joinSettled,
runtimeAgentId,
historyShare,
]);
Expand All @@ -1587,7 +1619,7 @@ export function ChannelChat({
const off = onRunStartedAway(channel.id, () => {
const previous = rejoining.current;
rejoining.current = (async () => {
await joinedPromise;
await joinSettled();
await previous;
const target = agentRef.current;
if (!current || turnsRef.current > 0 || target.isRunning) return;
Expand All @@ -1602,7 +1634,7 @@ export function ChannelChat({
current = false;
off();
};
}, [channel.id, copilotkit, joinedPromise]);
}, [channel.id, copilotkit, joinSettled]);

// Tool calls from this conversation act on this coworker's own computer.
useActiveBot(runtimeAgentId);
Expand Down Expand Up @@ -1856,7 +1888,7 @@ export function ChannelChat({
let current = true;
void (async () => {
// After the conversation has joined its thread: a run going then streams in through that join.
await joinedPromise;
await joinSettled();
while (current && carriedByServerRef.current) {
const target = agentRef.current;
// This tab's own turn follows the server's runs itself (`deliver`), and a join is a run.
Expand All @@ -1883,7 +1915,7 @@ export function ChannelChat({
return () => {
current = false;
};
}, [carriedByServer, isReady, channel.id, copilotkit, joinedPromise]);
}, [carriedByServer, isReady, channel.id, copilotkit, joinSettled]);

/**
* Tell the roster what was just said. Failures here must not block the conversation.
Expand Down
Loading
Loading