fix(cli): respect -m flag over agent model config#14503
Open
DerrickBarra wants to merge 6 commits intoanomalyco:devfrom
Open
fix(cli): respect -m flag over agent model config#14503DerrickBarra wants to merge 6 commits intoanomalyco:devfrom
DerrickBarra wants to merge 6 commits intoanomalyco:devfrom
Conversation
The CLI -m flag was being ignored because: 1. Agent model took precedence over CLI flag 2. isModelValid() required provider to be in synced cache This caused custom providers like openrouter/* to fail with 'No provider selected' or fallback to default models. Fix by checking CLI -m flag first without strict validation: - currentModel() now checks args.model before agent model - fallbackModel() trusts CLI models even if not in cache This allows users to specify any provider/model via CLI: opencode -m openrouter/meta-llama/llama-3.1-8b-instruct Fixes #<issue-number>
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
The CLI -m flag was being ignored because: 1. Agent model took precedence over CLI flag 2. isModelValid() required provider to be in synced cache This fix: 1. Adds allowUncached parameter to isModelValid() for CLI models 2. Passes CLI -m flag through getFirstValidModel() chain with priority 3. Allows custom providers like openrouter/* to work even if not in cache Fixes anomalyco#14502
getFirstValidModel() now destructures the model to return only providerID and modelID, stripping the allowUncached flag. This ensures the return type matches what the rest of the codebase expects while still using allowUncached for validation.
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.
Issue for this PR
Closes #14502
Type of change
What does this PR do?
Problem: The CLI -m flag was being ignored when an agent has a model configured or when the provider is not yet in the synced cache. This caused the TUI to show 'No provider selected' or fall back to default models (e.g., 'big-pickle') instead of using the CLI-specified model.
Root Cause: currentModel() checked agent model before CLI args, and isModelValid() required the provider to be in sync.data.provider cache.
Fix: Check CLI args.model first without strict validation in both currentModel() and fallbackModel().
How did you verify your code works?
Built OpenCode from source and tested with: opencode -m openrouter/meta-llama/llama-3.1-8b-instruct
Before: TUI showed 'Build · big-pickle' with 'Free usage exceeded' error
After: TUI shows 'Build · llama-3.1-8b-instruct' and uses OpenRouter correctly.
Checklist