Skip to content

fix: /status 优先从 session API 获取实际模型,修复模型显示不一致问题#17

Merged
ET06731 merged 1 commit into
ET06731:mainfrom
shf-275599:fix/status-model-source
May 16, 2026
Merged

fix: /status 优先从 session API 获取实际模型,修复模型显示不一致问题#17
ET06731 merged 1 commit into
ET06731:mainfrom
shf-275599:fix/status-model-source

Conversation

@shf-275599
Copy link
Copy Markdown
Contributor

@shf-275599 shf-275599 commented May 14, 2026

问题

/status 命令显示的模型与 TUI session 实际使用的模型不一致。

例如:/status 显示 opencode/deepseek-v4-flash-free,但 TUI 中 session 实际使用的是 minimax-m2.5-free

根因handleStatus() 只读取 ~/.local/state/opencode/model.jsonfavorites[0] 作为模型来源,完全不看当前 session 的实际模型。

修复

模型显示改为三级回退:

优先级 数据源 说明
Session 映射 model 字段 DB 中存储的 per-session 绑定模型
opencode API GET /session/{id} sessionData.model 实时提取
model.json 全局偏好 兜底,保持向后兼容

同时修复了重构时引入的重复 session 信息显示问题。

改动

  • src/handler/command-handler.tshandleStatus() 中合并 session API 请求,优先从 session 数据提取模型
  • package.json — 上游原有改动

验证

  • npx tsc --noEmit 通过
  • bun test 全部 432 个测试通过
  • 飞书实测 /status 显示模型与 TUI 一致

Summary by CodeRabbit

  • Chores

    • Removed unused dependency from project configuration
    • Updated package metadata to include license file
  • Refactor

    • Improved status command's model resolution logic to better prioritize session-based detection over fallback methods

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@shf-275599 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 58 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf52a177-211e-4be3-a3e0-df579f2d9197

📥 Commits

Reviewing files that changed from the base of the PR and between 4fdca21 and 1cc35f6.

📒 Files selected for processing (2)
  • package.json
  • src/handler/command-handler.ts

Walkthrough

Two orthogonal changes: removal of discord.js dependency and updated file allowlist in package.json; /status handler now prioritizes model resolution from session mapping, then session data, before falling back to file-based detection.

Changes

Package Dependencies and Distribution

Layer / File(s) Summary
Dependency and file manifest updates
package.json
discord.js dependency removed; "files" allowlist now includes "LICENSE" and omits "CHANGELOG.md".

Status Handler Model Resolution

Layer / File(s) Summary
Model priority chain
src/handler/command-handler.ts
/status handler reorganized to initialize modelStr from session mapping first, then derive from fetched session data (providerID + id) if unset, falling back to getCurrentModelFromFile() only as last resort. Context-usage variable declarations moved to follow the updated model-resolution block.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 The discord.js hops away so bright,
While LICENSE now shines in the files' light.
Model paths cascade in pretty order—
Session first, then data, then the border.
A small but tidy hop for our code! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main fix: prioritizing model retrieval from session API and fixing model display inconsistency issues in the /status command.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes the discord.js dependency and excludes CHANGELOG.md from the package distribution. It also refactors the model resolution logic in command-handler.ts to implement a priority system where session-specific models take precedence over API-provided models and global configuration. A review comment identifies a variable shadowing issue where a later re-definition of modelStr causes context limit calculations to bypass this new priority logic and perform redundant file I/O.

Comment thread src/handler/command-handler.ts Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
package.json (1)

43-53: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Remove the discord.js library import from the codebase or restore the dependency.

The discord.js dependency was removed from package.json, but the codebase still imports it in src/channel/discord/discord-plugin.ts at line 1. This will cause a runtime error when the Discord plugin is instantiated. Either restore the dependency or remove the Discord plugin implementation entirely.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` around lines 43 - 53, The Discord plugin import at the top of
src/channel/discord/discord-plugin.ts still references discord.js but the
dependency was removed from package.json, causing runtime failure; fix by either
restoring discord.js to package.json dependencies and running the package
manager (e.g., add "discord.js": "<appropriate-version>" then npm/yarn install)
so the import in discord-plugin.ts resolves, or remove/disable the Discord
plugin code paths (delete or gate the file and any registrations that reference
the DiscordPlugin class or instantiate it) so no code imports discord.js; ensure
you update any plugin registration logic that mentions DiscordPlugin to prevent
unresolved references.
src/handler/command-handler.ts (1)

1455-1455: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Variable shadowing breaks context limit calculation.

Line 1455 declares a new local modelStr that shadows the outer variable initialized at line 1379. This causes the context limit to be looked up using only the file-based model (getCurrentModelFromFile()), not the session's actual model that was determined by the three-level priority.

If the session is using a different model than what's in model.json, the displayed context usage percentage will be incorrect, undermining this PR's goal of showing accurate session model information.

🐛 Proposed fix
       const providerData = (await providerResp.json()) as {
         all?: Array<{
           id?: string
           models?: Record<string, { name?: string; limit?: { context?: number } }>
         }>
       }
-      const modelStr = await getCurrentModelFromFile()
       if (modelStr) {
         const parts = modelStr.split("/")

The outer modelStr (from line 1379) is already in scope and contains the correct model determined by the priority chain.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/handler/command-handler.ts` at line 1455, A local declaration "modelStr"
created from getCurrentModelFromFile() shadows the outer modelStr (the
session-resolved model) and causes context limit calculations to use the
file-based model instead of the session model; remove the inner declaration and
use the outer modelStr (or rename the inner variable) so the code that computes
context usage and calls the context-limit lookup uses the already-resolved
session modelStr (the variable defined earlier) rather than
getCurrentModelFromFile(), ensuring accuracy in context percentage display.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@package.json`:
- Around line 43-53: The Discord plugin import at the top of
src/channel/discord/discord-plugin.ts still references discord.js but the
dependency was removed from package.json, causing runtime failure; fix by either
restoring discord.js to package.json dependencies and running the package
manager (e.g., add "discord.js": "<appropriate-version>" then npm/yarn install)
so the import in discord-plugin.ts resolves, or remove/disable the Discord
plugin code paths (delete or gate the file and any registrations that reference
the DiscordPlugin class or instantiate it) so no code imports discord.js; ensure
you update any plugin registration logic that mentions DiscordPlugin to prevent
unresolved references.

In `@src/handler/command-handler.ts`:
- Line 1455: A local declaration "modelStr" created from
getCurrentModelFromFile() shadows the outer modelStr (the session-resolved
model) and causes context limit calculations to use the file-based model instead
of the session model; remove the inner declaration and use the outer modelStr
(or rename the inner variable) so the code that computes context usage and calls
the context-limit lookup uses the already-resolved session modelStr (the
variable defined earlier) rather than getCurrentModelFromFile(), ensuring
accuracy in context percentage display.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8bc96b02-8efa-4f4c-ac94-2f9e74eb23d9

📥 Commits

Reviewing files that changed from the base of the PR and between 3515c87 and 4fdca21.

📒 Files selected for processing (2)
  • package.json
  • src/handler/command-handler.ts

@shf-275599 shf-275599 force-pushed the fix/status-model-source branch from 4fdca21 to d0c9657 Compare May 14, 2026 00:30
/status 命令原本只读取 model.json 的全局偏好,导致显示的模型与实际
session 使用的模型不一致。

修复:
- 模型数据源改为 API 实时查询优先,DB 存储和 model.json 作为回退
- 消除 context 计算中 modelStr 变量遮蔽,确保 context 用量计算使用正确模型
- 去除因重构引入的重复 session 信息显示
@shf-275599 shf-275599 force-pushed the fix/status-model-source branch from d0c9657 to 1cc35f6 Compare May 14, 2026 00:37
@ET06731 ET06731 merged commit 7628018 into ET06731:main May 16, 2026
2 checks passed
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