Skip to content

feat(provider): discover local model context limits - #41104

Open
zcxGGmu wants to merge 1 commit into
anomalyco:devfrom
zcxGGmu:model-context
Open

feat(provider): discover local model context limits#41104
zcxGGmu wants to merge 1 commit into
anomalyco:devfrom
zcxGGmu:model-context

Conversation

@zcxGGmu

@zcxGGmu zcxGGmu commented Aug 7, 2026

Copy link
Copy Markdown

Issue for this PR

Refs #40908

Type of change

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

What does this PR do?

Adds a narrow discovery path for local / LAN OpenAI-compatible providers whose configured model is missing limit.context. During provider load, OpenCode now reads the provider's /models endpoint and fills the context limit from context_length, max_context_length, or native_context_length when the returned model ID matches.

The discovery is intentionally limited to local/private-network base URLs so provider setup does not make surprise network calls to hosted endpoints.

How did you verify your code works?

  • bun test ./test/provider/provider.test.ts --test-name-pattern 'openai-compatible model fills missing context limit from models endpoint'
  • bun test ./test/provider/provider.test.ts
  • bun typecheck in packages/opencode
  • bun run lint packages/opencode/src/provider/provider.ts packages/opencode/test/provider/provider.test.ts
  • git diff --check

Note: repo-wide pre-push typecheck is currently blocked by an existing @opencode-ai/enterprise/src/custom-elements.d.ts parse error unrelated to this diff, so I pushed with --no-verify after the focused checks passed.

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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

Based on my search, here are the potentially related PRs (excluding the current PR #41104):

Related PRs:

  1. Feat #6231 - automatic discovery of models from providers #39176 - "Feat Auto-discover models from OpenAI-compatible provider endpoints #6231 - automatic discovery of models from providers"

    • Directly related to automatic model discovery from providers
  2. feat(opencode): auto-discover models from OpenAI-compatible providers #32731 - "feat(opencode): auto-discover models from OpenAI-compatible providers"

    • Specifically addresses auto-discovery of models from OpenAI-compatible providers, which is the same provider type and discovery pattern as the current PR
  3. feat(opencode): local LAN provider discovery + auto-discover models #27554 - "feat(opencode): local LAN provider discovery + auto-discover models"

    • Combines local/LAN provider discovery with model auto-discovery, overlapping with the current PR's scope
  4. feat(opencode): add dynamic configuration and context discovery for LM Studio #15732 - "feat(opencode): add dynamic configuration and context discovery for LM Studio"

    • Addresses context discovery for local providers (LM Studio), similar problem domain

Why they're related:
These PRs address model auto-discovery and context limit discovery from OpenAI-compatible or local providers. PR #32731 and #39176 in particular may have overlapping functionality with the current PR's approach to discovering model context limits from provider endpoints. You may want to verify that #41104 doesn't duplicate work from these earlier PRs or that it complements rather than replaces them.

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.

2 participants