From e2b713cced07076ccb751e28b30d235fede1fa59 Mon Sep 17 00:00:00 2001 From: nicoechaniz Date: Tue, 12 May 2026 01:38:43 +0530 Subject: [PATCH] fix(model-metadata): skip OpenRouter for known providers, add kimi/moonshot to PROVIDER_TO_MODELS_DEV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on PR #23950 by @nicoechaniz. - Add "kimi" and "moonshot" to PROVIDER_TO_MODELS_DEV → kimi-for-coding - Gate OpenRouter metadata step behind "if not effective_provider": known providers should not be overridden by community-maintained OR data - Keep the targeted Kimi-family 32k guard as a secondary safety net inside the OR gate (for unknown providers with Kimi models) Co-authored-by: nicoechaniz --- agent/model_metadata.py | 48 +++++++++++++++++++++++------------------ agent/models_dev.py | 2 ++ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/agent/model_metadata.py b/agent/model_metadata.py index 0e735c0ba8e..12d5f4170bf 100644 --- a/agent/model_metadata.py +++ b/agent/model_metadata.py @@ -1566,27 +1566,33 @@ def get_model_context_length( if ctx: return ctx - # 6. OpenRouter live API metadata (provider-unaware fallback) - metadata = fetch_model_metadata() - if model in metadata: - or_ctx = metadata[model].get("context_length", DEFAULT_FALLBACK_CONTEXT) - # Guard against stale OpenRouter metadata for Kimi-family models. - # OpenRouter reports 32768 for moonshotai/kimi-k2.6, but the model - # actually supports 262144 (models.dev + official Kimi docs agree). - # Providers that host their own Kimi endpoints (Ollama Cloud, Kimi - # Coding, Moonshot) would otherwise trip the 64k minimum-context - # guard and reject a perfectly capable model. - # The filter is narrow: only reject exactly 32768 for Kimi-named - # models. If OpenRouter ever updates its data, the stale path - # becomes dead code with no impact. - if or_ctx == 32768 and _model_name_suggests_kimi(model): - logger.info( - "Rejecting OpenRouter metadata context=%s for %r " - "(Kimi-family underreport); falling through to hardcoded defaults", - or_ctx, model, - ) - else: - return or_ctx + # 6. OpenRouter live API metadata — provider-unaware fallback. + # Only consulted when the provider is unknown (no effective_provider), + # because OpenRouter data is community-maintained and can be incorrect + # for models that belong to known providers with curated defaults. + if not effective_provider: + metadata = fetch_model_metadata() + if model in metadata: + or_ctx = metadata[model].get("context_length", DEFAULT_FALLBACK_CONTEXT) + # Guard against stale OpenRouter metadata for Kimi-family models. + # OpenRouter reports 32768 for moonshotai/kimi-k2.6, but the model + # actually supports 262144 (models.dev + official Kimi docs agree). + # Providers that host their own Kimi endpoints (Ollama Cloud, Kimi + # Coding, Moonshot) would otherwise trip the 64k minimum-context + # guard and reject a perfectly capable model. + # The filter is narrow: only reject exactly 32768 for Kimi-named + # models. If OpenRouter ever updates its data, the stale path + # becomes dead code with no impact. + if or_ctx == 32768 and _model_name_suggests_kimi(model): + logger.info( + "Rejecting OpenRouter metadata context=%s for %r " + "(Kimi-family underreport); falling through to hardcoded defaults", + or_ctx, model, + ) + else: + return or_ctx + + # 7. (reserved) # 8. Hardcoded defaults (fuzzy match — longest key first for specificity) # Only check `default_model in model` (is the key a substring of the input). diff --git a/agent/models_dev.py b/agent/models_dev.py index 0398571559e..d709d7176d4 100644 --- a/agent/models_dev.py +++ b/agent/models_dev.py @@ -145,7 +145,9 @@ PROVIDER_TO_MODELS_DEV: Dict[str, str] = { "openai": "openai", "openai-codex": "openai", "zai": "zai", + "kimi": "kimi-for-coding", "kimi-coding": "kimi-for-coding", + "moonshot": "kimi-for-coding", "stepfun": "stepfun", "kimi-coding-cn": "kimi-for-coding", "minimax": "minimax",