Skip to content

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

TypeScript

fix(hcc): treat benign mid-pass supersessions as retirements, not failures (R1-M2)

Alfredo Lopezc34a6b166a61
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 527afff9d..da7d0ca03 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.216",
+ "version": "0.1.217",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.216",
+ "version": "0.1.217",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 875271749..eaab62ec1 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.216",
+ "version": "0.1.217",
"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/hostReconciler.test.ts b/host-context-controller/src/hostReconciler.test.ts
index 40a2c8a09..53625ff43 100644
--- a/host-context-controller/src/hostReconciler.test.ts
+++ b/host-context-controller/src/hostReconciler.test.ts
@@ -1176,6 +1176,15 @@ describe('HostReconciler Host inventory mutation authority', () => {
.spyOn(reconciler as any, 'ensureHostServiceAccount')
.mockResolvedValue(undefined)
+ // R1-M2: a benign mid-pass supersession must NOT be reported as a hard
+ // reconcile failure. The single reconcile() catch used to fire
+ // enqueueControllerError('reconcile_exception') → controller_error telemetry
+ // (status:'failed') AND an administrative 'failed' outcome to control-api for
+ // these retirements. Spy (observe-only) to prove the benign branch emits
+ // neither, while still re-throwing so callers treat it as a retire.
+ const enqueueControllerError = vi.spyOn(reconciler as any, 'enqueueControllerError')
+ const enqueueAdministrativeOutcome = vi.spyOn(reconciler as any, 'enqueueAdministrativeOutcome')
+
const pending = reconciler.reconcile(host)
await secretReadStarted.promise
selectedContext = contextV2
@@ -1183,6 +1192,12 @@ describe('HostReconciler Host inventory mutation authority', () => {
await expect(pending).rejects.toThrow(/Host mutation dependency changed/)
expect(ensureServiceAccount).not.toHaveBeenCalled()
+ expect(enqueueControllerError).not.toHaveBeenCalled()
+ expect(enqueueAdministrativeOutcome).not.toHaveBeenCalledWith(
+ expect.anything(),
+ 'failed',
+ expect.anything()
+ )
})
it('keeps a Host reconcile admitted when a watch replaces dependencies with deep-equal values', async () => {
diff --git a/host-context-controller/src/hostReconciler.ts b/host-context-controller/src/hostReconciler.ts
index 3ccf9e768..912119faf 100644
--- a/host-context-controller/src/hostReconciler.ts
+++ b/host-context-controller/src/hostReconciler.ts
@@ -128,6 +128,25 @@ class HostMutationDependencyChangedError extends Error {
}
}
+/**
+ * The four benign mid-pass supersession signals. revalidateHostMutationBoundary()
+ * throws these when the watch observes a newer spec/uid/authority-generation while
+ * a reconcile is in flight; a fresh reconcile runs afterwards, so the retired pass
+ * is a WITHDRAWAL, not a hard failure. Matched by `error.name` (string), NOT
+ * `instanceof`: the classes are unexported and statelessLifecycleExecutor.ts
+ * synthesizes name-equivalent plain Errors for the same races.
+ */
+const BENIGN_SUPERSESSION_ERROR_NAMES: ReadonlySet<string> = new Set([
+ 'HostInventoryAuthorityUnavailableError',
+ 'HostMutationIdentityChangedError',
+ 'HostMutationSpecRevisionChangedError',
+ 'HostMutationDependencyChangedError',
+])
+
+function isBenignSupersessionError(error: unknown): boolean {
+ return error instanceof Error && BENIGN_SUPERSESSION_ERROR_NAMES.has(error.name)
+}
+
/**
* The exact §13.2 destructive-cleanup predicate. Deletion of an orphan Host's
* owned bundle is permitted ONLY when watch authority is known, the watch
@@ -3777,6 +3796,16 @@ export class HostReconciler {
this.enqueueReconcileOutcome(admittedHost)
this.observeReconcileLatency(source, 'success', dispatchedAt, admittedAt)
} catch (error) {
+ if (isBenignSupersessionError(error)) {
+ // A newer spec/uid/authority-generation superseded this pass mid-flight;
+ // a fresh reconcile runs after. Model it as a withdrawal (superseded),
+ // NOT a hard failure — do NOT emit controller_error/reconcile_exception
+ // or an administrative 'failed' outcome. Callers already treat the
+ // rethrow as a retire (reconcileDelete → 'superseded', watch callers
+ // only console.error), so the rethrow is preserved.
+ this.observeReconcileLatency(source, 'superseded', dispatchedAt, admittedAt)
+ throw error
+ }
this.enqueueControllerError(admittedHost, 'reconcile_exception', error)
this.enqueueReconcileOutcome(admittedHost)
this.observeReconcileLatency(source, 'error', dispatchedAt, admittedAt)
@@ -3789,7 +3818,7 @@ export class HostReconciler {
private observeReconcileLatency(
source: HostReconcileSource,
- outcome: 'success' | 'error',
+ outcome: 'success' | 'error' | 'superseded',
dispatchedAt: number,
admittedAt: number
): void {