fix: /status 优先从 session API 获取实际模型,修复模型显示不一致问题#17
Conversation
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughTwo orthogonal changes: removal of ChangesPackage Dependencies and Distribution
Status Handler Model Resolution
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 winRemove the
discord.jslibrary import from the codebase or restore the dependency.The
discord.jsdependency was removed frompackage.json, but the codebase still imports it insrc/channel/discord/discord-plugin.tsat 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 winVariable shadowing breaks context limit calculation.
Line 1455 declares a new local
modelStrthat 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
📒 Files selected for processing (2)
package.jsonsrc/handler/command-handler.ts
4fdca21 to
d0c9657
Compare
/status 命令原本只读取 model.json 的全局偏好,导致显示的模型与实际 session 使用的模型不一致。 修复: - 模型数据源改为 API 实时查询优先,DB 存储和 model.json 作为回退 - 消除 context 计算中 modelStr 变量遮蔽,确保 context 用量计算使用正确模型 - 去除因重构引入的重复 session 信息显示
d0c9657 to
1cc35f6
Compare
问题
/status命令显示的模型与 TUI session 实际使用的模型不一致。例如:
/status显示opencode/deepseek-v4-flash-free,但 TUI 中 session 实际使用的是minimax-m2.5-free。根因:
handleStatus()只读取~/.local/state/opencode/model.json的favorites[0]作为模型来源,完全不看当前 session 的实际模型。修复
模型显示改为三级回退:
model字段GET /session/{id}sessionData.model实时提取model.json全局偏好同时修复了重构时引入的重复 session 信息显示问题。
改动
src/handler/command-handler.ts—handleStatus()中合并 session API 请求,优先从 session 数据提取模型package.json— 上游原有改动验证
npx tsc --noEmit通过bun test全部 432 个测试通过/status显示模型与 TUI 一致Summary by CodeRabbit
Chores
Refactor