Skip to content

修复与新增:路由策略及剩余额度优先策略 - #540

Closed
guyu233 wants to merge 8 commits into
caigee-cmd:mainfrom
guyu233:pr3/routing-strategies
Closed

guyu233 wants to merge 8 commits into
caigee-cmd:mainfrom
guyu233:pr3/routing-strategies

Conversation

@guyu233

@guyu233 guyu233 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

本 PR 基于 pr2/max-context 分支;如单独审查,请关注“路由策略及剩余额度优先策略”相关提交。

本 PR

  • 修复模型池策略覆盖时候选计数、容量判断和选号使用不同策略的问题。
  • 读取存储模型池策略时做归一化,避免历史大小写或旧值静默退回轮询。
  • 修复新建模型池默认策略与弹窗默认策略不一致。
  • 新增 least-quota-first 和 most-quota-first 两个策略。
  • 新策略按剩余额度百分比排序,并支持全局账号调度和模型池。

Adds logical models that aggregate real provider models behind one client-facing ID, with per-pool routing strategy, failover settings and weighted members. Keys can be restricted to aggregation grants. Adds a one-click per-account model availability probe that does not alter routing cooldowns or usage totals. Refreshes the console Models/Keys/navigation UI and embed assets. Adds a cross-region failover regression test and a project audit report. Ignores .dev-runtime/ which holds local auth blobs and runtime DBs.
@caigee-cmd

Copy link
Copy Markdown
Owner

感谢提交!这个 PR 有几个问题需要修一下再合,主要是两个阻断项:

🚨 阻断项 1:Migration 编号冲突

PR 在 internal/store/migrations.go 里新增的是 028_aggregations.sql,但 main 上已经有:

  • 028_account_credit_floor.sql
  • 029_account_percent_floor.sql

这会导致已有数据库启动时 checksum 校验失败。

怎么改: 把你的迁移改成 030_aggregations.sql,作为一个新条目追加在末尾。不要修改已有迁移的 SQL 内容(包括缩进、空格和注释,raw string 里的字节变了都会触发 checksum mismatch)。

🚨 阻断项 2:模型池 failover 的 MaxAttempts 被覆盖

newRouteLoop 里,pickNext 在 l.regionFilter == "" 分支重新计算了 l.attempts = e.attemptsFor(...),把 plan 传进来的 MaxAttempts 覆盖掉了。同时 region pin 逻辑会把 failover 限制在第一个成员的 region,跨 provider 的池成员根本轮不到。

怎么改: aggregated loop 里跳过 region pin,也不要重新计算 attempts,直接用 plan 里的 MaxAttempts。

⚠️ 其他需要修的问题

  1. PR 把 pr2/max-context 的代码也打包进来了(约 6900 行),包括模型池、强制最大上下文、availability probe 等功能。这样这个 PR 没办法单独 review 和合并,diff 也和 main 产生了大量冲突。建议:

  2. quotaRemainingRatio 的零值处理:Total == 0 && Percentage == 0 时返回 ratio 1.0,并被当作"已知"处理,会让没有配额快照的账号排在 most-quota-first 最前面。应该只在 Total > 0 或明确上报了 percentage 时才认为是已知值,否则视为 unknown,排到最后。

  3. vite.config.ts 端口改动(5179 → 5180,3010 → 4010)是本地开发配置,请还原,不要提交到 PR 里。

  4. docs/PROJECT_AUDIT.md:项目的 AGENTS.md 明确说不要新增额外的计划/笔记文件,这个文件请删掉,或者只保留在本地。

修好之后欢迎重新提交,路由策略功能本身的设计是对的,就差这几个地方。🙏

Rebuilt on current main. Migration is 031 (030 is reserved by the pending key aggregation PR). Display reasoning levels stay catalog-driven instead of merging the full gateway set, and local-only audit/vite changes are dropped. Changelog now notes probe quota cost and the priority-order default.
Chat requests no longer receive a gateway-chosen context window; only a client-supplied window is forwarded. Catalog maxima and Trae max mode are display/forward-only. The console per-model context setting and max-mode switches are dropped with a changelog note, and the changelog file now matches the passthrough semantics. Also aligns reasoning conversion with CC Switch (ultra tier, Anthropic thinking budgets).
@guyu233
guyu233 force-pushed the pr3/routing-strategies branch from ade4c52 to 5240a72 Compare November 23, 2026 08:16
@caigee-cmd

Copy link
Copy Markdown
Owner

感谢更新!上一轮的阻断项都修了,逐条确认:

  • quotaRemainingRatio 已改为 Total > 0 或 Percentage > 0 才算已知,零值快照返回 unknown 并排到最后
  • aggregated loop 已跳过 region pin,也不再重算 attempts,plan.MaxAttempts 不会被 attemptsFor 覆盖(chat.go 里 l.plan == nil 的守卫)
  • vite.config.ts 端口改动和 docs/PROJECT_AUDIT.md 已移除
  • 额度感知策略(least-quota-first / most-quota-first)保留了 region latch,没有关掉会话粘性,所以这个不需要再拆出去

还不能合,卡在 #538

本 PR 包含 #538 和 #539 的全部提交。#538 现在和已合并的 #574 冲突:两边都新增了 030_api_key_model_aggregation.sql,而且是两套不同的「模型聚合」实现(详见 #538 的评论)。#538 定稿后依次 rebase #539、本 PR 即可,路由策略这部分本身没有新的阻断项。

@guyu233

guyu233 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

已被独立拆分的 #581(聚合)和 #582(账号路由 failover)替代。原分支包含重复的聚合/上下文提交且已冲突,关闭以清理堆叠。

@guyu233 guyu233 closed this Nov 23, 2026
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