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(auth): corroborate a chat-error session expiry before destroying the profile\n\nThe chat-error dispatch added by this PR reached `runReauth` as `confirmed`,\nwhich by design SKIPS `confirmSessionTokenGone()` and runs the destructive\n`clearSession()` (`auth_clear_session` deletes the on-disk auth profile).\n\n`error_type: 'session_expired'` is not only a backend expiry.\n`web_errors_part_02.rs:36` classifies through `is_session_expired_message`,\nwhich also matches "no backend session token" and "session jwt required"\n(`core/observability.rs:1062-1064`). Those are LOCAL guards, not backend\nverdicts: they fire transiently before the core has read the on-disk auth\nprofile. Treating them as definitive is #2758 — "a forced re-login even though\nthe token survived the restart" — and this reintroduced it through a new door.\n`runReauth`'s own comment names both strings as the case corroboration exists\nfor.\n\nIt does not need the bootstrap path to bite; plain post-bootstrap is enough:\nchat error -> dispatch -> confirmed -> skip corroboration -> profile deleted.\nThe bootstrap queue makes it worse, holding the transient signal and replaying\nit as definitive at exactly the moment corroboration would have said "token\npresent".\n\nFix, keeping the socket path untouched:\n\n - the chat-error dispatch carries `reason: 'unconfirmed'`;\n - `onSocketExpired` honours `detail.reason`, defaulting to `confirmed` —\n `socketService` sends no reason, so an explicit backend push is unchanged;\n - the bootstrap replay states `reason: 'confirmed'` explicitly rather than\n leaning on that default, so it stays correct if the default is tightened.\n\nA genuine expiry still corroborates and signs out. Only the false positive is\nfiltered.\n\nCoverage, in two halves, because one test cannot see both:\n\n - `ChatRuntimeProvider.test.tsx` asserts the dispatched event carries\n `reason: 'unconfirmed'` — pinned at the dispatch, where the value is\n decided;\n - `CoreStateProvider.test.tsx` fires the event with the token still present\n and asserts `logout` is NOT called, plus a positive control firing the same\n event with the token gone that asserts it IS.\n\nRevert-checked. Reverting the dispatch alone fails only the ChatRuntimeProvider\nassertion (4ms); reverting `onSocketExpired` to a hardcoded `confirmed` fails\nonly the CoreStateProvider test. An earlier version of the CoreStateProvider\ntest constructed the event itself and so passed against the reverted dispatch —\nvacuous, and the reason the assertion now also lives at the dispatch site.\n
M3gA-Mind739ad7dd547e
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsxindex 06e8cac456..e9358eb1fe 100644--- a/app/src/providers/ChatRuntimeProvider.tsx+++ b/app/src/providers/ChatRuntimeProvider.tsx@@ -1290,8 +1290,22 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {// debounce in runReauth() ensures a concurrent socket event does not// cause a double-clear.if (event.error_type === 'session_expired') {+ // `reason: 'unconfirmed'` is load-bearing, not defensive. The core+ // classifies this error with `is_session_expired_message`, which+ // matches the LOCAL guards "no backend session token" and+ // "session jwt required" as well as a real backend expiry+ // (`core/observability.rs`). Those two fire transiently before the+ // on-disk auth profile has been read — #2758 is the bug where+ // treating them as definitive forced a re-login even though the+ // token had survived the restart. `unconfirmed` routes through+ // `confirmSessionTokenGone()` in `runReauth`, so a signal raised+ // while the token is still on disk stops short of the destructive+ // `clearSession()`. A genuine expiry still corroborates and signs+ // out; only the false positive is filtered.window.dispatchEvent(- new CustomEvent('openhuman:session-expired', { detail: { source: 'chat-error' } })+ new CustomEvent('openhuman:session-expired', {+ detail: { source: 'chat-error', reason: 'unconfirmed' },+ }));}}diff --git a/app/src/providers/CoreStateProvider.tsx b/app/src/providers/CoreStateProvider.tsxindex abfcbe3f7d..520b06ebdf 100644--- a/app/src/providers/CoreStateProvider.tsx+++ b/app/src/providers/CoreStateProvider.tsx@@ -785,7 +785,13 @@ export default function CoreStateProvider({ children }: { children: ReactNode })pendingConfirmedReauthRef.current = false;log('auth-expired: replaying confirmed reauth suppressed during bootstrap');window.dispatchEvent(- new CustomEvent('openhuman:session-expired', { detail: { source: 'bootstrap-replay' } })+ // Explicit rather than relying on the default: what is being replayed+ // was already established as a confirmed expiry before it was queued,+ // and saying so here keeps the replay correct if the default above is+ // ever made stricter.+ new CustomEvent('openhuman:session-expired', {+ detail: { source: 'bootstrap-replay', reason: 'confirmed' },+ }));}}, [state.isBootstrapping]);@@ -920,8 +926,22 @@ export default function CoreStateProvider({ children }: { children: ReactNode })typeof (event.detail as { source?: unknown }).source === 'string'? (event.detail as { source: string }).source: 'unknown';- // The socket `auth:session_expired` push is an explicit backend expiry → confirmed.- void runReauth('socket.session_expired', source, 'confirmed');+ // The socket `auth:session_expired` push is an explicit backend expiry, and+ // `socketService` sends no `reason` — so the default stays `confirmed`+ // and that path is unchanged. A dispatcher that KNOWS its signal is+ // merely suggestive says so, and is corroborated instead of trusted:+ // `ChatRuntimeProvider`'s chat-error dispatch sends `unconfirmed`,+ // because the core classifies local token-absent guards under the same+ // `session_expired` error type as a real expiry.+ const reason: AuthExpiredReason =+ event instanceof CustomEvent &&+ event.detail &&+ typeof event.detail === 'object' &&+ 'reason' in event.detail &&+ (event.detail as { reason?: unknown }).reason === 'unconfirmed'+ ? 'unconfirmed'+ : 'confirmed';+ void runReauth('socket.session_expired', source, reason);};window.addEventListener('core-rpc-auth-expired', onRpcExpired as EventListener);diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsxindex ad307e2107..3893b10d8e 100644--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx@@ -2070,6 +2070,16 @@ describe('ChatRuntimeProvider — skill tool-chain latency (#4273 AC3)', () => {window.removeEventListener('openhuman:session-expired', handler);expect(received).toHaveLength(1);expect((received[0] as CustomEvent).detail?.source).toBe('chat-error');+ // The reason is the load-bearing half, not decoration. `CoreStateProvider`+ // defaults a reason-less `openhuman:session-expired` to `confirmed`, which+ // SKIPS `confirmSessionTokenGone()` and runs the destructive+ // `clearSession()`. The core reaches this error type through+ // `is_session_expired_message`, which also matches the local guards+ // "no backend session token" and "session jwt required" — the transient+ // pre-profile-load signals #2758 exists to corroborate rather than trust.+ // Dropping this field silently reintroduces that bug through a new door,+ // so it is asserted here, at the dispatch, where the value is decided.+ expect((received[0] as CustomEvent).detail?.reason).toBe('unconfirmed');});it('does not dispatch openhuman:session-expired for non-session error types', () => {diff --git a/app/src/providers/__tests__/CoreStateProvider.test.tsx b/app/src/providers/__tests__/CoreStateProvider.test.tsxindex e97492cc76..786560acfa 100644--- a/app/src/providers/__tests__/CoreStateProvider.test.tsx+++ b/app/src/providers/__tests__/CoreStateProvider.test.tsx@@ -1047,6 +1047,85 @@ describe('session expiry fixes (#5868)', () => {// The pending reauth must replay and call logout.await waitFor(() => expect(vi.mocked(tauriCommands.logout)).toHaveBeenCalledTimes(1));});++ it('does not sign out on a chat-error expiry while the session token is still on disk (#2758)', async () => {+ // The failure mode this pins is a REGRESSION OF #2758, reached through a+ // new door. `is_session_expired_message` (core/observability.rs) classifies+ // the local guards "no backend session token" and "session jwt required"+ // under the same `session_expired` error type as a real backend expiry, and+ // those fire transiently before the on-disk auth profile has been read.+ //+ // `clearSession()` is destructive — `auth_clear_session` deletes the auth+ // profile — so a merely-suggestive signal must be corroborated first. That+ // is what `reason: 'unconfirmed'` buys: `runReauth` calls+ // `confirmSessionTokenGone()` and stops when the token is still there.+ //+ // Revert the dispatch to `confirmed` (or drop the `reason` from the+ // ChatRuntimeProvider dispatch) and this test fails: corroboration is+ // skipped and the user is signed out with a perfectly good token on disk.+ setCoreStateSnapshot({ ...getCoreStateSnapshot(), isBootstrapping: false, isReady: true });++ vi.mocked(coreStateApi.fetchCoreAppSnapshot).mockResolvedValue(+ makeSnapshot({ userId: 'u1', sessionToken: 'tok1' })+ );+ vi.mocked(tauriCommands.logout).mockReset();+ vi.mocked(tauriCommands.logout).mockResolvedValue(undefined as never);+ // The whole point: the token is STILL PRESENT. Corroboration must find it+ // and abandon the sign-out.+ vi.mocked(tauriCommands.getSessionToken).mockResolvedValue('tok1');++ render(+ <CoreStateProvider>+ <Consumer />+ </CoreStateProvider>+ );+ await waitFor(() => expect(screen.getByTestId('ready').textContent).toBe('ready'));++ await act(async () => {+ window.dispatchEvent(+ new CustomEvent('openhuman:session-expired', {+ detail: { source: 'chat-error', reason: 'unconfirmed' },+ })+ );+ });++ // Let the async corroboration settle before asserting the negative, so this+ // cannot pass merely by checking too early.+ await waitFor(() => expect(vi.mocked(tauriCommands.getSessionToken)).toHaveBeenCalled());+ expect(vi.mocked(tauriCommands.logout)).not.toHaveBeenCalled();+ });++ it('still signs out on a chat-error expiry once the token is genuinely gone', async () => {+ // The positive control for the test above: `unconfirmed` must not become a+ // way to never sign out. Same dispatch, same path — only the corroboration+ // result differs — so a fix that simply ignored chat-error expiries would+ // pass the previous test and fail this one.+ setCoreStateSnapshot({ ...getCoreStateSnapshot(), isBootstrapping: false, isReady: true });++ vi.mocked(coreStateApi.fetchCoreAppSnapshot).mockResolvedValue(+ makeSnapshot({ userId: 'u1', sessionToken: 'tok1' })+ );+ vi.mocked(tauriCommands.logout).mockReset();+ vi.mocked(tauriCommands.logout).mockResolvedValue(undefined as never);+ vi.mocked(tauriCommands.getSessionToken).mockResolvedValue(null);++ render(+ <CoreStateProvider>+ <Consumer />+ </CoreStateProvider>+ );+ await waitFor(() => expect(screen.getByTestId('ready').textContent).toBe('ready'));++ await act(async () => {+ window.dispatchEvent(+ new CustomEvent('openhuman:session-expired', {+ detail: { source: 'chat-error', reason: 'unconfirmed' },+ })+ );+ });++ await waitFor(() => expect(vi.mocked(tauriCommands.logout)).toHaveBeenCalledTimes(1));+ });});describe('coreStatePollFailureDebugMessage', () => {