Skip to content

fix(models): preserve AvailableModels capability metadata - #3

Open
SenZh wants to merge 3 commits into
openchamber:mainfrom
SenZh:fix/model-metadata-discovery
Open

SenZh wants to merge 3 commits into
openchamber:mainfrom
SenZh:fix/model-metadata-discovery

Conversation

@SenZh

@SenZh SenZh commented Sep 14, 2026

Copy link
Copy Markdown

Summary

Fixes three related metadata/runtime issues discovered while using Cursor models in OpenCode on slower networks.

1. Model discovery metadata (AvailableModels path)

  • Increase AvailableModels RPC timeout (5s -> 30s) and config discovery timeout (35s) to avoid silent fallback to GetUsableModels
  • Normalize reasoning_effort, supportsImages, and supportsThinking from Cursor API responses
  • Infer context window from variant params, contextTokenLimitForMaxMode, and tooltip markdown (including variant-level tooltip, e.g. Gemini 1M)
  • Take Math.max context across grouped variants
  • Emit per-model image/reasoning flags in provider and config descriptors instead of hardcoding all models as image-capable with 200k context
  • Set attachment: true on config model descriptors so OpenCode does not strip image inputs before they reach the proxy

2. Session title generation (NameAgent path)

  • Increase NameAgent RPC timeout (5s -> 15s); live calls often need ~6-7s due to h2-bridge subprocess + network RTT
  • Add timeout/failure logging instead of silently returning empty titles
  • Broaden title-generation prompt detection for OpenCode 1.18 ("Generate a brief title", etc.)

Root cause

Models: On slow links, the default 5s RPC budget caused AvailableModels to time out and silently degrade to GetUsableModels, flattening capability metadata (notably context window to 200k). The normalizer also ignored Gemini-style reasoning_effort, never mapped API image/thinking flags, missed variant-level tooltip context, and config descriptors lacked attachment: true — causing all models to appear text-only in the UI.

Titles: OpenCode sends agent=title requests through the plugin proxy. The plugin routes these to Cursor's NameAgent RPC (not the user's chat model). The default 5s client timeout was shorter than typical end-to-end latency, so title generation silently no-op'd and sessions stayed at New session - <timestamp>.

Test plan

  • npm run build
  • npm run test (smoke suite — regression cases for reasoning_effort, supportsImages, variant tooltip context, contextTokenLimitForMaxMode, config attachment, grouped variant Math.max)
  • Live verification: Gemini 3.8 Flash shows image input + 1M context; session titles auto-generate after first message
  • Maintainer: verify mixed context sizes (200k/272k/300k/1M) on your network after merge

470785 added 3 commits September 14, 2026 11:15
AvailableModels RPC can exceed the default 5s bridge timeout, causing a
silent fallback to GetUsableModels with flattened 200k context windows.
Increase discovery timeouts, normalize reasoning_effort/supportsImages/
supportsThinking, infer context from variant params and tooltip data, and
emit accurate image/reasoning flags in provider descriptors.
Read context window from variant-level tooltipData (e.g. Gemini 1M),
take the max context across grouped variants, and set attachment: true
on config model descriptors so OpenCode does not strip image inputs.
@SenZh

SenZh commented Sep 14, 2026

Copy link
Copy Markdown
Author

Hi maintainers — thanks for maintaining this plugin!

This PR bundles three fixes found during real-world use with Cursor OAuth on a slower network. All changes are covered by the smoke test suite and verified locally against live Cursor API responses.

What was broken:

  1. Model list — After ~5s, AvailableModels timed out -> silent fallback to GetUsableModels -> every model showed 200k context and incorrect capabilities. Gemini 3.8 Flash showed text-only despite API returning supportsImages: true.
  2. Image input — Even when metadata was correct, config descriptors missing attachment: true caused OpenCode to strip images before the proxy.
  3. Session titlesNameAgent RPC (used for agent=title) hit the 5s default timeout (~6-7s actual). Titles stayed as New session - <timestamp>. Other providers work because they use standard chat/completions, not this RPC path.

Note on CI: The repo only has a manual Release workflow — no PR checks run automatically. I ran npm run build and npm run test locally; all pass.

Happy to split into separate PRs or adjust anything. Let me know if you'd like a live repro script or logs.

@thaoran

thaoran commented Sep 16, 2026

Copy link
Copy Markdown

+1 — hit exactly this on 2.5.1 (OpenCode 1.18.9, macOS, OpenChamber desktop).

Independently traced the same root cause before finding this PR: the live AvailableModels call takes 11–18s here (measured repeatedly, ~296KB payload), so the hardcoded 5s timeoutMs in cursor-rpc always kills the bridge and silently degrades to GetUsableModels — every model ends up at DEFAULT_CONTEXT_WINDOW = 200k with flat legacy-slug IDs and no 1m/300k/272k tiers.

Verified the fix direction locally: bumping the RPC default from 5s → 30s makes a fresh opencode models register the full grouped catalog (104 models), and opencode debug config shows correct limits (claude-sonnet-5 → 300k, gpt-5.6-sol → 272k, -1m tiers → 1M).

Looking forward to this being merged — the tooltip-based context inference for models whose variants don't carry a context param (grok/gemini) is a nice touch beyond the timeout fix. I had filed this as an issue earlier today; removing it as a duplicate of this PR.

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