fix(opencode-go): refresh model catalog on startup without re-login - #21
Conversation
The OpenCode Go model->provider map is materialized into config.toml at login and read from there at runtime, so bundled/served catalog changes (new models like qwen3.7-max, corrected Qwen shape) never reached an existing install until a manual `pythinker login --opencode-go`. The every-startup background `refresh_managed_models` task already keeps other managed providers current, but it silently skipped OpenCode Go: its provider keys parse to non-existent platform ids, and the generic `_apply_models` assigns all discovered ids to a single provider key, which can't express OpenCode Go's two-shape (OpenAI/Anthropic) split. Wire OpenCode Go into that refresh with its own discovery and a dedicated apply that upserts/prunes across both shape providers while preserving the user's default_model and default_thinking (the login path resets them). Discovery failures are isolated so they can't abort other providers' saves. This only updates config.models, not config.providers, so provider base_url repairs still require a re-login.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds model refresh and discovery plumbing for OpenCode Go providers. It introduces APIs to fetch saved API keys, discover live models, and apply discoveries to the config while pruning stale entries and preserving user defaults. The refresh flow is then integrated into the existing managed provider sync pipeline with error isolation. ChangesOpenCode Go Model Refresh Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Problem
The OpenCode Go model→provider map is materialized into
config.tomlat login and read from there at runtime. So when the bundled/served catalog changes — a new model like qwen3.7-max, or a corrected Qwen API-shape — it never reaches an existing install until the user manually runspythinker login --opencode-go. Updating the binary alone (even to the version that ships qwen3.7-max) does not refresh it.Why the existing refresh didn't cover it
auth.platforms.refresh_managed_modelsalready runs as a background task on every startup and keeps other managed providers current vialist_models. But it silently skipped OpenCode Go:managed:opencode-go-openai/-anthropic) parse to non-existent platform ids →get_platform_by_idreturnsNone→ "platform not found" →continue(logged a spurious warning every startup)._apply_modelsassigns all discovered ids to a single provider key — which can't express OpenCode Go's two-shape split (qwen → Anthropic-compatible, others → OpenAI-compatible).Fix
Wire OpenCode Go into the existing every-startup refresh with its own discovery and a dedicated apply:
opencode_go.py:refresh_opencode_go_models()(re-discover using the saved key) andapply_opencode_go_models()(upsert + prune across both shape providers, preserving the user'sdefault_modelanddefault_thinking— the login path resets them; a refresh must not).platforms.py: skip OpenCode Go keys in the generic loop (also removes the per-startup spurious warning), then refresh it via its own path. Discovery failures are isolated so they can't abort other providers' saves.No new config field/version-marker — the background task already fires after any update, so refreshed models land on the next launch.
Scope / caveat
This updates
config.modelsonly, notconfig.providers. Model-list staleness now self-heals; a stale provider base_url (e.g. the old anthropic-base-without-/v1) would still require a re-login.Tests
test_opencode_go_auth.py: upsert + shape-correction preserving user prefs; prune + default reassignment only when the default was removed; no-op returns False; discovery reuses the saved key.test_platforms.py: OpenCode Go refreshed without re-login (qwen3.7-max appears on the Anthropic provider, prefs preserved, persisted); discovery-failure isolation (a generic provider still saves).Summary by CodeRabbit