Skip to content

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

TypeScript

fix(hcc): reset SecretInformer backoff on successful watch establish

Alfredo Lopezb26ba1a3a52b
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 1393c6c3b..eacc27b90 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.266",
+ "version": "0.1.267",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.266",
+ "version": "0.1.267",
"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 b178f5fd1..80eff8d53 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.266",
+ "version": "0.1.267",
"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 b91a5e7a4..c27b3ed5d 100644
--- a/host-context-controller/src/informers/secretInformer.test.ts
+++ b/host-context-controller/src/informers/secretInformer.test.ts
@@ -101,25 +101,64 @@ describe('SecretInformer', () => {
expect(onEvent).not.toHaveBeenCalled()
})
- it('reconnects with exponential backoff after a disconnect', async () => {
+ it('reconnects at the base delay after a healthy watch closes', async () => {
vi.useFakeTimers()
await informer.start()
expect(watchFn).toHaveBeenCalledTimes(1)
- // Simulate a server-side disconnect.
+ // Simulate a server-side disconnect of an established stream.
calls[0].done(new Error('stream ended'))
- // First reconnect scheduled at 1s.
await vi.advanceTimersByTimeAsync(999)
expect(watchFn).toHaveBeenCalledTimes(1)
await vi.advanceTimersByTimeAsync(2)
expect(watchFn).toHaveBeenCalledTimes(2)
- // Second disconnect → backoff now 2s.
+ // A second healthy close must not climb — that was the quiet-namespace cap.
calls[1].done(new Error('stream ended again'))
+ await vi.advanceTimersByTimeAsync(999)
+ expect(watchFn).toHaveBeenCalledTimes(2)
+ await vi.advanceTimersByTimeAsync(2)
+ expect(watchFn).toHaveBeenCalledTimes(3)
+ })
+
+ it('still climbs backoff when watch establishment fails', async () => {
+ vi.useFakeTimers()
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ watchFn.mockRejectedValue(new Error('forbidden'))
+
+ await expect(informer.start()).resolves.toBe(false)
+ expect(watchFn).toHaveBeenCalledTimes(1)
+
+ 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()
+
+ await informer.start()
+ expect(watchFn).toHaveBeenCalledTimes(1)
+
+ // No Secret events — the pre-#461 reset was unreachable here.
+ calls[0].done(null)
+ await vi.advanceTimersByTimeAsync(999)
+ expect(watchFn).toHaveBeenCalledTimes(1)
+ await vi.advanceTimersByTimeAsync(2)
+ expect(watchFn).toHaveBeenCalledTimes(2)
+
+ calls[1].done(null)
+ await vi.advanceTimersByTimeAsync(999)
+ expect(watchFn).toHaveBeenCalledTimes(2)
await vi.advanceTimersByTimeAsync(2)
expect(watchFn).toHaveBeenCalledTimes(3)
})
diff --git a/host-context-controller/src/informers/secretInformer.ts b/host-context-controller/src/informers/secretInformer.ts
index 24f2813dc..fe38a6d87 100644
--- a/host-context-controller/src/informers/secretInformer.ts
+++ b/host-context-controller/src/informers/secretInformer.ts
@@ -7,9 +7,9 @@
* 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 any successful event (not just successful
- * watch start) so a long-lived stream that fails after days still resumes
- * at the lowest delay.
+ * 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).
*/
import * as k8s from '@kubernetes/client-node'
import {
@@ -147,6 +147,9 @@ 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.
+ this.attempts = 0
secretInformerRunning.set(1)
console.log(`[SecretInformer] watch established for namespace ${this.namespace}`)
return true