Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-ui): stop capability probe spinning on silent 401; clear its cache on logout

Andy Paviaba9e07b7ad87
diff --git a/control-ui/components/AuthContext.tsx b/control-ui/components/AuthContext.tsx
index d30f48015..b497da826 100644
--- a/control-ui/components/AuthContext.tsx
+++ b/control-ui/components/AuthContext.tsx
@@ -12,6 +12,7 @@ import {
setGlobalAuthErrorHandler,
} from '../lib/api'
import { buildControlUiLoginPath, getCurrentControlUiPath } from '../lib/authRedirect'
+import { invalidateRegistryCapabilityCache } from '../lib/hooks/useRegistryCapability'
import { useToast } from './Toast'
type AuthState = {
@@ -102,6 +103,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
await logoutControlUI()
} finally {
sessionExpiredToastShownRef.current = false
+ // Drop the module-level registry-capability cache so a same-tab
+ // logout→login doesn't serve the previous user's org identity.
+ invalidateRegistryCapabilityCache()
setAuthState({ id: '', isLoggedIn: false, isLoading: false, username: '', email: '' })
router.replace(CONTROL_ROUTES.login)
}
diff --git a/control-ui/lib/hooks/__tests__/useRegistryCapability.test.tsx b/control-ui/lib/hooks/__tests__/useRegistryCapability.test.tsx
index ca7223cd9..e0e6902e4 100644
--- a/control-ui/lib/hooks/__tests__/useRegistryCapability.test.tsx
+++ b/control-ui/lib/hooks/__tests__/useRegistryCapability.test.tsx
@@ -3,6 +3,7 @@ import { cleanup, render, screen, waitFor } from '@testing-library/react'
import * as api from '../../api'
import {
__resetRegistryCapabilityCacheForTests,
+ invalidateRegistryCapabilityCache,
useRegistryCapability,
} from '../useRegistryCapability'
@@ -121,4 +122,44 @@ describe('useRegistryCapability', () => {
render(<Probe />)
await waitFor(() => expect(screen.getByText('error')).toBeInTheDocument())
})
+
+ it('silent auth error → stops loading without surfacing an error (global handler navigates away)', async () => {
+ vi.mocked(api.getPublishScope).mockRejectedValue(
+ Object.assign(new Error('unauthorized'), { silent: true })
+ )
+ vi.mocked(api.getRegistryConnection).mockResolvedValue({
+ state: 'connected',
+ authEnabled: true,
+ })
+ render(<Probe />)
+ // Must not get stuck on "loading", and must not surface the Retry error.
+ await waitFor(() => expect(screen.getByText('none')).toBeInTheDocument())
+ expect(screen.queryByText('loading')).toBeNull()
+ expect(screen.queryByText('error')).toBeNull()
+ })
+
+ it('invalidateRegistryCapabilityCache clears the cached identity so the next mount refetches', async () => {
+ vi.mocked(api.getRegistryConnection).mockResolvedValue({
+ state: 'connected',
+ authEnabled: true,
+ })
+ vi.mocked(api.getPublishScope).mockResolvedValue({
+ scope: '@acme',
+ curator: false,
+ orgName: 'acme',
+ })
+ const first = render(<Probe />)
+ await waitFor(() => expect(screen.getByTestId('org').textContent).toBe('acme'))
+ first.unmount()
+
+ // Logout clears the cache; a different user then logs in.
+ invalidateRegistryCapabilityCache()
+ vi.mocked(api.getPublishScope).mockResolvedValue({
+ scope: '@beta',
+ curator: false,
+ orgName: 'beta',
+ })
+ render(<Probe />)
+ await waitFor(() => expect(screen.getByTestId('org').textContent).toBe('beta'))
+ })
})
diff --git a/control-ui/lib/hooks/useRegistryCapability.ts b/control-ui/lib/hooks/useRegistryCapability.ts
index 619c93979..48aa88ea6 100644
--- a/control-ui/lib/hooks/useRegistryCapability.ts
+++ b/control-ui/lib/hooks/useRegistryCapability.ts
@@ -84,12 +84,21 @@ function sharedLoad(): Promise<RegistryCapability> {
return inflight
}
-/** Test hook: drop the module cache + in-flight request so each test is isolated. */
-export function __resetRegistryCapabilityCacheForTests(): void {
+/**
+ * Clear the session-stable identity cache + any in-flight probe. Call on auth
+ * changes (logout) so a same-tab logout→login does not serve the previous user's
+ * org identity until a manual reload.
+ */
+export function invalidateRegistryCapabilityCache(): void {
capabilityCache = null
inflight = null
}
+/** Test hook: drop the module cache + in-flight request so each test is isolated. */
+export function __resetRegistryCapabilityCacheForTests(): void {
+ invalidateRegistryCapabilityCache()
+}
+
/**
* Compose the two capability probes the registry redesign renders controls from
* (design spec §5.1: render from capability, not role guesses).
@@ -132,7 +141,14 @@ export function useRegistryCapability(): RegistryCapabilityState {
setLoading(false)
},
err => {
- if (cancelled || isSilentApiError(err)) return
+ if (cancelled) return
+ // A silent 401 is handled by the global auth handler (it navigates away),
+ // so don't surface an error — but still clear loading so the surface can't
+ // spin if that handler ever no-ops.
+ if (isSilentApiError(err)) {
+ setLoading(false)
+ return
+ }
setError(true)
setLoading(false)
}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 95845edfe..7d68e0e4e 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.377",
+ "version": "0.1.378",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.377",
+ "version": "0.1.378",
"dependencies": {
"@clerum/llm-providers": "file:../packages/llm-providers",
"@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",
diff --git a/control-ui/package.json b/control-ui/package.json
index 9a03b3d58..f261022b8 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.377",
+ "version": "0.1.378",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",