Skip to content

[BUG]: Context tab shows Context Limit / Usage as em-dash for custom openai-compatible models even with configured limit.context #37456

Closed

Description

@chirag127

Description

The Context tab (the token/context breakdown panel opened from the circular context-usage indicator) shows — for the "Context Limit" and "Usage" stats when using a custom @ai-sdk/openai-compatible provider — even when an explicit limit.context is configured for that model in opencode.json.

Because the limit renders as —, the usage percentage is also —, so the whole context-tracking readout is unusable for these models, and there is no visible indication anywhere of the model's context window.

Root cause (from source)

packages/app/src/components/session/session-context-metrics.ts:

type Model = {
  name?: string
  limit: {            // declared non-optional…
    context: number
  }
}

const build = (messages, providers) => {
  const message = lastAssistantWithTokens(messages)
  if (!message) return undefined
  const provider = providers.find((item) => item.id === message.providerID)
  const model = provider?.models[message.modelID]
  const limit = model?.limit.context          // …but accessed as if it can be missing
  const total = tokenTotal(message)
  return {
    ...
    limit,
    usage: limit ? Math.round((total / limit) * 100) : null,
  }
}

limit resolves to undefined whenever:

  1. provider.models[message.modelID] returns no entry (the model the SDK reports for the assistant message is keyed differently than the config entry, e.g. gateway/router providers), or
  2. the resolved model object has no limit (custom/local models whose window can't be auto-fetched and no override was merged into the resolved model).

Note the type declares limit: { context: number } as required, but the code reads model?.limit.context. If a resolved model exists but has no limit, model.limit is undefined and .context is an unsafe access. Either way the tab falls back to the em-dash.

packages/app/src/components/session/session-context-tab.tsx:

{ label: "context.stats.limit", value: () => formatter().number(ctx()?.limit) },
{ label: "context.stats.usage", value: () => formatter().percent(ctx()?.usage) },

session-context-format.ts renders undefined/null as "—", so a missing limit surfaces as — with no fallback.

Expected behavior

The Context tab should display the model's context limit whenever it is knowable:

  1. If the user configured limit.context in opencode.json, always display and use it (config override should win over auto-detected metadata).
  2. If not configured, fall back to models.dev / the provider's /v1/models metadata.
  3. If still unknown, show a clear hint (e.g. "not set — configure limit.context") instead of a bare —, so it's discoverable.
  4. model.limit should be treated as optional in the type (limit?: { context?: number }) since custom/local providers legitimately lack it, and the access should be null-safe.

Actual behavior

"Context Limit" and "Usage" render as — in the Context tab; no context window is shown anywhere for the model.

Steps to reproduce

  1. Configure a custom OpenAI-compatible provider with an explicit limit:
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "omniroute": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OmniRoute",
      "options": { "baseURL": "http://localhost:20128/v1", "apiKey": "sk-..." },
      "models": {
        "hyperspaceaihai/anthropic--claude-opus-latest": {
          "name": "opus",
          "limit": { "context": 1000000, "output": 128000 }
        }
      }
    }
  }
}
  1. Start a session on omniroute/hyperspaceaihai/anthropic--claude-opus-latest and send a few messages so token usage accrues.
  2. Open the Context tab from the circular context-usage indicator.
  3. Observe "Context Limit: —" and "Usage: —", despite limit.context: 1000000 being configured.

OpenCode version

1.18.3

Operating System

Windows 11 (10.0.26200)

Related issues


Filed by an AI assistant at the user's request after inspecting the config, the session-context-metrics.ts / session-context-tab.tsx / session-context-format.ts source at HEAD, and the existing issue tracker.

Activity

  1. github-actions commented on Jul 17, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The issue footer explicitly states it was "Filed by an AI assistant at the user's request". AI-generated walls of text are not acceptable per our contributing guidelines. Please rewrite this issue in your own words, keeping it concise and focused on the actual problem you experienced.

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


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

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

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

Metadata

Metadata

Assignees

Labels

needs:complianceThis means the issue will auto-close after 2 hours.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions