Skip to content

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

TypeScript

fix(host-context-controller): strict agent budget parsing and a drift test against gfsc

Alfredo Lopeza60371431326
diff --git a/host-context-controller/README.md b/host-context-controller/README.md
index 0997190e1..60c952037 100644
--- a/host-context-controller/README.md
+++ b/host-context-controller/README.md
@@ -415,27 +415,36 @@ a permissive policy — see the NetworkPolicy and GFS tables:
Read by `src/gfsConfig.ts`. Invalid values **throw at startup** rather than silently defaulting.
-| Variable | Default | Description |
-| --------------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
-| `CONTEXT_MAPPER_GFSC_PORT` | `8087` | gfsc service port. |
-| `CONTEXT_MAPPER_GFSC_IMAGE` | `clerum/gfs-controller:test` | gfsc writer Deployment image. **The default is a `:test` tag** — override it. |
-| `CONTEXT_MAPPER_GFSC_IMAGE_PULL_POLICY` | `IfNotPresent` | Must be exactly `Always` \| `IfNotPresent` \| `Never`; any other non-empty value **throws** at startup. |
-| `CONTEXT_MAPPER_GFSC_IMAGE_PULL_SECRET` | _(unset)_ | Optional `imagePullSecrets` name for gfsc. |
-| `CONTEXT_MAPPER_GFSC_PRIORITY_CLASS` | _(unset)_ | Optional `priorityClassName` for the gfsc Deployment. |
-| `CONTEXT_MAPPER_GFSC_INIT_IMAGE` | `busybox:1.36` | gfsc init-container image. |
-| `CONTEXT_MAPPER_GFSC_REQUEST_MEMORY` | `128Mi` | gfsc memory request. |
-| `CONTEXT_MAPPER_GFSC_REQUEST_CPU` | `100m` | gfsc CPU request. |
-| `CONTEXT_MAPPER_GFSC_LIMIT_MEMORY` | `256Mi` | gfsc memory limit. |
-| `CONTEXT_MAPPER_GFSC_LIMIT_CPU` | `500m` | gfsc CPU limit. |
-| `CONTEXT_MAPPER_GFS_POSTGRES_APP_LABEL` | `control-postgres` | `app` pod label selecting the Postgres pods gfsc may reach (NetworkPolicy). |
-| `CONTEXT_MAPPER_GFS_POSTGRES_PORT` | `5432` | Postgres port for the gfsc egress policy. |
-| `CONTEXT_MAPPER_GFS_JWT_CONFIGMAP` | `gfs-config` | ConfigMap holding the JWT public key gfsc verifies against. |
-| `CONTEXT_MAPPER_GFS_JWT_CONFIGMAP_KEY` | `jwt-public-key` | Key within that ConfigMap. |
-| `CONTEXT_MAPPER_GFS_PG_SECRET` | `gfs-controller-db` | Secret holding the gfsc Postgres connection string. |
-| `CONTEXT_MAPPER_GFS_PG_SECRET_KEY` | `connection-string` | Key within that Secret. |
-| `CONTEXT_MAPPER_GFS_DRIVE_NAME` | `main` | Default GFS drive name. |
-| `CONTEXT_MAPPER_GFS_TOKEN_AUDIENCE` | `gfs-controller` | Expected `aud` claim on GFS access tokens. |
-| `CONTEXT_MAPPER_GFS_RESYNC_SEC` | `60` | Periodic GlobalFileSystem `fullReconcile` (seconds); drives convergence to `Ready` and the root-directory seed. `0` disables. |
+| Variable | Default | Description |
+| -------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `CONTEXT_MAPPER_GFSC_PORT` | `8087` | gfsc service port. |
+| `CONTEXT_MAPPER_GFSC_IMAGE` | `clerum/gfs-controller:test` | gfsc writer Deployment image. **The default is a `:test` tag** — override it. |
+| `CONTEXT_MAPPER_GFSC_IMAGE_PULL_POLICY` | `IfNotPresent` | Must be exactly `Always` \| `IfNotPresent` \| `Never`; any other non-empty value **throws** at startup. |
+| `CONTEXT_MAPPER_GFSC_IMAGE_PULL_SECRET` | _(unset)_ | Optional `imagePullSecrets` name for gfsc. |
+| `CONTEXT_MAPPER_GFSC_PRIORITY_CLASS` | _(unset)_ | Optional `priorityClassName` for the gfsc Deployment. |
+| `CONTEXT_MAPPER_GFSC_INIT_IMAGE` | `busybox:1.36` | gfsc init-container image. |
+| `CONTEXT_MAPPER_GFSC_REQUEST_MEMORY` | `128Mi` | gfsc memory request. |
+| `CONTEXT_MAPPER_GFSC_REQUEST_CPU` | `100m` | gfsc CPU request. |
+| `CONTEXT_MAPPER_GFSC_LIMIT_MEMORY` | `256Mi` | gfsc memory limit. |
+| `CONTEXT_MAPPER_GFSC_LIMIT_CPU` | `500m` | gfsc CPU limit. |
+| `CONTEXT_MAPPER_GFS_POSTGRES_APP_LABEL` | `control-postgres` | `app` pod label selecting the Postgres pods gfsc may reach (NetworkPolicy). |
+| `CONTEXT_MAPPER_GFS_POSTGRES_PORT` | `5432` | Postgres port for the gfsc egress policy. |
+| `CONTEXT_MAPPER_GFS_JWT_CONFIGMAP` | `gfs-config` | ConfigMap holding the JWT public key gfsc verifies against. |
+| `CONTEXT_MAPPER_GFS_JWT_CONFIGMAP_KEY` | `jwt-public-key` | Key within that ConfigMap. |
+| `CONTEXT_MAPPER_GFS_PG_SECRET` | `gfs-controller-db` | Secret holding the gfsc Postgres connection string. |
+| `CONTEXT_MAPPER_GFS_PG_SECRET_KEY` | `connection-string` | Key within that Secret. |
+| `CONTEXT_MAPPER_GFS_DRIVE_NAME` | `main` | Default GFS drive name. |
+| `CONTEXT_MAPPER_GFS_TOKEN_AUDIENCE` | `gfs-controller` | Expected `aud` claim on GFS access tokens. |
+| `CONTEXT_MAPPER_GFS_RESYNC_SEC` | `60` | Periodic GlobalFileSystem `fullReconcile` (seconds); drives convergence to `Ready` and the root-directory seed. `0` disables. |
+| `CONTEXT_MAPPER_GFSC_AGENT_READ_RL_PER_MIN_PER_REPLICA` | `300` | Per-subject agent (host principal) read budget per minute, per gfsc replica. Written to every gfsc pod as `GFS_AGENT_READ_RL_PER_MIN_PER_REPLICA`. Canonical decimal from 1 to 60000; an empty or non-canonical value (`0x10`, `1e3`, `45.0`, `045`) **throws** at startup. |
+| `CONTEXT_MAPPER_GFSC_AGENT_WRITE_RL_PER_MIN_PER_REPLICA` | `120` | Same for writes, written as `GFS_AGENT_WRITE_RL_PER_MIN_PER_REPLICA`. Same rules. |
+
+The two agent budgets are part of the gfsc pod template, like `CONTEXT_MAPPER_GFSC_IMAGE`.
+Changing either value, or the gfsc image, changes the writer's pod-template hash, so the
+next reconcile restarts the whole gfsc fleet once: readers are scaled to 0, the writer is
+recreated (`strategy: Recreate`), and readers return after the writer is available
+(`src/gfsReconciler.ts`). Reads and writes through gfsc are unavailable for that window.
+The defaults equal gfsc's own (`gfs-controller/src/config.ts`), which a test pins.
### NetworkPolicy
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 70da79a11..5ad97342e 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.349",
+ "version": "0.1.350",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.349",
+ "version": "0.1.350",
"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 a82cc17fe..024739be8 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.349",
+ "version": "0.1.350",
"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/gfsConfig.test.ts b/host-context-controller/src/gfsConfig.test.ts
index a2e73e5e5..271df2c7b 100644
--- a/host-context-controller/src/gfsConfig.test.ts
+++ b/host-context-controller/src/gfsConfig.test.ts
@@ -46,6 +46,23 @@ describe('gfsDefaultFactoryConfig agent rate-limit budgets', () => {
)
}
})
+
+ it.each([
+ 'CONTEXT_MAPPER_GFSC_AGENT_READ_RL_PER_MIN_PER_REPLICA',
+ 'CONTEXT_MAPPER_GFSC_AGENT_WRITE_RL_PER_MIN_PER_REPLICA',
+ ])('L1: %s accepts only a canonical decimal, like gfsc', key => {
+ for (const value of ['', '0x10', '1e3', ' 45 ', '45.0', '045', '+45']) {
+ process.env[key] = value
+ expect(() => gfsDefaultFactoryConfig(), `value ${JSON.stringify(value)}`).toThrow(
+ `[gfs] ${key} must be an integer between 1 and 60000, got ${JSON.stringify(value)}`
+ )
+ }
+ // Witness: the same variable still accepts a canonical value.
+ process.env[key] = '45'
+ expect(gfsDefaultFactoryConfig()).toMatchObject({
+ [key.includes('READ') ? 'agentReadRlPerMinPerReplica' : 'agentWriteRlPerMinPerReplica']: 45,
+ })
+ })
})
describe('gfsDefaultFactoryConfig', () => {
diff --git a/host-context-controller/src/gfsConfig.ts b/host-context-controller/src/gfsConfig.ts
index a6adc60e7..f9e1fbf7c 100644
--- a/host-context-controller/src/gfsConfig.ts
+++ b/host-context-controller/src/gfsConfig.ts
@@ -32,18 +32,16 @@ function envInt(key: string, fallback: number): number {
}
/**
- * A gfsc agent budget. Validated here with gfsc's own bounds so a bad value fails
- * the operator at startup instead of crash-looping every gfsc pod it reaches.
+ * A gfsc agent budget. Validated here with gfsc's own rules so a bad value fails
+ * the operator at startup instead of crash-looping every gfsc pod it reaches:
+ * only an absent variable selects the default, and only a canonical decimal
+ * (no sign, exponent, hex, fraction, padding or leading zero) is accepted.
*/
function envAgentBudget(key: string, fallback: number): number {
const value = process.env[key]
- if (value === undefined || value === '') return fallback
- const parsed = Number(value)
- if (
- !Number.isSafeInteger(parsed) ||
- parsed <= 0 ||
- parsed > MAX_GFSC_AGENT_RL_PER_MIN_PER_REPLICA
- ) {
+ if (value === undefined) return fallback
+ const parsed = /^[1-9]\d*$/.test(value) ? Number(value) : Number.NaN
+ if (!Number.isSafeInteger(parsed) || parsed > MAX_GFSC_AGENT_RL_PER_MIN_PER_REPLICA) {
throw new Error(
`[gfs] ${key} must be an integer between 1 and ${MAX_GFSC_AGENT_RL_PER_MIN_PER_REPLICA}, got ${JSON.stringify(value)}`
)
diff --git a/host-context-controller/src/k8s/gfsFactory.gfscDefaults.test.ts b/host-context-controller/src/k8s/gfsFactory.gfscDefaults.test.ts
new file mode 100644
index 000000000..24b5e6c17
--- /dev/null
+++ b/host-context-controller/src/k8s/gfsFactory.gfscDefaults.test.ts
@@ -0,0 +1,50 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import ts from 'typescript'
+import {
+ DEFAULT_GFSC_AGENT_READ_RL_PER_MIN_PER_REPLICA,
+ DEFAULT_GFSC_AGENT_WRITE_RL_PER_MIN_PER_REPLICA,
+ MAX_GFSC_AGENT_RL_PER_MIN_PER_REPLICA,
+} from './gfsFactory'
+
+/**
+ * HCC writes the agent budgets into every gfsc pod, and gfsc has its own
+ * defaults and ceiling for an image that rolls out before the operator's env.
+ * The two packages share no module, so this reads gfsc's source and fails when
+ * either side changes a value alone.
+ */
+const GFSC_CONFIG = resolve(__dirname, '../../../gfs-controller/src/config.ts')
+
+function exportedNumericConst(sourceFile: ts.SourceFile, symbol: string): number {
+ for (const statement of sourceFile.statements) {
+ if (!ts.isVariableStatement(statement)) continue
+ const exported = statement.modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword)
+ if (!exported || (statement.declarationList.flags & ts.NodeFlags.Const) === 0) continue
+ for (const declaration of statement.declarationList.declarations) {
+ if (!ts.isIdentifier(declaration.name) || declaration.name.text !== symbol) continue
+ const initializer = declaration.initializer
+ if (initializer === undefined || !ts.isNumericLiteral(initializer)) {
+ throw new Error(`${symbol} in ${GFSC_CONFIG} must be initialized with a numeric literal`)
+ }
+ return Number(initializer.text)
+ }
+ }
+ throw new Error(`${symbol} is not an exported const in ${GFSC_CONFIG}`)
+}
+
+describe('gfsc agent budget defaults', () => {
+ it('L18: HCC defaults and ceiling equal the ones gfsc applies on its own', () => {
+ const source = readFileSync(GFSC_CONFIG, 'utf8')
+ const sourceFile = ts.createSourceFile(GFSC_CONFIG, source, ts.ScriptTarget.Latest, true)
+ expect({
+ read: exportedNumericConst(sourceFile, 'AGENT_READ_RL_PER_MIN_DEFAULT'),
+ write: exportedNumericConst(sourceFile, 'AGENT_WRITE_RL_PER_MIN_DEFAULT'),
+ max: exportedNumericConst(sourceFile, 'AGENT_RL_PER_MIN_MAX'),
+ }).toEqual({
+ read: DEFAULT_GFSC_AGENT_READ_RL_PER_MIN_PER_REPLICA,
+ write: DEFAULT_GFSC_AGENT_WRITE_RL_PER_MIN_PER_REPLICA,
+ max: MAX_GFSC_AGENT_RL_PER_MIN_PER_REPLICA,
+ })
+ })
+})