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
feat(session): emit session-expired event on browser owner auth failure
Steven Enamakel905c38689723
diff --git a/app/src/services/session/__tests__/sessionOwner.test.ts b/app/src/services/session/__tests__/sessionOwner.test.tsindex 00b0504bb5..a07dccd0c4 100644--- a/app/src/services/session/__tests__/sessionOwner.test.ts+++ b/app/src/services/session/__tests__/sessionOwner.test.ts@@ -99,6 +99,10 @@ describe('sessionOwner (browser / cloud owner)', () => {expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({ token: 'login-tok' });expect(fetchMock.mock.calls[1][0]).toBe('https://api.test/auth/me');expect(fetchMock.mock.calls[1][1].headers.Authorization).toBe('Bearer jwt-1');+ for (const call of fetchMock.mock.calls) {+ expect(call[1].headers['x-sdk-name']).toBe('openhuman');+ expect(call[1].headers['x-tauri-version']).toBe('1.0.0');+ }expect(mockCallCoreRpc).toHaveBeenCalledWith({method: 'openhuman.auth_set_credential',params: { token: 'jwt-1', kind: 'session', userId: 'u9', user: { _id: 'u9', email: 'a@b' } },@@ -179,12 +183,23 @@ describe('sessionOwner (browser / cloud owner)', () => {.mockResolvedValueOnce({ result: { token: 'jwt' } }).mockResolvedValueOnce({ result: {} });fetchMock.mockResolvedValueOnce(jsonResponse(401, {}));-- await expect(owner.fetchCurrentUser()).rejects.toThrow(/^REJECTED:/);+ const expired = vi.fn();+ window.addEventListener('openhuman:session-expired', expired as EventListener);++ try {+ await expect(owner.fetchCurrentUser()).rejects.toThrow(/^REJECTED:/);+ } finally {+ window.removeEventListener('openhuman:session-expired', expired as EventListener);+ }expect(mockCallCoreRpc).toHaveBeenLastCalledWith({method: 'openhuman.auth_clear_credential',params: { kind: 'session' },});+ expect(expired).toHaveBeenCalledTimes(1);+ expect((expired.mock.calls[0][0] as CustomEvent).detail).toEqual({+ source: 'browser-owner.auth/me',+ reason: 'confirmed',+ });});it('caches a fetched user per token until forced', async () => {diff --git a/app/src/services/session/sessionOwner.ts b/app/src/services/session/sessionOwner.tsindex 1015d64958..be80eacf53 100644--- a/app/src/services/session/sessionOwner.ts+++ b/app/src/services/session/sessionOwner.ts@@ -44,6 +44,14 @@ export interface SessionOwnerState {const AUTH_ME_TIMEOUT_MS = 12_000;+/**+ * Product attribution for TinyHumans backend requests, mirroring the+ * `x-sdk-name` the Rust hosts send. The browser and cloud owners are always+ * OpenHuman's own renderer, so the default identity applies.+ */+export const PRODUCT_IDENTITY_HEADER = 'x-sdk-name';+export const PRODUCT_IDENTITY = 'openhuman';+/*** Whether the Tauri shell is the session owner for the core the renderer is* talking to. Cloud mode points the renderer at a remote core through its own@@ -72,7 +80,12 @@ const backendFetch = async (path: string, init: RequestInit): Promise<Response>return withTimeout(fetch(`${backendUrl}${path}`, {...init,- headers: { 'Content-Type': 'application/json', ...versionHeaders, ...(init.headers ?? {}) },+ headers: {+ 'Content-Type': 'application/json',+ [PRODUCT_IDENTITY_HEADER]: PRODUCT_IDENTITY,+ ...versionHeaders,+ ...(init.headers ?? {}),+ },}),AUTH_ME_TIMEOUT_MS,path@@ -207,6 +220,15 @@ const browserCurrentUser = async (force: boolean): Promise<SessionCurrentUser> =method: 'openhuman.auth_clear_credential',params: { kind: 'session' },}).catch(() => undefined);+ // Same confirmed-expiry signal the shell owner raises through+ // `auth://expired`: the credential is gone, so the core-state layer+ // must sign out now rather than keep a stale signed-in snapshot until+ // the next poll.+ window.dispatchEvent(+ new CustomEvent('openhuman:session-expired', {+ detail: { source: 'browser-owner.auth/me', reason: 'confirmed' },+ })+ );throw error;}return {