Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): gate llm-model rename on the old pair to avoid silent stranding (R1-H1)
Diego Zacarias21c339e14840
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex c43035183..7ba317823 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.444",+ "version": "0.1.445","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.444",+ "version": "0.1.445","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 33dc163fa..ce887b6fd 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.444",+ "version": "0.1.445","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/llmModels.ts b/control-api/src/routes/admin/llmModels.tsindex b6c536c2d..cfd79449c 100644--- a/control-api/src/routes/admin/llmModels.ts+++ b/control-api/src/routes/admin/llmModels.ts@@ -105,8 +105,11 @@ export function createAdminLlmModelsRouter(gateway: K8sGateway): Router {// this single module (regla D4).const impactSources = modelImpactSourcesFromGateway(gateway, hostNamespaces)- // Availability-reduction gate (Fase 3). A DELETE (always) or a PUT that flips- // `enabled` true→false yanks the model out of the runtime allowlist ConfigMap.+ // Availability-reduction gate (Fase 3). A DELETE (always), a PUT that flips+ // `enabled` true→false, or a PUT that RENAMES an enabled pair (its old+ // identity leaves the ConfigMap on re-materialize) yanks the model out of the+ // runtime allowlist ConfigMap. The caller computes the impact over whichever+ // pair leaves — the OLD one on rename.// Without `?force`, if any Host/grant still references `(provider, model)`,// answer 409 WITH the impact body so the operator sees what would be stranded// instead of breaking it silently. Returns true when a 409 was sent (the@@ -234,18 +237,34 @@ export function createAdminLlmModelsRouter(gateway: K8sGateway): Router {return}// Read the stored row FIRST: needed both to 404 a missing row and to- // classify whether this write REDUCES availability. Only a transition of- // `enabled` true→false pulls the model out of the runtime ConfigMap and- // can strand references; a PUT that keeps it enabled (incl. a re-enable or- // a metadata-only edit) never trips the gate.+ // classify whether this write pulls the PUBLISHED `(provider, model)` pair+ // out of the runtime ConfigMap and can strand references. Two mutations do+ // that, both only while the row is currently enabled (an already-disabled+ // pair is not in the ConfigMap, so nothing can be stranded — case 4):+ // (a) DISABLE — `enabled` true→false; the pair leaves the allowlist.+ // (b) RENAME — the identity `(provider, model)` changes while the row+ // stays enabled; re-materialization regroups from the CURRENT rows+ // (`listEnabledGroupedByProvider`), so the OLD pair vanishes from the+ // ConfigMap exactly like a disable, silently invalidating any+ // Host/grant that referenced it. The impact is computed over the OLD+ // pair (`existing.provider`/`existing.model`) — that is what would be+ // stranded — and answered with the same 409+impact body and `?force`+ // escape as disable/delete.+ // RENAME compares VALUES, not key-presence: the admin UI form resubmits+ // `provider` and `model` on every PUT even when unchanged, so a presence+ // check would false-positive every toggle/metadata edit.const existing = await getAllowedModel(req.params.id)if (!existing) {res.status(404).json({ error: 'not_found' })return}- const reducesAvailability = existing.enabled === true && parsed.data.enabled === false+ const disables = parsed.data.enabled === false+ const renamed =+ (parsed.data.provider !== undefined && parsed.data.provider !== existing.provider) ||+ (parsed.data.model !== undefined && parsed.data.model !== existing.model)+ const oldPairLeavesConfigMap = existing.enabled === true && (disables || renamed)if (- reducesAvailability &&+ oldPairLeavesConfigMap &&(await blockedByImpact(req, res, existing.provider, existing.model))) {returndiff --git a/control-api/test/routes.adminLlmModelsImpact.test.ts b/control-api/test/routes.adminLlmModelsImpact.test.tsindex 9b53b8dd8..a6978a44d 100644--- a/control-api/test/routes.adminLlmModelsImpact.test.ts+++ b/control-api/test/routes.adminLlmModelsImpact.test.ts@@ -228,6 +228,70 @@ describe('admin llm-models ?force impact gate', () => {.expect(200)})+ // ── R1-H1: a PUT that RENAMES an enabled pair pulls the OLD pair out of the+ // runtime ConfigMap on re-materialize exactly like a disable, silently+ // stranding any Host/grant that referenced it. The gate must fire on the OLD+ // pair. These assert the OBSERVABLE 409 + impact body (T4).+ it('R1-H1: PUT that RENAMES an enabled referenced pair (model changes) → 409 with impact on the OLD pair', async () => {+ installPool({ modelRow: makeModelRow({ enabled: true }) })+ const gateway = new MockGateway('mcp-host')+ await seedHost(gateway, 'agent-a', primarySpec) // references the OLD (claude, claude-haiku-4-5)++ // The admin UI form resubmits provider+model on every PUT; here `model`+ // actually changes → identity rename while staying enabled.+ const res = await authed('put', `/api/v1/admin/llm-models/${MODEL_ID}`, gateway)+ .send({ provider: PROVIDER, model: 'claude-opus-4-8', enabled: true })+ .expect(409)+ expect(res.body.error).toBe('model_in_use')+ // Impact is over the OLD pair — that is what would be stranded.+ expect(res.body.impact.provider).toBe(PROVIDER)+ expect(res.body.impact.model).toBe(MODEL)+ expect(res.body.impact.hostsAffected).toEqual([+ { namespace: 'mcp-host', name: 'agent-a', roles: ['primary'] },+ ])+ })++ it('R1-H1: PUT that RENAMES the provider of an enabled referenced pair → 409 (identity is the tuple)', async () => {+ installPool({ modelRow: makeModelRow({ enabled: true }) })+ const gateway = new MockGateway('mcp-host')+ await seedHost(gateway, 'agent-a', primarySpec)++ await authed('put', `/api/v1/admin/llm-models/${MODEL_ID}`, gateway)+ .send({ provider: 'anthropic', model: MODEL, enabled: true })+ .expect(409)+ })++ it('R1-H1: PUT rename + ?force=true → proceeds (200), the escape works', async () => {+ installPool({ modelRow: makeModelRow({ enabled: true }) })+ const gateway = new MockGateway('mcp-host')+ await seedHost(gateway, 'agent-a', primarySpec)++ await authed('put', `/api/v1/admin/llm-models/${MODEL_ID}?force=true`, gateway)+ .send({ provider: PROVIDER, model: 'claude-opus-4-8', enabled: true })+ .expect(200)+ })++ it('R1-H1 regression guard: PUT resubmits the SAME provider+model (form no-op) with references → 200, no false positive', async () => {+ installPool({ modelRow: makeModelRow({ enabled: true }) })+ const gateway = new MockGateway('mcp-host')+ await seedHost(gateway, 'agent-a', primarySpec)++ // Identity unchanged (same values) — the gate compares VALUES, not presence.+ await authed('put', `/api/v1/admin/llm-models/${MODEL_ID}`, gateway)+ .send({ provider: PROVIDER, model: MODEL, enabled: true, display_name: 'Claude Haiku' })+ .expect(200)+ })++ it('R1-H1: renaming an ALREADY-DISABLED referenced pair → 200 (old pair was not in the ConfigMap)', async () => {+ installPool({ modelRow: makeModelRow({ enabled: false }) })+ const gateway = new MockGateway('mcp-host')+ await seedHost(gateway, 'agent-a', primarySpec)++ await authed('put', `/api/v1/admin/llm-models/${MODEL_ID}`, gateway)+ .send({ provider: PROVIDER, model: 'claude-opus-4-8', enabled: false })+ .expect(200)+ })+it('PUT enabled false→false (already disabled) → never 409', async () => {installPool({ modelRow: makeModelRow({ enabled: false }) })const gateway = new MockGateway('mcp-host')