Skip to content

Plugin model editor serves placeholder limit.context (200,000) for config-defined models at plugin init — corrected value only reaches the final registry #53477

Closed as not planned

Description

@luke-radar

opencode version: v2.0.23 (binary install, Linux x64)

Summary

Plugins receive model metadata through ctx.model.transform. At plugin-init time, the model editor reports limit.context: 200000 — the built-in Model.Info default — for models explicitly defined in the user's opencode.json with a different limit. Everything user-facing (GET /api/model, the TUI context indicator) correctly shows the configured value, so the correction happens after the point plugins snapshot from. A plugin that caches limits at init silently operates on a value 5× too small for large-context models.

Steps to reproduce

  1. Define a custom provider+model in opencode.json: provider "mygw" with npm "@ai-sdk/openai-compatible", options.baseURL "https://gateway.example.internal/v1", models.bigmodel with limit {context: 1048576, output: 65536}.
  2. Install a plugin reading the editor at init: export const MyPlugin = opencodePlugin(async (ctx) => { ctx.model.transform((editor) => { for (const model of editor.list()) console.log(${model.providerID}/${model.id}, model.limit.context) }) }).
  3. Start opencode: plugin logs 200000 for mygw/bigmodel, while /api/model and the TUI context bar report 1048576.

Expected

Plugin-visible editor carries the configured limit.context.

Actual

Editor entry is built from the static default before the config value is merged into it.

Field evidence (systematic, not stale)

Context-management plugin (@tarquinen/opencode-dcp 3.2.0) nudging at "% of context window"; model limit.context=1,048,576, threshold 30% of the limit it sees. Measured warning boundary across two independent instances started days apart: first nudge between 56,944 and 60,179 tokens (second instance 60,268). 30% × 200,000 = 60,000 — boundary matches the DEFAULT limit exactly; 30% × 1,048,576 = 314,572 never triggered. User-facing indicator on the same sessions showed correct 1,048,576 — final registry right, only the plugin-visible snapshot stale.

Likely cause

Model.Info's schema carries a statics default factory (packages/schema/src/model.ts ~line 158): default: (providerID, id) => ({ id, providerID, ..., limit: { context: 200_000, output: 32_000 } }). Several paths create a missing model via Model.Info.default(providerID, modelID) then apply a partial update — packages/core/src/provider.ts (~356), packages/core/src/model.ts (~136), packages/plugin/optimize.ts (~77), packages/plugin/identity.ts (~26), modal provider plugin (~100), github-copilot/gitlab/chatgpt provider plugins. When the model editor is read after such a creation but before the user config's model definition is merged into that entry (config merge at provider.ts ~1494–1620 does honor limit.context), plugins observe the placeholder.

Impact

Any plugin computing thresholds from the context window (context management, auto-compaction, cost estimators) silently mis-scales by real-limit ÷ 200,000; users saw "MAX CONTEXT LIMIT REACHED" warnings from ~6% real usage on a 1M-context model.

Suggested fix

Ensure config-defined model definitions (including limit) are merged into the model editor BEFORE ctx.model.transform editors are handed to plugins — plugins should never observe a Model.Info.default() placeholder for a config-defined model. Our workaround: absolute per-model token thresholds in the plugin instead of percentages.

Environment

opencode v2.0.23 (binary install), Linux x64; affected plugin @tarquinen/opencode-dcp 3.2.0 (reads ctx.model.transform at init; its own cache-once behavior compounds but the placeholder value is the root).

Activity

  1. added
    needs:compliance
    on Oct 6, 2026
  2. github-actions commented on Oct 6, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • Please use the Bug Report template and include its required Description field. The current report uses a custom Summary/Expected/Actual structure and does not include that required field.

    Please edit this issue to address the above within 72 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    • #21564: GitHub Copilot plugin ignores user-configured model limit overrides, a similar plugin/model-limit behavior.
    • #29555: Custom provider model context limit is ignored in TUI context percentages, a similar configured-limit symptom.

    If you believe this was flagged incorrectly, please let a maintainer know.

  3. github-actions commented on Oct 9, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 72-hour window.

    Feel free to open a new issue that follows our issue templates.

  4. removed
    needs:compliance
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions