Skip to content

fix(opencode2): keep agents whose declared model cannot resolve - #215

Merged
pgermishuys merged 1 commit into
mainfrom
fix/opencode2-model-fallback
Sep 22, 2026
Merged

pgermishuys merged 1 commit into
mainfrom
fix/opencode2-model-fallback

Conversation

@pgermishuys

Copy link
Copy Markdown
Contributor

Related: #209 (item 3)

The problem, reproduced

All eight builtins declare the bare model claude-sonnet-4-5 (packages/config/src/builtins.ts:74 and seven more). The adapter dropped any agent whose declared model didn't resolve against the live catalog.

So on a host that doesn't carry that model, every builtin vanished. I ran this against the real opencode2 beta-19151 CLI — a fixture declaring the eight builtins with no model override, against a catalog containing only proof/proof-model:

count: 7
Build
General
Explore
Compaction
Title
Summary
Plan

Seven host builtins. Zero Weave agents. /weave:start gone too, since command readiness requires an owned Tapestry. No log line — the only record was a model_unavailable issue in the status RPC, which a user has no reason to open.

Every verification fixture pins its agents to proof/proof-model, for good hermetic reasons, which is exactly why nothing caught this: the default path is the one path no fixture takes.

The change

An unresolvable declared model now costs the agent its model, not its existence. The agent is registered without a model ref — the same inherit shape an agent declaring no model already produces — so OpenCode applies its native model selection. One model_unavailable issue per affected agent is still recorded.

Same fixture, after:

loom, tapestry, shuttle, pattern, thread, spindle, weft, warp

The trade

This is not a free win, and the docs say so plainly. The agent runs on a model the user did not name, and status is the only record. Two related behaviours change with it:

  • An ambiguous bare model (two providers offering it) no longer drops the agent — it still refuses to guess a provider, but hands model choice to the host.
  • An unknown variant no longer drops the agent. It does not fall back to the base model, which would be a silent downgrade of the same model; it hands choice to the host.

What it replaces is a failure mode that removed the entire product from the host. Declaring a model that doesn't resolve isn't a request to have no agent.

Alternatives considered and not taken: removing models from the builtins so Weave stops dictating a model at all (correct, but changes defaults for every adapter), and logging a warning without changing behaviour (diagnosable, but the install is still empty).

Scope

V2 adapter only. packages/config/src/builtins.ts is untouched, so no other harness changes behaviour. The same trap still exists for any other adapter whose catalog lacks claude-sonnet-4-5 — worth a follow-up, deliberately not bundled here.

Tests

Six scenarios pinned the old behaviour and now state the new promises. Two of them — the foreign-agent collision case and the lazy-transform case — were incidentally relying on the builtins being dropped in order to isolate their own subject, and now say what they actually mean.

Full suite green: 5072 pass, 13 skip, 0 fail. Typecheck, lint and doc links clean.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 22, 2026 18:49
@coderabbitai

coderabbitai Bot commented Sep 22, 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: 33aa1534-b5d1-49f9-97b3-f8f81ccedf7b

📥 Commits

Reviewing files that changed from the base of the PR and between 51555af and 0a424fa.

📒 Files selected for processing (3)
  • docs/adapters/opencode2-core.md
  • packages/adapters/opencode2/src/v2/catalog.ts
  • tests/adapters/opencode2.scenario.test.ts

Included review availability: 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: V2 — opencode2 loom is Weave-owned (Podman)
  • GitHub Check: Verify opencode2 (Podman)
  • GitHub Check: V1 — opencode default_agent == loom
  • GitHub Check: Legacy @opencode_weave/weave → Weave upgrade keeps every agent
  • GitHub Check: Claude Code — settings.json .agent == loom
  • GitHub Check: Lint, Typecheck, Build & Test
🧰 Additional context used
🪛 LanguageTool
docs/adapters/opencode2-core.md

[grammar] ~119-~119: Ensure spelling is correct
Context: ...t runs on a model the user did not name, which status is the only record of. The alt...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~121-~121: Ensure spelling is correct
Context: ...rnative, omitting the agent, cost every builtin on a host whose catalog does not carry ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • OpenCode 2 agents remain available even when their declared models cannot be resolved.
    • OpenCode can now apply its native model selection for affected agents.
    • Status reporting identifies each agent with an unavailable model.
    • Built-in agents and the start command remain available when no declared models resolve.
    • Agent listings now consistently include built-in and user-defined agents in these scenarios.

Walkthrough

The OpenCode 2 adapter now registers agents when declared models cannot be resolved. These agents receive no model reference, OpenCode selects the model, and model_unavailable issues remain reported. Tests cover registration, commands, collisions, and lazy listing.

Changes

OpenCode model fallback

Layer / File(s) Summary
Agent registration fallback
packages/adapters/opencode2/src/v2/catalog.ts, docs/adapters/opencode2-core.md
Unresolvable declared models no longer remove agents. The adapter registers them without a model reference and retains one model_unavailable issue per affected agent.
Scenario validation
tests/adapters/opencode2.scenario.test.ts
Scenarios now verify builtin registration, weave:start retention, undefined models, collision counts, and lazy agent listing.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 0a424

No merge-blocking risk is established; the fallback behavior is covered by source inspection and scenario assertions.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits syntax with the fix type and opencode2 scope. It accurately describes the main change.
Description check ✅ Passed The description clearly explains the unresolved-model behavior, implementation scope, trade-offs, tests, and verification results. It is directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 models in the moonlit glow
When one cannot resolve, the agents still show
OpenCode chooses where the next path goes
Issues name each agent that nobody knows
Eight little builtins remain in a row

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

All eight builtins declare the bare model `claude-sonnet-4-5`. The adapter
dropped any agent whose declared model did not resolve against the live
catalog, so on a host that does not carry that model every builtin
disappeared. `/weave:start` went with them, because command readiness
requires an owned Tapestry. The only record was a `status` RPC a user has
no reason to open, so a plausible host configuration produced an install
that looked like it had done nothing.

An unresolvable declared model now costs the agent its model, not its
existence. The agent is registered without a model ref — the same
`inherit` shape an agent that declares no model already produces — and
OpenCode applies its own native model selection. One `model_unavailable`
issue per affected agent is still recorded, so `status` names every agent
whose declared model did not resolve.

This is a trade, not a free win: the agent runs on a model the user did
not name, and `status` is the only record of that. It replaces a failure
that removed the whole product from the host with one that keeps it
working on the host's own default. Declaring a model that does not resolve
is not read as a request to have no agent.

Scope is the V2 adapter only. `packages/config/src/builtins.ts` keeps its
`claude-sonnet-4-5` declarations, so other harnesses are unaffected.

Verified against the real opencode2 beta-19151 CLI, with a fixture whose
agents use the builtin default model and a catalog carrying none of it:
before, `ctx.agent.list()` reported 7 host builtins and zero Weave agents;
after, all eight are present and Weave-owned.

Six scenarios pinned the old behaviour and now state the new promises,
including two that were incidentally relying on the builtins being dropped
to isolate their own subject.

Refs #209

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

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

🟡 Changes recommended

Documentation updates are needed to cover the public behavior, bounded diagnostics, and contradictory references.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Keeps OpenCode 2 agents available when declared models cannot resolve, using host-native model selection while recording diagnostics.

Changes:

  • Preserves agents with unresolved, ambiguous, or invalid model selections.
  • Updates scenario coverage for fallback registration and command readiness.
  • Documents fallback behavior and refreshes Codesight metadata.
File Summary Final review comments
tests/​adapters/​opencode2.scenario.test.ts Updates fallback and readiness scenarios. —
packages/​adapters/​opencode2/​src/​v2/​catalog.ts Retains agents without resolved model references and records issues. —
docs/​adapters/​opencode2-core.md Documents model-selection fallback semantics. Nit (2 votes): Update public documentation. Nit (1 vote): Document the 64-issue status limit. Nit (1 vote): Reconcile contradictory model-resolution references.
.codesight/​CODESIGHT.md Refreshes scan metadata. —

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

Comment on lines +113 to +117
When an agent declares models and none are valid or available, the agent is
still registered — without a model ref, the same shape an agent that declares
no model produces — and OpenCode applies its own native model selection. The
adapter reports one `model_unavailable` issue per affected agent, so `status`
names every agent whose declared model did not resolve.
Copilot AI review requested due to automatic review settings September 22, 2026 18:57
@pgermishuys
pgermishuys force-pushed the fix/opencode2-model-fallback branch from bd3b467 to 0a424fa Compare September 22, 2026 18:57

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

🟡 Changes recommended

Update authoritative/public documentation and clarify the status issue limit.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Low severity

Open (3)

Comment on lines +113 to +115
When an agent declares models and none are valid or available, the agent is
still registered — without a model ref, the same shape an agent that declares
no model produces — and OpenCode applies its own native model selection. The
Comment on lines +116 to +117
adapter reports one `model_unavailable` issue per affected agent, so `status`
names every agent whose declared model did not resolve.
@pgermishuys
pgermishuys merged commit 818b6be into main Sep 22, 2026
8 checks passed
@pgermishuys
pgermishuys deleted the fix/opencode2-model-fallback branch September 22, 2026 19:14
pgermishuys added a commit that referenced this pull request Sep 22, 2026
…ve adapter (#216)

npm has exactly one version of `@weaveio/weave-adapter-opencode2`: 0.1.0,
cut at 29393cf. `package.json` has since said 0.1.1 and 0.1.2, but neither
was ever tagged, so neither was published.

At 29393cf there was no `src/v2/` directory. The published package's
exports confirm what it predates — only `.` and `./server`, no `./rpc` and
no `./tui`. Unreleased since then: agent materialization in plugin setup
(#163), real-CLI verification (#164), the whole native core integration
(#167) with its catalog-backed agents, `/weave:start`, plan RPC, TUI,
config refresh and native delegation, and #214/#215.

Every capability documented in docs/adapters/opencode2-core.md describes
code that has never been on npm. A user running `weave init --harness
opencode2` gets the bare package name, which resolves to 0.1.0.

This bumps the package to 0.2.0-next.0. The `-next.N` suffix publishes to
the `next` dist-tag, so `latest` stays on 0.1.0 and no existing install is
upgraded; the release is opt-in until it has been used against a real host.

Also adds the changeset #215 landed without, and lists the OpenCode 2
adapter in RELEASING.md's tag table. The publish workflow has accepted
`opencode2@*` tags since it was written; only the documentation omitted it,
which is the likeliest reason this package was never released.

No source change. The tag is not pushed here.

Co-authored-by: Claude Opus 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.

2 participants