fix: respect OPENCODE_DISABLE_MODELS_FETCH flag in ModelsDev.get() #307
+1
−0
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.
What does this PR do?
Fixes OPENCODE_DISABLE_MODELS_FETCH to actually work.
Previously the flag only prevented refresh() from fetching - but get() would still read cached data or fall back to build-time embedded macro data. So even with the flag set and cache deleted, users still saw models.dev models merged in.
Now get() returns {} immediately when the flag is set, so only locally configured providers/models appear.
export async function get() {
if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {}
// ...
}
Related: anomalyco#4959
How did you verify your code works?
Ran OPENCODE_DISABLE_MODELS_FETCH=true bun dev models and compared output to ~/.config/opencode/opencode.json:
Greptile Summary
This PR fixes
OPENCODE_DISABLE_MODELS_FETCHto fully prevent models.dev data from being used. Previously, the flag only preventedrefresh()from fetching new data, butget()would still read cached data or fall back to build-time embedded data. Nowget()returns an empty object immediately when the flag is set.Key changes:
if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {}at the start ofModelsDev.get()on line 79Testing: Manual verification with
OPENCODE_DISABLE_MODELS_FETCH=true bun dev modelsconfirmed correct behavior.Confidence Score: 5/5
refresh(), and has been manually tested. The empty object return is safe since the consuming code already handles empty provider records (as seen in provider.ts:608-609 where it usesmapValueswhich works fine with empty objects).Important Files Changed
get()to respectOPENCODE_DISABLE_MODELS_FETCHflagSequence Diagram
sequenceDiagram participant User participant Provider participant ModelsDev participant Flag participant Cache participant Macro Note over User,Macro: Before this PR (Flag set but still returns data) User->>Provider: Get providers Provider->>ModelsDev: get() ModelsDev->>Flag: Check OPENCODE_DISABLE_MODELS_FETCH Flag-->>ModelsDev: true Note over ModelsDev: Flag is set, but get() continues... ModelsDev->>Cache: Read cached models.json alt Cache exists Cache-->>ModelsDev: Return cached data else No cache ModelsDev->>Macro: Load embedded data Macro-->>ModelsDev: Return build-time data end ModelsDev-->>Provider: Return models.dev providers Provider-->>User: Returns local + models.dev merged Note over User,Macro: After this PR (Flag properly respected) User->>Provider: Get providers Provider->>ModelsDev: get() ModelsDev->>Flag: Check OPENCODE_DISABLE_MODELS_FETCH Flag-->>ModelsDev: true ModelsDev-->>Provider: return {} (early exit) Provider-->>User: Returns only local providers