fix(provider): normalize additional provider aliases - #126
Conversation
|
Warning Review limit reached
Next review available in: 3 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
Walkthrough本次变更重构了 provider 归一化与分组核心逻辑(canonicalize_provider_segment、normalize_provider_for_grouping、provider_tags),将 azure/github-copilot 系归一到 microsoft,moonshotai 归一到 kimi,mistralai 归一到 mistral,并更新了 ORIGINAL_PROVIDER_TAGS 常量。相应地同步了定价查找、聚合统计、CLI 显示格式化与会话解析各处的测试断言。 ChangesProvider 归一化重构与下游同步
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Merging this PR will improve performance by 62.5%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | normalize_provider_for_grouping[openai_codex_provider] |
9.1 µs | 3.6 µs | ×2.5 |
| ⚡ | normalize_provider_for_grouping[opencode_openrouter_path] |
9.2 µs | 3.8 µs | ×2.4 |
| ⚡ | normalize_provider_for_grouping[anthropic_provider_path] |
8.6 µs | 3.7 µs | ×2.3 |
| ⚡ | mixed_batch |
18.8 µs | 8.4 µs | ×2.2 |
| ⚡ | normalize_provider_for_grouping[zai_provider_alias] |
8.7 µs | 4.1 µs | ×2.1 |
| ⚡ | aggregation_engine_push_finish[model_only] |
266 ms | 158.9 ms | +67.45% |
| ⚡ | aggregation_engine_push_finish[workspace_model] |
320 ms | 222.7 ms | +43.65% |
| ⚡ | normalize_provider_for_grouping[github_copilot_provider] |
5.3 µs | 3.8 µs | +39.71% |
| ⚡ | aggregation_engine_push_finish[graph_sessions_time] |
1,081.7 ms | 868.3 ms | +24.58% |
| ⚡ | normalize_provider_for_grouping[kimi_provider_path] |
4.5 µs | 3.6 µs | +23.45% |
| ⚡ | aggregation_engine_push_finish[all_views] |
2.8 s | 2.3 s | +20.17% |
| ⚡ | aggregation_engine_push_finish[tui_client_model] |
760 ms | 645.2 ms | +17.79% |
| ⚡ | aggregation_engine_push_finish[tui_workspace_model] |
896.7 ms | 785.9 ms | +14.09% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing codex-provider-normalization (f139df8) with personal/local-clients (ede53ee)1
Footnotes
2f3a5cc to
dbfa7f0
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
crates/tokscale-cli/src/tui/ui/widgets.rs (1)
182-218: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win清理不可达的
"github-copilot"匹配分支。
normalize_provider_for_grouping现在会将github-copilot/copilot-chat规范化为"microsoft"(参见provider_identity.rs中"github_copilot" | "copilot_chat" => "microsoft"),因此本文件213行"github-copilot" => "GitHub Copilot".to_string()分支永远不会被匹配到,属于死代码,容易造成误导(读者可能误以为该 provider 仍显示为 "GitHub Copilot")。测试用例(第362行("github-copilot", "MicroSoft"))也印证了实际生效的是210行的"microsoft"分支。建议直接删除该死分支。
🧹 建议删除死代码
"cohere" => "Cohere".to_string(), "microsoft" => "MicroSoft".to_string(), "opencode" => "OpenCode".to_string(), "owl" => "Owl".to_string(), - "github-copilot" => "GitHub Copilot".to_string(), "commandcode" => "Command".to_string(), "unisound" => "UniSound".to_string(),🤖 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 `@crates/tokscale-cli/src/tui/ui/widgets.rs` around lines 182 - 218, Remove the unreachable github-copilot branch from get_single_provider_display_name in widgets.rs, since normalize_provider_for_grouping already maps github-copilot/copilot-chat to microsoft and the microsoft arm is the one that actually applies. Keep the existing provider display-name fallback logic intact, but delete the dead "GitHub Copilot" match arm to avoid misleading future readers and align the function with provider_identity normalization.crates/tokscale-core/src/provider_identity.rs (1)
100-110: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value移除
widgets.rs中失效的github-copilot分支:normalize_provider_for_grouping已把github-copilot/copilot-chat归到microsoft,因此这里不会再命中"github-copilot=>GitHub Copilot"。保留这条分支只会误导后续维护。🤖 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 `@crates/tokscale-core/src/provider_identity.rs` around lines 100 - 110, The provider normalization logic still has a stale GitHub Copilot-specific branch that can no longer be reached because normalize_provider_for_grouping already maps github-copilot and copilot-chat to microsoft. Remove the obsolete github-copilot handling from the provider grouping/mapping logic in provider_identity.rs, keeping the remaining microsoft, google, and opencode cases intact so the symbols normalize_provider_for_grouping and the related match arms stay consistent.
🤖 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.
Nitpick comments:
In `@crates/tokscale-cli/src/tui/ui/widgets.rs`:
- Around line 182-218: Remove the unreachable github-copilot branch from
get_single_provider_display_name in widgets.rs, since
normalize_provider_for_grouping already maps github-copilot/copilot-chat to
microsoft and the microsoft arm is the one that actually applies. Keep the
existing provider display-name fallback logic intact, but delete the dead
"GitHub Copilot" match arm to avoid misleading future readers and align the
function with provider_identity normalization.
In `@crates/tokscale-core/src/provider_identity.rs`:
- Around line 100-110: The provider normalization logic still has a stale GitHub
Copilot-specific branch that can no longer be reached because
normalize_provider_for_grouping already maps github-copilot and copilot-chat to
microsoft. Remove the obsolete github-copilot handling from the provider
grouping/mapping logic in provider_identity.rs, keeping the remaining microsoft,
google, and opencode cases intact so the symbols normalize_provider_for_grouping
and the related match arms stay consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 97284704-5668-40e6-8e9e-c11066f73df5
📒 Files selected for processing (7)
crates/tokscale-cli/src/tui/ui/widgets.rscrates/tokscale-core/src/aggregate/tui.rscrates/tokscale-core/src/lib_tests.rscrates/tokscale-core/src/pricing/lookup.rscrates/tokscale-core/src/pricing/lookup_tests.rscrates/tokscale-core/src/provider_identity.rscrates/tokscale-core/src/sessions/claudecode.rs
dbfa7f0 to
8297ab8
Compare
8297ab8 to
f139df8
Compare
What Changed
Normalize more provider aliases through the shared provider identity layer:
xai-oauth,grok,grok-oauth,grok-cli, andsupergrokcanonicalize/group asxai.moonshotai,moonshot-ai,kimi,kimi-code, andkimi-for-codingcanonicalize/group askimi.z.ai,z-ai,zhipu,zhipuai,bigmodel.cn, andopen.bigmodel.cncanonicalize/group aszai.vertex,vertex-ai,google-gemini-cli, andgoogle-antigravitycanonicalize/group asgoogle.github-copilot,copilot-chat,azure, andazure_aicanonicalize/group asmicrosoft.mistralai,meta_llama,fireworks_ai, andtogether_aicanonicalize/group asmistral,meta,fireworks, andtogether.Provider display now renders
microsoftasMicrosoft, and the stalegithub-copilotdisplay arm was removed because Copilot is now represented by the unified Microsoft provider identity.Aggregation now trusts finalized
UnifiedMessage.provider_idvalues instead of re-running provider normalization inside each accumulator.finalize_token_priced_messagesremains the canonicalization boundary for both model and provider ids.finalize_token_priced_messagesnow resolves provider ids through the full ingress order:owlshims, canonical providers, custom literal provider tags, model inference, thenunknown.Why
Local OMP data and built-in provider aliases were leaking raw provider names such as
xai-oauth, which made provider grouping and display inconsistent. Kimi was also usingmoonshotaias the canonical provider even though the displayed/provider grouping identity should bekimi.The aggregation engine already consumes finalized messages and did not re-canonicalize model ids; provider ids now follow the same boundary.
Custom provider ids such as
venicemust survive finalize so provider-aware pricing can match provider-scoped catalog keys.owlprovider shims must also survive finalize as the grouping/provider identity while still pricing through the inferred model provider.Pricing Impact
Kimi is now treated as the original provider tag for provider-aware pricing so existing
moonshotai/kimi-*pricing keys still match when the provider hint iskimi.Azure and Copilot catalog/provider hints now use the same
microsoftcanonical provider identity; there is no separate display-vs-pricing provider split.Custom provider names still participate in provider-aware pricing as literal provider tags without being promoted to canonical provider identities.
Validation
cargo test -p tokscale-core provider_identity --quietcargo test -p tokscale-core aggregate:: --quietcargo test -p tokscale-core test_provider_hint_prefers_matching_pricing_source --quietcargo test -p tokscale-core test_finalize_token_priced_messages_preserves --quietcargo test -p tokscale-core test_finalize_token_priced_messages_canonicalizes_provider --quietcargo test -p tokscale-core test_apply_token_pricing_prices_owl --quietcargo test -p tokscale-core --quietcargo test -p tokscale-cli --quietcargo bench -p tokscale-core --bench normalization normalize_provider_for_grouping -- --sample-size 10cargo bench -p tokscale-core --bench aggregation all_views -- --sample-size 10aggregation_engine_push_finish/all_viewstime improved by about 23%.