Skip to content

Fix OpenCode model preference sync and defaults#90

Merged
gricha merged 2 commits intomainfrom
fix/opencode-model-preferences
Jan 11, 2026
Merged

Fix OpenCode model preference sync and defaults#90
gricha merged 2 commits intomainfrom
fix/opencode-model-preferences

Conversation

@gricha
Copy link
Copy Markdown
Owner

@gricha gricha commented Jan 11, 2026

Summary

  • Fixes OpenCode workspace sync to respect configured model (agents.opencode.model) and host ~/.config/opencode/opencode.json model instead of always forcing claude-sonnet-4.
  • Makes model default selection deterministic on Web + Mobile (prefers Opus/Sonnet variants when available, and validates configured model exists in the discovered list).

Testing

  • bun run validate

Notes

  • OpenCode model priority is now: perry config → host opencode.json → fallback default.

Comment on lines 350 to +358
useEffect(() => {
const fetchAgentType = agentType === 'opencode' ? 'opencode' : 'claude-code'
api.listModels(fetchAgentType, workspaceName)
.then(({ models }) => {
.then(async ({ models }) => {
setAvailableModels(models)
if (models.length > 0 && !selectedModel) {
api.getAgents().then((agents) => {
const configModel = fetchAgentType === 'opencode'
? agents.opencode?.model
: agents.claude_code?.model
const defaultModel = configModel || models[0].id
setSelectedModel(defaultModel)
}).catch(() => {
setSelectedModel(models[0].id)
})

if (models.length === 0) return

const current = selectedModelRef.current

This comment was marked as outdated.

@gricha
Copy link
Copy Markdown
Owner Author

gricha commented Jan 11, 2026

Sentry’s race-condition note is valid: the listModels promise from an old workspaceName can resolve after you’ve switched workspaces and overwrite availableModels / selectedModel.

Fix: web/src/components/Chat.tsx now guards the async handler with an active flag set to false in the useEffect cleanup, so stale responses are ignored.

Pushed in commit f089271.

@gricha gricha merged commit 0a1bb14 into main Jan 11, 2026
9 checks passed
@gricha gricha deleted the fix/opencode-model-preferences branch January 11, 2026 04:54
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.

1 participant