Repository navigation
Description
Epic: #929 | Blocked by: — | Phase: 2 | Related: #1516 restructures the intrinsic path and is the natural place to land the fix
Problem
On OpenAIBackend, any call whose model_options include a raw model entry crashes at the API call site with a bare Python duplicate-kwarg error, instead of either honouring the override or failing with a Mellea-side explanation:
TypeError: ...chat.completions.create... got multiple values for keyword argument 'model'
How it gets there
In OpenAIBackend._generate_from_intrinsic (mellea/backends/openai.py), the model key passes through three steps, in this order:
- The intrinsic rewriter sets
modelto the intrinsic name in its parameters (the Granite Switch convention: the model parameter selects the adapter) —mellea/formatters/granite/intrinsics/input.py. EmbeddedBinding.apply_activationpops it (mellea/backends/adapters/_core.py), because for an embedded adapter the real model is the base model already being served.- The user overlay
api_params.update(user_api_params)runs after the pop, andModelOption.replace_keyscopies unknown keys through (mellea/backends/model_options.py) — so a user-suppliedmodelre-entersapi_params.
The final call is create(model=self._model_id, ..., **api_params), so the re-injected key collides with the explicit keyword argument.
On the ordinary (non-intrinsic) chat path the same collision exists without steps 1-2: generate_from_chat_context also calls create(model=self._model_id, ..., **backend_specific), and backend_specific is built by the same key-copying overlay (mellea/backends/openai.py). The intrinsic path is simply where a user is likely to pass the key, because the rewriter's io.yaml defaults put model in the parameter space and the docs show it.
Reproduction
Verified locally (against the #1559 branch, adapter registered, OpenAI async client mocked at the network boundary):
backend.add_adapter(
EmbeddedIntrinsicAdapter("answerability", config=config, technology="alora")
)
mot, _ = await mfuncs.aact(
Intrinsic("answerability"), ctx, backend, strategy=None,
model_options={"model": "answerability_alora"},
)
# -> TypeError: got multiple values for keyword argument 'model'Decision (2026-08-20) — reject
Chosen during the PR #1559 review session: a user-supplied model in model_options should fail fast with a clear error that redirects to the established model-selection mechanism, rather than colliding at create() or being silently dropped. Rationale, all verified in the codebase:
- Model selection in Mellea is a backend/session-level act, not a per-call option:
OpenAIBackendfixesmodel_idat construction and sends it on every call. - The framework's own multi-model patterns use distinct backend objects, not
model_options:SOFAISamplingStrategytakes separates1_solver_backend/s2_solver_backend/judge_backend, andm serve's model-routing deliberately stripsmodelout ofmodel_options(cli/serve/app.py: "used for routing, not generation") and routes by starting a session against the chosen model. - A multi-model single endpoint is already expressible today as two backends sharing a
base_url— honouring the key would introduce a parallel second selection mechanism instead of enabling anything new. - On intrinsic/Switch calls the field additionally carries adapter-selection semantics, so honouring it there would put two contradictory instructions in one request.
Suggested error wording: "model cannot be set via model_options on OpenAIBackend — model selection happens at the backend/session level (construct a backend per model, or start a session against the chosen model_id)."
Implementation note: one check in the per-call model-options handling covers both the chat and intrinsic paths (the collision is identical on both); add a test per path.
Expected behaviour (options considered)
The semantics are currently decided by accident (an obscure crash). One of:
- Reject — calls reject a user-supplied
modelwith a clear error (the backend's model is fixed at construction). - Honour — per-call model routing:
create(model=<user value>), so one backend could target different models on a multi-model OpenAI-compatible server. Note this is not achievable cleanly on the intrinsic/Switch path, where the model field doubles as adapter-selection semantics — honouring it there would put two contradictory instructions in one request — so honouring would at minimum need an intrinsic exception (reject there, honour elsewhere). - Drop — ignore the key (the backend's model wins); the override is silently discarded.
Context
- Pre-existing: the ordering predates feat(backends): EmbeddedBinding implements apply_activation (Granite Switch path); remove render_controls + set_request_adapter (Epic #929 Phase 2) #1142 — feat(backends): EmbeddedBinding implements apply_activation (Granite Switch path); remove render_controls + set_request_adapter (Epic #929 Phase 2) #1142 only relocated the pop from the inline block into
EmbeddedBinding.apply_activation, at the same position relative to the user overlay. Noted in PR feat(backends): EmbeddedBinding implements apply_activation (Granite Switch path); remove render_controls + set_request_adapter (Epic #929 Phase 2) #1559's second review round (2026-08-19) and deliberately left out of that PR's scope. - Trigger: any deliberate raw
modelkey inmodel_optionson anyOpenAIBackendcall; the high-levelcore.*/rag.*wrappers do not pass one, and intrinsics are the most likely entry point because the key is visible in their parameter space. - The fix belongs in
OpenAIBackend's model-options handling, not inapply_activation; the reject/honour/drop decision above is what this issue is for. refactor(intrinsics): resolve the adapter's output contract from the adapter, not a parallel argument (Epic #929 Phase 2) #1516 (output-contract resolution) restructures the intrinsic part of the path and is a natural place to align on it.
Activity
[-]Intrinsic calls: user-supplied model in model_options collides with the binding's model pop (follow-up to #1142)[/-][+]OpenAIBackend: user-supplied model in model_options collides with the hardcoded model kwarg (follow-up to #1142)[/+]test(backends): cover OpenAI completions model option rejection (gene…
fix(backends): reject OpenAI model option overrides (generative-compu…