The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix: stabilize onboarding and thread selection e2e
Steven Enamakel08cd9d4b4522
diff --git a/app/src/components/InitProgressScreen/InitProgressScreen.tsx b/app/src/components/InitProgressScreen/InitProgressScreen.tsxindex 26bc1cea8e..3d88efded1 100644--- a/app/src/components/InitProgressScreen/InitProgressScreen.tsx+++ b/app/src/components/InitProgressScreen/InitProgressScreen.tsx@@ -82,6 +82,7 @@ export default function InitProgressScreen({<div className="fixed inset-0 z-9999 flex items-center justify-center bg-stone-950/90 p-4 backdrop-blur-sm"><divrole="dialog"+ data-testid="harness-init-dialog"aria-modal="true"aria-labelledby="harness-init-title"className="w-full max-w-md rounded-2xl border border-stone-700/60 bg-stone-900 p-6 shadow-2xl">@@ -101,6 +102,7 @@ export default function InitProgressScreen({<p className="text-xs text-content-muted">{t('harnessInit.backgroundHint')}</p><buttontype="button"+ data-testid="harness-init-continue"onClick={onContinue}className="shrink-0 rounded-lg border border-stone-700 px-3 py-1.5 text-sm text-content-faint hover:bg-stone-800 hover:text-white">{t('harnessInit.runInBackground')}@@ -121,6 +123,7 @@ export default function InitProgressScreen({<div className="mt-4 flex justify-end gap-2"><buttontype="button"+ data-testid="harness-init-continue"onClick={onContinue}className="rounded-lg px-3 py-1.5 text-sm text-content-faint hover:text-white">{t('harnessInit.continueAnyway')}diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex af2fa551e2..5bc66a7150 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -1,5 +1,6 @@import debugFactory from 'debug';import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';+import { useStore } from 'react-redux';import { useLocation, useNavigate, useParams } from 'react-router-dom';import { type ChatSendError, chatSendError } from '../../chat/chatSendError';@@ -69,6 +70,7 @@ import {useRustChat,} from '../../services/chatService';import { callCoreRpc } from '../../services/coreRpcClient';+import type { RootState } from '../../store';import {beginInferenceTurn,clearRuntimeForThread,@@ -89,6 +91,7 @@ import {clearThreadInferenceActive,createNewThread,deleteThread,+ invalidateThreadSelection,loadThreadMessages,loadThreads,markThreadInferenceActive,@@ -269,6 +272,7 @@ const Conversations = ({const composer = composerOverride ?? composerProp;const { t } = useT();const dispatch = useAppDispatch();+ const store = useStore<RootState>();const navigate = useNavigate();const location = useLocation();const { threadId: routeThreadId } = useParams<{ threadId?: string }>();@@ -357,10 +361,9 @@ const Conversations = ({const persistedFailedMessageByThreadRef = useRef<Map<string, ThreadMessage>>(new Map());const createThreadErrorRef = useRef(createThreadError);createThreadErrorRef.current = createThreadError;- // Startup thread restoration is asynchronous. If the user chooses a thread- // while its initial `loadThreads` is in flight, that older callback must not- // overwrite the newer selection when it resolves.- const threadSelectionIntentRef = useRef(0);+ // The Redux selection intent is updated by every setSelectedThread action,+ // including worker-thread cards rendered inside the transcript. Async+ // startup/create continuations compare against it before selecting a thread.const displayedSendError = deriveChatErrorBanner(sendError,createThreadError,@@ -740,11 +743,11 @@ const Conversations = ({const turnSignatureByThreadRef = useRef<Map<string, readonly unknown[]>>(new Map());const handleCreateNewThread = async (fromInitialLoad = false) => {- if (!fromInitialLoad) threadSelectionIntentRef.current += 1;- const selectionIntentAtCreate = threadSelectionIntentRef.current;+ if (!fromInitialLoad) dispatch(invalidateThreadSelection());+ const selectionIntentAtCreate = store.getState().thread.selectionIntentVersion ?? 0;try {const thread = await dispatch(createNewThread()).unwrap();- if (threadSelectionIntentRef.current !== selectionIntentAtCreate) return;+ if ((store.getState().thread.selectionIntentVersion ?? 0) !== selectionIntentAtCreate) return;dispatch(setSelectedThread(thread.id));void dispatch(loadThreadMessages(thread.id));if (shouldSyncChatRoute) {@@ -841,12 +844,16 @@ const Conversations = ({useEffect(() => {let cancelled = false;- const selectionIntentAtLoad = threadSelectionIntentRef.current;+ const selectionIntentAtLoad = store.getState().thread.selectionIntentVersion ?? 0;void dispatch(loadThreads()).unwrap().then(data => {- if (cancelled || threadSelectionIntentRef.current !== selectionIntentAtLoad) return;+ if (+ cancelled ||+ (store.getState().thread.selectionIntentVersion ?? 0) !== selectionIntentAtLoad+ )+ return;// Match the sidebar's default General filter here so initial/resume// selection can't auto-pick a thread hidden by the selected tab.const visibleThreads = data.threads.filter(t => isThreadVisibleInTab(t, GENERAL_TAB_VALUE));@@ -1940,7 +1947,6 @@ const Conversations = ({selectedThreadId={selectedThreadId ?? null}onCreateThread={() => void handleCreateNewThread()}onSelectThread={id => {- threadSelectionIntentRef.current += 1;dispatch(setSelectedThread(id));void dispatch(loadThreadMessages(id));if (shouldSyncChatRoute) {@@ -2354,7 +2360,6 @@ const Conversations = ({type="button"data-analytics-id="chat-header-back-to-parent-thread"onClick={() => {- threadSelectionIntentRef.current += 1;dispatch(setSelectedThread(selectedThreadParent.id));void dispatch(loadThreadMessages(selectedThreadParent.id));navigate(chatThreadPath(selectedThreadParent.id));diff --git a/app/src/pages/__tests__/Conversations.render.test.tsx b/app/src/pages/__tests__/Conversations.render.test.tsxindex 7d334dcf15..f29cd63a7b 100644--- a/app/src/pages/__tests__/Conversations.render.test.tsx+++ b/app/src/pages/__tests__/Conversations.render.test.tsx@@ -266,6 +266,7 @@ async function openSidebar() {const emptyThreadState = {threads: [],selectedThreadId: null,+ selectionIntentVersion: 0,activeThreadIds: {},welcomeThreadId: null,messagesByThreadId: {},@@ -734,6 +735,43 @@ describe('Conversations — smoke render (#1123 welcome-lock removal)', () => {});});+ it('keeps an explicit sidebar selection made while initial thread loading is pending', async () => {+ const threads = [+ makeThread({ id: 't-1', title: 'Initial Thread' }),+ makeThread({ id: 't-2', title: 'Explicitly Selected Thread' }),+ ];+ let resolveThreads: ((value: { threads: Thread[]; count: number }) => void) | undefined;+ mockGetThreads.mockImplementation(+ () =>+ new Promise(resolve => {+ resolveThreads = resolve;+ })+ );++ let store: ReturnType<typeof buildStore> | undefined;+ await act(async () => {+ store = await renderConversations({+ thread: {+ ...emptyThreadState,+ threads,+ selectedThreadId: 't-1',+ messagesByThreadId: { 't-1': [], 't-2': [] },+ },+ });+ });+ await waitFor(() => expect(mockGetThreads).toHaveBeenCalled());++ fireEvent.click(screen.getByTestId('thread-row-t-2'));+ expect(store?.getState().thread.selectedThreadId).toBe('t-2');++ await act(async () => {+ resolveThreads?.({ threads, count: threads.length });+ });++ expect(store?.getState().thread.selectedThreadId).toBe('t-2');+ expect(screen.getByTestId('thread-row-t-2')).toHaveClass('bg-surface/70');+ });+// Sidebar "New thread" button was removed in the composer flattening refactor.// The "+ New" header button (tested below) is the remaining create-thread entry point.diff --git a/app/src/store/threadSlice.ts b/app/src/store/threadSlice.tsindex 1487ab0a41..3a1b5fe3bb 100644--- a/app/src/store/threadSlice.ts+++ b/app/src/store/threadSlice.ts@@ -13,6 +13,8 @@ export const THREAD_NOT_FOUND_MESSAGE = 'This thread is no longer available.';interface ThreadState {threads: Thread[];selectedThreadId: string | null;+ /** Incremented by every explicit thread selection to invalidate stale async continuations. */+ selectionIntentVersion: number;/*** Set of threads that currently have an in-flight inference turn, keyed by* thread id. Replaces the legacy single `activeThreadId` so that turns on@@ -60,6 +62,7 @@ interface ThreadState {const initialState: ThreadState = {threads: [],selectedThreadId: null,+ selectionIntentVersion: 0,activeThreadIds: {},welcomeThreadId: null,messagesByThreadId: {},@@ -471,11 +474,16 @@ const threadSlice = createSlice({state.createThreadError = null;},setSelectedThread: (state, action: { payload: string }) => {+ state.selectionIntentVersion = (state.selectionIntentVersion ?? 0) + 1;state.selectedThreadId = action.payload;state.messages = state.messagesByThreadId[action.payload] ?? [];state.messagesError = null;},+ invalidateThreadSelection: state => {+ state.selectionIntentVersion = (state.selectionIntentVersion ?? 0) + 1;+ },clearSelectedThread: state => {+ state.selectionIntentVersion = (state.selectionIntentVersion ?? 0) + 1;state.selectedThreadId = null;state.messages = [];state.messagesError = null;@@ -693,6 +701,7 @@ const threadSlice = createSlice({export const {clearCreateThreadError,setSelectedThread,+ invalidateThreadSelection,clearSelectedThread,setActiveThread,markThreadInferenceActive,diff --git a/app/test/playwright/helpers/core-rpc.ts b/app/test/playwright/helpers/core-rpc.tsindex 6f536c4512..33360b7eac 100644--- a/app/test/playwright/helpers/core-rpc.ts+++ b/app/test/playwright/helpers/core-rpc.ts@@ -250,35 +250,49 @@ export async function waitForAppReady(page: Page): Promise<void> {// Harness setup can install runtimes on a cold core. It deliberately blocks// user input behind a full-screen dialog until the user chooses to continue// in the background, so settle that product flow before a spec drives UI.- const init = await callCoreRpc<{ snapshot?: { overall?: string; started_at?: string | null } }>(- 'openhuman.harness_init_status'- );- if (init.snapshot?.overall === 'running' || init.snapshot?.overall === 'failed') {+ const readInitStatus = async (): Promise<{+ overall?: string;+ started_at?: string | null;+ } | null> => {+ try {+ const result = await callCoreRpc<{+ snapshot?: { overall?: string; started_at?: string | null };+ }>('openhuman.harness_init_status');+ return result.snapshot ?? null;+ } catch (error) {+ // Some slim or older cores do not expose this optional status method.+ if (+ error instanceof Error &&+ error.message.includes('unknown method: openhuman.harness_init_status')+ ) {+ return null;+ }+ throw error;+ }+ };+ const init = await readInitStatus();+ if (init?.overall === 'running' || init?.overall === 'failed') {const alreadyDismissed = await page.evaluate(startedAt =>- window.sessionStorage.getItem('harness-init-dismissed-run') === (startedAt ?? 'unkeyed'),- init.snapshot.started_at+ window.sessionStorage.getItem('harness-init-dismissed-run') === (startedAt ?? 'pending'),+ init.started_at);if (alreadyDismissed) return;- const continueButton = page.getByRole('button', { name: /Run in background|Continue anyway/ });+ const continueButton = page.getByTestId('harness-init-continue');await expect.poll(async () => {if (await continueButton.isVisible().catch(() => false)) return true;- const current = await callCoreRpc<{ snapshot?: { overall?: string } }>(- 'openhuman.harness_init_status'- );- return current.snapshot?.overall === 'done' || current.snapshot?.overall === 'idle';+ const current = await readInitStatus();+ return current?.overall === 'done' || current?.overall === 'idle' || current === null;},{ timeout: 10_000 }).toBe(true);if (await continueButton.isVisible().catch(() => false)) {await continueButton.click();- await expect(page.getByRole('dialog', { name: 'Setting things up' })).toBeHidden({- timeout: 5_000,- });+ await expect(page.getByTestId('harness-init-dialog')).toBeHidden({ timeout: 5_000 });}}}diff --git a/app/test/playwright/specs/onboarding-modes.spec.ts b/app/test/playwright/specs/onboarding-modes.spec.tsindex f1f6868196..fad2cc3eae 100644--- a/app/test/playwright/specs/onboarding-modes.spec.ts+++ b/app/test/playwright/specs/onboarding-modes.spec.ts@@ -1,6 +1,11 @@import { expect, type Page, test } from '@playwright/test';-import { bootRuntimeReadyGuestPage, callCoreRpc, waitForAppReady } from '../helpers/core-rpc';+import {+ bootRuntimeReadyGuestPage,+ callCoreRpc,+ signInViaBypassUser,+ waitForAppReady,+} from '../helpers/core-rpc';const MOCK_ADMIN_BASE = `http://127.0.0.1:${process.env.E2E_MOCK_PORT || '18473'}`;@@ -17,7 +22,7 @@ async function clickTestId(page: Page, testId: string, timeout = 10_000): Promistry {await locator.waitFor({ state: 'visible', timeout });await expect(locator).toBeEnabled({ timeout: 5_000 });- await locator.click({ force: true, timeout: 5_000 });+ await locator.click({ timeout: 5_000 });return true;} catch {return false;@@ -83,24 +88,7 @@ test.describe('Onboarding modes', () => {test('TinyHumans sessions land directly in chat', async ({ page }) => {await resetMock().catch(() => undefined);await bootRuntimeReadyGuestPage(page);- const payload = Buffer.from(- JSON.stringify({- sub: 'pw-onboarding-cloud',- userId: 'pw-onboarding-cloud',- exp: Math.floor(Date.now() / 1000) + 3600,- })- ).toString('base64url');- await callCoreRpc('openhuman.auth_store_session', {- token: `eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.${payload}.sig`,- userId: 'pw-onboarding-cloud',- user: {- _id: 'pw-onboarding-cloud',- id: 'pw-onboarding-cloud',- displayName: 'Playwright User',- },- });- await page.goto('/#/home');- await waitForAppReady(page);+ await signInViaBypassUser(page, 'pw-onboarding-cloud');await expect.poll(() => page.evaluate(() => window.location.hash)).toMatch(/^#\/chat/);});@@ -114,6 +102,9 @@ test.describe('Onboarding modes', () => {await expect(page.getByTestId('onboarding-custom-search-step')).toBeVisible();expect(await clickTestId(page, 'onboarding-search-skip')).toBe(true);+ await expect+ .poll(() => page.evaluate(() => window.location.hash), { timeout: 10_000 })+ .toContain('/onboarding/custom/vault');await expect(page.getByTestId('onboarding-custom-vault-step')).toBeVisible();// Voice, OAuth and embeddings are no longer wizard steps.diff --git a/crates/openhuman-embed/src/host_internals.rs b/crates/openhuman-embed/src/host_internals.rsindex 01ee76f93c..4038703555 100644--- a/crates/openhuman-embed/src/host_internals.rs+++ b/crates/openhuman-embed/src/host_internals.rs@@ -80,7 +80,7 @@ pub mod core {}pub mod runtime {pub use openhuman_core::core::runtime::{- is_saas, CoreContext, CoreRuntime, Mode, SaasConfig,+ current_tenant, is_saas, CoreContext, CoreRuntime, Mode, SaasConfig,};pub mod saas {pub use openhuman_core::core::runtime::saas::build;