The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): a tab whose access token expired keeps its last status answers
Teknium820967473d4d
diff --git a/apps/desktop/src/app/command-center/index.tsx b/apps/desktop/src/app/command-center/index.tsxindex 6dd640fdb34..02a781bdc90 100644--- a/apps/desktop/src/app/command-center/index.tsx+++ b/apps/desktop/src/app/command-center/index.tsx@@ -26,6 +26,7 @@ import {Wrench} from '@/lib/icons'import { exportSession } from '@/lib/session-export'+import { isSignedOutStatus } from '@/lib/signed-out-status'import { fmtDateTime } from '@/lib/time'import { useStoreSelector } from '@/lib/use-session-slice'import { cn } from '@/lib/utils'@@ -223,7 +224,9 @@ export function CommandCenterView({})])- setStatus(nextStatus)+ // The Webapp's signed-out body (an access token expired since the last gated request) leaves+ // out what this panel shows, so the last full answer stays up.+ setStatus(previous => (previous && isSignedOutStatus(nextStatus) ? previous : nextStatus))setLogs(nextLogs.lines)} catch (error) {setSystemError(error instanceof Error ? error.message : String(error))diff --git a/apps/desktop/src/app/shell/hooks/use-status-snapshot.test.ts b/apps/desktop/src/app/shell/hooks/use-status-snapshot.test.tsindex 2ab2c5afc79..c528de918b3 100644--- a/apps/desktop/src/app/shell/hooks/use-status-snapshot.test.ts+++ b/apps/desktop/src/app/shell/hooks/use-status-snapshot.test.ts@@ -527,3 +527,23 @@ describe('useStatusSnapshot', () => {expect(requestGateway).not.toHaveBeenCalled()})})++describe('useStatusSnapshot on a signed-out status read', () => {+ it('keeps the last full snapshot when a Webapp read comes back signed out', async () => {+ const full = { active_sessions: 2, auth_required: true, install_id: 'i', version: '1.0.0' }+ vi.mocked(getStatus).mockImplementation(async () => full as never)+ const requestGateway = vi.fn().mockResolvedValue({}) as unknown as GatewayRequester++ const { result } = renderHook(() => useStatusSnapshot('open', requestGateway))+ await flushAsync()+ expect(result.current.statusSnapshot).toEqual(full)++ // An access token expired since the tab's last gated request: the public route answers signed out.+ vi.mocked(getStatus).mockImplementation(async () => ({ auth_required: true, version: '1.0.0' }) as never)+ await act(async () => {+ await vi.advanceTimersByTimeAsync(60_000)+ })+ expect(getStatus).toHaveBeenCalledTimes(2)+ expect(result.current.statusSnapshot).toEqual(full)+ })+})diff --git a/apps/desktop/src/app/shell/hooks/use-status-snapshot.ts b/apps/desktop/src/app/shell/hooks/use-status-snapshot.tsindex 8665d25b04f..6aba6ec4d4a 100644--- a/apps/desktop/src/app/shell/hooks/use-status-snapshot.ts+++ b/apps/desktop/src/app/shell/hooks/use-status-snapshot.ts@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'import { getStatus } from '@/hermes'import { type I18nContextValue, useI18n } from '@/i18n'import { evaluateRuntimeReadiness, type RuntimeReadinessResult } from '@/lib/runtime-readiness'+import { isSignedOutStatus } from '@/lib/signed-out-status'import { $freeTierStatus, refreshFreeTierStatus, setFreeTierRoute } from '@/store/free-tier'import { $setupReadyTick } from '@/store/live-sync'import { dismissNotification, notify } from '@/store/notifications'@@ -143,7 +144,9 @@ export function useStatusSnapshot(return}- if (statusResult.status === 'fulfilled') {+ // A Webapp tab whose access token expired since its last gated request reads the+ // signed-out body, which omits most of the snapshot and the warning: keep the last one.+ if (statusResult.status === 'fulfilled' && !isSignedOutStatus(statusResult.value)) {const next = statusResult.value// Preserve reference identity on a no-op: the 60s tick re-reads a// usually-unchanged snapshot, and a fresh object for the same contentdiff --git a/apps/desktop/src/lib/browser-served-profiles.test.ts b/apps/desktop/src/lib/browser-served-profiles.test.tsindex d8da25211ac..d726211e9d7 100644--- a/apps/desktop/src/lib/browser-served-profiles.test.ts+++ b/apps/desktop/src/lib/browser-served-profiles.test.ts@@ -73,3 +73,56 @@ describe('overlapping served set reads', () => {expect(served.serves('solo')).toBe(false)})})++// What the gateway's Webapp answers a caller it does not count as signed in, as a signed-in tab+// whose access token expired since its last gated request reads it.+const SIGNED_OUT_STATUS = {+ auth_flows: ['cookie'],+ auth_providers: ['password'],+ auth_required: true,+ components: {},+ gateway_running: true,+ gateway_state: 'running',+ overall: 'ok',+ release_date: '2026.10.28',+ version: '0.0.0'+}++describe('a signed-out status read', () => {+ it('keeps the last served set and asks again on the next inventory read', async () => {+ const api = vi+ .fn()+ .mockResolvedValueOnce({ active_sessions: 0, gateway_shared_with: ['default'], install_id: 'i' })+ .mockResolvedValueOnce(SIGNED_OUT_STATUS)+ .mockResolvedValueOnce({ active_sessions: 0, gateway_shared_with: ['default', 'solo'], install_id: 'i' })++ const served = createServedProfiles(api as unknown as <T>(request: HermesApiRequest) => Promise<T>)++ await served.refresh(['default', 'solo'])+ expect(served.serves('solo')).toBe(false)++ // The list changed, so the set is re-read, and that read comes back signed out.+ await served.refresh(['default', 'solo', 'fresh'])+ expect(api).toHaveBeenCalledTimes(2)+ expect(served.serves('solo')).toBe(false)+ expect(served.serves('fresh')).toBe(false)++ // The signed-out read settled nothing, so the same list is read again inside the TTL.+ await served.refresh(['default', 'solo', 'fresh'])+ expect(api).toHaveBeenCalledTimes(3)+ expect(served.serves('solo')).toBe(true)+ })++ it('still reads a full body without the set as an older backend', async () => {+ const api = vi+ .fn()+ .mockResolvedValueOnce({ active_sessions: 0, gateway_shared_with: ['default'], install_id: 'i' })+ .mockResolvedValueOnce({ active_sessions: 0, auth_required: true, install_id: 'i' })++ const served = createServedProfiles(api as unknown as <T>(request: HermesApiRequest) => Promise<T>)++ await served.refresh(['default', 'solo'])+ await served.refresh(['default', 'solo', 'fresh'])+ expect(served.serves('solo')).toBe(true)+ })+})diff --git a/apps/desktop/src/lib/browser-served-profiles.ts b/apps/desktop/src/lib/browser-served-profiles.tsindex 057f49fd721..b56f9de4305 100644--- a/apps/desktop/src/lib/browser-served-profiles.ts+++ b/apps/desktop/src/lib/browser-served-profiles.ts@@ -1,5 +1,6 @@import type { HermesApiRequest } from '@/global'import { browserLaunchProfileOrDefault } from '@/lib/platform'+import { isSignedOutStatus } from '@/lib/signed-out-status'// The multiplexer applies a park, unpark or standalone change on its 30 s profile rescan, and none// of those changes the installed list, so a known served set is re-read on that cadence.@@ -47,6 +48,15 @@ export function createServedProfiles(api: <T>(request: HermesApiRequest) => PromtimeoutMs: SERVED_SET_READ_TIMEOUT_MS})+ // An access token that expired since the tab's last gated request reads as signed out here,+ // and that body omits the set; it is no answer about which profiles are served. Keep the last+ // set, and let the next inventory read ask again once a gated request has rotated the cookies.+ if (isSignedOutStatus(status)) {+ readFor = null++ return+ }+const shared = status?.gateway_shared_with// Absent on a backend older than the field; [] on a gateway that serves only its own profile.diff --git a/apps/desktop/src/lib/signed-out-status.ts b/apps/desktop/src/lib/signed-out-status.tsnew file mode 100644index 00000000000..59ffbd1f968--- /dev/null+++ b/apps/desktop/src/lib/signed-out-status.ts@@ -0,0 +1,18 @@+/**+ * Whether an `/api/status` answer is the trimmed body the gateway's Webapp gives a caller it does+ * not count as signed in. `/api/status` is public, so the gate never refreshes on it: a signed-in+ * tab whose access token expired since its last gated request also gets this body, until its next+ * gated request rotates the cookies. The body says nothing about the gateway's profiles or the+ * install, so a reader keeps the answer it already has instead of reading the missing fields as+ * an older backend. The full body always carries `active_sessions`, and on a gated bind+ * `auth_required` is true.+ */+export function isSignedOutStatus(status: unknown): boolean {+ if (!status || typeof status !== 'object') {+ return false+ }++ const body = status as Record<string, unknown>++ return body.auth_required === true && !('active_sessions' in body) && !('install_id' in body)+}diff --git a/apps/desktop/src/store/system-actions-signed-out-status.test.ts b/apps/desktop/src/store/system-actions-signed-out-status.test.tsnew file mode 100644index 00000000000..8a695874064--- /dev/null+++ b/apps/desktop/src/store/system-actions-signed-out-status.test.ts@@ -0,0 +1,47 @@+import { afterEach, describe, expect, it, vi } from 'vitest'++import type * as HermesApi from '@/hermes'++const getStatus = vi.fn()+const hermesApi = vi.fn()+const confirm = vi.fn()++vi.mock('@/hermes', async importOriginal => ({+ ...(await importOriginal<typeof HermesApi>()),+ getStatus: () => getStatus(),+ hermesApi: (request: unknown) => hermesApi(request)+}))++vi.mock('@/store/confirm', () => ({ confirm: (request: unknown) => confirm(request) }))++import { confirmSharedGatewayRestart } from './system-actions'++// The Webapp's body for a caller it does not count as signed in: a tab whose access token expired+// since its last gated request reads this until a gated request rotates its cookies.+const SIGNED_OUT_STATUS = { auth_required: true, gateway_running: true, overall: 'ok', version: '0.0.0' }++afterEach(() => {+ vi.resetAllMocks()+})++describe('confirmSharedGatewayRestart on a signed-out status read', () => {+ it('re-reads after a gated request and still asks before restarting the shared multiplexer', async () => {+ getStatus+ .mockResolvedValueOnce(SIGNED_OUT_STATUS)+ .mockResolvedValueOnce({ active_sessions: 0, gateway_shared_with: ['default', 'alpha'], install_id: 'i' })+ hermesApi.mockResolvedValue({})+ confirm.mockResolvedValue(true)++ await expect(confirmSharedGatewayRestart()).resolves.toEqual(['default', 'alpha'])+ expect(hermesApi).toHaveBeenCalledWith({ path: '/api/auth/me' })+ expect(confirm).toHaveBeenCalledTimes(1)+ })++ it('reads a full status once', async () => {+ getStatus.mockResolvedValueOnce({ active_sessions: 0, gateway_shared_with: null, install_id: 'i' })++ await expect(confirmSharedGatewayRestart()).resolves.toBeNull()+ expect(getStatus).toHaveBeenCalledTimes(1)+ expect(hermesApi).not.toHaveBeenCalled()+ })+})diff --git a/apps/desktop/src/store/system-actions.ts b/apps/desktop/src/store/system-actions.tsindex b26c169f4bb..2cdad8b69c9 100644--- a/apps/desktop/src/store/system-actions.ts+++ b/apps/desktop/src/store/system-actions.ts@@ -1,8 +1,9 @@import { atom } from 'nanostores'-import { getActionStatus, getStatus, restartGateway } from '@/hermes'+import { getActionStatus, getStatus, hermesApi, restartGateway } from '@/hermes'import { translateNow } from '@/i18n'import { sharedGatewayProfiles } from '@/lib/shared-gateway-restart'+import { isSignedOutStatus } from '@/lib/signed-out-status'import { confirm } from '@/store/confirm'import { reconnectGateway } from '@/store/gateway-reconnect'import { notify, notifyError } from '@/store/notifications'@@ -84,7 +85,17 @@ export async function confirmSharedGatewayRestart(): Promise<false | null | strilet shared: null | string[] = nulltry {- shared = sharedGatewayProfiles(await getStatus())+ let status = await getStatus()++ // A Webapp tab whose access token expired since its last gated request reads the signed-out+ // body, which omits the served set. A gated read rotates the cookies; then ask again, so a+ // restart of the shared multiplexer still asks first.+ if (isSignedOutStatus(status)) {+ await hermesApi({ path: '/api/auth/me' })+ status = await getStatus()+ }++ shared = sharedGatewayProfiles(status)} catch {// Status unavailable: fall back to the plain restart rather than blocking it.return null