Skip to content

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

TypeScript

fix(hcc): distinguish live vs compiled orphan-cap on census (#478)

Alfredo Lopez4f6034c2c5c0
diff --git a/host-context-controller/README.md b/host-context-controller/README.md
index 35a182d9d..f10fdcf55 100644
--- a/host-context-controller/README.md
+++ b/host-context-controller/README.md
@@ -439,16 +439,16 @@ Read by `src/gfsConfig.ts`. Invalid values **throw at startup** rather than sile
### NetworkPolicy
-| Variable | Default | Description |
-| ------------------------------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `CONTEXT_MAPPER_RUNTIME_NAMESPACES` | `mcp-server,mcp-host,sandbox-recipes,rpc-proxy` | Namespaces that get L0 deny-all + L1 infrastructure policies. Manifest overrides to `mcp-server,sandbox-recipes,rpc-proxy,sandbox-ui` — note it **drops `mcp-host`**, whose policies are static (`deploy/base/mcp-host/networkpolicies.yaml`), because an HCC deny-all would block mcp-host from reaching LLM APIs. |
-| `CONTEXT_MAPPER_MINIMAL_INFRA_NAMESPACES` | `` (empty) | Subset of runtime namespaces that get **only** deny-all + DNS egress — no HCC-API or K8s-API egress. Manifest sets `sandbox-ui`. |
-| `CONTEXT_MAPPER_K8S_API_CIDRS` | _(unset → `[]`)_ | K8s API-server CIDRs for `allow-k8s-api-egress-*`. Empty falls back to `KUBERNETES_SERVICE_HOST`. **Validated fail-closed at module load**: a malformed entry, or one broader than `/24` (IPv4) or `/120` (IPv6), **crashes startup** rather than programming a permissive policy. |
-| `CONTEXT_MAPPER_NODELOCAL_DNS_CIDR` | `` (empty) | DNS infrastructure CIDR for NodeLocal DNSCache / kube-dns. Must be exactly one IPv4 `/32`; anything else throws at startup. |
-| `CONTEXT_MAPPER_NETPOL_RESYNC_SEC` | `0` | Periodic NetworkPolicy coordinated convergence (seconds). Re-enters the single-flight pass; `0` disables the interval (merge default). Startup still converges once. **Enable is a separate ops decision** (issue #478): before any non-zero value, add a freshness gate **or** use a controller-runtime 10h-scale period. Do not treat `300` as the enable value while passes last minutes. |
-| `CONTEXT_MAPPER_NETPOL_ORPHAN_DELETE_CAP` | `10` | Absolute orphan-delete cap for a namespace-wide NetworkPolicy sweep. Candidates **strictly above** this count refuse the pass (no deletes, no certification). |
-| `CONTEXT_MAPPER_NETPOL_ORPHAN_DELETE_CAP_PERCENT` | `20` | Percent orphan-delete cap against the listed managed fleet. Strict `>`. Inert on a tiny inventory where `percent * listed < 1`. |
-| `KUBERNETES_SERVICE_HOST` | _(injected by Kubernetes)_ | Not set by the operator — the `/32` fallback source when `CONTEXT_MAPPER_K8S_API_CIDRS` is empty. |
+| Variable | Default | Description |
+| ------------------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| `CONTEXT_MAPPER_RUNTIME_NAMESPACES` | `mcp-server,mcp-host,sandbox-recipes,rpc-proxy` | Namespaces that get L0 deny-all + L1 infrastructure policies. Manifest overrides to `mcp-server,sandbox-recipes,rpc-proxy,sandbox-ui` — note it **drops `mcp-host`**, whose policies are static (`deploy/base/mcp-host/networkpolicies.yaml`), because an HCC deny-all would block mcp-host from reaching LLM APIs. |
+| `CONTEXT_MAPPER_MINIMAL_INFRA_NAMESPACES` | `` (empty) | Subset of runtime namespaces that get **only** deny-all + DNS egress — no HCC-API or K8s-API egress. Manifest sets `sandbox-ui`. |
+| `CONTEXT_MAPPER_K8S_API_CIDRS` | _(unset → `[]`)_ | K8s API-server CIDRs for `allow-k8s-api-egress-*`. Empty falls back to `KUBERNETES_SERVICE_HOST`. **Validated fail-closed at module load**: a malformed entry, or one broader than `/24` (IPv4) or `/120` (IPv6), **crashes startup** rather than programming a permissive policy. |
+| `CONTEXT_MAPPER_NODELOCAL_DNS_CIDR` | `` (empty) | DNS infrastructure CIDR for NodeLocal DNSCache / kube-dns. Must be exactly one IPv4 `/32`; anything else throws at startup. |
+| `CONTEXT_MAPPER_NETPOL_RESYNC_SEC` | `0` | Periodic NetworkPolicy coordinated convergence (seconds). Re-enters the single-flight pass; `0` disables the interval (merge default). Startup still converges once. Default `0` logs a `console.warn` on every boot (same pattern as Host/SFS/GFS/LlmHook) — expected; it names the self-heal gap. **Enable is a separate ops decision** (issue #478): before any non-zero value, add a freshness gate **or** use a controller-runtime 10h-scale period. Do not treat `300` as the enable value while passes last minutes. |
+| `CONTEXT_MAPPER_NETPOL_ORPHAN_DELETE_CAP` | `10` | Absolute orphan-delete cap for a namespace-wide NetworkPolicy sweep. Candidates **strictly above** this count refuse the pass (no deletes, no certification). Governs **every** `fullReconcile` (startup, event-driven, and the resync timer), not only a periodic tick. A legitimate bulk offboarding above the cap withholds certification until an operator raises it. Read-only census: `scripts/ops/hcc-netpol-orphan-census.sh` — `live_cap_would_trip` is Deployment env only; `controller_cap_would_trip` applies these compiled defaults when the env is unset. |
+| `CONTEXT_MAPPER_NETPOL_ORPHAN_DELETE_CAP_PERCENT` | `20` | Percent orphan-delete cap against the listed managed fleet. Strict `>`. Inert on a tiny inventory where `percent * listed < 1`. Same every-`fullReconcile` scope as the absolute cap. |
+| `KUBERNETES_SERVICE_HOST` | _(injected by Kubernetes)_ | Not set by the operator — the `/32` fallback source when `CONTEXT_MAPPER_K8S_API_CIDRS` is empty. |
### Plugin image allowlist
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 6055cad7b..dbbd87fd5 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.248",
+ "version": "0.1.249",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.248",
+ "version": "0.1.249",
"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 b4d204505..d3d738da8 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.248",
+ "version": "0.1.249",
"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/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.ts
index fd7a605e8..b7a3078bb 100644
--- a/host-context-controller/src/networkPolicyReconciler.ts
+++ b/host-context-controller/src/networkPolicyReconciler.ts
@@ -88,6 +88,10 @@ export type NetPolOrphanSweepCapReason = 'absolute' | 'percent'
* strict `>`: exactly `absoluteCap` candidates still delete. The percent
* rule is inert on a tiny listed fleet (`percent*listed < 1`) so a single
* real orphan cannot look like a cache-wipe.
+ *
+ * Runs on every `fullReconcile` (startup, event-driven, and the resync
+ * timer), not only a periodic tick. A legitimate bulk offboarding above
+ * the cap withholds certification until an operator raises the env.
*/
export function evaluateNetPolOrphanSweepCap(
orphanCount: number,
diff --git a/package-lock.json b/package-lock.json
index 1d6c79b45..d1877e307 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,39 +13,6 @@
"prettier": "^3.0.0"
}
},
- "mcp-servers/doc-generator": {
- "name": "@clerum/doc-generator-mcp",
- "version": "1.0.0",
- "extraneous": true,
- "dependencies": {
- "@modelcontextprotocol/sdk": "^1.12.1",
- "exceljs": "^4.4.0",
- "express": "^4.21.2",
- "markdown-it": "^14.1.0"
- },
- "devDependencies": {
- "@types/express": "^5.0.0",
- "@types/markdown-it": "^14.1.2",
- "@types/node": "^22.13.0",
- "tsx": "^4.19.0",
- "typescript": "^5.7.0"
- }
- },
- "mcp-servers/web-search": {
- "name": "@clerum/web-search-mcp",
- "version": "1.0.0",
- "extraneous": true,
- "dependencies": {
- "@modelcontextprotocol/sdk": "^1.12.1",
- "express": "^4.21.2"
- },
- "devDependencies": {
- "@types/express": "^5.0.0",
- "@types/node": "^22.13.0",
- "tsx": "^4.19.0",
- "typescript": "^5.7.0"
- }
- },
"node_modules/@babel/code-frame": {
"version": "7.29.7",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz",
@@ -1531,82 +1498,6 @@
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
- },
- "tests/e2e/fixtures": {
- "name": "@clerum/e2e-test-fixtures",
- "version": "1.0.0",
- "extraneous": true,
- "dependencies": {
- "@kubernetes/client-node": "^1.0.0"
- },
- "devDependencies": {
- "@types/node": "^20.10.0",
- "typescript": "^5.3.0",
- "vitest": "^4.0.18"
- },
- "peerDependencies": {
- "vitest": ">=4.0.0"
- }
- },
- "tests/e2e/fixtures/mock-mcp-server": {
- "version": "0.1.0",
- "extraneous": true,
- "dependencies": {
- "@modelcontextprotocol/sdk": "^1.0.0",
- "zod": "^3.23.0"
- },
- "devDependencies": {
- "@types/node": "^22.0.0",
- "typescript": "^5.6.0"
- }
- },
- "tests/e2e/fixtures/mock-secrets-server": {
- "name": "@clerum/mock-secrets-server",
- "version": "1.0.0",
- "extraneous": true,
- "dependencies": {
- "cors": "^2.8.5",
- "express": "^4.18.2"
- },
- "devDependencies": {
- "@types/cors": "^2.8.17",
- "@types/express": "^4.17.21",
- "@types/node": "^20.10.0",
- "tsx": "^4.7.0",
- "typescript": "^5.3.0",
- "vitest": "^4.0.18"
- }
- },
- "tests/e2e/fixtures/mock-stdio-mcp-server": {
- "version": "0.1.0",
- "extraneous": true,
- "dependencies": {
- "@modelcontextprotocol/sdk": "^1.0.0",
- "zod": "^3.23.0"
- },
- "devDependencies": {
- "@types/node": "^22.0.0",
- "typescript": "^5.6.0"
- }
- },
- "tests/e2e/playwright": {
- "name": "clerum-playwright-tests",
- "version": "0.1.0",
- "extraneous": true,
- "devDependencies": {
- "@playwright/test": "^1.50.0",
- "@types/node": "^22.0.0"
- }
- },
- "workflow-recipes/tests/e2e": {
- "name": "workflow-recipes-e2e",
- "version": "0.1.0",
- "extraneous": true,
- "devDependencies": {
- "@types/node": "^20.10.0",
- "typescript": "^5.3.0",
- "vitest": "^3.0.0"
- }
}
}
}
diff --git a/scripts/ops/hcc-netpol-orphan-census.sh b/scripts/ops/hcc-netpol-orphan-census.sh
index 958b57734..8b70dd040 100755
--- a/scripts/ops/hcc-netpol-orphan-census.sh
+++ b/scripts/ops/hcc-netpol-orphan-census.sh
@@ -7,7 +7,13 @@
#
# CONTEXT_MAPPER_* knobs are read from the live host-context-controller
# Deployment. Code defaults are never printed as cluster facts: an absent
-# env is UNSET.
+# env is UNSET. `live_cap_would_trip` therefore stays none when the
+# Deployment omitted the cap keys.
+#
+# The running controller still applies compiled defaults in that case
+# (absolute 10, percent 20 — host-context-controller/src/config.ts).
+# `controller_cap_would_trip` answers that question so a reader cannot
+# treat live_cap_would_trip=none as "the sweep will proceed".
#
# Double-samples 90s apart. Adjudicates only when the desired Context +
# McpServer identity set is identical across samples; otherwise
@@ -155,6 +161,22 @@ echo "[census] listed_managed=${LISTED} orphan_count=${ORPHAN_COUNT}"
echo "[census] orphans (namespace name policy-type):"
printf "%s" "${SAMPLE2}" | sed -n "/^ORPHANS<<EOF/,/^EOF/{ /^ORPHANS<<EOF/d; /^EOF/d; p; }"
+# Controller compiled defaults (config.ts). Used only for
+# controller_cap_would_trip, never as a substitute for live env.
+COMPILED_ABS_DEFAULT=10
+COMPILED_PCT_DEFAULT=20
+
+cap_would_trip() {
+ local orphan_count="$1" listed="$2" abs="$3" pct="$4"
+ if [[ "${orphan_count}" -gt "${abs}" ]]; then
+ printf "absolute"
+ elif [[ "${listed}" -gt 0 && $((listed * pct)) -ge 100 && $((orphan_count * 100)) -gt $((listed * pct)) ]]; then
+ printf "percent"
+ else
+ printf "none"
+ fi
+}
+
CAP_REASON="none"
if [[ "${ORPHAN_CAP}" != "UNSET" && "${ORPHAN_COUNT}" -gt "${ORPHAN_CAP}" ]]; then
CAP_REASON="absolute"
@@ -165,7 +187,19 @@ elif [[ "${ORPHAN_CAP_PCT}" != "UNSET" && "${LISTED}" -gt 0 ]]; then
fi
fi
+CONTROLLER_ABS="${ORPHAN_CAP}"
+CONTROLLER_PCT="${ORPHAN_CAP_PCT}"
+if [[ "${CONTROLLER_ABS}" == "UNSET" ]]; then
+ CONTROLLER_ABS="${COMPILED_ABS_DEFAULT}"
+fi
+if [[ "${CONTROLLER_PCT}" == "UNSET" ]]; then
+ CONTROLLER_PCT="${COMPILED_PCT_DEFAULT}"
+fi
+CONTROLLER_CAP_REASON="$(cap_would_trip "${ORPHAN_COUNT}" "${LISTED}" "${CONTROLLER_ABS}" "${CONTROLLER_PCT}")"
+
echo "[census] live_cap_would_trip=${CAP_REASON}"
+echo "[census] compiled_default_absolute=${COMPILED_ABS_DEFAULT} compiled_default_percent=${COMPILED_PCT_DEFAULT}"
+echo "[census] controller_cap_would_trip=${CONTROLLER_CAP_REASON} (live env, else compiled defaults)"
if [[ "${ORPHAN_COUNT}" -eq 0 ]]; then
echo "[census] VERDICT=CLEAN"
else