Repository navigation
fix: resolve model refs against the registry snapshot before switching - #404
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #403.
Root cause
The backend registry validates
(providerId, modelId)by exact string match — no alias layer at that boundary (upstreampackages/provider/src/registry.tsvalidateSelection). The bridge advertised model values fromloadAllModels()(legacybuiltin:dialect, frozen config.json model lists) andapplyModelSwitchsent them tosession/setModelnearly 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 asProvider Registry 中不存在 Modeland clients (T3 Code) aborted the session open.Fix
src/config/model-resolution.ts— single inbound resolution layer: parsesprovider\\model,provider/model,custom:<urlencoded>:<model>and legacy bare ids; folds config ↔ registry provider dialects (accountProviderIdFor/configProviderIdFor, mirroring upstream's frozenlegacy-model-provider-identity.tsmap); case-folds model ids against the snapshot vocabulary (mirrors upstreamnormalizeOfficialGlmModelId); resolves bare ids only when unique. No cross-provider substitution — upstream explicitly declines family mapping.applyModelSwitchresolves every value againstserver.modelAvailabilityfirst; 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>).lastSwitchedModelValue): the materialization pin,session/set_config_option, thesetModelextension and/modelnow remember the registry-dialect value the switch actually landed on, so post-resume re-asserts never replay a stale dialect.session/set_config_optionmodel failures throw a message naming the rejected value.Verified:
pnpm typecheckclean, full suite 1264 passed, lint 0 errors, Review pass with 0 findings ≥80 confidence.