Repository navigation
Description
Summary
When jcode is used as a Zed external agent over ACP, the model selector exposed via
configOptions / session/set_config_option lists models from the active
OpenAI-compatible profile's catalog, but switching to any of them fails with
OPENROUTER_API_KEY not found in environment or ~/.config/jcode/openrouter.env.
The session silently stays on the fallback model (deepseek-v4-pro). The advertised
models are unselectable, and the host receives a JSON-RPC error instead of a model change.
Environment
- jcode v0.71.1 (dd8755f), Linux x86_64
- Host: Zed via ACP (
client_instance_id=acp) - Active provider:
opencode-gocatalog profile →https://opencode.ai/zen/go/v1,
authOPENCODE_GO_API_KEY(in~/.config/jcode/opencode-go.env);[providers]
empty inconfig.toml OPENROUTER_API_KEYis not configured anywhere (no env var, no
~/.config/jcode/openrouter.env)
Steps to reproduce
- Configure only the
opencode-goprofile (jcode login --provider opencode-go)
and no OpenRouter key. - Start a session in Zed with
jcode acpas the external agent. The default model
deepseek-v4-proworks (streams tohttps://opencode.ai/zen/go/v1). - Open the agent panel model selector (populated from ACP
configOptions) and pick
deepseek-v4-flash. - Zed sends
session/set_config_option(configId: "model",value: "deepseek-v4-flash");
jcode logsserver_model_change_failedand the model staysdeepseek-v4-pro.
Expected behavior
Switching to a model that the active profile's own catalog already serves should
select it on that same profile (same endpoint and credentials). The selector should
only present models that can actually be activated.
Actual behavior
Every switch to a non-default model fails:
[ERROR] EVENT event=server_model_change_failed error="OPENROUTER_API_KEY not found in environment or /home/xxx/.config/jcode/openrouter.env (retried after reloading auth from disk: OPENROUTER_API_KEY not fou..." fallback_model=deepseek-v4-pro
The ACP client receives a JSON-RPC error (Failed to set model: ...) and the session
keeps running deepseek-v4-pro.
Root cause
The ACP layer sends bare model ids. session_config_options
(src/cli/acp.rs:1015) builds option values from available_models (deduped bare
ids from listable_model_names_from_routes), and handle_set_config_option
(src/cli/acp.rs:506) forwards Request::SetModel { model: "deepseek-v4-flash" }
verbatim.
In MultiProvider::set_model (crates/jcode-base/src/provider/mod.rs), the
unprefixed id first hits the "keep unprefixed names on that active endpoint" branch
(~L1922):
if self.active_provider() == ActiveProvider::OpenRouter
&& self.active_openrouter_execution_provider()
.is_some_and(|provider| !provider.supports_provider_routing_features())
{
return self.set_model_on_provider(ActiveProvider::OpenRouter, requested_model);
}That branch intends to keep bare ids on the active OpenAI-compatible endpoint, but
the OpenRouter arm it calls then computes needs_rebind
(provider/mod.rs:1138) as true whenever the slot is an OpenAI-compatible
catalog profile runtime whose profile id is not the generic openai-compatible
profile (only OPENAI_COMPAT_PROFILE.id is exempt):
profile.id != crate::provider_catalog::OPENAI_COMPAT_PROFILE.idThe slot is therefore rebound to the real OpenRouter API-key runtime via
new_openrouter_api_key_runtime() (crates/jcode-provider-openrouter-runtime/src/lib.rs:1582),
which fails when OPENROUTER_API_KEY is absent, even though the requested model is
already served by the active profile's own catalog. set_model_with_auth_refresh
retries once after reloading auth from disk, fails again, and send_model_changed_result
logs server_model_change_failed with the previous model as fallback.
The TUI picker avoids this by emitting route-qualified specs (<profile>:<model>,
see issue #444); the ACP path, /model <bare-id> and session-resume paths send bare
ids and hit the rebind. Confirmed present on both master and v0.71.1.
Suggested fix
- Resolver (recommended, B1): in the OpenRouter arm of
set_model_on_provider_with_credential_modes, skip the rebind when the active
profile's own route catalog already serves the requested model
(route.model == modelwithapi_method == "openai-compatible:<active profile>"
andavailable), and just callset_modelon the existing slot. This matches the
intent of the "keep unprefixed names on the active endpoint" branch and fixes every
bare-id path (ACP,/model <id>, session resume), not just the ACP surface. - ACP layer (B2): build
configOptionsmodel values as profile-qualified specs
(<profile>:<model>, e.g.opencode-go:deepseek-v4-flash) with the bare id as
display name, deduplicating in favor of the active profile (same preference rule as
openai_compatible_profile_owning_model). This is the server-side analog of the
workaround used in ACP layer: no model catalog, nosession/set_model, no reasoning-effort control #813.
Related issues
- ACP layer: no model catalog, no
session/set_model, no reasoning-effort control #813 documents the same underlying resolver problem as a side note of an ACP
feature request for hermes-family hosts (session/set_model). Filed separately
because this is a bug in the already-shippedconfigOptionspath used by Zed, and
the resolver fix (B1) is independent of the ACP contract decision. - ACP mode doesn't advertise model selector, session modes, or token usage — all present in the TUI but missing over ACP #765 (closed) introduced the
configOptionsmodel selector that Zed uses.
Activity
1jehuang commentedon Aug 9, 2026
Confirmed from the resolver path. A bare model ID already served by the active named catalog profile can incorrectly trigger a native OpenRouter rebind. I am preparing a focused resolver fix that preserves the active profile, with regression coverage.
--- — Jcode agent (automated triage), on behalf of @1jehuang
1jehuang commentedon Aug 9, 2026
The verified fix is now in PR #856. Focused regressions passed, and the combined TUI build completed successfully.
--- — Jcode agent (automated triage), on behalf of @1jehuang
fix: preserve active catalog profile for model switches (fixes 1jehua…
chore: sync fork with upstream jcode (fresh merge onto current master) (
maxivillus commentedon Aug 18, 2026
Thanks for the fix in #856 — the
session/set_config_optionmodel-switch path is fixed.One related path is still broken on v0.77.1 though:
Resumed ACP sessions. When an ACP session is resumed and its provider context is still
an OpenAI-compatible runtime (e.g. a proxy profile), a bare model ID from the gpt-* family
is still resolved back to the generic native-OpenRouter slot — the session then fails with
OPENROUTER_API_KEY not found(or hits the wrong backend) instead of routing to theconfigured native OpenAI OAuth runtime that owns the model family.
The reverse-check of the #856 fix against v0.77.1 confirms it only covers the switcher
path, not session resume. We carry a small local patch for it (bare gpt-* → native OAuth
runtime on resume; ~60 lines incl. regression tests) — happy to open a PR if the fix shape
is acceptable.
Reference patch (applies cleanly on v0.77.1, diff inline):
fix: preserve active catalog profile for model switches (fixes 1jehua…
fix: preserve active catalog profile for model switches (fixes 1jehua…
fix: preserve active catalog profile for model switches (fixes 1jehua…
fix: preserve active catalog profile for model switches (fixes 1jehua…
fix: preserve active catalog profile for model switches (fixes 1jehua…
fix: preserve active catalog profile for model switches (fixes 1jehua…