Skip to content

fix(opencode2): keep an agent's model when its variant is not offered - #266

Merged
pgermishuys merged 1 commit into
mainfrom
fix/opencode2-agent-variant
Sep 28, 2026
Merged

pgermishuys merged 1 commit into
mainfrom
fix/opencode2-agent-variant

Conversation

@pgermishuys

Copy link
Copy Markdown
Contributor

Fixes #265.

Problem

An agent-level variant that the selected model does not offer rejected the whole model entry. variant none on a Claude model made every entry fail, because Copilot's Claude models offer no none variant while GPT models do. The agent then fell to a builtin fallback, or to no model at all, and an OpenCode 2 subagent with no model runs on its parent's model. A user saw Shuttle (configured for Sonnet 5) run on Loom's Opus 5.5.

Change

  • resolveVariant (v2/model-resolution.ts) now separates the two forms:
    • #variant on an entry is part of that entry: if the model doesn't offer it, the entry is still skipped, as the existing scenario decides.
    • The agent-level variant applies to whichever entry is selected, so a model that doesn't offer it keeps the agent and runs without a variant. The resolution returns droppedVariant.
  • The catalog records a variant_unavailable issue for that agent, and health and the status RPC gain the code (RPC API report updated), so the change stays visible.
  • Docs: docs/model-resolution.md and docs/adapters/opencode2-core.md. The model-resolution doc also still said an agent with no viable model is omitted, which has been out of date since fix(opencode2): keep agents whose declared model cannot resolve #215; now corrected. CHANGELOG entry under Unreleased.

Tests

  • New scenarios under "a user sets one variant for the whole agent":
    • the variant is applied when offered;
    • the model is kept when the variant isn't offered;
    • status names variant_unavailable and not model_unavailable;
    • a builtin (shuttle) keeps the user's model even when a builtin fallback does offer the variant.
  • The three new negative scenarios failed before the fix. bun run typecheck, bun run lint and bun run test pass (5916 pass, 0 fail).
  • Live check: OpenCode 2 v2.0.16 with a real GitHub Copilot catalog, this build dropped into the plugin cache, and a config where 5 agents have variant none. From GET /api/agent:
Agent before after
shuttle, spindle (claude-sonnet-5) gpt-6-sol#none / gpt-6-luna#none (builtin fallback) claude-sonnet-5
thread (claude-haiku-4.5) gpt-6-luna#none claude-haiku-4.5
warp/weft review copies (claude-opus-5.5) no model claude-opus-5.5
warp, weft (gpt-6-sol, offers none) gpt-6-sol#none gpt-6-sol#none (unchanged)
shuttle, with a 2nd provider offering gpt-6-sol no model, so it ran on the parent's model claude-sonnet-5

🤖 Generated with Claude Code

https://claude.ai/code/session_01SFsPx8V3UJ3xP4E9qZDpKw

An agent-level `variant` the selected model does not offer rejected the
model entry. `variant none` on a Claude model (Copilot's Claude models have
no `none` variant; GPT models do) made every entry fail, so the agent fell to
a builtin fallback or to no model, and a subagent then ran on its parent's
model. The agent-level variant now applies to whichever entry is selected:
a model that lacks it runs without it, and status reports
`variant_unavailable`. A `#variant` on an entry stays strict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFsPx8V3UJ3xP4E9qZDpKw
Copilot AI lite review requested due to automatic review settings September 28, 2026 08:19
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 247ced4c-a64b-498f-8064-65d18ca4a490

📥 Commits

Reviewing files that changed from the base of the PR and between d55bcb3 and f2cc487.

⛔ Files ignored due to path filters (4)
  • .codesight/CODESIGHT.md is excluded by !.codesight/**
  • .codesight/config.md is excluded by !.codesight/**
  • .codesight/coverage.md is excluded by !.codesight/**
  • .codesight/middleware.md is excluded by !.codesight/**
📒 Files selected for processing (9)
  • docs/adapters/opencode2-core.md
  • docs/model-resolution.md
  • packages/adapters/opencode2/CHANGELOG.md
  • packages/adapters/opencode2/etc/weave-adapter-opencode2-rpc.api.md
  • packages/adapters/opencode2/src/rpc.ts
  • packages/adapters/opencode2/src/v2/catalog.ts
  • packages/adapters/opencode2/src/v2/health.ts
  • packages/adapters/opencode2/src/v2/model-resolution.ts
  • tests/adapters/opencode2.scenario.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: copilot-pull-request-reviewer
  • GitHub Check: Legacy @opencode_weave/weave → Weave upgrade keeps every agent
  • GitHub Check: V1 — opencode default_agent == loom
  • GitHub Check: V2 — opencode2 loom is Weave-owned (Podman)
  • GitHub Check: Pinned host — this revision
  • GitHub Check: Lint, Typecheck, Build & Test
  • GitHub Check: Verify opencode2 (Podman)
🧰 Additional context used
🪛 LanguageTool
docs/adapters/opencode2-core.md

[grammar] ~147-~147: Ensure spelling is correct
Context: ... whichever model is selected, including builtin fallbacks the user never paired it with...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🔇 Additional comments (9)
packages/adapters/opencode2/src/v2/model-resolution.ts (1)

18-19: LGTM!

Also applies to: 48-70, 109-115

tests/adapters/opencode2.scenario.test.ts (1)

325-377: LGTM!

Also applies to: 379-403

docs/adapters/opencode2-core.md (1)

144-149: LGTM!

docs/model-resolution.md (1)

91-98: LGTM!

packages/adapters/opencode2/CHANGELOG.md (1)

5-11: LGTM!

packages/adapters/opencode2/src/v2/catalog.ts (1)

45-49: LGTM!

Also applies to: 232-243

packages/adapters/opencode2/src/v2/health.ts (1)

8-8: LGTM!

packages/adapters/opencode2/src/rpc.ts (1)

25-25: LGTM!

packages/adapters/opencode2/etc/weave-adapter-opencode2-rpc.api.md (1)

38-38: LGTM!


📝 Summary

Summary by CodeRabbit

  • New Features
    • Agent-level variants are applied when supported by the selected model. If unavailable, the agent can still use that model without the variant, and its status reports variant_unavailable.
    • Agents with no viable declared model remain registered without a model and report model_unavailable.
  • Documentation
    • Updated OpenCode 2 behavior and status issue documentation.

Walkthrough

OpenCode 2 now keeps a selected model when an agent-level variant is unavailable, omits that variant, and reports variant_unavailable. An explicit entry-level #variant remains required for that model entry to be used.

Changes

OpenCode 2 variant handling

Layer / File(s) Summary
Resolve agent-level variants
packages/adapters/opencode2/src/v2/model-resolution.ts, tests/adapters/opencode2.scenario.test.ts, docs/adapters/opencode2-core.md, docs/model-resolution.md, packages/adapters/opencode2/CHANGELOG.md
Model resolution drops an unavailable descriptor-level variant while retaining the selected model. An unavailable entry-level #variant still rejects the entry. Scenario tests and documentation describe these outcomes.
Report dropped variants
packages/adapters/opencode2/src/v2/catalog.ts, packages/adapters/opencode2/src/v2/health.ts, packages/adapters/opencode2/src/rpc.ts, packages/adapters/opencode2/etc/weave-adapter-opencode2-rpc.api.md
The catalog records variant_unavailable with the agent name and dropped variant. Health and RPC issue-code declarations include the new code.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CatalogCandidate
  participant resolveOpenCode2Model
  participant Status
  CatalogCandidate->>resolveOpenCode2Model: Resolve the selected model and variant
  resolveOpenCode2Model-->>CatalogCandidate: Return the model and any droppedVariant
  CatalogCandidate->>Status: Record variant_unavailable for a dropped variant
Loading

Suggested reviewers: josevelaz

Merge Risk: ⚪ Minimal · up to f2cc4

No actionable issue remains in the supplied evidence; the PR is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to f2cc4

A configured choice is now preserved when an optional setting is unavailable, and the mismatch is reported. In large configurations, the additional warnings could obscure other problems. No direct new access path was established.

Retained concerns

  • Low · security · inferred: In a catalog with enough issues, new variant warnings can fill the 64-entry health limit before later model-fallback or agent-collision diagnostics reach status. This can weaken visibility into execution on an unintended model; it does not change the model references in the catalog.
Security review details

Security Blast Radius

  • inferred — The changed selection affects agents whose configured variant is absent from the selected model's catalog entry. The inspected path preserves their configured provider identifier; downstream credential lookup was not verified.

Security Findings and Attack Paths

  • inferred — With enough preceding variant warnings, the bounded status response can omit a later warning that an agent has no resolved model and may use native selection. This is a diagnostic-visibility risk, not evidence of a new authorization bypass.

Trust Boundaries and Controls

  • observed — An explicit model-entry variant remains required for that entry, whereas an unavailable agent-level variant is dropped. The status handler resolves scope before returning the bounded health projection.

Resilience and Maintainability Implications

  • observed — The new internal issue does not make status serialization reject a valid catalog: health strips fields outside the strict public issue schema and caps the response at its declared limit.

Hardening Proposals

  • proposed — Consider reserving status capacity for model-fallback and collision diagnostics, or exposing a truncation indicator, so variant warnings cannot silently crowd them out.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits with the valid fix(opencode2): prefix and accurately summarizes the main change.
Description check ✅ Passed The description clearly explains the variant-resolution change, affected reporting, documentation updates, tests, and live validation.
Linked Issues check ✅ Passed The PR satisfies the coding requirements in directly linked issue #265. model-resolution.ts keeps the selected model when an agent-level variant is unavailable, drops the variant, and preserves stri…
Out of Scope Changes check ✅ Passed The changes stay within issue #265. The documentation, changelog, public API schema, issue types, model-resolution code, health reporting, and scenario tests support the requested variant-resolution b…
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the model list,
A dropped variant skips the twist.
The chosen model stays in place,
Status names the missing case.
I thump beside the tidy code,
Then hop along the review road.

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No blocking issues remain; the public-docs update is a minor documentation nit.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Fixes OpenCode 2 model selection so unsupported agent-level variants no longer replace the configured model.

Changes:

  • Preserves models when agent-level variants are unavailable.
  • Adds variant_unavailable health and status reporting.
  • Adds regression tests and updates documentation, API reports, and changelog.
File Reviewed changes
tests/​adapters/​opencode2.scenario.test.ts Adds regression scenarios.
packages/​adapters/​opencode2/​src/​v2/​model-resolution.ts Preserves models with unsupported variants.
packages/​adapters/​opencode2/​src/​v2/​health.ts Adds the health issue code.
packages/​adapters/​opencode2/​src/​v2/​catalog.ts Records unavailable variants.
packages/​adapters/​opencode2/​src/​rpc.ts Extends status reporting.
packages/​adapters/​opencode2/​etc/​weave-adapter-opencode2-rpc.api.md Updates the API report.
packages/​adapters/​opencode2/​CHANGELOG.md Documents the fix.
docs/​model-resolution.md Documents resolution behavior.
docs/​adapters/​opencode2-core.md Documents adapter semantics.
.codesight/​middleware.md Updates generated metadata.
.codesight/​coverage.md Updates generated metadata.
.codesight/​config.md Updates generated metadata.
.codesight/​CODESIGHT.md Updates generated metadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/model-resolution.md
Comment on lines +91 to +94
An entry-level `#variant` must exist in the live model entry, or the entry is
not viable. The descriptor-level `variant` applies to whichever entry is
selected: when that model does not offer it, the agent keeps the model, runs
without a variant, and health reports a bounded `variant_unavailable` issue. If
@pgermishuys
pgermishuys merged commit 082ff17 into main Sep 28, 2026
10 checks passed
@pgermishuys
pgermishuys deleted the fix/opencode2-agent-variant branch September 28, 2026 09:46
pgermishuys added a commit that referenced this pull request Sep 28, 2026
Bumps @weaveio/weave-adapter-opencode2 to 0.2.0-next.5 to release the
agent-variant fix (#266): an agent-level variant the selected model does not
offer no longer costs the agent its model.

Refs #265


Claude-Session: https://claude.ai/code/session_01SFsPx8V3UJ3xP4E9qZDpKw

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

OpenCode 2: an agent-level variant the model doesn't offer silently changes the agent's model

2 participants