Skip to content

The agent that grows with you

fix(upstage): default new Solar models to the 512K context window

Changhyun Min98f758ae7e8d
diff --git a/agent/model_metadata.py b/agent/model_metadata.py
index 086f17b3a03..feccf70cd2e 100644
--- a/agent/model_metadata.py
+++ b/agent/model_metadata.py
@@ -376,8 +376,9 @@ DEFAULT_CONTEXT_LENGTHS = {
"grok-3": 131072, "grok-2": 131072, "grok": 131072,
# Kimi — K3 is 1 Mi (matches the endpoint-scoped override); older Kimi 256K.
"kimi-k3": 1_048_576, "kimi": 262144,
- # Upstage Solar — /v1/models returns no context_length; dated variants resolve via prefix.
- "solar-open2": 262144, "solar-pro3": 131072, "solar-pro2": 65536, "solar-mini": 32768,
+ # Upstage Solar — /v1/models returns no context_length. Later generations and new lineups
+ # default to 512K (Upstage /v1/solar/models max_model_len, 2026-09).
+ "solar-open2": 262144, "solar-pro3": 131072, "solar-pro2": 65536, "solar-mini": 32768, "solar-": 524288,
# Tencent Hunyuan (262144 = 256 × 1024, aligned with OpenRouter live metadata)
"hy4-preview": 1_048_576, "hy3-preview": 262144, "hy3": 262144,
# "Ox Alpha" stealth model (OpenCode Zen / OpenRouter slugs); "Union Alpha" stealth model
@@ -537,9 +538,23 @@ def _server_root(base_url: str) -> str:
return server_url[:-3] if server_url.endswith("/v1") else server_url
+# Families whose generation digit is part of the name (``solar-mini`` vs ``solar-mini4``): their keys
+# match only on an id boundary, after folding aggregator slugs (``solar-pro-3``) into the native form.
+_BOUNDARY_MATCHED_KEY_PREFIXES = ("solar-",)
+_HYPHENATED_GENERATION_RE = re.compile(
+ rf"((?:{'|'.join(map(re.escape, _BOUNDARY_MATCHED_KEY_PREFIXES))})[a-z]+)-(\d{{1,2}})(?=[-:.@]|$)")
+
+
def _catalog_key_matches(key: str, model_lower: str) -> bool:
"""Substring match with version separators normalised on both sides, so a relay slug like
- ``z-ai-glm-5-3`` still hits the ``glm-5.3`` entry instead of the ``glm`` catch-all (#97398)."""
+ ``z-ai-glm-5-3`` still hits the ``glm-5.3`` entry instead of the ``glm`` catch-all (#97398).
+ Boundary-matched families: a key must be followed by ``-:.@`` or the end, and a key ending in
+ ``-`` is the family default for bare names (``org/`` allowed) continuing with a lineup letter."""
+ if key.startswith(_BOUNDARY_MATCHED_KEY_PREFIXES):
+ model_lower = _HYPHENATED_GENERATION_RE.sub(r"\1\2", model_lower)
+ if key.endswith("-"):
+ return re.match(re.escape(key) + "[a-z]", model_lower.rsplit("/", 1)[-1]) is not None
+ return re.search(re.escape(key) + r"(?:[-:.@]|$)", model_lower) is not None
return key in model_lower or _normalize_model_version(key) in _normalize_model_version(model_lower)
diff --git a/plugins/model-providers/upstage/__init__.py b/plugins/model-providers/upstage/__init__.py
index cedd34c267b..3a2ccb57e90 100644
--- a/plugins/model-providers/upstage/__init__.py
+++ b/plugins/model-providers/upstage/__init__.py
@@ -5,6 +5,7 @@ so an unset reasoning_config defaults reasoning ON at ``medium``, matching the
"medium (default)" the /reasoning panel shows. Explicit settings always win.
"""
+import re
from typing import Any
from agent.reasoning_effort import EFFORT_LADDER, SOLAR_EFFORTS, clamp_effort
@@ -12,8 +13,9 @@ from providers import register_provider
from providers.base import ProviderProfile
# Deny-list on purpose: new Solar models are assumed reasoning-capable; only these known
-# non-reasoning families ignore reasoning_effort. Substring match covers dated variants.
-_NON_REASONING_MODEL_MARKERS = ("solar-mini", "syn-pro")
+# non-reasoning families ignore reasoning_effort. ``solar-mini`` covers its dated ids
+# (solar-mini-250422) but not later mini generations (solar-mini4), which do reason.
+_NON_REASONING_MODEL_RE = re.compile(r"solar-mini(?:[-:.@]|$)|syn-pro")
class UpstageProfile(ProviderProfile):
@@ -23,7 +25,7 @@ class UpstageProfile(ProviderProfile):
self, *, reasoning_config: dict | None = None, model: str | None = None, **context
) -> tuple[dict[str, Any], dict[str, Any]]:
m = (model or "").strip().lower()
- if any(marker in m for marker in _NON_REASONING_MODEL_MARKERS):
+ if _NON_REASONING_MODEL_RE.search(m):
return {}, {}
if not reasoning_config or not isinstance(reasoning_config, dict):
return {}, {"reasoning_effort": "medium"} # unset -> reasoning ON for agents
diff --git a/tests/agent/test_model_metadata.py b/tests/agent/test_model_metadata.py
index 9b4360f3e65..868976e8e91 100644
--- a/tests/agent/test_model_metadata.py
+++ b/tests/agent/test_model_metadata.py
@@ -318,6 +318,49 @@ class TestDefaultContextLengths:
patch("agent.models_dev.fetch_models_dev", return_value={}):
assert get_model_context_length(model, provider=provider, base_url=base_url) == 1_048_576
+ @staticmethod
+ def _upstage_ctx(model):
+ with patch("agent.model_metadata.get_cached_context_length", return_value=None), \
+ patch("agent.model_metadata._query_ollama_api_show", return_value=None), \
+ patch("agent.model_metadata.fetch_endpoint_model_metadata", return_value={}), \
+ patch("agent.model_metadata.fetch_model_metadata", return_value={}), \
+ patch("agent.models_dev.fetch_models_dev", return_value={}):
+ return get_model_context_length(model, provider="upstage", base_url="https://api.upstage.ai/v1")
+
+ def test_upstage_solar_ids_match_legacy_keys_only_on_an_id_boundary(self):
+ """Upstage /v1/models has no context field, so the table decides. ``solar-mini`` must not
+ claim ``solar-mini4`` (its 32K is below MINIMUM_CONTEXT_LENGTH, so the agent refused to
+ start); Solar ids without a legacy key get the Solar family window, not the 256K fallback."""
+ from agent.model_metadata import MINIMUM_CONTEXT_LENGTH, _longest_key_match
+
+ family = DEFAULT_CONTEXT_LENGTHS["solar-"]
+ assert family > DEFAULT_FALLBACK_CONTEXT
+ for model in ("solar-mini4", "solar-mini4-preview", "upstage/solar-mini4", "solar-pro4",
+ "solar-pro4-260806", "solar-pro4-quant", "solar-mini12", "solar-foo"):
+ assert self._upstage_ctx(model) == family, model
+ # The gateway labels a table miss as "default"; it must agree with the resolver.
+ assert _longest_key_match(DEFAULT_CONTEXT_LENGTHS, model.lower())[1] == family, model
+
+ # Legacy ids keep their own (smaller) windows: dated, org-prefixed, aggregator-hyphenated
+ # (``solar-pro-3``) and quant/variant-suffixed ids included.
+ for variant, bare in (("solar-mini-250422", "solar-mini"), ("upstage/solar-mini", "solar-mini"),
+ ("solar-pro2-251215", "solar-pro2"), ("solar-pro3-260323", "solar-pro3"),
+ ("upstage/solar-pro-3", "solar-pro3"), ("solar-pro3.1", "solar-pro3"),
+ ("solar-open2@q4_k_m", "solar-open2")):
+ assert self._upstage_ctx(variant) == self._upstage_ctx(bare), variant
+ assert self._upstage_ctx("solar-mini") < MINIMUM_CONTEXT_LENGTH
+ assert self._upstage_ctx("solar-pro3") < family
+
+ # Ids merely containing "solar", and open-weight Solar ids, are not Solar API lineups.
+ for model in ("ft:solar-news-correction", "acme-solar-foo", "upstage/solar-10.7b-instruct"):
+ assert self._upstage_ctx(model) != family, model
+
+ def test_explicit_solar_key_beats_the_family_default(self):
+ with patch.dict(DEFAULT_CONTEXT_LENGTHS, {"solar-foo": 300_000}):
+ assert self._upstage_ctx("solar-foo") == 300_000
+ assert self._upstage_ctx("solar-foo-260101") == 300_000
+ assert self._upstage_ctx("solar-foo2") == DEFAULT_CONTEXT_LENGTHS["solar-"]
+
def test_empty_model_uses_fallback_context(self):
assert get_model_context_length("") == DEFAULT_FALLBACK_CONTEXT
assert get_model_context_length(None) == DEFAULT_FALLBACK_CONTEXT # type: ignore[arg-type]
diff --git a/tests/plugins/model_providers/test_upstage_profile.py b/tests/plugins/model_providers/test_upstage_profile.py
index 39cd93b93a4..bc7120e7026 100644
--- a/tests/plugins/model_providers/test_upstage_profile.py
+++ b/tests/plugins/model_providers/test_upstage_profile.py
@@ -100,7 +100,9 @@ class TestUpstageReasoning:
)
assert top_level == {}
- @pytest.mark.parametrize("model", ["solar-pro3", "solar-pro", "solar-open2"])
+ @pytest.mark.parametrize(
+ "model", ["solar-pro3", "solar-pro", "solar-open2", "solar-mini4", "solar-mini4-preview"]
+ )
def test_no_config_defaults_reasoning_on(self, upstage_profile, model):
# Unset reasoning_config → default ON at medium (matches the /reasoning
# "medium (default)" label), not Solar's server default of minimal/off.
@@ -108,10 +110,13 @@ class TestUpstageReasoning:
assert top_level == {"reasoning_effort": "medium"}
- @pytest.mark.parametrize("model", ["solar-mini", "solar-mini-202610", "syn-pro"])
+ @pytest.mark.parametrize(
+ "model", ["solar-mini", "solar-mini-250422", "solar-mini-202610", "solar-mini@q4", "syn-pro"]
+ )
def test_deny_listed_models_never_send_reasoning(self, upstage_profile, model):
# solar-mini / syn-pro ignore reasoning_effort, so never send it —
- # even when the user explicitly enables reasoning.
+ # even when the user explicitly enables reasoning. Later mini
+ # generations (solar-mini4) do reason and are not deny-listed.
extra_body, top_level = upstage_profile.build_api_kwargs_extras(
reasoning_config={"enabled": True, "effort": "high"}, model=model
)