From cb0065eba7d291b8ac441502ec713d4bbd571340 Mon Sep 17 00:00:00 2001 From: allenliang2022 Date: Sun, 31 May 2026 16:37:07 +0800 Subject: [PATCH] fix(context): scope global model.context_length to model.default only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The global `model.context_length` setting in config.yaml was being applied to every session regardless of which model was active. This silently clobbered the real metadata of any non-default model — e.g. a user with `model.default: claude-opus-4.8` + `model.context_length: 232000` who switched a session to a 1M-context variant would see the session capped at 232K instead of 1M. Now the global override is only applied when the session model equals `model.default`. Other models fall through to their real metadata. Repro: config.yaml: model: default: claude-opus-4.8 context_length: 232000 Switch a session to claude-opus-4.7-1m-internal — before this fix the context indicator shows 232K; after the fix it shows 1M. --- api/routes.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/routes.py b/api/routes.py index fa6c75579..33a9956be 100644 --- a/api/routes.py +++ b/api/routes.py @@ -2045,8 +2045,16 @@ def _resolve_context_length_for_session_model( try: _model_cfg_load = _cfg_for_cl.get('model', {}) if isinstance(_cfg_for_cl, dict) else {} if isinstance(_model_cfg_load, dict): + # Only apply the global model.context_length override when the + # session model matches model.default. Otherwise a global cap + # set for the default model (e.g. 232000) silently clobbers + # other models' real metadata (e.g. a 1M-context variant). + _cfg_default_model = str(_model_cfg_load.get('default') or '').strip() _raw_cfg_ctx_load = _model_cfg_load.get('context_length') - if _raw_cfg_ctx_load is not None: + if _raw_cfg_ctx_load is not None and ( + not _cfg_default_model + or _cfg_default_model == model_for_lookup + ): try: _parsed_load = int(_raw_cfg_ctx_load) if _parsed_load > 0: