fix(provider): strip trailing slash from model name strings - #43492
fix(provider): strip trailing slash from model name strings#43492AndyS77 wants to merge 1 commit into
Conversation
Model names with trailing slashes (e.g. 'qwen3-4b/') caused lookup
failures because split('/') produced an empty or slash-bearing modelID
that didn't match stored keys. Strip trailing slashes before splitting
in all model-string parse functions.
Closes anomalyco#43473
Co-Authored-By: zai-glm-52 <noreply@ai.local>
Agent: @bug-fix
Scope: anomalyco#43473
|
The following comment was made by an LLM, it may be inaccurate: I found a related PR: fix(core): strip trailing slash from parsed model IDs (PR #43490) This PR appears to be addressing the exact same issue - stripping trailing slashes from model parsing. PR #43490 likely covers similar changes in the core package related to model ID parsing. You may want to check if there's any overlap in scope or if one PR should be closed in favor of the other, or if they should be consolidated. |
|
Thanks for the heads up. I reviewed #43490 — it fixes the same bug but only in packages/core/src/model.ts (1 file, 1 line). This PR covers the same fix across all five model-string parse functions that had the issue: parseModel in provider.ts, parse in core/model.ts, parse in tui/util/model.ts, pick in cli/cmd/run.ts, and parseModelSelection in acp/config-option.ts. Happy to consolidate if a maintainer prefers — both fix #43473. |
Issue for this PR
Closes #43473
Type of change
What does this PR do?
Model names with trailing slashes (e.g.
qwen3-4b/) caused lookup failures. WhenparseModel("qwen3-4b/")was called,split("/")produced an emptymodelID(or a slash-bearing one forprovider/model/), which never matched the keys inprovider.models. This resulted in aModelNotFoundErroreven though the model was correctly loaded and listed.The fix strips trailing slashes with
.replace(/\/+$/, "")before.split("/")in all model-string parse functions:packages/opencode/src/provider/provider.ts—parseModel()packages/core/src/model.ts—parse()packages/tui/src/util/model.ts—parse()packages/opencode/src/cli/cmd/run.ts—pick()packages/opencode/src/acp/config-option.ts—parseModelSelection()(trimmed once at top, used in all branches)How did you verify your code works?
Added tests for trailing-slash handling in all affected packages:
packages/opencode/test/provider/provider.test.ts— 3 tests: trailing slash on model, trailing slash on provider/model, multiple trailing slashespackages/core/test/model.test.ts— 2 tests: basic parse, strips trailing slashpackages/tui/test/util/model.test.ts— 1 test: strips trailing slashpackages/opencode/test/acp/config-option.test.ts— 1 test: strips trailing slash from model selectionAll tests pass.
Screenshots / recordings
N/A — no UI changes.
Checklist