Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: close final-review findings on the registry auto-claim branch
Jose Ramirez61cc0d1cb668
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 773a08f43..948967183 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.374",+ "version": "0.1.375","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.374",+ "version": "0.1.375","dependencies": {"@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-api/package.json b/control-api/package.jsonindex f5306e2be..9821d001b 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.374",+ "version": "0.1.375","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/routes/admin/registryConnect.ts b/control-api/src/routes/admin/registryConnect.tsindex 5bdd0a2cd..c71a32747 100644--- a/control-api/src/routes/admin/registryConnect.ts+++ b/control-api/src/routes/admin/registryConnect.ts@@ -20,6 +20,14 @@ import { signPop } from '../../services/registryPopSigner.js'* token — the deployment has none yet). Persists into registry_connection.* Managed mode has no connect flow (409 not_self_hosted).*+ * GET reports state ∈ disconnected|pending|connecting|approved|rejected|connected.+ * `connecting` means the registry auto-approved the registration and the+ * inline claim did not land yet; it is finished by POST+ * /admin/registry/connect/recover, never by pasting a token — under+ * auto-approval no operator ever issues one. `approved` keeps the original+ * operator-approved meaning: a human pastes the one-time claim token via POST+ * /admin/registry/connect/claim.+ ** Error mapping (C-M6): register 400 org_blocklisted and claim 409* already_claimed/client_unavailable are surfaced with distinct codes rather* than the opaque 502 registry_integration_error, and GET polls the registry@@ -181,7 +189,9 @@ export function createRegistryConnectRouter(): Router {}// GET status — current state; polls the registry so operator approval is- // visible pre-claim (state ∈ disconnected|pending|approved|rejected|connected).+ // visible pre-claim (state ∈ disconnected|pending|connecting|approved|rejected|connected).+ // `connecting` is finished via POST /admin/registry/connect/recover, not by+ // pasting a token.router.get('/admin/registry/connect', requireAuthForControlUI, async (req, res, next) => {try {const ctx = await requireSelfHostedAdmin(req, res)@@ -521,6 +531,10 @@ export function createRegistryConnectRouter(): Router {res.status(409).json({ error: 'deployment_suspended' })return}+ // Unreachable by construction: the registry's rejectDeployment is+ // gated `WHERE status = 'pending'`, so a locally-'approved' row can+ // never observe 'rejected' here — kept for defense in depth, which is+ // also why the panel has no dedicated UI branch for this code.if (poll?.status === 'rejected') {res.status(409).json({ error: 'rejected' })returndiff --git a/control-api/test/routes.registryConnect.test.ts b/control-api/test/routes.registryConnect.test.tsindex 7c33b9f55..21e065218 100644--- a/control-api/test/routes.registryConnect.test.ts+++ b/control-api/test/routes.registryConnect.test.ts@@ -402,38 +402,46 @@ describe('registry connect flow', () => {})describe('register — auto-claim (201)', () => {- it('claims immediately and reports connected', async () => {- connDb.getRegistryConnection.mockResolvedValue(null)- connDb.markConnected.mockResolvedValue(true)- const spy = routeFetch({- '/register': () =>- json(- {- deployment_id: 'dep-1',- key_id: 'kid-1',- status: 'approved',- claim_token: 'tok-abc',- claim_expires_at: '2026-07-30T00:00:00Z',- },- 201- ),- '/claim': () => json({ client_id: 'cid', client_secret: 'csecret', org: 'acme' }, 200),- })- const res = await request(app())- .post('/admin/registry/connect/request')- .send({ requested_org_name: 'acme', contact_email: '[email protected]' })- .expect(200)- expect(res.body).toMatchObject({ state: 'connected', org: 'acme' })- expect(res.body.authEnabled).toBe(true)- // The claim call must actually carry the token the registry minted, and- // be PoP-authenticated — otherwise every auto-approved self-hoster gets a- // registry-side 401 and silently falls back to 202 connecting.- const [claimUrl, claimInit] = spy.mock.calls[1]!- expect(String(claimUrl)).toContain('/claim')- expect((claimInit as RequestInit).headers).toHaveProperty('DPoP')- const claimBody = JSON.parse(String((claimInit as RequestInit).body))- expect(claimBody.claim_token).toBe('tok-abc')- })+ // Parameterized over registryAuthEnabled: the beforeEach default is `true`,+ // so a mutation replacing `authEnabled: config.registryAuthEnabled` with the+ // literal `true` on the 201-connected response passes an authEnabled-only-true+ // suite. The `false` case is the one that would catch it.+ it.each([true, false])(+ 'claims immediately and reports connected (registryAuthEnabled=%s)',+ async registryAuthEnabled => {+ cfg.registryAuthEnabled = registryAuthEnabled+ connDb.getRegistryConnection.mockResolvedValue(null)+ connDb.markConnected.mockResolvedValue(true)+ const spy = routeFetch({+ '/register': () =>+ json(+ {+ deployment_id: 'dep-1',+ key_id: 'kid-1',+ status: 'approved',+ claim_token: 'tok-abc',+ claim_expires_at: '2026-07-30T00:00:00Z',+ },+ 201+ ),+ '/claim': () => json({ client_id: 'cid', client_secret: 'csecret', org: 'acme' }, 200),+ })+ const res = await request(app())+ .post('/admin/registry/connect/request')+ .send({ requested_org_name: 'acme', contact_email: '[email protected]' })+ .expect(200)+ expect(res.body).toMatchObject({ state: 'connected', org: 'acme' })+ expect(res.body.authEnabled).toBe(registryAuthEnabled)+ // The claim call must actually carry the token the registry minted, and+ // be PoP-authenticated — otherwise every auto-approved self-hoster gets a+ // registry-side 401 and silently falls back to 202 connecting.+ const [claimUrl, claimInit] = spy.mock.calls[1]!+ expect(String(claimUrl)).toContain('/claim')+ expect((claimInit as RequestInit).headers).toHaveProperty('DPoP')+ const claimBody = JSON.parse(String((claimInit as RequestInit).body))+ expect(claimBody.claim_token).toBe('tok-abc')+ }+ )// The mocks return undefined, so `await x` and `void x` produce IDENTICAL// invocationCallOrder — an ordering assertion built on call order is greendiff --git a/control-api/test/services.registryConnectionDb.test.ts b/control-api/test/services.registryConnectionDb.test.tsindex 565feb926..05db471bc 100644--- a/control-api/test/services.registryConnectionDb.test.ts+++ b/control-api/test/services.registryConnectionDb.test.ts@@ -386,8 +386,13 @@ describe('markConnected — scoped write', () => {const upd = dbQuery.mock.calls.find(([sql]) =>String(sql).includes('UPDATE registry_connection'))- expect(String(upd![0])).toMatch(/WHERE\s+deployment_id\s*=\s*\$4/)- expect(String(upd![0])).toMatch(/status\s*<>\s*'connected'/)+ // ONE contiguous assertion: mutating the AND to OR (a row belonging to a+ // DIFFERENT deployment with status 'pending' would then also match) must+ // fail this test. Two independent regexes each match an OR-joined clause+ // just as well as an AND-joined one, so they cannot catch that mutation.+ expect(String(upd![0])).toMatch(+ /WHERE\s+deployment_id\s*=\s*\$4\s+AND\s+status\s*<>\s*'connected'/+ )expect((upd![1] as string[])[3]).toBe('dep-9')})diff --git a/control-ui/components/RegistryConnectPanel.tsx b/control-ui/components/RegistryConnectPanel.tsxindex 747bb90d9..eb67ce2dc 100644--- a/control-ui/components/RegistryConnectPanel.tsx+++ b/control-ui/components/RegistryConnectPanel.tsx@@ -157,7 +157,7 @@ export default function RegistryConnectPanel() {else if (code === 'registration_capacity')setFormError('The registry is not accepting new registrations right now. Try again later.')else if (code === 'rate_limited')- setFormError('Too many registration attempts from this network. Try again tomorrow.')+ setFormError('Too many registration attempts from this network. Try again later.')else if (code === 'invalid_contact_email')setFormError('That contact email is not a valid address. Use a full address such as [email protected].'@@ -189,6 +189,12 @@ export default function RegistryConnectPanel() {setFormError('That claim token has expired. Ask your operator to re-issue it.')else if (code === 'claim_rejected')setFormError('That claim token was rejected. Check it and try again.')+ else if (code === 'connection_superseded')+ // Terminal, not retryable: the registry already burned this one-time+ // token and the credentials it returned could not be saved here.+ setFormError(+ 'This deployment can no longer authenticate: its one-time credentials were issued but never stored. Disconnect, then register again with a different organization name.'+ )else if (code === 'not_pending')await load() // server state moved on — re-syncelse setFormError('Could not complete the claim. Try again shortly.')diff --git a/control-ui/components/__tests__/RegistryConnectPanel.test.tsx b/control-ui/components/__tests__/RegistryConnectPanel.test.tsxindex 0a15c4847..a0d898a2f 100644--- a/control-ui/components/__tests__/RegistryConnectPanel.test.tsx+++ b/control-ui/components/__tests__/RegistryConnectPanel.test.tsx@@ -139,6 +139,34 @@ describe('RegistryConnectPanel', () => {await waitFor(() => expect(screen.getByText(/has expired/)).toBeInTheDocument())})+ // The server can 409 connection_superseded when markConnected matches no+ // row (the claim token was already redeemed and burned, but the credentials+ // could not be saved to this connection). Falling through to the generic+ // "Could not complete the claim. Try again shortly." would tell the user to+ // retry a claim that can never succeed again.+ it('shows terminal copy on a connection_superseded code, not a retry prompt', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'approved',+ deploymentId: 'd',+ requestedOrgName: 'acme',+ })+ vi.mocked(api.submitRegistryClaim).mockRejectedValue(+ Object.assign(new Error('x'), { code: 'connection_superseded' })+ )+ render(<RegistryConnectPanel />)+ await waitFor(() => screen.getByPlaceholderText('paste claim token'))+ fireEvent.change(screen.getByPlaceholderText('paste claim token'), {+ target: { value: 'tok-1' },+ })+ fireEvent.click(screen.getByText('Complete connection'))+ await waitFor(() =>+ expect(+ screen.getByText(/one-time credentials were issued but never stored/i)+ ).toBeInTheDocument()+ )+ expect(screen.queryByText(/Try again shortly/i)).toBeNull()+ })+it('shows connected + Disconnect when already connected', async () => {vi.mocked(api.getRegistryConnection).mockResolvedValue({state: 'connected',@@ -336,6 +364,28 @@ describe('RegistryConnectPanel', () => {).toBeInTheDocument()})+ // handleRecover's terminal arm (already_claimed / connection_superseded)+ // drives the "Disconnect, then register again" copy. This is distinct from+ // the "shows the terminal message when recovery is already claimed" test+ // above, which exercises GET's recoveryError JSX, not this REJECTION path.+ // Deleting this catch branch would keep the suite green while the user+ // retries forever, spending an unthrottled registry rotate each time.+ it('shows terminal disconnect-and-restart copy when recovery reports already_claimed', async () => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connecting',+ deploymentId: 'dep-1',+ requestedOrgName: 'acme',+ })+ vi.mocked(api.recoverRegistryConnection).mockRejectedValue(+ Object.assign(new Error('x'), { code: 'already_claimed' })+ )+ render(<RegistryConnectPanel />)+ await userEvent.click(await screen.findByRole('button', { name: /finish connecting/i }))+ expect(+ await screen.findByText(/one-time credentials were issued but never stored/i)+ ).toBeInTheDocument()+ })+// IMPORTANT-1 fix: handleRequest's direct `connecting` branch (:129-136) had// zero coverage — every other connecting-view test reached that state via// GET/load(), never via requestRegistryConnection() itself resolvingdiff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex e9cbf1349..de6dae349 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.355",+ "version": "0.1.356","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.355",+ "version": "0.1.356","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.jsonindex aa450626d..6edf226be 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.355",+ "version": "0.1.356","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/docs/how-to/connect-to-registry.md b/docs/how-to/connect-to-registry.mdindex 60ec9d89f..ed19d4bc4 100644--- a/docs/how-to/connect-to-registry.md+++ b/docs/how-to/connect-to-registry.md@@ -36,11 +36,14 @@ one of two state machines, depending on how the registry is configured:network blip, or the registry briefly unavailable), the panel shows**Finishing the connection** with a **Finish connecting** button; press itto retry. In most cases, retrying with **Finish connecting** will succeed and- you never need a token. If the panel reports that the deployment can no- longer authenticate, **Finish connecting** will not help — the only path- forward is **Start over**, which permanently deletes the deployment's stored- registry credentials and gives up the organization name. If you use- **Start over**, you must register again under a different organization name.+ you never need a token. If the panel says to contact support, do that: a+ suspended deployment can be reversed by Evenfire, and **Start over** would+ destroy a keypair you may still need. Only use **Start over** when the+ panel says the deployment's one-time credentials were issued but never+ stored. That connection cannot be recovered: **Start over** permanently+ deletes the deployment's stored registry credentials and gives up the+ organization name. If you use **Start over**, you must register again+ under a different organization name.- **Open registration disabled** — the request lands as **pending**. AnEvenfire operator reviews it and either approves or rejects it. On