Skip to content

fix: resolve model refs against the registry snapshot before switching - #404

Merged
william0wang merged 1 commit into
mainfrom
fix/model-resolution-403
Nov 18, 2026
Merged

william0wang merged 1 commit into
mainfrom
fix/model-resolution-403

Conversation

@william0wang

Copy link
Copy Markdown
Owner

Fixes #403.

Root cause

The backend registry validates (providerId, modelId) by exact string match — no alias layer at that boundary (upstream packages/provider/src/registry.ts validateSelection). The bridge advertised model values from loadAllModels() (legacy builtin: dialect, frozen config.json model lists) and applyModelSwitch sent them to session/setModel nearly raw — only the provider id was dialect-translated, never the pair validated/normalized against the registry. Any drift between the advertised list and the live registry (stale model id, dialect mismatch, probe timeout leaving the legacy menu in place) ended as Provider Registry 中不存在 Model and clients (T3 Code) aborted the session open.

Fix

  • New src/config/model-resolution.ts — single inbound resolution layer: parses provider\\model, provider/model, custom:<urlencoded>:<model> and legacy bare ids; folds config ↔ registry provider dialects (accountProviderIdFor/configProviderIdFor, mirroring upstream's frozen legacy-model-provider-identity.ts map); case-folds model ids against the snapshot vocabulary (mirrors upstream normalizeOfficialGlmModelId); resolves bare ids only when unique. No cross-provider substitution — upstream explicitly declines family mapping.
  • applyModelSwitch resolves every value against server.modelAvailability first; an unresolved provider-qualified ref is still sent dialect-folded (the backend is the final authority — the snapshot may lag a just-added model); a bare id absent from a live snapshot stays final (no request). The failure warn now names the registry context (N model(s) under <provider>).
  • All switch paths record the landed identity (lastSwitchedModelValue): the materialization pin, session/set_config_option, the setModel extension and /model now remember the registry-dialect value the switch actually landed on, so post-resume re-asserts never replay a stale dialect.
  • session/set_config_option model failures throw a message naming the rejected value.

Verified: pnpm typecheck clean, full suite 1264 passed, lint 0 errors, Review pass with 0 findings ≥80 confidence.

Every model switch pinned stale, legacy-dialect ids onto the wire: the
backend registry validates (providerId, modelId) by exact string match
with no alias layer, so an advertised value from a frozen config.json
(builtin:zai-coding-plan\GLM-5.3) failed with 'Provider Registry
中不存在 Model' and clients aborted the session open (T3 Code, #403).

New model-resolution.ts normalizes every inbound spelling — backslash /
slash separators, custom: URL-encoding, config-vs-registry provider
dialects, official model id case — against the session's registry
snapshot before session/setModel. Provider-qualified refs that resolve
to nothing are still sent dialect-folded (the backend is the final
authority; the snapshot may lag); bare ids keep their uniqueness gate.
All switch paths now remember the registry-dialect identity the switch
landed on (lastSwitchedModelValue), so re-asserts never replay a stale
dialect, and the switch-failure warn carries registry context.
@william0wang
william0wang merged commit ae758d7 into main Nov 18, 2026
2 checks passed
@william0wang
william0wang deleted the fix/model-resolution-403 branch November 18, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

T3 Code integration breaks with ≥0.85.0

1 participant