Skip to content

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

TypeScript

fix(hcc,wrc): keep metadata-only NP revoke and unblock HCC typecheck

Alfredo Lopez9df681af696f
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index c76d3e955..677db12b5 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.285",
+ "version": "0.1.286",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.285",
+ "version": "0.1.286",
"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 31e93dd0b..2bc819451 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.285",
+ "version": "0.1.286",
"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/k8sClient.test.ts b/host-context-controller/src/k8sClient.test.ts
index ccfd97f06..b48e67bc5 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -2031,13 +2031,9 @@ describe('McpServerWatcher startup', () => {
}
})
- it('does not fan out on a Context MODIFIED that does not move desired revision (#460 Phase 2)', async () => {
- // A MODIFIED that does not move the desired revision — a status or label
- // write by another controller — used to run scoped revocation so a lost
- // delete fence could reach the convergence retry. That path was also the
- // #460 Loop A Host fan-out. Phase 2 returns after the cache update;
- // subtractive-drift recovery is the periodic netPol resync (#478 / infra
- // gcp-dev enable), not metadata-only Context events.
+ it('does not fan out Host/SFS on a Context MODIFIED that does not move desired revision (#460 Phase 2)', async () => {
+ // Metadata-only MODIFIED still runs scoped NP revoke (lost-fence can
+ // throw). Host/SFS fan-out is the Loop A storm and stays skipped.
let contextWatchCallback:
| ((
type: string,
@@ -2065,8 +2061,16 @@ describe('McpServerWatcher startup', () => {
generation: 4,
spec: { contextId: 'steady-context', mcpServers: [] },
})
+ ;(watcher as any).hosts.set('bound-host', {
+ name: 'bound-host',
+ namespace: 'mcp-host',
+ spec: { host: 'bound-host', contextRef: 'steady-context', secretRef: 'host-secret' },
+ })
markNetworkPolicyRevocationAuthoritative(watcher)
const passesBefore = mocks.netPolFullReconcile.mock.calls.length
+ const hostReconcile = vi.spyOn(watcher.getHostReconciler(), 'reconcile')
+ const sfsPropagate = vi.spyOn(watcher as any, 'reconcileSharedFileSystemsReferencedByContext')
+ const cachedBefore = (watcher as any).contexts.get('steady-context')
try {
await contextWatchCallback!('MODIFIED', {
@@ -2079,13 +2083,85 @@ describe('McpServerWatcher startup', () => {
spec: { contextId: 'steady-context', mcpServers: [] },
})
- expect((watcher as any).netPolReconciler.reconcileContext).not.toHaveBeenCalled()
+ expect((watcher as any).contexts.get('steady-context')).toBe(cachedBefore)
+ expect((watcher as any).netPolReconciler.reconcileContext).toHaveBeenCalledWith(
+ expect.objectContaining({ name: 'steady-context', generation: 4 }),
+ expect.objectContaining({ honorsLostFence: false })
+ )
+ expect(hostReconcile).not.toHaveBeenCalled()
+ expect(sfsPropagate).not.toHaveBeenCalled()
expect(mocks.netPolFullReconcile.mock.calls.length).toBe(passesBefore)
} finally {
await watcher.stop()
}
})
+ it('retries convergence when a metadata-only Context MODIFIED loses the delete fence', async () => {
+ let contextWatchCallback:
+ | ((
+ type: string,
+ apiObj: {
+ metadata: { name: string; namespace: string; uid: string; generation?: number }
+ spec: { contextId: string; mcpServers: string[] }
+ }
+ ) => Promise<void>)
+ | undefined
+ mocks.watch.mockImplementationOnce(async (path, _options, callback) => {
+ if (path.endsWith('/contexts')) contextWatchCallback = callback
+ return { abort: vi.fn() }
+ })
+
+ const watcher = new McpServerWatcher()
+ await (watcher as any).startContextWatch('lost-fence-metadata-only-rv')
+ ;(watcher as any).contextCacheSynced = true
+ ;(watcher as any).mcpServerCacheSynced = true
+ ;(watcher as any).hostCacheSynced = true
+ ;(watcher as any).mcpWatchGeneration = 1
+ ;(watcher as any).contexts.set('steady-context', {
+ name: 'steady-context',
+ namespace: 'mcp-server',
+ uid: 'steady-context-uid',
+ generation: 4,
+ spec: { contextId: 'steady-context', mcpServers: [] },
+ })
+ ;(watcher as any).hosts.set('bound-host', {
+ name: 'bound-host',
+ namespace: 'mcp-host',
+ spec: { host: 'bound-host', contextRef: 'steady-context', secretRef: 'host-secret' },
+ })
+ markNetworkPolicyRevocationAuthoritative(watcher)
+ const passesBefore = mocks.netPolFullReconcile.mock.calls.length
+ const hostReconcile = vi.spyOn(watcher.getHostReconciler(), 'reconcile')
+ const sfsPropagate = vi.spyOn(watcher as any, 'reconcileSharedFileSystemsReferencedByContext')
+ ;(watcher as any).netPolReconciler.reconcileContext.mockRejectedValueOnce(
+ Object.assign(new Error('the UID in the precondition does not match'), { code: 409 })
+ )
+
+ try {
+ await contextWatchCallback!('MODIFIED', {
+ metadata: {
+ name: 'steady-context',
+ namespace: 'mcp-server',
+ uid: 'steady-context-uid',
+ generation: 4,
+ },
+ spec: { contextId: 'steady-context', mcpServers: [] },
+ })
+
+ expect((watcher as any).netPolReconciler.reconcileContext).toHaveBeenCalledWith(
+ expect.objectContaining({ name: 'steady-context' }),
+ expect.objectContaining({ honorsLostFence: false })
+ )
+ expect(hostReconcile).not.toHaveBeenCalled()
+ expect(sfsPropagate).not.toHaveBeenCalled()
+ await vi.waitFor(() =>
+ expect(mocks.netPolFullReconcile.mock.calls.length).toBeGreaterThan(passesBefore)
+ )
+ } finally {
+ await watcher.stop()
+ }
+ })
+
it('still retries convergence when a desired-state Context MODIFIED loses the delete fence', async () => {
let contextWatchCallback:
| ((
@@ -2663,7 +2739,7 @@ describe('McpServerWatcher startup', () => {
await watcher.stop()
})
- it('T4 — skips Context fan-out on metadata-only MODIFIED (same uid/generation/spec)', async () => {
+ it('T4 — skips Host/SFS fan-out on metadata-only MODIFIED (same uid/generation/spec)', async () => {
const watcher = new McpServerWatcher()
let contextWatchCallback:
| ((
@@ -2708,12 +2784,11 @@ describe('McpServerWatcher startup', () => {
sfsPropagate.mockClear()
const revisionBefore = (watcher as any).contextDesiredRevision
- await contextWatchCallback!('MODIFIED', {
- ...added,
- metadata: { ...added.metadata, labels: { 'clerum.io/recipe': 'other-recipe' } },
- })
+ const cachedBefore = (watcher as any).contexts.get('shared-context')
+ await contextWatchCallback!('MODIFIED', added)
await flushMicrotasks()
+ expect((watcher as any).contexts.get('shared-context')).toBe(cachedBefore)
expect((watcher as any).contexts.get('shared-context')).toEqual(
expect.objectContaining({
name: 'shared-context',
@@ -2722,7 +2797,10 @@ describe('McpServerWatcher startup', () => {
})
)
expect((watcher as any).contextDesiredRevision).toBe(revisionBefore)
- expect(netPol.reconcileContext).not.toHaveBeenCalled()
+ expect(netPol.reconcileContext).toHaveBeenCalledWith(
+ expect.objectContaining({ name: 'shared-context', generation: 1011 }),
+ expect.objectContaining({ honorsLostFence: false })
+ )
expect(hostReconcile).not.toHaveBeenCalled()
expect(sfsPropagate).not.toHaveBeenCalled()
diff --git a/host-context-controller/src/k8sClient.ts b/host-context-controller/src/k8sClient.ts
index b3d7556af..dc1cb34c5 100644
--- a/host-context-controller/src/k8sClient.ts
+++ b/host-context-controller/src/k8sClient.ts
@@ -4334,7 +4334,12 @@ export class McpServerWatcher implements McpServerProvider {
if (type === 'ADDED' || type === 'MODIFIED') {
desiredStateChanged =
previous === undefined || !sameContextDesiredRevision(previous, context)
- this.contexts.set(context.name, context)
+ // Keep the cached object identity when desired revision did not move.
+ // Scoped revoke uses `contexts.get(name) === selectedContext`; replacing
+ // the entry on every label/status MODIFIED aborts an in-flight pass.
+ if (desiredStateChanged || previous === undefined) {
+ this.contexts.set(context.name, context)
+ }
} else if (type === 'DELETED') {
desiredStateChanged = this.contexts.delete(context.name)
}
@@ -4363,11 +4368,13 @@ export class McpServerWatcher implements McpServerProvider {
// Metadata-only Context MODIFIED (label ping-pong, annotation churn)
// does not change desired revision. Skip SFS propagate and Host fan-out
- // — that accidental resync is the #460 Loop A storm. Mirrors the
- // McpServer status-only early return above.
- if (type === 'MODIFIED' && !desiredStateChanged) {
+ // — that accidental resync is the #460 Loop A storm. Keep scoped
+ // NetworkPolicy revoke: without a delta certificate honorsLostFence is
+ // false, so a lost delete fence still throws into full convergence.
+ // Periodic resync (default 0 / #478) is not the healer for this path.
+ const metadataOnlyModified = type === 'MODIFIED' && !desiredStateChanged
+ if (metadataOnlyModified) {
this.changeCallback?.()
- return
}
// Re-reconcile every SFS this Context referenced before or after the
@@ -4376,11 +4383,13 @@ export class McpServerWatcher implements McpServerProvider {
const nextForSfs = type === 'DELETED' ? undefined : context
const contextInventoryAuthoritative = () => this.hasContextInventoryAuthority(watchGeneration)
const serverInventoryGeneration = this.mcpWatchGeneration
- void this.reconcileSharedFileSystemsReferencedByContext(
- previous,
- nextForSfs,
- contextInventoryAuthoritative
- )
+ if (!metadataOnlyModified) {
+ void this.reconcileSharedFileSystemsReferencedByContext(
+ previous,
+ nextForSfs,
+ contextInventoryAuthoritative
+ )
+ }
const previousContextId = previous?.spec.contextId
const effectContextIds =
@@ -4427,9 +4436,9 @@ export class McpServerWatcher implements McpServerProvider {
this.contexts.get(selectedContext.name) === selectedContext,
// Only opt in when there is a certificate to withhold. Without
// one the result below is discarded, so a reported lost fence
- // would vanish: no throw to reach the retry, and the recovery
- // in the desired-state branch does not run for an event that
- // did not move the revision.
+ // would vanish: no throw to reach the retry. Metadata-only
+ // MODIFIED never builds a certificate, so this stays false and
+ // a 409 still reaches full convergence without Host/SFS fan-out.
honorsLostFence: deltaSafetyCertificate !== undefined,
}
)
@@ -4461,6 +4470,9 @@ export class McpServerWatcher implements McpServerProvider {
}
if (this.stopped || watchGeneration !== this.contextWatchGeneration) return
+ if (metadataOnlyModified) {
+ return
+ }
// Re-reconcile any Host that points at this Context so that changes to
// spec.sharedFileSystems[] propagate into the mcp-host pod template.
try {
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index 523c9265d..aba5d2c98 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.323",
+ "version": "0.1.324",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.323",
+ "version": "0.1.324",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@aws-sdk/client-s3": "^3.1009.0",
diff --git a/workflow-recipes/package.json b/workflow-recipes/package.json
index b26da66da..62ddd2793 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.323",
+ "version": "0.1.324",
"description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface",
"main": "dist/main.js",
"engines": {
diff --git a/workflow-recipes/src/reconciler/mcpDelegation.test.ts b/workflow-recipes/src/reconciler/mcpDelegation.test.ts
index f778fde72..fb897e774 100644
--- a/workflow-recipes/src/reconciler/mcpDelegation.test.ts
+++ b/workflow-recipes/src/reconciler/mcpDelegation.test.ts
@@ -1339,6 +1339,41 @@ describe('ensureRecipeContext', () => {
expect(mockCustomApi.replaceNamespacedCustomObject).not.toHaveBeenCalled()
})
+ it('writes a private Context when the recipe label does not match', async () => {
+ const mockCustomApi = {
+ createNamespacedCustomObject: vi.fn().mockRejectedValueOnce({ code: 409 }),
+ getNamespacedCustomObject: vi.fn().mockResolvedValue({
+ metadata: {
+ resourceVersion: '3',
+ labels: { 'clerum.io/recipe': 'other-recipe', 'clerum.io/managed-by': 'wrc' },
+ },
+ spec: { contextId: 'wf-test-recipe', mcpServers: ['server-a', 'server-b'] },
+ }),
+ replaceNamespacedCustomObject: vi.fn().mockResolvedValue({}),
+ }
+ const deps: DelegationDeps = {
+ customApi: mockCustomApi as unknown as DelegationDeps['customApi'],
+ coreApi: {} as DelegationDeps['coreApi'],
+ }
+
+ await ensureRecipeContext(deps, 'test-recipe', ['server-a', 'server-b'], 'mcp-server', ownerRef)
+
+ const replaceCall = mockCustomApi.replaceNamespacedCustomObject.mock.calls[0]?.[0]
+ expect(replaceCall).toEqual(
+ expect.objectContaining({
+ name: 'wf-test-recipe',
+ body: expect.objectContaining({
+ metadata: expect.objectContaining({
+ labels: expect.objectContaining({
+ 'clerum.io/recipe': 'test-recipe',
+ 'clerum.io/managed-by': 'wrc',
+ }),
+ }),
+ }),
+ })
+ )
+ })
+
it('H04c — re-throws non-409 errors', async () => {
const mockCustomApi = {
createNamespacedCustomObject: vi.fn().mockRejectedValue(new Error('API error')),
diff --git a/workflow-recipes/src/reconciler/mcpDelegation.ts b/workflow-recipes/src/reconciler/mcpDelegation.ts
index 43c438de5..7cc02cdd4 100644
--- a/workflow-recipes/src/reconciler/mcpDelegation.ts
+++ b/workflow-recipes/src/reconciler/mcpDelegation.ts
@@ -127,16 +127,27 @@ function sameMcpServerSet(left: readonly string[], right: readonly string[]): bo
return true
}
-function contextReplaceIsNoOp(
+function authoredContextLabels(
explicitContext: boolean,
+ recipeName: string
+): Record<string, string> {
+ return {
+ [CONTEXT_MANAGED_BY_LABEL]: CONTEXT_MANAGED_BY_WRC,
+ ...(!explicitContext ? { [CONTEXT_RECIPE_LABEL]: recipeName } : {}),
+ }
+}
+
+function contextReplaceIsNoOp(
existingLabels: Record<string, string> | undefined,
existingServers: readonly string[],
mergedServers: readonly string[],
- recipeName: string
+ authoredLabels: Record<string, string>
): boolean {
if (!sameMcpServerSet(existingServers, mergedServers)) return false
- if ((existingLabels ?? {})[CONTEXT_MANAGED_BY_LABEL] !== CONTEXT_MANAGED_BY_WRC) return false
- if (!explicitContext && (existingLabels ?? {})[CONTEXT_RECIPE_LABEL] !== recipeName) return false
+ const labels = existingLabels ?? {}
+ for (const [key, value] of Object.entries(authoredLabels)) {
+ if (labels[key] !== value) return false
+ }
return true
}
@@ -710,8 +721,8 @@ export async function ensureRecipeContext(
namespace,
...(!explicitContext && sameNsAsRecipe && { ownerReferences: [ownerReference] }),
labels: {
- 'clerum.io/recipe': recipeName,
- 'clerum.io/managed-by': 'wrc',
+ [CONTEXT_RECIPE_LABEL]: recipeName,
+ [CONTEXT_MANAGED_BY_LABEL]: CONTEXT_MANAGED_BY_WRC,
},
},
spec: {
@@ -747,23 +758,11 @@ export async function ensureRecipeContext(
// Semantic post-merge equality. Do not stamp clerum.io/spec-hash on a
// shared Context: N recipe writers would flap the annotation the same
// way clerum.io/recipe already flaps resourceVersion (#460 Phase 1).
- if (
- contextReplaceIsNoOp(
- explicitContext,
- existingLabels,
- existingServers,
- mergedServers,
- recipeName
- )
- ) {
+ const authoredLabels = authoredContextLabels(explicitContext, recipeName)
+ if (contextReplaceIsNoOp(existingLabels, existingServers, mergedServers, authoredLabels)) {
return { wrote: false }
}
- const authoredLabels: Record<string, string> = {
- [CONTEXT_MANAGED_BY_LABEL]: CONTEXT_MANAGED_BY_WRC,
- ...(!explicitContext ? { [CONTEXT_RECIPE_LABEL]: recipeName } : {}),
- }
-
try {
await deps.customApi.replaceNamespacedCustomObject({
group: CRD_GROUP,