Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): filter attention feed to enabled stale models (R1-M2)
Diego Zacariase865e3503924
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 80584b3fb..72a8a89e6 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.447",+ "version": "0.1.448","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.447",+ "version": "0.1.448","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 e361dcf57..411da771b 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.447",+ "version": "0.1.448","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 cfd79449c..ef2ac191b 100644--- a/control-api/src/routes/admin/llmModels.ts+++ b/control-api/src/routes/admin/llmModels.ts@@ -133,10 +133,11 @@ export function createAdminLlmModelsRouter(gateway: K8sGateway): Router {}// ── Operator attention feed (Fase 5, Pieza C) ───────────────────────────────- // Persistent alert backing the non-destructive Fase 4 cron: every `stale`- // catalog model that is STILL referenced by a Host/grant, so the operator can- // disable it through the impact-gated PUT. Only actionable items (referenced)- // appear; an unreferenced stale model yields nothing. Reuses `impactSources`+ // Persistent alert backing the non-destructive Fase 4 cron: every enabled+ // `stale` catalog model that is STILL referenced by a Host/grant, so the+ // operator can disable it through the impact-gated PUT. Only actionable items+ // appear; an unreferenced stale model — or one already disabled — yields+ // nothing (`listStaleAllowedModels` filters `AND enabled`). Reuses `impactSources`// (the same fail-loud enumeration the `?force` gate uses, regla D4): if any// Host LIST fails, `computeAttention` propagates → asyncHandler → 500, never a// partial feed that hides a live reference. Inherits the `/admin/*` control-uidiff --git a/control-api/src/services/llmAllowedModels.ts b/control-api/src/services/llmAllowedModels.tsindex 4d3bb51eb..ff9c8e114 100644--- a/control-api/src/services/llmAllowedModels.ts+++ b/control-api/src/services/llmAllowedModels.ts@@ -216,16 +216,28 @@ export async function listAllowedModels(db: DbClient = pool): Promise<LlmAllowed}/**- * Stale rows only — models the Fase 4 sync flagged as vanished from the external- * catalog (`stale=true`) but left `enabled` intact. The operator-attention feed- * (Fase 5) enumerates these and reports the ones still referenced. Deterministic- * ordering keeps the feed stable across calls.+ * Stale AND enabled rows — models the Fase 4 sync flagged as vanished from the+ * external catalog (`stale=true`) while leaving `enabled` intact, so they still+ * ship in the runtime allowlist ConfigMap and keep working. The operator-+ * attention feed (Fase 5) is the sole consumer: it enumerates these and reports+ * the ones still referenced as `stale_model_referenced` — an ACTIONABLE item+ * whose remedy is the impact-gated PUT that disables the model.+ *+ * The `AND enabled` filter is load-bearing for that contract. A `stale` model+ * that is ALREADY disabled but still referenced (a dangling reference left after+ * a force-disable) is NOT actionable through this feed — its suggested action+ * ("disable it") is already done — so surfacing it would make the feed never+ * converge to zero after the very action it asked for. That "disabled + still+ * referenced" state is a distinct, diagnostic-only concern (a future+ * `dangling_reference` kind, designed separately); it is not lost here — it stays+ * derivable via `computeModelImpact`. Deterministic ordering keeps the feed+ * stable across calls.*/export async function listStaleAllowedModels(db: DbClient = pool): Promise<LlmAllowedModel[]> {const result = await db.query(`SELECT ${MODEL_COLUMNS}FROM llm_allowed_models- WHERE stale+ WHERE stale AND enabledORDER BY provider ASC, model ASC`)return (result.rows as Record<string, unknown>[]).map(rowToModel)diff --git a/control-api/src/services/llmAttention.ts b/control-api/src/services/llmAttention.tsindex 95a8648b1..dd4a78560 100644--- a/control-api/src/services/llmAttention.ts+++ b/control-api/src/services/llmAttention.ts@@ -7,10 +7,14 @@* non-destructive default is only safe if the operator is told to act. This* module produces that persistent alert: the set of ACTIONABLE attention items.*- * TODAY there is exactly one item kind — a `stale` model that is STILL- * referenced by some Host/grant, so the operator must decide to disable it- * (through the Fase 3 impact-gated PUT). A `stale` model that nobody references- * is NOT actionable and produces NO item.+ * TODAY there is exactly one item kind — a `stale` AND `enabled` model that is+ * STILL referenced by some Host/grant, so the operator must decide to disable it+ * (through the Fase 3 impact-gated PUT). Two cases produce NO item: a `stale`+ * model that nobody references (nothing to act on), and a `stale` model that is+ * ALREADY disabled (its suggested action is already done — the enabled filter+ * lives in `listStaleAllowedModels`, so those rows never reach this module). A+ * disabled-but-still-referenced model is a distinct diagnostic concern (a future+ * `dangling_reference` kind), not an actionable attention item.** The `kind` discriminator is an OPEN string union on purpose: future phases add* item kinds (e.g. a re-appeared model, a pricing gap) without breaking the@@ -49,10 +53,12 @@ import {export const ATTENTION_KIND_STALE_MODEL_REFERENCED = 'stale_model_referenced'/**- * A `stale` catalog model that is still referenced by a live Host/grant — the- * operator must disable it (impact-gated PUT) to converge. Carries the same- * `hostsAffected`/`grantsAffected` shape the Fase 3 impact body uses, so the- * frontend renders both surfaces identically.+ * A `stale` AND `enabled` catalog model that is still referenced by a live+ * Host/grant — the operator must disable it (impact-gated PUT) to converge. An+ * already-disabled stale model is filtered out upstream (`listStaleAllowedModels`)+ * and never produces this item. Carries the same `hostsAffected`/`grantsAffected`+ * shape the Fase 3 impact body uses, so the frontend renders both surfaces+ * identically.*/export interface StaleModelReferencedItem {kind: typeof ATTENTION_KIND_STALE_MODEL_REFERENCEDdiff --git a/control-api/test/routes.adminAttention.test.ts b/control-api/test/routes.adminAttention.test.tsindex 4044e1526..de9a39fe6 100644--- a/control-api/test/routes.adminAttention.test.ts+++ b/control-api/test/routes.adminAttention.test.ts@@ -55,6 +55,9 @@ const ACTIVE_ADMIN = {const PROVIDER = 'claude'const STALE_MODEL = 'claude-haiku-4-5'const OTHER_STALE_MODEL = 'claude-opus-legacy'+// A stale row that has ALREADY been disabled. Sorts after STALE_MODEL under the+// query's ORDER BY provider, model, so a leaked ordering is deterministic.+const DISABLED_STALE_MODEL = 'claude-sonnet-disabled'// A raw `llm_allowed_models` DB row shaped to the migration schema, run through// the REAL `rowToModel` mapper on the way out (T1). `stale` defaults true here@@ -126,7 +129,17 @@ function installPool(opts: {return { rows, rowCount: rows.length }}if (/FROM llm_allowed_models/.test(text) && /WHERE stale/.test(text)) {- return { rows: staleRows, rowCount: staleRows.length }+ // No real Postgres in this suite, so emulate the query's OWN WHERE clause+ // instead of trusting the caller to pre-filter: when the SQL under test+ // filters `AND enabled`, drop disabled rows exactly as Postgres would.+ // Keying off the real SQL is what lets this stand in for the DB across the+ // fix — pre-fix (`WHERE stale`) the disabled row leaks through, post-fix it+ // is filtered. Rows keep the real `rowToModel` input shape (T1).+ const filtersEnabled = /\bAND enabled\b/.test(text)+ const rows = filtersEnabled+ ? staleRows.filter(r => (r as { enabled?: unknown }).enabled === true)+ : staleRows+ return { rows, rowCount: rows.length }}return { rows: [], rowCount: 0 }})@@ -286,6 +299,38 @@ describe('GET /admin/attention', () => {])})+ it('a stale but DISABLED referenced model is NOT actionable → absent; an enabled one appears (R1-M2)', async () => {+ // A force-disable can leave a dangling reference: stale=true, enabled=false,+ // still referenced by a Host. Its suggested action ("disable it, impact-gated+ // PUT") is ALREADY done, so the feed must NOT re-surface it — otherwise it+ // never converges to zero after the action it itself asked for. A stale AND+ // enabled referenced model still must appear. Both rows carry the real+ // `rowToModel` input shape (T1); the assertion is the observable item list the+ // banner renders (T4).+ installPool({+ staleRows: [+ makeModelRow({+ id: '11111111-1111-4111-8111-111111111111',+ model: STALE_MODEL,+ enabled: true,+ }),+ makeModelRow({+ id: '44444444-4444-4444-8444-444444444444',+ model: DISABLED_STALE_MODEL,+ enabled: false,+ }),+ ],+ })+ const gateway = new MockGateway('mcp-host')+ await seedHost(gateway, 'agent-enabled', primarySpec(STALE_MODEL))+ await seedHost(gateway, 'agent-disabled', primarySpec(DISABLED_STALE_MODEL))++ const res = await authedGet(gateway).expect(200)+ // Only the enabled stale model is an actionable item; the disabled one, though+ // still referenced, is filtered out at the query (`WHERE stale AND enabled`).+ expect(res.body.items.map((i: { model: string }) => i.model)).toEqual([STALE_MODEL])+ })+it('detects stale references across BOTH real host namespaces', async () => {expect(config.hostsNamespace).not.toBe(config.namespace) // preconditioninstallPool({ staleRows: [makeModelRow()] })