Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(auth): recover from session refresh probes
Maxvint98819811d015
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsxindex 0712ffe61..448268c39 100644--- a/ui/src/context/ApiContext.tsx+++ b/ui/src/context/ApiContext.tsx@@ -1,7 +1,7 @@import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';import { useTranslation } from 'react-i18next';import { useToast } from './ToastContext';-import { apiFetch } from '../lib/apiFetch';+import { apiFetch, recoverRemoteAuthFromSessionProbe } from '../lib/apiFetch';import type { TurnActivityGroupWire } from '../lib/agentActivity';import type { AgentGraphParams, AgentGraphResult, AgentGraphVisibility } from '../lib/agentGraph';import { visibilityActivityEvents } from '../lib/sessionVisibilityEvents';@@ -2170,9 +2170,11 @@ export const ApiProvider: React.FC<{ children: React.ReactNode }> = ({ childrenif (eventSourceRef.current !== source) return;closeActiveWorkbenchEventSource();// EventSource does not expose a failed response's status or JSON body.- // Probe the session through apiFetch so an authorization-refresh 401- // enters the same full-page/PWA login recovery path as ordinary APIs.- void apiFetch('/api/session', { cache: 'no-store' }).catch(() => undefined);+ // Probe through apiFetch, then inspect the successful /api/session form;+ // both 401s and the 200 refresh payload enter the shared login recovery.+ void apiFetch('/api/session', { cache: 'no-store' })+ .then(recoverRemoteAuthFromSessionProbe)+ .catch(() => undefined);setWorkbenchEventConnectionState('reconnecting');dispatchToWorkbenchHandlers((handlers) => handlers.onEventBridgeStatus?.({ connected: false }));dispatchToWorkbenchHandlers((handlers) => handlers.onError?.(err));diff --git a/ui/src/lib/apiFetch.test.ts b/ui/src/lib/apiFetch.test.tsindex 40cf36abd..bfa60ee7f 100644--- a/ui/src/lib/apiFetch.test.ts+++ b/ui/src/lib/apiFetch.test.ts@@ -4,7 +4,7 @@ const deferRemoteAuthRedirect = vi.hoisted(() => vi.fn());vi.mock('./remoteAuth', () => ({ deferRemoteAuthRedirect }));-import { apiFetch } from './apiFetch';+import { apiFetch, recoverRemoteAuthFromSessionProbe } from './apiFetch';describe('apiFetch remote auth recovery', () => {beforeEach(() => {@@ -48,4 +48,15 @@ describe('apiFetch remote auth recovery', () => {await new Promise((resolve) => setTimeout(resolve, 0));expect(deferRemoteAuthRedirect).not.toHaveBeenCalled();});++ it('recovers from a successful session probe that requires authorization refresh', async () => {+ await recoverRemoteAuthFromSessionProbe(Response.json({+ remote: true,+ authenticated: false,+ authorization_refresh_required: true,+ }));++ expect(deferRemoteAuthRedirect).toHaveBeenCalledOnce();+ expect(window.location.assign).not.toHaveBeenCalled();+ });});diff --git a/ui/src/lib/apiFetch.ts b/ui/src/lib/apiFetch.tsindex d93cd55b1..4125a7668 100644--- a/ui/src/lib/apiFetch.ts+++ b/ui/src/lib/apiFetch.ts@@ -104,6 +104,35 @@ async function maybeRedirectOnRemoteAuthExpiry(response: Response): Promise<voidif (!error || !REMOTE_AUTH_RECOVERY_ERRORS.has(error)) {return;}+ beginRemoteAuthRecovery();+}++export async function recoverRemoteAuthFromSessionProbe(response: Response): Promise<void> {+ if (!response.ok) return;+ let payload: unknown;+ try {+ payload = await response.json();+ } catch {+ return;+ }+ const session = payload as {+ remote?: boolean;+ authenticated?: boolean;+ authorization_refresh_required?: boolean;+ } | null;+ if (+ session?.remote === true+ && session.authenticated === false+ && session.authorization_refresh_required === true+ ) {+ beginRemoteAuthRecovery();+ }+}++function beginRemoteAuthRecovery(): void {+ if (redirectingForRemoteAuth || typeof window === 'undefined') {+ return;+ }// A cross-origin OAuth redirect from an iOS Home-Screen app opens in a// separate browser sheet. Never raise that sheet automatically: hand control// back to AuthGuard so the PWA can ask for an explicit sign-in action.