Skip to content

fix(provider): discover LM Studio models from /v1/models#26756

Closed
ipogosov wants to merge 3 commits into
anomalyco:devfrom
ipogosov:codex-lmstudio-model-discovery
Closed

fix(provider): discover LM Studio models from /v1/models#26756
ipogosov wants to merge 3 commits into
anomalyco:devfrom
ipogosov:codex-lmstudio-model-discovery

Conversation

@ipogosov

Copy link
Copy Markdown

Issue for this PR

Closes #2047

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

OpenCode currently relies on its static models catalog for the LM Studio provider, so models the user has loaded or unloaded inside LM Studio are not reflected in OpenCode until the catalog is updated and shipped. This is the bug described in #2047auth logout / auth login does not refresh the visible model list because nothing actually consults LM Studio.

This PR makes the LM Studio provider discover its own models at runtime from the live OpenAI-compatible /v1/models endpoint and use that response as the source of truth for visible models:

  • The provider hits <lmstudio-base-url>/v1/models whenever its model list is requested, and uses the IDs it gets back to drive what OpenCode shows. Stale catalog-only entries that LM Studio no longer reports are pruned, so unloading or removing a model in LM Studio actually removes it from OpenCode.
  • Configured model metadata (display names, context window, capability flags, etc.) is preserved as overrides: a discovered model that also exists in the user's config inherits that config's fields, so manual tuning is not blown away by discovery.
  • Discovery has a safe opt-out via options.discoverModels: false for users who prefer the previous "trust the catalog" behavior or who can't reach /v1/models from where OpenCode runs.
  • Obvious embedding and rerank models are filtered out of the discovered list by default (so the chat picker isn't polluted with non-chat models); options.includeEmbeddingModels: true re-includes them for users who want to wire them up explicitly.

The change is scoped to the LM Studio provider; other providers' model resolution paths are not touched.

How did you verify your code works?

  • bun typecheck from packages/opencode
  • bun test --timeout 30000 test/provider/provider.test.ts — new tests cover the discovery happy path, the prune-stale-catalog-entries case, the config-overrides-discovered-model case, the discoverModels: false opt-out, and the embedding-filter / includeEmbeddingModels: true cases
  • bun run build --single --skip-install to confirm the standalone build still produces an executable with the change in place
  • pre-push hook: bun turbo typecheck across the workspace
  • Manually exercised against a local LM Studio instance: loading and unloading models in LM Studio now shows up in OpenCode's model picker without restart / re-login

Screenshots / recordings

N/A, non-UI change. The visible effect is in OpenCode's model picker reflecting LM Studio's actual loaded set.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several related PRs that address LM Studio model discovery features. However, excluding the current PR #26756, these are all historical PRs (from 2024 and earlier) that were either merged or closed:

Related PRs (not current duplicates):

These appear to be earlier attempts or partial implementations of similar functionality. The current PR #26756 seems to be a comprehensive implementation that addresses issue #2047 specifically.

No duplicate PRs found among currently open PRs.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LM Studio Failure to refresh models

1 participant