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
chore: files changed app/src/services/coreStateApi.ts,app/src/services/session/sessionOwner.ts
Steven Enamakel31ef0de08b2e
diff --git a/app/src/services/coreStateApi.ts b/app/src/services/coreStateApi.tsindex 63a9c7bb41..c505a2f157 100644--- a/app/src/services/coreStateApi.ts+++ b/app/src/services/coreStateApi.ts@@ -3,7 +3,7 @@ import type { TeamInvite, TeamMember, TeamWithRole } from '../types/team';import type { LocalAiStatus } from '../utils/tauriCommands/localAi';import type { ServiceStatus } from '../utils/tauriCommands/service';import { callCoreRpc } from './coreRpcClient';-import { fetchCurrentUser, useShellSessionOwner } from './session/sessionOwner';+import { fetchCurrentUser } from './session/sessionOwner';interface OnboardingTasks {accessibilityPermissionGranted: boolean;@@ -132,11 +132,10 @@ export const fetchCoreAppSnapshot = async (): Promise<AppStateSnapshotResult> =>const result: AppStateSnapshotResult = { ...response.result };// The core reports the credential it holds and the user payload it was// handed at login (`auth.user`); the *live* current user comes from the- // session owner's `/auth/me` cache. On the desktop that is the Tauri shell,- // whose cache makes this poll-frequency call cheap. Browser and cloud mode- // have no cached owner, so they keep the stored payload rather than paying- // a backend round trip on every poll.- if (result.auth?.isAuthenticated && useShellSessionOwner()) {+ // session owner's `/auth/me` cache — the Tauri shell's on the desktop, a+ // small in-page one in the browser build and cloud mode — so this+ // poll-frequency call stays cheap.+ if (result.auth?.isAuthenticated) {try {const current = await fetchCurrentUser(false);if (current.user) {diff --git a/app/src/services/session/sessionOwner.ts b/app/src/services/session/sessionOwner.tsindex df9626f0f8..1015d64958 100644--- a/app/src/services/session/sessionOwner.ts+++ b/app/src/services/session/sessionOwner.ts@@ -153,38 +153,67 @@ const coreSetCredential = async (params: {};const browserStoreSessionToken = async (token: string, user?: object): Promise<void> => {+ browserCurrentUserCache = null;if (isLocalSessionToken(token)) {await coreSetCredential({ token, kind: 'local', user });return;}const me = await browserFetchMe(token);await coreSetCredential({ token, kind: 'session', userId: userIdFromPayload(me), user: me });+ browserCurrentUserCache = { token, fetchedAt: Date.now(), user: me };};-const browserCurrentUser = async (): Promise<SessionCurrentUser> => {+// The browser owner has no shell-side cache, so it keeps its own: one+// `/auth/me` per token per window, unless a caller forces a refresh.+const BROWSER_CURRENT_USER_TTL_MS = 30_000;+let browserCurrentUserCache: { token: string; fetchedAt: number; user: object } | null = null;++/** Drop the browser owner's cached user (sign-out, tests). */+export const resetBrowserCurrentUserCache = (): void => {+ browserCurrentUserCache = null;+};++const browserCurrentUser = async (force: boolean): Promise<SessionCurrentUser> => {const state = await callCoreRpc<{result: { isAuthenticated: boolean; credential?: string | null; user: object | null };}>({ method: 'openhuman.auth_get_state' });const core = state.result;- if (!core.isAuthenticated) return { user: null, stale: false, staleSeconds: null };+ if (!core.isAuthenticated) {+ browserCurrentUserCache = null;+ return { user: null, stale: false, staleSeconds: null };+ }if (core.credential !== 'session') return { user: core.user, stale: false, staleSeconds: null };const tokenResponse = await callCoreRpc<{ result: { token: string | null } }>({method: 'openhuman.auth_get_session_token',});const token = tokenResponse.result.token;if (!token) return { user: core.user, stale: false, staleSeconds: null };+ const cached = browserCurrentUserCache;+ if (!force && cached && cached.token === token) {+ const age = Date.now() - cached.fetchedAt;+ if (age < BROWSER_CURRENT_USER_TTL_MS) {+ return { user: cached.user, stale: false, staleSeconds: Math.floor(age / 1000) };+ }+ }try {- return { user: await browserFetchMe(token), stale: false, staleSeconds: 0 };+ const user = await browserFetchMe(token);+ browserCurrentUserCache = { token, fetchedAt: Date.now(), user };+ return { user, stale: false, staleSeconds: 0 };} catch (error) {const message = error instanceof Error ? error.message : String(error);if (message.startsWith('REJECTED:')) {+ browserCurrentUserCache = null;await callCoreRpc({method: 'openhuman.auth_clear_credential',params: { kind: 'session' },}).catch(() => undefined);throw error;}- return { user: core.user, stale: true, staleSeconds: null };+ return {+ user: cached?.user ?? core.user,+ stale: true,+ staleSeconds: cached ? Math.floor((Date.now() - cached.fetchedAt) / 1000) : null,+ };}};@@ -218,6 +247,7 @@ export const logoutSession = async (): Promise<void> => {await invoke('auth_logout');return;}+ browserCurrentUserCache = null;await callCoreRpc({ method: 'openhuman.auth_clear_credential', params: { kind: 'session' } });};@@ -236,7 +266,7 @@ export const fetchCurrentUser = async (force = false): Promise<SessionCurrentUse}>('auth_current_user', { force });return { user: cached.user, stale: cached.stale, staleSeconds: cached.staleSeconds };}- return browserCurrentUser();+ return browserCurrentUser(force);};/** The shell owner's full view (desktop only); `null` elsewhere. */