Skip to content

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

TypeScript

fix(reconciler): log the status-condition write only when it happened

Alfredo Lopez99aa59b108da
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index a7be92d08..1d8cc6aa0 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.271",
+ "version": "0.1.272",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.271",
+ "version": "0.1.272",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 9dfecf275..2e6efbaea 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.271",
+ "version": "0.1.272",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/reconciler.test.ts b/host-context-controller/src/reconciler.test.ts
index 52e867406..5d1ea3130 100644
--- a/host-context-controller/src/reconciler.test.ts
+++ b/host-context-controller/src/reconciler.test.ts
@@ -935,7 +935,7 @@ describe('PR-B B1 — writeStatusCondition', () => {
reason: 'ok',
message: 'ok',
})
- ).resolves.toBeUndefined()
+ ).resolves.toBe(false)
expect(customApi.patchNamespacedCustomObjectStatus).not.toHaveBeenCalled()
})
@@ -1869,6 +1869,43 @@ describe('updateStatusConditions', () => {
expect(types).toContain('NetworkReady')
expect(types).toContain('DeploymentReady')
})
+
+ it('does not log Updated status conditions when both writes were skipped', async () => {
+ const server = makeServer({ name: 'pg' })
+ const identical = {
+ status: {
+ conditions: [
+ {
+ type: 'NetworkReady',
+ status: 'True',
+ reason: 'NetworkPoliciesApplied',
+ message: 'NetworkPolicies and Service created',
+ lastTransitionTime: '2020-01-02T00:00:00.000Z',
+ },
+ {
+ type: 'DeploymentReady',
+ status: 'True',
+ reason: 'ReplicasAvailable',
+ message: 'Deployment has ready replicas',
+ lastTransitionTime: '2020-01-02T00:00:00.000Z',
+ },
+ ],
+ },
+ }
+ customApi.getNamespacedCustomObjectStatus.mockResolvedValue(identical)
+ const log = vi.spyOn(console, 'log').mockImplementation(() => {})
+ try {
+ await (
+ reconciler as unknown as {
+ updateStatusConditions(server: McpServerCRD, deploymentReady: boolean): Promise<void>
+ }
+ ).updateStatusConditions(server, true)
+ expect(customApi.patchNamespacedCustomObjectStatus).not.toHaveBeenCalled()
+ expect(log.mock.calls.flat().join('\n')).not.toContain('Updated status conditions')
+ } finally {
+ log.mockRestore()
+ }
+ })
})
describe('unconfigured inventory authority fails closed (G1)', () => {
diff --git a/host-context-controller/src/reconciler.ts b/host-context-controller/src/reconciler.ts
index c1cb7d7e2..96a812002 100644
--- a/host-context-controller/src/reconciler.ts
+++ b/host-context-controller/src/reconciler.ts
@@ -1845,7 +1845,7 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
isCurrent: () => boolean = () => true
): Promise<void> {
try {
- await this.writeStatusCondition(
+ const networkWrote = await this.writeStatusCondition(
server,
{
type: 'NetworkReady',
@@ -1855,7 +1855,7 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
},
isCurrent
)
- await this.writeStatusCondition(
+ const deploymentWrote = await this.writeStatusCondition(
server,
{
type: 'DeploymentReady',
@@ -1873,9 +1873,11 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
},
isCurrent
)
- console.log(
- `[Reconciler] Updated status conditions on "${server.name}" (DeploymentReady=${deploymentReady})`
- )
+ if (networkWrote || deploymentWrote) {
+ console.log(
+ `[Reconciler] Updated status conditions on "${server.name}" (DeploymentReady=${deploymentReady})`
+ )
+ }
} catch (error) {
// Status subresource may not exist yet — log but don't fail reconciliation
console.warn(`[Reconciler] Failed to update status conditions on "${server.name}":`, error)
@@ -1904,8 +1906,8 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
server: McpServerCRD,
condition: Omit<McpServerCondition, 'lastTransitionTime'>,
isCurrent: () => boolean = () => true
- ): Promise<void> {
- if (!isCurrent()) return
+ ): Promise<boolean> {
+ if (!isCurrent()) return false
const now = new Date().toISOString()
// Update the missing-secret gauge for SecretResolved conditions.
@@ -1930,7 +1932,7 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
// if anything changed since our read; we then re-read and retry, so no
// writer's condition is lost.
for (let attempt = 1; attempt <= STATUS_CONDITION_WRITE_MAX_ATTEMPTS; attempt += 1) {
- if (!isCurrent()) return
+ if (!isCurrent()) return false
// Re-read on every optimistic-conflict retry. Merging against the
// latest resourceVersion preserves conditions written by peer
// controllers between our read and patch.
@@ -1956,15 +1958,15 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
console.warn(
`[Reconciler] McpServer "${server.name}" deleted mid-reconcile — skipping status update`
)
- return
+ return false
}
console.warn(
`[Reconciler] Failed to read status for "${server.name}" — skipping status update for type "${condition.type}" to avoid clobbering other status fields:`,
error
)
- return
+ return false
}
- if (!isCurrent()) return
+ if (!isCurrent()) return false
const prior = existingConditions.find(c => c.type === condition.type)
const observedGeneration = condition.observedGeneration ?? server.generation
@@ -1981,7 +1983,7 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
// reconcile — a tight self-loop that also amplifies NetworkPolicy
// optimistic-lock contention downstream.
if (unchanged) {
- return
+ return false
}
const lastTransitionTime =
@@ -2035,7 +2037,7 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
// The generated client prefers JSON Patch for this endpoint. Send an
// actual patch document so status writes keep working across client
// upgrades instead of relying on merge-patch object bodies.
- if (!isCurrent()) return
+ if (!isCurrent()) return false
await this.customApi.patchNamespacedCustomObjectStatus({
group: 'clerum.io',
version: 'v1alpha1',
@@ -2044,14 +2046,14 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
name: server.name,
body: statusPatch,
})
- return
+ return true
} catch (error) {
const errorCode = getErrorCode(error)
if (errorCode === 404) {
console.warn(
`[Reconciler] McpServer "${server.name}" deleted mid-reconcile — status patch skipped`
)
- return
+ return false
}
// 409 (Conflict) or 422 (a `test` op failed) mean a concurrent writer
// won the race. Re-read and retry rather than lose our condition. Any
@@ -2067,9 +2069,10 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv
`[Reconciler] Failed to write status condition ${condition.type}=${condition.status} on "${server.name}" (attempt ${attempt}/${STATUS_CONDITION_WRITE_MAX_ATTEMPTS}):`,
error
)
- return
+ return false
}
}
+ return false
}
// ─── Public API ─────────────────────────────────────────────────────