fix(context): scope global model.context_length to model.default only

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.
This commit is contained in:
allenliang2022
2026-05-31 16:37:07 +08:00
parent d4d87a901b
commit cb0065eba7
+9 -1
View File
@@ -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: