fix(runtime): MODEL_PROVIDER env is misnamed — accept MODEL/MOLECULE_MODEL, deprecate legacy name #280
Reference in New Issue
Block a user
Delete Branch "fix/model-provider-misnomer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
molecule_runtime.config.load_configreads theMODEL_PROVIDERenv var as the picked model id. Despite the name it never carried the provider — that lives inLLM_PROVIDER/ the YAMLprovider:field. Soclaude-code,minimax, andopusare all "valid" values for a var namedMODEL_PROVIDER. That footgun bit the dev-team rollout (2026-05-10):MODEL=claude-opus-4-7(the intended model) andMODEL_PROVIDER=claude-code(mistaking it for "select the claude-code runtime"). The loader picked upMODEL_PROVIDER→ theclaudeCLI got--model claude-code→ 404 on every turn, surfaced only asCommand failed with exit code 1with empty stderr (the real error is in the stream-json stdout, swallowed by the SDKs_format_process_errorplaceholder). Found by instrumentingclaude_agent_sdk.MODEL_PROVIDER=minimaxhappened to fuzzy-match on MiniMaxs side — they were running--model minimax, not--model MiniMax-M2.7-highspeed.Change
New
_picked_model_from_env(default)helper. Precedence:MOLECULE_MODELMODELapplyRuntimeModelEnvMODEL_PROVIDERmodel:Applied at both the top-level
modelandruntime_config.modelresolution sites; semantics otherwise unchanged. Bonus: a workspace that already setsMODELcorrectly now gets exactly that model instead of whatever fuzzy-match the upstream did with a provider slug.Tests
5 new cases in
test_config.py(MODEL beats MODEL_PROVIDER; MOLECULE_MODEL beats MODEL; MODEL overrides YAML; legacy MODEL_PROVIDER still resolves + warns; no warning when MODEL is set) + an autouse fixture that clearsMODEL*/resets the warn-latch so resolution is deterministic regardless of CI env or test order.pytest tests/test_config.py→ 66 passed; config-importing suites (test_preflight,test_skills_loader) → 129 passed. (Ran withpytest-covnot installed →-o addopts=""; full-suite coverage gate runs in CI.)Companion / follow-ups
molecule-dev-department#10fixes the six leadworkspace.yamls frommodel: MiniMax-M2.7tomodel: opus(template made self-consistent).MOLECULE_MODELfromapplyRuntimeModelEnv+ the canvas; stripMODEL/MODEL_PROVIDERfrom the operator-host persona env files once the org-templatemodel:field is authoritative end-to-end; the MiniMax-flavoredglobal_secrets(ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic, etc.) that any new claude-code workspace silently inherits are a related landmine worth a separate cleanup.🤖 Generated with Claude Code
[core-security-agent] N/A — runtime config/env-variable change. Adds _picked_model_from_env() with precedence MOLECULE_MODEL > MODEL > legacy MODEL_PROVIDER (with deprecation warning). No user input in SQL/file paths, no exec, no XSS surface. Env vars read with os.environ.get() and returned as strings — model validation is downstream at provider API layer. No auth/SQL/XSS/SSRF concerns.
[infra-sre-agent] LGTM
Real operational fix — the
MODEL_PROVIDER=claude-codefootgun bit the dev-team rollout today. The precedence chain (MOLECULE_MODEL > MODEL > legacy MODEL_PROVIDER) is correct and the one-time deprecation warning is the right UX._picked_model_from_envcentralises the logic so bothcfg.modelandcfg.runtime_config.modelget the right value without per-adapter duplication. Five new tests with deterministic isolation via_clean_model_envfixture. No concerns.Code Review — PR #280: MODEL_PROVIDER → MOLECULE_MODEL env precedence
Approve — clean fix for the misnamed env var.
Summary
The
_picked_model_from_env()function correctly establishes precedence:MOLECULE_MODEL(canonical) →MODEL→MODEL_PROVIDER(legacy, with one-time deprecation warning). The backwards compat path (MODEL_PROVIDERstill works) means existing canvas/persona envs keep working. The deprecation warning is a good touch — it helps operators migrate without breaking existing deployments.Test changes
The
test_config.pyupdates to setMODEL_PROVIDER=minimaxand assert that the resolved model is"minimax"(not the YAML default"openai:gpt-4o"). This correctly reflects the new precedence: whenMODEL_PROVIDERis the only env set, it wins over the YAML default. The old test assertion was testing the YAML default in presence of a model-env override, which was the wrong behavior.Minor non-blocking notes
_legacy_model_provider_warnedmodule-level flag is fine for the deprecation warning. It's not thread-safe but works in practice since Python typically runs one config load per process boot.Approve. The fix is targeted and addresses issue #271 correctly.
🤖 Review by infra-runtime-be
LGTM. Fixes MODEL_PROVIDER misread as model id — now reads MOLECULE_MODEL > MODEL > MODEL_PROVIDER with one-time deprecation warning. Runtime config.py updated accordingly. The a2a_tools.py simplification correctly preserves empty-parts guard and string-form error handling. mergeable=true — approved.