Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): key GFS token evidence by Host uid and clear it on delete
Alfredo Lopez237877ee1361
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex b2905694f..8e2309e28 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.340",+ "version": "0.1.341","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.340",+ "version": "0.1.341","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.jsonindex 81dfb1b9c..543c8b462 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.340",+ "version": "0.1.341","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/administrativeOutcomeReporter.ts b/host-context-controller/src/administrativeOutcomeReporter.tsindex f14e252d7..40f2881ec 100644--- a/host-context-controller/src/administrativeOutcomeReporter.ts+++ b/host-context-controller/src/administrativeOutcomeReporter.ts@@ -87,6 +87,15 @@ export class BoundedAdministrativeOutcomeReporter implements AdministrativeOutco})}+ /**+ * The dedupe key is the `sourceEventId`, which carries no `reasonCode`: for a+ * given operation, generation, Host uid and outcome the first failure wins+ * and later ones are deduplicated. That matches the server, which hashes the+ * `reasonCode` into the stored row — a second `failed` with another reason+ * under the same key would come back 409 and never be stored either. The+ * per-reason detail is not lost: `controller_error` keeps it in full, with a+ * unique occurrence id per event (#696).+ */enqueueHostOutcome(projection: AdministrativeHostOutcomeProjection): void {const { sourceEventId } = projectionif (this.seen.delete(sourceEventId)) {diff --git a/host-context-controller/src/hostReconciler.ts b/host-context-controller/src/hostReconciler.tsindex 2f8242593..179d65cb6 100644--- a/host-context-controller/src/hostReconciler.ts+++ b/host-context-controller/src/hostReconciler.ts@@ -1286,8 +1286,46 @@ export class HostReconciler {return HostReconciler.shortHash([...GFS_HOST_SCOPES].sort())}- private static gfsLifecycleEvidenceKey(host: Pick<HostCRD, 'namespace' | 'name'>): string {- return `${host.namespace}/${host.name}`+ /**+ * Evidence is keyed by the Host uid, not by namespace/name: a Host deleted+ * and recreated under the same name is a different object, and a name-keyed+ * entry left behind would be reported as the new object's rotation (#696).+ */+ private static gfsLifecycleEvidenceKey(+ host: Pick<HostCRD, 'namespace' | 'name' | 'uid'>+ ): string | undefined {+ if (host.uid === undefined) return undefined+ return `${HostReconciler.gfsLifecycleEvidencePrefix(host.namespace, host.name)}${host.uid}`+ }++ private static gfsLifecycleEvidencePrefix(namespace: string, name: string): string {+ return `${namespace}/${name}/`+ }++ /**+ * Without a uid the objects cannot be told apart, so nothing is recorded: an+ * entry under an incomplete key would be claimed by whichever Host answers+ * to the name next. The real mappers copy metadata.uid from the API server,+ * so this warns rather than papering over a snapshot that lost it.+ */+ private recordGfsLifecycleEvidence(host: HostCRD, outcome: GfsTokenLifecycleOutcome): void {+ const key = HostReconciler.gfsLifecycleEvidenceKey(host)+ if (key === undefined) {+ log.warn('skipping gfs token lifecycle evidence: Host snapshot has no uid', {+ host: host.name,+ namespace: host.namespace,+ outcome,+ })+ return+ }+ this.gfsTokenLifecycleEvidence.set(key, outcome)+ }++ private clearGfsLifecycleEvidence(namespace: string, name: string): void {+ const prefix = HostReconciler.gfsLifecycleEvidencePrefix(namespace, name)+ for (const key of this.gfsTokenLifecycleEvidence.keys()) {+ if (key.startsWith(prefix)) this.gfsTokenLifecycleEvidence.delete(key)+ }}private static effectiveBootstrapRefreshBeforeSec(refreshTtlSec: number): number {@@ -1843,7 +1881,7 @@ export class HostReconciler {resourceName: name,refreshExpInHours,})- this.gfsTokenLifecycleEvidence.set(HostReconciler.gfsLifecycleEvidenceKey(host), 'reused')+ this.recordGfsLifecycleEvidence(host, 'reused')const selectedRevision =rolloutPending || HostReconciler.shouldRollForRuntimeSecret(deployment, false)? existingRevision@@ -1923,7 +1961,7 @@ export class HostReconciler {await observeCreate('Secret', () =>this.coreApi.createNamespacedSecret({ namespace: host.namespace, body }))- this.gfsTokenLifecycleEvidence.set(HostReconciler.gfsLifecycleEvidenceKey(host), 'minted')+ this.recordGfsLifecycleEvidence(host, 'minted')log.info('created mcp-host-runtime-token Secret', {host: host.name,namespace: host.namespace,@@ -1945,7 +1983,7 @@ export class HostReconciler {namespace: host.namespace,body: replaceBody,})- this.gfsTokenLifecycleEvidence.set(HostReconciler.gfsLifecycleEvidenceKey(host), 'rotated')+ this.recordGfsLifecycleEvidence(host, 'rotated')log.info('rotated mcp-host-runtime-token Secret', {host: host.name,namespace: host.namespace,@@ -1962,7 +2000,7 @@ export class HostReconciler {} catch (err) {lastErr = errif (makeExpectedHostGfsSubject(host.namespace, host.name)) {- this.gfsTokenLifecycleEvidence.set(HostReconciler.gfsLifecycleEvidenceKey(host), 'failed')+ this.recordGfsLifecycleEvidence(host, 'failed')}if (err instanceof Error && err.name === 'GfsHostTokenValidationError') breakconst delayMs = 1000 * Math.pow(2, attempt - 1)@@ -2201,8 +2239,8 @@ export class HostReconciler {payload: HccInfrastructureTelemetryPayload): void {const evidenceKey = HostReconciler.gfsLifecycleEvidenceKey(host)- const gfsOutcome = this.gfsTokenLifecycleEvidence.get(evidenceKey)- this.gfsTokenLifecycleEvidence.delete(evidenceKey)+ const gfsOutcome = evidenceKey ? this.gfsTokenLifecycleEvidence.get(evidenceKey) : undefined+ if (evidenceKey) this.gfsTokenLifecycleEvidence.delete(evidenceKey)this.enqueueHostTelemetry(host, 'reconcile_outcome', reasonCode, {...payload,// control-api allowlists `transition`, not gfs_* keys (#328).@@ -4429,13 +4467,10 @@ export class HostReconciler {// rethrow as a retire (reconcileDelete → 'superseded', watch callers// only log the error), so the rethrow is preserved.// This exit emits no outcome, so drop the GFS evidence this pass- // recorded. Keyed by namespace/name, a leftover would be reported by- // the next pass, or by a recreated Host with the same name. The- // stateless suspension path also calls reconcileCore without emitting- // an outcome and does not clear the entry (#696).- this.gfsTokenLifecycleEvidence.delete(- HostReconciler.gfsLifecycleEvidenceKey(admittedHost)- )+ // recorded: a leftover would be reported by the next pass over the+ // same object. The stateless suspension path also calls reconcileCore+ // without emitting an outcome and does not clear the entry (#696).+ this.clearGfsLifecycleEvidence(admittedHost.namespace, admittedHost.name)this.observeReconcileLatency(source, 'superseded', dispatchedAt, admittedAt)throw error}@@ -4865,6 +4900,10 @@ export class HostReconciler {await this.deleteHostRuntimeResources(name, namespace)this.clearStatus(name)this.desktopHosts.delete(name)+ // The delete path has no uid to key by, so every entry for this+ // namespace/name goes: the object is gone and no outcome will carry its+ // evidence (#696).+ this.clearGfsLifecycleEvidence(namespace, name)})}diff --git a/host-context-controller/src/infrastructureTelemetryReporter.test.ts b/host-context-controller/src/infrastructureTelemetryReporter.test.tsindex 27ea9c311..79f7b0b4d 100644--- a/host-context-controller/src/infrastructureTelemetryReporter.test.ts+++ b/host-context-controller/src/infrastructureTelemetryReporter.test.ts@@ -225,7 +225,7 @@ describe('BoundedInfrastructureTelemetryReporter', () => {expect(gaps).toHaveLength(2)})- it('does not count a 409 idempotency conflict as an evidence gap', async () => {+ it('counts a 409 idempotency conflict as an evidence gap (#696)', async () => {infrastructureTelemetryFlushesTotal.reset()infrastructureTelemetryGapsTotal.reset()const fetchFn = vi.fn(@@ -254,7 +254,14 @@ describe('BoundedInfrastructureTelemetryReporter', () => {expect(fetchFn).toHaveBeenCalledOnce()const flushes = (await infrastructureTelemetryFlushesTotal.get()).valuesexpect(flushes.find(value => value.labels.result === 'conflict')?.value).toBe(1)- expect((await infrastructureTelemetryGapsTotal.get()).values).toEqual([])+ // The stored row holds a different payload hash, so this observation was+ // never stored: a gap, told apart from a rejection by `reason`.+ expect((await infrastructureTelemetryGapsTotal.get()).values).toEqual([+ {+ labels: { telemetry_type: 'lifecycle_transition', reason: 'conflict' },+ value: 1,+ },+ ])})it('isolates a blackholed submission and continues flushing later telemetry', async () => {diff --git a/host-context-controller/src/infrastructureTelemetryReporter.ts b/host-context-controller/src/infrastructureTelemetryReporter.tsindex 47c687f88..142aa8243 100644--- a/host-context-controller/src/infrastructureTelemetryReporter.ts+++ b/host-context-controller/src/infrastructureTelemetryReporter.ts@@ -153,14 +153,14 @@ export class BoundedInfrastructureTelemetryReporter implements InfrastructureTelonAccepted: () => infrastructureTelemetryFlushesTotal.inc({ result: 'accepted' }),onTerminal: (projection, result) => {infrastructureTelemetryFlushesTotal.inc({ result })- // A conflict means a row already exists for the key. A rejected event- // is never stored, so it is a gap in the evidence.- if (result === 'rejected') {- infrastructureTelemetryGapsTotal.inc({- telemetry_type: projection.telemetryType,- reason: result,- })- }+ // Neither terminal result stores this observation: `rejected` is+ // refused outright, and `conflict` means a row under that key already+ // holds a different payload hash, so ours is dropped. Both are gaps in+ // the evidence; the `reason` label keeps them apart (#696).+ infrastructureTelemetryGapsTotal.inc({+ telemetry_type: projection.telemetryType,+ reason: result,+ })},onRetry: projection =>infrastructureTelemetryRetriesTotal.inc({ telemetry_type: projection.telemetryType }),diff --git a/host-context-controller/test/hostReconciler.test.ts b/host-context-controller/test/hostReconciler.test.tsindex 7100fb1b9..b6e01bda0 100644--- a/host-context-controller/test/hostReconciler.test.ts+++ b/host-context-controller/test/hostReconciler.test.ts@@ -183,17 +183,24 @@ function createReconciler(}describe('HostReconciler', () => {- it('keys GFS lifecycle evidence by canonical namespace/name', () => {+ it('keys GFS lifecycle evidence by namespace/name/uid and refuses a missing uid (#696)', () => {const helper = HostReconciler as unknown as {- gfsLifecycleEvidenceKey(host: Pick<HostCRD, 'namespace' | 'name'>): string+ gfsLifecycleEvidenceKey(host: Pick<HostCRD, 'namespace' | 'name' | 'uid'>): string | undefined}- expect(helper.gfsLifecycleEvidenceKey({ namespace: 'tenant-a', name: 'shared-name' })).toBe(- 'tenant-a/shared-name'- )- expect(helper.gfsLifecycleEvidenceKey({ namespace: 'tenant-b', name: 'shared-name' })).toBe(- 'tenant-b/shared-name'- )+ expect(+ helper.gfsLifecycleEvidenceKey({ namespace: 'tenant-a', name: 'shared-name', uid: 'uid-1' })+ ).toBe('tenant-a/shared-name/uid-1')+ expect(+ helper.gfsLifecycleEvidenceKey({ namespace: 'tenant-b', name: 'shared-name', uid: 'uid-1' })+ ).toBe('tenant-b/shared-name/uid-1')+ // Same namespace/name, different object: the key must not collide.+ expect(+ helper.gfsLifecycleEvidenceKey({ namespace: 'tenant-a', name: 'shared-name', uid: 'uid-2' })+ ).not.toBe('tenant-a/shared-name/uid-1')+ expect(+ helper.gfsLifecycleEvidenceKey({ namespace: 'tenant-a', name: 'shared-name' })+ ).toBeUndefined()})it('binds GFS material to the exact Host and records only safe lifecycle annotations', async () => {@@ -491,6 +498,26 @@ describe('HostReconciler', () => {})describe('GFS token evidence on reconcile_outcome (#328)', () => {+ /**+ * The evidence map is an implementation detail of the reconciler, but it is+ * the only place a pass that emits no outcome can leave something behind,+ * which is exactly the leak the uid key closes (#696).+ */+ function gfsEvidenceOf(reconciler: HostReconciler): Map<string, string> {+ return (reconciler as unknown as { gfsTokenLifecycleEvidence: Map<string, string> })+ .gfsTokenLifecycleEvidence+ }++ function evidenceKeyOf(host: Pick<HostCRD, 'namespace' | 'name' | 'uid'>): string | undefined {+ return (+ HostReconciler as unknown as {+ gfsLifecycleEvidenceKey(+ host: Pick<HostCRD, 'namespace' | 'name' | 'uid'>+ ): string | undefined+ }+ ).gfsLifecycleEvidenceKey(host)+ }+function reconcileOutcomes(reporter: InfrastructureTelemetryReporter) {return vi.mocked(reporter.enqueue)@@ -607,6 +634,86 @@ describe('HostReconciler', () => {expect(outcomes[0]?.payload).toMatchObject({ reason_code: 'reconcile_exception' })expect(outcomes[0]?.payload).not.toHaveProperty('transition')})++ it('does not lend a leftover entry to a same-name Host with a new uid (#696)', async () => {+ const reporter = createTelemetryReporterMock()+ const { reconciler, rbacApi } = createReconciler({+ infrastructureTelemetryReporter: reporter,+ })+ const evidence = gfsEvidenceOf(reconciler)+ // What a pass that recorded evidence and emitted no outcome leaves behind+ // (the stateless suspension path), written under the key the reconciler+ // itself would use for that object — so a key that ignored the uid would+ // be picked up below. The Host that takes over the name is a different+ // object and must not report that rotation.+ const leftoverKey = evidenceKeyOf({+ namespace: 'mcp-host',+ name: 'alpha-host',+ uid: 'host-uid-1',+ })+ expect(leftoverKey).toBeDefined()+ evidence.set(leftoverKey!, 'rotated')++ rbacApi.readNamespacedRole.mockRejectedValueOnce({ code: 500 })+ await expect(+ reconciler.reconcile(makeHost({ uid: 'host-uid-2', generation: 3 }))+ ).rejects.toEqual({ code: 500 })++ const outcomes = reconcileOutcomes(reporter)+ // Liveness: the new object's pass did emit its outcome; that pass reached+ // no GFS write of its own, so any transition would be the leftover.+ expect(outcomes).toHaveLength(1)+ expect(outcomes[0]?.payload).toMatchObject({ reason_code: 'reconcile_exception' })+ expect(outcomes[0]?.payload).not.toHaveProperty('transition')+ expect(evidence.get(leftoverKey!)).toBe('rotated')+ })++ it('clears every entry for a deleted Host and leaves other Hosts alone (#696)', async () => {+ const { reconciler } = createReconciler()+ const evidence = gfsEvidenceOf(reconciler)+ const deletedKey = evidenceKeyOf({+ namespace: 'mcp-host',+ name: 'alpha-host',+ uid: 'host-uid-1',+ })!+ const survivorKey = evidenceKeyOf({+ namespace: 'mcp-host',+ name: 'other-host',+ uid: 'host-uid-9',+ })!+ evidence.set(deletedKey, 'rotated')+ evidence.set(survivorKey, 'minted')+ // Witness: the entry the delete has to remove exists before the call.+ expect(evidence.has(deletedKey)).toBe(true)++ await reconciler.reconcileDelete('alpha-host', 'mcp-host')++ expect(evidence.has(deletedKey)).toBe(false)+ expect(evidence.get(survivorKey)).toBe('minted')+ })++ it('records no evidence and warns when the Host snapshot has no uid (#696)', async () => {+ const warn = vi.spyOn(HostContextLogger.prototype, 'warn').mockImplementation(() => undefined)+ onTestFinished(() => warn.mockRestore())+ const reporter = createTelemetryReporterMock()+ const { reconciler } = createReconciler({ infrastructureTelemetryReporter: reporter })+ const host = makeHost({ generation: 3 })+ delete (host as { uid?: string }).uid++ await reconciler.reconcile(host)++ // Liveness: the pass ran to an outcome, so the GFS write did happen —+ // the evidence is missing because it was refused, not because the path+ // never executed.+ const outcomes = reconcileOutcomes(reporter)+ expect(outcomes).toHaveLength(1)+ expect(warn).toHaveBeenCalledWith(+ 'skipping gfs token lifecycle evidence: Host snapshot has no uid',+ expect.objectContaining({ host: 'alpha-host', namespace: 'mcp-host' })+ )+ expect(gfsEvidenceOf(reconciler).size).toBe(0)+ expect(outcomes[0]?.payload).not.toHaveProperty('transition')+ })})it('emits Host-backed controller_error and failed reconcile_outcome on reconcile failure', async () => {