Skip to content

fix(opencode): read v2's native default variant as the Default option - #537

Open
ump45nose wants to merge 1 commit into
BytePioneer-AI:mainfrom
ump45nose:fix/528-opencode-v2-default-variant
Open

ump45nose wants to merge 1 commit into
BytePioneer-AI:mainfrom
ump45nose:fix/528-opencode-v2-default-variant

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Summary

OpenCode v2 的会话读取接口把默认 Thinking 变体原样返回为字符串 "default"。v2Catalog() 用 encodeOpenCodeVariant(undefined) 表示默认档位(ocv.default),而 v2State() 把原生的 "default" 当成普通变体名编码成 ocv.ZGVmYXVsdA,不在该模型的 availableThinkingOptions 里,于是 harnessConfigurationStateSchema 拒绝状态,界面显示「无法切换模型 / Model state was not confirmed」,而原生会话其实已经切换。

改动只在 v2 原生状态转换边界(packages/adapters/opencode/src/v2/state.ts):

  • 新增 effectiveVariant():原生变体为 "default",且该模型的 supportedThinkingOptionIds 里没有名为 default 的真实变体时,映射为目录的 Default 选项 ocv.default。
  • 如果某个模型自己确实声明了名为 default 的变体,保留其原有 ID,不做合并。
  • v1 的变体编码(encodeOpenCodeVariant / opencode-adapter.ts)和状态 schema 校验都没有改动。

Related issues

Fixes #528

Test plan

  • 新增 packages/adapters/opencode/test/v2.test.ts 中的 OpenCode v2 Thinking state 三个用例(原生 "default" → ocv.default 且在可用列表中;模型自己声明 default 变体时保留;显式变体 high 保持原 ID)。
    • 修复前:reads the native default variant as the catalog's Default option 失败,expected 'ocv.ZGVmYXVsdA' to be 'ocv.default'。
    • 修复后通过。
  • npx tsc -b 后 npx vitest run --config tests/vitest.config.js packages/adapters/opencode/test/:12 files passed / 2 skipped(real 测试),123 passed / 3 skipped。
  • npx tsc -p tests/tsconfig.json --noEmit:通过。
  • npx eslint 两个改动文件、node tools/check-boundaries.mjs、npx prettier --check 两个改动文件:通过。
  • 未验证:没有连接真实的 OpenCode v2.0.27 / Codex Desktop 做实机切换;没有跑完整的 npm test(含 Rust 部分),只跑了 OpenCode adapter 的定向测试。Node v24.21.0,Linux x64。

AI assistance disclosure: this change was prepared with help from an AI coding assistant. I reviewed the diff and ran the commands listed above myself.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: BytePioneer-AI/codex-host/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cd43166c-b091-466d-bbdb-1c7721520846
📥 Commits

Reviewing files that changed from the base of the PR and between 1aa9f65 and 3a83bab.

📒 Files selected for processing: 2
  • packages/adapters/opencode/src/v2/state.ts
  • packages/adapters/opencode/test/v2.test.ts

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

⏰ Context from checks skipped due to timeout: 4
  • GitHub Check: Check macos-14
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check windows-latest
  • GitHub Check: Check Linux ARM64
📝 Summary

Summary by CodeRabbit

  • 问题修复
    • 修正 OpenCode 的思考选项显示:当模型不支持名为“default”的变体时,默认选项会正确显示为无变体的“Default”;模型支持该变体时,仍保留其显式选项。
    • 其他显式变体(如“high”)继续显示为对应选项。

OpenCode v2 状态转换新增有效 Thinking 变体选择逻辑。当模型目录不支持编码后的 default 变体时,状态映射到 Default 选项;测试覆盖此情形及显式变体。

Changes: OpenCode v2 Thinking 状态映射

Layer / File(s) Summary
归一化 Thinking 变体并验证状态
packages/adapters/opencode/src/v2/state.ts, packages/adapters/opencode/test/v2.test.ts
v2State 根据模型目录是否包含编码后的 default 变体,设置 effectiveThinkingOptionId。测试覆盖默认值映射到无变体的 Default 选项,以及保留显式 default 和 high 变体。

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: bytepioneer-ai

Merge Risk: ⚪ Minimal · up to 3a83b

No actionable issue is established for the OpenCode v2 Thinking state change; it is mergeable after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed 标题准确概括了主要修复:将 OpenCode v2 的原生 default variant 读取为目录中的 Default 选项。标题简洁、明确,并与变更内容一致。
Description check Passed 描述与变更内容直接相关。它说明了问题原因、v2 状态转换逻辑、例外处理、测试覆盖范围和验证结果。
Linked Issues check Passed PR 实现了 #528 的编码归一化要求。v2State() 现在调用 effectiveVariant();当原生变体为 "default" 且模型没有该名称的真实变体时,返回目录默认 ID ocv.default。模型声明真实 default 变体时保留其编码 ID。显式 high 变体保持原 ID。新增的三个 v2 Thinking state 测试覆盖这些情况,并验…
Out of Scope Changes check Passed 变更仅涉及 OpenCode v2 状态转换及其定向测试。测试直接验证 #528 的默认和显式 Thinking 变体映射。未发现与 #528 无关的生产代码、v1 行为或 schema 变更。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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

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.

[Bug] OpenCode v2 默认 Thinking 编码不一致,导致模型切换后状态确认失败

1 participant