Skip to content

[Bug]: ctx.model.transform serves placeholder limit.context (200000) for config-defined models — percentage-based plugins mis-scale on 1M models #55768

Closed

Description

@lanyuanxiaoyao

Description

Plugins that read the model registry through ctx.model.transform are served the built-in Model.Info placeholder limit: { context: 200000, output: 32000 } for models explicitly defined in opencode.json with a different limit. Every user-facing surface is correct — GET /api/model and the TUI context indicator report the configured value — so the placeholder is visible to plugins only, and any plugin scaling thresholds from the context window silently works against a window up to 5x too small.

Measured on one process, 11 seconds apart, opencode 2.0.27, model declared with limit: { context: 1000000, output: 393216 }:

  • plugin @tarquinen/opencode-dcp@3.2.0, its own debug log: Cached model context limit | limit=200000
  • opencode api GET /api/model: deepseek-api/deepseek-flash -> context=1000000 output=393216

Impact: DCP resolves maxContextLimit: "90%" against 200000, so its "CRITICAL WARNING: MAX CONTEXT LIMIT REACHED / use the compress tool now" nudge fires near 180,000 tokens of a 1M window. A second custom provider (zhipu-api/glm-5.3-flash, also declared 1,000,000) behaves the same, and ~/.local/share/opencode/storage/plugin/dcp/ses_*.json records the nudges (nudges.contextLimitAnchors).

This reads as the same defect as #53477 (auto-closed by the compliance bot on 2026-10-09 with no maintainer reply): Model.Info.default() fills the placeholder, and the config merge that does honor limit.context lands after the editor snapshot plugins read. Related: #40908, #53235 / PR #54398, #35863.

Absolute thresholds on the plugin side avoid the symptom but do not fix the host handoff.

Plugins

@tarquinen/opencode-dcp@3.2.0, @openviking/opencode-plugin

OpenCode version

2.0.27

Steps to reproduce

  1. In opencode.json define an OpenAI-compatible provider and a model with an explicit limit, e.g. package "aisdk:@ai-sdk/openai-compatible" and models.bigmodel.limit = { context: 1000000, output: 393216 }.
  2. opencode api GET /api/model reports context=1000000 for it.
  3. Any plugin logging the editor at init shows 200000 instead:
    opencodePlugin(async (ctx) => {
    ctx.model.transform((editor) => {
    for (const m of editor.list()) console.log(${m.providerID}/${m.id}, m.limit.context)
    })
    })
    -> prints 200000 while the registry reports 1000000.
  4. With DCP configured as percentages, the compression nudge then fires at ~18% of the real context window.

Screenshot and/or share link

No response

Operating System

Windows 11 25H2 (build 26200.9445)

Terminal

Windows Terminal

Activity

  1. opencode-agent commented on Oct 15, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I can confirm this on 2.0.27, and it still happens on the latest dev (af6ec83).

    What I did:

    1. Defined a custom @ai-sdk/openai-compatible provider in opencode.json with a model set to limit: { context: 1000000, output: 393216 }.
    2. Loaded a small local plugin that logs m.limit from inside ctx.model.transform.
    3. Queried GET /api/model on the same server.

    The registry reports context=1000000 output=393216. The plugin's transform editor sees context=200000 output=32000, the built-in placeholder. The script below reproduces it.

    From reading the code, the config's model limit is applied in a model transform that is deliberately registered after external plugins' transforms. Until then, the model only has the default placeholder, so plugins see 200000 when their transform runs. This is the same problem as #53477, which was closed automatically for not following the issue template. Related: #40908, #53235 / #54398, #35863.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces anomalyco/opencode#55768: ctx.model.transform sees placeholder limit for config-defined models.
    # Usage: ./repro.sh            (uses `opencode` on PATH)
    #        OC_DEV=/path/to/opencode-checkout ./repro.sh   (runs from source)
    set -euo pipefail
    W=${KEEP:-$(mktemp -d)}
    mkdir -p "$W/probe" "$W/proj" "$W/home"
    cat > "$W/probe/package.json" <<'J'
    { "name": "limit-probe", "version": "0.0.0", "type": "module", "main": "./index.ts", "exports": { ".": "./index.ts" } }
    J
    cat > "$W/probe/index.ts" <<J
    import { appendFileSync } from "node:fs"
    export default {
      id: "limit-probe",
      setup: async (ctx: any) => {
        await ctx.model.transform((editor: any) => {
          for (const m of editor.list())
            if (m.providerID === "mock")
              appendFileSync("$W/probe.log", \`plugin editor: \${m.providerID}/\${m.id} context=\${m.limit.context} output=\${m.limit.output}\n\`)
        })
      },
    }
    J
    cat > "$W/proj/opencode.json" <<J
    {
      "plugins": ["$W/probe"],
      "provider": {
        "mock": {
          "name": "Mock",
          "npm": "@ai-sdk/openai-compatible",
          "options": { "baseURL": "http://127.0.0.1:9/v1", "apiKey": "x" },
          "models": { "bigmodel": { "name": "Big", "limit": { "context": 1000000, "output": 393216 } } }
        }
      }
    }
    J
    cd "$W/proj"
    export HOME="$W/home"
    if [ -n "${OC_DEV:-}" ]; then
      OC=(bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts")
    else
      OC=(opencode)
    fi
    "${OC[@]}" --version
    PORT=$((20000 + RANDOM % 20000))
    export OPENCODE_PASSWORD=repro-secret
    "${OC[@]}" serve --hostname 127.0.0.1 --port "$PORT" >"$W/serve.log" 2>&1 &
    SRV=$!
    trap 'kill $SRV 2>/dev/null || true' EXIT
    for i in $(seq 1 120); do grep -q "listening" "$W/serve.log" && break; sleep 1; done
    echo "--- GET /api/model (registry):"
    "${OC[@]}" api --server "http://127.0.0.1:$PORT" GET /api/model | jq -c '.data[]|select(.providerID=="mock")|{id,limit}'
    echo "--- what the plugin saw in ctx.model.transform:"
    cat "$W/probe.log"

    Run it: bash repro.sh

  2. Dante-dan commented on Oct 15, 2026

    @Dante-dan
    Contributor

    I'll look into seeding configured model limits before external model transforms, while keeping the existing late config override precedence. I'll check the provider/plugin regression tests as well.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions