Skip to content

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

TypeScript

fix(control-api): make stale warning lookup best-effort (R1-B1) so it never blocks host writes

Diego Zacarias4e5a9642d81b
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 979801deb..c43035183 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.443",
+ "version": "0.1.444",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.443",
+ "version": "0.1.444",
"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.json
index b982c1e0a..33dc163fa 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.443",
+ "version": "0.1.444",
"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/hostSpecValidation.ts b/control-api/src/routes/admin/hostSpecValidation.ts
index 29bc4b3bc..7224a9783 100644
--- a/control-api/src/routes/admin/hostSpecValidation.ts
+++ b/control-api/src/routes/admin/hostSpecValidation.ts
@@ -412,7 +412,24 @@ async function maybeWarnStale(
if (tol.storedRoles.any.has(key)) return
if (tol.warnedKeys.has(key)) return
const getState = tol.deps.getModelAllowlistState ?? getModelAllowlistStateDefault
- const state = await getState(provider, model)
+ // Best-effort: this is an EXTRA lookup (separate from the isModelAllowed gate
+ // query) that ONLY feeds the additive stale warning. The PR invariant is that
+ // the soft quarantine is additive and NEVER blocks a write (never 422/409/500).
+ // A blip on this query (connection reset) must not turn a valid Host
+ // create/update into an HTTP 500 — swallow it, proceed WITHOUT a warning, and
+ // let the write persist. The correctness gate (isModelAllowed) is untouched: it
+ // still propagates its failures and still hard-rejects a disallowed model.
+ let state: { enabled: boolean; stale: boolean } | null
+ try {
+ state = await getState(provider, model)
+ } catch (err) {
+ console.warn(
+ `[Admin] stale-model warning lookup failed for "${provider}/${model}"; proceeding without a warning: ${
+ err instanceof Error ? err.message : String(err)
+ }`
+ )
+ return
+ }
if (state?.enabled && state.stale) {
tol.warnedKeys.add(key)
tol.warnings.push({ code: STALE_MODEL_ASSIGNED, provider, model, field })
diff --git a/control-api/test/routes.resources.staleModelWarning.test.ts b/control-api/test/routes.resources.staleModelWarning.test.ts
index 9d9d9d875..a6aa1cada 100644
--- a/control-api/test/routes.resources.staleModelWarning.test.ts
+++ b/control-api/test/routes.resources.staleModelWarning.test.ts
@@ -95,6 +95,50 @@ describe('Host stale soft-quarantine warnings (Fase 6)', () => {
expect(res.body.warnings).toBeUndefined()
})
+ // R1-B1: the stale-warning lookup (getModelAllowlistState) is an EXTRA query,
+ // separate from the isModelAllowed gate. It ONLY feeds the additive warning, so
+ // a failure on it must NEVER block a valid write — the PR invariant is "additive,
+ // never blocks (never 422/409/500)". Before the fix the rejection propagated
+ // through validateHostSpec → asyncHandler → HTTP 500, ahead of createResource /
+ // updateResource. Assert the OBSERVABLE result (T4): the Host still persists.
+ it('CREATE persists (201) when the stale-warning lookup rejects (best-effort, no 500)', async () => {
+ llm.getModelAllowlistState.mockRejectedValue(new Error('db connection reset'))
+ const gateway = new MockGateway(HOSTS_NS)
+
+ const res = await request(buildApp(gateway))
+ .post('/admin/hosts')
+ .send({ metadata: { name: 'h1' }, spec: staleSpec })
+
+ expect(res.status).toBe(201)
+ // The CR actually landed with the requested spec — not just a non-500 status.
+ expect((res.body as { metadata: { name: string } }).metadata.name).toBe('h1')
+ expect((res.body as { spec: typeof staleSpec }).spec.model.name).toBe('M')
+ const stored = (await gateway.getResource('hosts', 'h1', HOSTS_NS)) as {
+ spec: typeof staleSpec
+ }
+ expect(stored.spec.model.name).toBe('M')
+ // Best-effort degrade: no warning surfaced, but the write is not blocked.
+ expect(res.body.warnings).toBeUndefined()
+ })
+
+ it('EDIT persists (200) when the stale-warning lookup rejects (best-effort, no 500)', async () => {
+ llm.getModelAllowlistState.mockRejectedValue(new Error('db connection reset'))
+ const gateway = new MockGateway(HOSTS_NS)
+ // Stored default is a fresh model; the edit switches it to a new pair, which
+ // is exactly the path that triggers the (now-guarded) warning lookup.
+ await gateway.createResource('hosts', { metadata: { name: 'h1' }, spec: freshSpec }, HOSTS_NS)
+
+ const res = await request(buildApp(gateway)).put('/admin/hosts/h1').send({ spec: staleSpec })
+
+ expect(res.status).toBe(200)
+ expect((res.body as { spec: typeof staleSpec }).spec.model.name).toBe('M')
+ const stored = (await gateway.getResource('hosts', 'h1', HOSTS_NS)) as {
+ spec: typeof staleSpec
+ }
+ expect(stored.spec.model.name).toBe('M')
+ expect(res.body.warnings).toBeUndefined()
+ })
+
it('does NOT surface a warning when the write fails to persist (updateResource throws)', async () => {
class ThrowingGateway extends MockGateway {
override async updateResource(): Promise<unknown> {