Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): remap registry browse 401 to 502 so control-ui doesn't force-logout
Jose Ramirez172c50015f53
diff --git a/control-api/src/services/registryClient.ts b/control-api/src/services/registryClient.tsindex 9299b0f04..2e74f5ea2 100644--- a/control-api/src/services/registryClient.ts+++ b/control-api/src/services/registryClient.ts@@ -254,6 +254,19 @@ async function registryFetch<T>(path: string, init?: RequestInit): Promise<T> {const res = await authedFetch(path, init)if (!res.ok) {const body = await res.text()+ // A persistent 401 (authedFetch already evict-retried once) is a registry+ // machine-token / integration fault — NOT the admin's control-ui session.+ // Remap to 502 so control-ui's global 401 handler doesn't force-logout the+ // admin when the registry rejects control-api (e.g. auth off, or a+ // half-configured/failing connection). Mirrors orgRegistryFetch, which+ // already does this. Every other status is forwarded verbatim so a+ // registry 404 stays a 404 (see the e2e-registry-publish-update-remove+ // failure class below).+ if (res.status === 401) {+ throw Object.assign(new Error('Registry 401: registry_integration_error'), {+ status: 502,+ })+ }// Attach the upstream status so the global error handler (app.ts) can// forward 4xx responses to the API client. Without `.status`, a registry// 404 surfaces as a 500 Internal Server Error from control-api — thediff --git a/control-api/test/registryClient.test.ts b/control-api/test/registryClient.test.tsindex 81cf6e386..bbb670213 100644--- a/control-api/test/registryClient.test.ts+++ b/control-api/test/registryClient.test.ts@@ -312,6 +312,36 @@ describe('registryClient — GET retry-once (transient resilience)', () => {expect(entryCalls.length).toBe(2)})+ it('remaps a persistent registry 401 to 502 (so control-ui does not force-logout)', async () => {+ // authedFetch evict-retries a 401 once; both attempts 401 → registryFetch+ // remaps to 502. A bare 401 here would trip control-ui's global 401 handler+ // and force-logout a valid admin session — the "session expires quickly" bug.+ const fetchMock = entriesQueue([+ () => new Response(JSON.stringify({ error: 'unauthorized' }), { status: 401 }),+ () => new Response(JSON.stringify({ error: 'unauthorized' }), { status: 401 }),+ ])+ vi.stubGlobal('fetch', fetchMock)+ Object.assign(process.env, ENV_OVERRIDE)++ const err = (await searchEntries({ q: 'thing' }).catch(e => e)) as Error & { status?: number }+ // Load-bearing: status MUST be 502, NOT 401.+ expect(err.status).toBe(502)+ expect(err.status).not.toBe(401)+ expect(err.message).toMatch(/registry_integration_error/)+ })++ it('still forwards a registry 404 verbatim (not remapped)', async () => {+ // Guards the 401 remap against over-reach: non-401 statuses must pass through+ // so a registry 404 stays a 404 (the e2e-registry-publish-update-remove class).+ const fetchMock = entriesQueue([() => new Response('missing', { status: 404 })])+ vi.stubGlobal('fetch', fetchMock)+ Object.assign(process.env, ENV_OVERRIDE)++ const err = (await searchEntries({ q: 'thing' }).catch(e => e)) as Error & { status?: number }+ expect(err.status).toBe(404)+ expect(err.message).toMatch(/Registry 404/)+ })+it('does NOT retry a non-GET (POST publish) on 503', async () => {const fetchMock = vi.fn().mockImplementation((url: string) => {if (url.endsWith('/oauth/token')) return Promise.resolve(fakeTokenResponse('tok', 600))