Skip to content

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

TypeScript

fix(hcc): do not reset SecretInformer backoff when done fires first

Alfredo Lopezebab903da9af
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 97eaf2810..31d749e28 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.267",
+ "version": "0.1.268",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.267",
+ "version": "0.1.268",
"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 15a92640f..df9dadbc5 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.267",
+ "version": "0.1.268",
"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/informers/secretInformer.test.ts b/host-context-controller/src/informers/secretInformer.test.ts
index c27b3ed5d..2e44cddd2 100644
--- a/host-context-controller/src/informers/secretInformer.test.ts
+++ b/host-context-controller/src/informers/secretInformer.test.ts
@@ -143,6 +143,35 @@ describe('SecretInformer', () => {
warnSpy.mockRestore()
})
+ it('climbs backoff when Watch.watch calls done(err) then resolves (client 1.4.0)', async () => {
+ vi.useFakeTimers()
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ watchFn.mockImplementation(
+ async (path: string, _qs: Record<string, unknown>, cb: WatchCallback, done: DoneCallback) => {
+ const abort = vi.fn()
+ const ctrl = { abort } as unknown as AbortController
+ calls.push({ path, cb, done, abort })
+ done(new Error('Forbidden'))
+ return ctrl
+ }
+ )
+
+ await expect(informer.start()).resolves.toBe(false)
+ expect(watchFn).toHaveBeenCalledTimes(1)
+ expect(calls[0].abort).toHaveBeenCalled()
+
+ await vi.advanceTimersByTimeAsync(999)
+ expect(watchFn).toHaveBeenCalledTimes(1)
+ await vi.advanceTimersByTimeAsync(1)
+ expect(watchFn).toHaveBeenCalledTimes(2)
+
+ await vi.advanceTimersByTimeAsync(1999)
+ expect(watchFn).toHaveBeenCalledTimes(2)
+ await vi.advanceTimersByTimeAsync(1)
+ expect(watchFn).toHaveBeenCalledTimes(3)
+ warnSpy.mockRestore()
+ })
+
it('resets backoff on successful establish so a quiet namespace reconnects at 1s', async () => {
vi.useFakeTimers()
diff --git a/host-context-controller/src/informers/secretInformer.ts b/host-context-controller/src/informers/secretInformer.ts
index fe38a6d87..c118b3d49 100644
--- a/host-context-controller/src/informers/secretInformer.ts
+++ b/host-context-controller/src/informers/secretInformer.ts
@@ -7,9 +7,10 @@
* created after the McpServer, or a required key is added later).
*
* Disconnect behavior: exponential backoff 1s → 2s → 4s → … capped at 30s.
- * The backoff counter resets on a successfully established watch and on any
- * subsequent event. A quiet namespace that reconnects cleanly every recycle
- * must not climb to the 30s cap (#461).
+ * Reset only while the stream is still live after `watch()` resolves, and on
+ * any later Secret event. `@kubernetes/[email protected]` calls `done(err)`
+ * then resolves on HTTP 403 / fetch failure; that path must keep climbing
+ * (#461 / jozer review 5065983153).
*/
import * as k8s from '@kubernetes/client-node'
import {
@@ -105,9 +106,10 @@ export class SecretInformer {
if (this.stopped) return false
const path = `/api/v1/namespaces/${this.namespace}/secrets`
+ let watchEnded = false
const watchCallback = (type: string, apiObj: unknown): void => {
- if (this.stopped) return
+ if (this.stopped || watchEnded) return
const evtType = type as SecretEventType
if (evtType !== 'ADDED' && evtType !== 'MODIFIED' && evtType !== 'DELETED') {
@@ -134,7 +136,8 @@ export class SecretInformer {
}
const doneCallback = (err: Error | null) => {
- if (this.stopped) return
+ if (this.stopped || watchEnded) return
+ watchEnded = true
if (err) {
console.warn('[SecretInformer] watch ended with error:', err.message)
} else {
@@ -146,9 +149,15 @@ export class SecretInformer {
try {
this.attempts += 1
- this.abortController = await this.watch.watch(path, {}, watchCallback, doneCallback)
- // Establishment proves the stream is healthy. Event-only reset left
- // quiet namespaces (no Secret churn) permanently at the 30s cap.
+ const request = await this.watch.watch(path, {}, watchCallback, doneCallback)
+ // Client 1.4.0: HTTP 403 / fetch failure calls done(err) then resolves.
+ // Resetting here would pin every informer at 1s forever.
+ if (this.stopped || watchEnded) {
+ request.abort()
+ this.abortController = null
+ return false
+ }
+ this.abortController = request
this.attempts = 0
secretInformerRunning.set(1)
console.log(`[SecretInformer] watch established for namespace ${this.namespace}`)