Skip to content

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

TypeScript

fix(minikube): refuse a Host model name without a provider and check it

Alfredo Lopez216c67709e71
diff --git a/deploy/overlays/minikube/instances/host.yaml b/deploy/overlays/minikube/instances/host.yaml
index 37da38839..ffa86f5b3 100644
--- a/deploy/overlays/minikube/instances/host.yaml
+++ b/deploy/overlays/minikube/instances/host.yaml
@@ -8,10 +8,11 @@ spec:
contextRef: context1
secretRef: chatllm-api-keys
model:
- # Overwritten by full-setup.sh step 6f, which auto-detects the provider
- # from .env. This literal is only the apply-time placeholder.
- provider: zai
- name: glm-5.1
+ # Overwritten by full-setup.sh step 6f, which resolves the pair from .env
+ # (scripts/minikube/host-model.sh) and checks it against llm_allowed_models.
+ # This literal is only the apply-time placeholder: the no-key default.
+ provider: openai
+ name: gpt-5.4-mini
workflowControl:
scopes:
- workflow:list
diff --git a/scripts/bootstrap-cluster.sh b/scripts/bootstrap-cluster.sh
index 24b21cc3c..c575c5178 100755
--- a/scripts/bootstrap-cluster.sh
+++ b/scripts/bootstrap-cluster.sh
@@ -37,10 +37,21 @@ BOLD='\033[1m'
log() { echo -e "${CYAN}[BOOTSTRAP]${NC} $*"; }
ok() { echo -e "${GREEN} OK${NC} — $*"; }
+warn() { echo -e "${YELLOW} WARN${NC} — $*"; }
err() { echo -e "${RED} ERROR${NC} — $*"; }
KC="kubectl --context=${PROFILE}"
+# Resolve the Host model up front, by the same rule as full-setup.sh
+# (scripts/minikube/host-model.sh), so a CLERUM_MODEL_NAME without
+# CLERUM_MODEL_PROVIDER stops here instead of after the cluster is built.
+# This script runs no control-api migrations, so there is no
+# llm_allowed_models table to check the pair against.
+# shellcheck source=scripts/minikube/host-model.sh
+source "${SCRIPT_DIR}/minikube/host-model.sh"
+resolve_host_model || exit 1
+log "Host model: ${RESOLVED_PROVIDER}/${RESOLVED_MODEL}"
+
# ─── Step 1: Verify cluster ───────────────────────────────────────
echo -e "\n${BOLD}═══ Step 1: Verify Cluster ═══${NC}"
if ! $KC cluster-info &>/dev/null; then
@@ -221,8 +232,8 @@ spec:
contextRef: context1
secretRef: chatllm-api-keys
model:
- provider: ${CLERUM_MODEL_PROVIDER:-zai}
- name: ${CLERUM_MODEL_NAME:-glm-4.7}
+ provider: ${RESOLVED_PROVIDER}
+ name: ${RESOLVED_MODEL}
workflowControl:
scopes:
- workflow:list
diff --git a/scripts/check-prereqs.sh b/scripts/check-prereqs.sh
index 20b028cc9..cfef988c5 100755
--- a/scripts/check-prereqs.sh
+++ b/scripts/check-prereqs.sh
@@ -295,11 +295,20 @@ azure:AZURE_OPENAI_API_KEY"
if [ -n "$LLM_KEYS_SET" ]; then
ok ".env LLM key set —$LLM_KEYS_SET"
else
- # Non-fatal: setup boots with test placeholders (default zai). The agent
- # just can't reach a model until a real key is added — matches the
- # "optional" behavior documented in docs/deploy/minikube.md.
- warn ".env no LLM key set — setup will boot with placeholders (default zai); the agent can't call a model until you add one"
- echo " Set one of 22 providers in .env (OPENAI_API_KEY / CLAUDE_API_KEY / GEMINI_API_KEY / GROQ_API_KEY / MISTRAL_API_KEY …); setup infers the provider. Full list: docs/deploy/llm-providers.md"
+ # Non-fatal: setup boots with test placeholders (default
+ # openai/gpt-5.4-mini). The agent just can't reach a model until a real
+ # key is added — matches the "optional" behavior documented in
+ # docs/deploy/minikube.md.
+ warn ".env no LLM key set — setup will boot with placeholders (default openai/gpt-5.4-mini); the agent can't call a model until you add one"
+ echo " Set one of 22 providers in .env (OPENAI_API_KEY / CLAUDE_API_KEY / GEMINI_API_KEY / GROQ_API_KEY / MISTRAL_API_KEY …). Setup infers the provider from OPENAI_API_KEY / CLAUDE_API_KEY / ZAI_API_KEY / BAILIAN_API_KEY; any other provider needs CLERUM_MODEL_PROVIDER and CLERUM_MODEL_NAME. Full list: docs/deploy/llm-providers.md"
+ fi
+
+ # CLERUM_MODEL_NAME names one provider's model; without CLERUM_MODEL_PROVIDER
+ # full-setup.sh refuses it (scripts/minikube/host-model.sh) rather than pair
+ # it with whichever key is present.
+ if [ -n "$(env_value CLERUM_MODEL_NAME "$ENV_FILE")" ] &&
+ [ -z "$(env_value CLERUM_MODEL_PROVIDER "$ENV_FILE")" ]; then
+ warn ".env CLERUM_MODEL_NAME is set without CLERUM_MODEL_PROVIDER — full-setup will refuse it; set both, or remove CLERUM_MODEL_NAME"
fi
# Provider/key consistency — non-fatal, catches a common mismatch.
diff --git a/scripts/minikube/apply-llm-secret.sh b/scripts/minikube/apply-llm-secret.sh
index 7bdd07065..f7c133dec 100755
--- a/scripts/minikube/apply-llm-secret.sh
+++ b/scripts/minikube/apply-llm-secret.sh
@@ -13,8 +13,11 @@
#
# Backward compatible: the four original providers (openai/claude/zai/
# bailian) keep their test-placeholder fallbacks so an empty .env (CI, first
-# boot) still stands up the default `zai` agent. Real values override the
+# boot) still stands up the default `openai` agent (openai/gpt-5.4-mini, which
+# does not reply until a real key is added). Real values override the
# placeholders; the other 18 providers appear only when their key is set.
+# Which provider the Host uses is decided by scripts/minikube/host-model.sh,
+# the same rule full-setup.sh applies; the summary line below reports it.
#
# The Secret stores keys in the registry `dataKey` form (lowercase-hyphen,
# e.g. `openai-api-key`), which is what mcp-host's LLM-secret watch expects.
@@ -113,8 +116,16 @@ kubectl --context="$CONTEXT" create secret generic chatllm-api-keys \
"${ARGS[@]}" \
--dry-run=client -o yaml | kubectl --context="$CONTEXT" apply -f -
+# The provider full-setup.sh will pick for the Host, by the shared rule: an
+# explicit CLERUM_MODEL_PROVIDER, else the first of the four original keys
+# present, else openai.
+# shellcheck source=scripts/minikube/host-model.sh
+source "${SCRIPT_DIR}/host-model.sh"
+HOST_PROVIDER="$(resolve_model_provider)"
+HOST_PROVIDER="${HOST_PROVIDER:-openai}"
+
if [ "${#REAL_KEYS[@]}" -gt 0 ]; then
- echo " LLM API keys applied — real keys from .env: ${REAL_KEYS[*]} (provider: ${CLERUM_MODEL_PROVIDER:-zai})"
+ echo " LLM API keys applied — real keys from .env: ${REAL_KEYS[*]} (provider: ${HOST_PROVIDER})"
else
- echo " LLM API keys applied — no keys in .env; using test placeholders (provider: ${CLERUM_MODEL_PROVIDER:-zai})"
+ echo " LLM API keys applied — no keys in .env; using test placeholders (provider: ${HOST_PROVIDER})"
fi
diff --git a/scripts/minikube/full-setup.sh b/scripts/minikube/full-setup.sh
index 211a8237c..18c4c5058 100755
--- a/scripts/minikube/full-setup.sh
+++ b/scripts/minikube/full-setup.sh
@@ -310,6 +310,9 @@ fi
# `make minikube-deploy-all` and `build-images.sh --verify-only` already use.
# shellcheck source=scripts/minikube/image-mode.sh
source "${SCRIPT_DIR}/image-mode.sh"
+# Host model resolution and its llm_allowed_models check (step 6f).
+# shellcheck source=scripts/minikube/host-model.sh
+source "${SCRIPT_DIR}/host-model.sh"
if [ "$SKIP_BUILD" = true ]; then
RECORDED_IMAGE_SOURCE="$(image_mode_source "$PROJECT_DIR")" || exit 1
if [ "$RECORDED_IMAGE_SOURCE" != "$IMAGE_SOURCE" ]; then
@@ -1919,55 +1922,18 @@ else
log "Skipping demo MCP servers (SEED_PROFILE=minimal) — context1 starts empty."
fi
-# Resolve the model provider from whichever key the user actually supplied.
-# Priority order matches docs/architecture/overview.md:724 and
-# .env.quickstart.example. An explicit CLERUM_MODEL_PROVIDER always wins.
-# Without this, the Host pins zai while zai-api-key is a placeholder, so the
-# agent never replies for anyone who set a different provider's key.
-resolve_model_provider() {
- if [ -n "${CLERUM_MODEL_PROVIDER:-}" ]; then
- printf '%s' "${CLERUM_MODEL_PROVIDER}"
- return 0
- fi
- if [ -n "${OPENAI_API_KEY:-}" ]; then printf 'openai'; return 0; fi
- if [ -n "${CLAUDE_API_KEY:-}" ]; then printf 'claude'; return 0; fi
- if [ -n "${ZAI_API_KEY:-}" ]; then printf 'zai'; return 0; fi
- if [ -n "${BAILIAN_API_KEY:-}" ]; then printf 'bailian'; return 0; fi
- printf ''
-}
-
-# These MUST stay in sync with the canonical registry at
-# mcp-host/src/llm/registryCore.ts:50,57,64,72 — that is the single source of
-# truth (config.ts:301 reads it via descriptorFor(provider).defaultModel).
-# Verify against that file before committing; a drifted model id fails at the
-# first message, which is the exact bug this task fixes.
-default_model_for_provider() {
- case "$1" in
- openai) printf 'gpt-5.4-mini' ;;
- claude) printf 'claude-sonnet-4-6' ;;
- zai) printf 'glm-5.1' ;;
- bailian) printf 'qwen3-coder-plus' ;;
- *) printf '' ;;
- esac
-}
-
-RESOLVED_PROVIDER="$(resolve_model_provider)"
-if [ -z "$RESOLVED_PROVIDER" ]; then
- # No key at all. Warn, do not abort — the platform still comes up fully and
- # quickstart.md:39 already documents that the agent will not reply. This is
- # deliberately softer than the ADMIN_PASSWORD precondition (Task 4).
- warn "No LLM API key found in .env (OPENAI_API_KEY / CLAUDE_API_KEY / ZAI_API_KEY / BAILIAN_API_KEY)."
- warn "Defaulting Host to zai with a placeholder key — the chatllm agent will NOT reply."
- warn "Set a key in .env and re-run to fix."
- RESOLVED_PROVIDER="zai"
-fi
-RESOLVED_MODEL="${CLERUM_MODEL_NAME:-$(default_model_for_provider "$RESOLVED_PROVIDER")}"
-if [ -z "$RESOLVED_MODEL" ]; then
- err "Unknown provider '${RESOLVED_PROVIDER}' — set CLERUM_MODEL_NAME explicitly in .env."
- exit 1
-fi
-
# 6f. Apply Host model from .env/default E2E model
+# The rule lives in scripts/minikube/host-model.sh: an explicit
+# CLERUM_MODEL_PROVIDER wins, CLERUM_MODEL_NAME without it is refused, and
+# otherwise the provider follows the first key present (openai/gpt-5.4-mini,
+# with a warning, when there is none). The pair must then be an enabled
+# llm_allowed_models row in this profile's control-postgres, which the
+# migrations above created; a refusal stops setup before the Host is applied.
+# A no-key run still comes up fully: docs/get-started/quickstart.md documents
+# that the agent does not reply until a key is added.
+resolve_host_model || exit 1
+log "Checking Host model ${RESOLVED_PROVIDER}/${RESOLVED_MODEL} against llm_allowed_models..."
+assert_host_model_allowed "$RESOLVED_PROVIDER" "$RESOLVED_MODEL" || exit 1
log "Applying Host model ${RESOLVED_PROVIDER}/${RESOLVED_MODEL} (source: ${CLERUM_MODEL_PROVIDER:+CLERUM_MODEL_PROVIDER}${CLERUM_MODEL_PROVIDER:-auto-detected from .env})..."
cat <<HOSTEOF | $KC apply -f -
apiVersion: clerum.io/v1alpha1
diff --git a/scripts/minikube/host-model.sh b/scripts/minikube/host-model.sh
new file mode 100644
index 000000000..89ef40310
--- /dev/null
+++ b/scripts/minikube/host-model.sh
@@ -0,0 +1,138 @@
+#!/usr/bin/env bash
+# ======================================================================
+# Which model the minikube chatllm Host runs, and proof that it may
+# ======================================================================
+#
+# Sourced library, shared by scripts/minikube/full-setup.sh (step 6f) and
+# scripts/bootstrap-cluster.sh. It defines functions only: it sets no shell
+# options and reports through the caller's err/warn functions.
+#
+# The rule (docs/llm-providers/README.md):
+# - CLERUM_MODEL_PROVIDER and CLERUM_MODEL_NAME set -> used as given.
+# - CLERUM_MODEL_PROVIDER only -> that provider's
+# default model.
+# - CLERUM_MODEL_NAME without CLERUM_MODEL_PROVIDER -> refused. The name
+# belongs to one provider, and pairing it with whichever key happens to be
+# present is how openai/glm-4.7 reached a Host and failed on its first
+# message.
+# - neither -> the provider of the first key present, in the order
+# OPENAI_API_KEY, CLAUDE_API_KEY, ZAI_API_KEY, BAILIAN_API_KEY, with its
+# default model. With no key at all: openai/gpt-5.4-mini, with a warning
+# that the agent will not reply until a key is added.
+#
+# Usage (library):
+# source scripts/minikube/host-model.sh
+# resolve_host_model || exit 1 # sets RESOLVED_PROVIDER/MODEL
+# assert_host_model_allowed "$RESOLVED_PROVIDER" "$RESOLVED_MODEL" || exit 1
+# ======================================================================
+
+# The provider named by CLERUM_MODEL_PROVIDER, else the provider of the first
+# key present. Prints nothing when neither exists.
+resolve_model_provider() {
+ if [ -n "${CLERUM_MODEL_PROVIDER:-}" ]; then
+ printf '%s' "${CLERUM_MODEL_PROVIDER}"
+ return 0
+ fi
+ if [ -n "${OPENAI_API_KEY:-}" ]; then printf 'openai'; return 0; fi
+ if [ -n "${CLAUDE_API_KEY:-}" ]; then printf 'claude'; return 0; fi
+ if [ -n "${ZAI_API_KEY:-}" ]; then printf 'zai'; return 0; fi
+ if [ -n "${BAILIAN_API_KEY:-}" ]; then printf 'bailian'; return 0; fi
+ printf ''
+}
+
+# These MUST equal the defaultModel values in mcp-host/src/llm/registryCore.ts,
+# the single source of truth mcp-host reads through
+# descriptorFor(provider).defaultModel. scripts/tests/test-minikube-host-model.sh
+# (H11) reads that file and fails on any drift.
+default_model_for_provider() {
+ case "$1" in
+ openai) printf 'gpt-5.4-mini' ;;
+ claude) printf 'claude-sonnet-4-6' ;;
+ zai) printf 'glm-5.1' ;;
+ bailian) printf 'qwen3-coder-plus' ;;
+ *) printf '' ;;
+ esac
+}
+
+# Sets RESOLVED_PROVIDER and RESOLVED_MODEL from the environment by the rule in
+# the header. Returns 1, after err, when the pair cannot be resolved.
+resolve_host_model() {
+ RESOLVED_PROVIDER=""
+ RESOLVED_MODEL=""
+ if [ -n "${CLERUM_MODEL_NAME:-}" ] && [ -z "${CLERUM_MODEL_PROVIDER:-}" ]; then
+ err "CLERUM_MODEL_NAME='${CLERUM_MODEL_NAME}' is set without CLERUM_MODEL_PROVIDER. A model name belongs to one provider: set CLERUM_MODEL_PROVIDER in .env, or remove CLERUM_MODEL_NAME to use the detected provider's default model."
+ return 1
+ fi
+
+ RESOLVED_PROVIDER="$(resolve_model_provider)"
+ if [ -z "$RESOLVED_PROVIDER" ]; then
+ warn "No LLM API key found in .env (OPENAI_API_KEY / CLAUDE_API_KEY / ZAI_API_KEY / BAILIAN_API_KEY)."
+ warn "Defaulting Host to openai with a placeholder key — the chatllm agent will NOT reply."
+ warn "Set a key in .env and re-run to fix."
+ RESOLVED_PROVIDER="openai"
+ fi
+
+ if [ -n "${CLERUM_MODEL_NAME:-}" ]; then
+ RESOLVED_MODEL="${CLERUM_MODEL_NAME}"
+ else
+ RESOLVED_MODEL="$(default_model_for_provider "$RESOLVED_PROVIDER")"
+ fi
+ if [ -z "$RESOLVED_MODEL" ]; then
+ err "Provider '${RESOLVED_PROVIDER}' has no default model here — set CLERUM_MODEL_NAME explicitly in .env."
+ return 1
+ fi
+ return 0
+}
+
+# Proves (provider, model) is an enabled row of llm_allowed_models in the
+# profile's control-postgres before the Host is applied. Needs KC (the kubectl
+# command with the profile's --context). Only `enabled` is read: `stale` is a
+# soft quarantine that leaves a model usable (control-api llmAllowedModels.ts).
+#
+# The values travel as psql variables and the SQL reads them as :'provider'
+# and :'model', so neither is ever interpolated into SQL text.
+#
+# Refusals (each an err line and a non-zero return):
+# HOST_MODEL_UNKNOWN no row for the pair
+# HOST_MODEL_DISABLED the row exists with enabled = false
+# HOST_MODEL_CHECK_FAILED the query could not run or answered something else
+assert_host_model_allowed() {
+ local provider="${1:-}" model="${2:-}" answer
+ if [ -z "$provider" ] || [ -z "$model" ]; then
+ err "HOST_MODEL_CHECK_FAILED: assert_host_model_allowed needs a provider and a model (got '${provider}' / '${model}')."
+ return 1
+ fi
+ if [ -z "${KC:-}" ]; then
+ err "HOST_MODEL_CHECK_FAILED: KC is not set, so the profile's control-postgres cannot be queried for ${provider}/${model}."
+ return 1
+ fi
+ # $KC is a command plus its --context flag and must split into words.
+ # shellcheck disable=SC2086
+ if ! answer="$($KC exec -i -n control-plane deployment/control-postgres -- \
+ psql -U postgres -d profiles -v ON_ERROR_STOP=1 \
+ -v "provider=${provider}" -v "model=${model}" -Atq -f - <<'SQL'
+SELECT enabled FROM llm_allowed_models
+ WHERE provider = :'provider' AND model = :'model';
+SQL
+ )"; then
+ err "HOST_MODEL_CHECK_FAILED: the llm_allowed_models query for ${provider}/${model} failed in control-postgres (see the kubectl/psql error above)."
+ return 1
+ fi
+ case "$answer" in
+ t)
+ return 0
+ ;;
+ f)
+ err "HOST_MODEL_DISABLED: ${provider}/${model} is in llm_allowed_models but disabled. Enable it in the Control UI, or set CLERUM_MODEL_PROVIDER and CLERUM_MODEL_NAME to an enabled model."
+ return 1
+ ;;
+ '')
+ err "HOST_MODEL_UNKNOWN: ${provider}/${model} is not in llm_allowed_models. Set CLERUM_MODEL_PROVIDER and CLERUM_MODEL_NAME in .env to a model that catalog enables for that provider."
+ return 1
+ ;;
+ *)
+ err "HOST_MODEL_CHECK_FAILED: unexpected answer from llm_allowed_models for ${provider}/${model}: '$(printf '%s' "$answer" | tr '\n' ' ')'."
+ return 1
+ ;;
+ esac
+}
diff --git a/scripts/tests/test-minikube-host-model.sh b/scripts/tests/test-minikube-host-model.sh
index c36fc1e1e..0ddb979e7 100755
--- a/scripts/tests/test-minikube-host-model.sh
+++ b/scripts/tests/test-minikube-host-model.sh
@@ -23,8 +23,11 @@ pass() { echo "PASS: $1"; PASSED=$((PASSED + 1)); }
fail() { echo "FAIL: $1"; FAIL=1; FAILED=$((FAILED + 1)); }
# The library reports through the caller's err/warn, as full-setup.sh defines
-# them. These print plain prefixes the cases can match.
+# them. These print plain prefixes the cases can match. Only the sourced
+# library calls them, which shellcheck cannot see.
+# shellcheck disable=SC2329
err() { printf 'ERROR -- %s\n' "$*"; }
+# shellcheck disable=SC2329
warn() { printf 'WARN -- %s\n' "$*"; }
WORK="$(mktemp -d)"
@@ -68,6 +71,8 @@ run_case() {
CLERUM_MODEL_PROVIDER CLERUM_MODEL_NAME RESOLVED_PROVIDER RESOLVED_MODEL
export PATH="$WORK/bin:$PATH"
export KUBECTL_STUB_LOG="$stub_log" KUBECTL_STUB_MODE="$stub_mode"
+ # Scoped to this case's subshell on purpose.
+ # shellcheck disable=SC2030
export KC="kubectl --context=fixture"
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do
export "${1?}"
@@ -84,7 +89,9 @@ run_case() {
) </dev/null 2>&1
}
-# What full-setup.sh step 6f does before the Host heredoc.
+# What full-setup.sh step 6f does before the Host heredoc. run_case invokes it
+# inside the case's subshell, where resolve_host_model sets the two variables.
+# shellcheck disable=SC2329,SC2031
resolve_then_check() {
resolve_host_model || return $?
assert_host_model_allowed "$RESOLVED_PROVIDER" "$RESOLVED_MODEL"
@@ -253,6 +260,7 @@ assert_h9_full_setup_sources_the_library_and_checks_before_the_host() {
# shellcheck disable=SC2016
source_line="$(grep -nF 'source "${SCRIPT_DIR}/host-model.sh"' "$FULL_SETUP" | head -n 1 | cut -d: -f1)"
resolve_line="$(grep -nE '^resolve_host_model \|\| exit 1$' "$FULL_SETUP" | head -n 1 | cut -d: -f1)"
+ # shellcheck disable=SC2016
assert_line="$(grep -nE '^assert_host_model_allowed "\$RESOLVED_PROVIDER" "\$RESOLVED_MODEL" \|\| exit 1$' "$FULL_SETUP" | head -n 1 | cut -d: -f1)"
heredoc_line="$(grep -nF 'cat <<HOSTEOF' "$FULL_SETUP" | head -n 1 | cut -d: -f1)"
if [ -n "$source_line" ] && [ -n "$resolve_line" ] && [ -n "$assert_line" ] && [ -n "$heredoc_line" ] &&
@@ -291,15 +299,15 @@ registry_default_model() {
}
assert_h11_default_models_match_the_mcp_host_registry() {
- local provider registry_value library_value
- for provider in openai claude zai bailian; do
- registry_value="$(registry_default_model "$provider")"
+ local registry_provider registry_value library_value
+ for registry_provider in openai claude zai bailian; do
+ registry_value="$(registry_default_model "$registry_provider")"
# shellcheck source=scripts/minikube/host-model.sh
- library_value="$( (source "$LIB" && default_model_for_provider "$provider") 2>/dev/null)"
+ library_value="$( (source "$LIB" && default_model_for_provider "$registry_provider") 2>/dev/null)"
if [ -n "$registry_value" ] && [ "$library_value" = "$registry_value" ]; then
- pass "H11 default_model_for_provider $provider = registryCore.ts ($registry_value)"
+ pass "H11 default_model_for_provider $registry_provider = registryCore.ts ($registry_value)"
else
- fail "H11 $provider: library '${library_value}' vs registryCore.ts '${registry_value}'"
+ fail "H11 $registry_provider: library '${library_value}' vs registryCore.ts '${registry_value}'"
fi
done
}