已合并
fix(deployment): 显式 id=None 时自动生成,避免部署状态互相覆盖与 fallback 失效 #343
fix(deployment): 显式 id=None 时自动生成,避免部署状态互相覆盖与 fallback 失效 #343
已合并
庄昭雄创建于 10月18日
庄昭雄
庄昭雄
10月18日

Paired: GitHub #139 ↔ GitCode !343

What type of PR is this?
/kind bug

What does this PR do / why do we need it:

intelli_router 的 Deployment.id 文档语义是「可选,缺省时自动生成」,但 dataclass 的 default_factory 只在省略参数时生效。agent-core 的包装层会把配置里的缺省值原样透传成 id=None("id": dep_cfg.get("route_id") or dep_cfg.get("id")),而 Deployment.__post_init__ 既不补全也不校验 id,于是多个部署共享 id=None:

  • ReliableRouter 的状态(deployment_status / consecutive_failures / cooldown_until)以 d.id 为 key → 全部折叠到 "null",互相覆盖;
  • 失败后 available = [d for d in available if d.id != selected.id] 中 None != None 为假 → 一次清空所有 None-id 候选,健康备用部署一次都不会被请求,直接 AllDeploymentsFailed。

修法(intelli_router/core/deployment.py,+14 行):__post_init__ 里 id is None 时自动生成 8 位 id(与 default_factory 一致);非字符串抛 TypeError、空白字符串抛 ValueError。另加 8 条测试。

Which issue(s) this PR fixes:

无既有 issue:已核对全仓 76 条 issue 与最近 100 条 MR,intelli_router 相关(#72/#71/#66/#51/#50/#49/…/#39、!315/!314/!303/!301/!309)全部 closed,且 #51 只校验 tpm/rpm/consecutive_failures 未含 id;GitHub 上游 route_id 0 命中,历史 intelliRouter 改造 PR(#81/#84/#95/#97/#99)都 merged,缺陷在其之后仍存在。

What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.):

两个本地 OpenAI 兼容 mock(A 固定 500,B 正常),strategy="ordered-failover"、num_retries=2,不需要真实 LLM:

[基线 f70ae82] 部署 id 缺省(文档允许)
  [with_ids=False] ids: None None
  INVOKE FAILED: AllDeploymentsFailed All deployments failed for model 'm1' | bad hits: 1 ok hits: 0
  stats: {"deployment_status": {"null": "cooldown"}, "consecutive_failures": {"null": 1}, ...}

[本 PR] 同一份代码、同一组 mock
  [with_ids=False] ids: 3fd018cf 1af87ae0
  INVOKE OK: ok | bad hits: 1 ok hits: 1
  stats: {"deployment_status": {"3fd018cf": "cooldown", "1af87ae0": "healthy"}, ...}
  • 对照(with_ids=True,同一份代码其他不变):基线/本 PR 都 INVOKE OK | bad hits 1, ok hits 1。
  • cd intelli_router && PYTHONPATH=. pytest tests -q → 620 passed, 3 skipped(基线 612 + 新增 8)。
  • 只回退 deployment.py、保留新测试 → 8 failed, 24 passed;恢复补丁 → 32 passed。

Self-checklist:(Please check carefully,and mark an x in the [] brackets. We will review your completion status.)

注意:本 PR 的 base 是 feature/intelliRouter(intelli_router 子包只存在于该分支,develop 上没有)。

Linked Closing Issues:

Fixes #85

likedislike
Pull Request已成功合入, 合并人@openJiuwen-bot
(感谢 庄昭雄 的贡献)
atomgit-bot
atomgit-bot
10月18日 评论:

变更摘要

本 PR 修复 intelli_router 中 Deployment.id 缺省语义失效的问题:由于 dataclass 的 default_factory 仅在省略参数时生效,而 agent-core 包装层会把配置中缺失的 id 原样透传为 id=None,导致多个部署共用同一 id(被折叠为 "null"),进而使 ReliableRouter 的 deployment_status / consecutive_failures / cooldown_until 按 key 互相覆盖,并使失败剔除逻辑一次清空全部 None-id 候选、fallback 失效。修复在 Deployment.__post_init__ 中补全显式 None 的自动生成路径,并新增校验与测试。

主要改动

  • 补全显式 id=None 的缺省语义: 在 intelli_router/core/deployment.py 的 Deployment.__post_init__ 中,当 self.id is None 时自动生成 8 位 id(str(uuid.uuid4())[:8]),与 default_factory 行为保持一致,避免多部署共享 id=None 导致状态互相覆盖与 fallback 失效。
  • 新增 id 类型与空白校验: 非字符串 id 抛 TypeError,空白字符串抛 ValueError,使非法输入被显式拒绝而非静默透传。
  • 新增 id 相关测试: 在 intelli_router/tests/test_core_deployment.py 中新增 8 条用例,覆盖显式 id=None 自动生成、两次生成不同、非字符串 TypeError 与空白 ValueError。
  • 接口行为变更: Deployment(id=None) 从「保持 None」变为「自动生成 id」,属于文档既有语义的补齐,调用方无需改动。
likedislike
不准确?
OopenJiuwen-bot成员
10月18日 将YiyangShao,xinyu-jiuwen设为审查人
atomgit-bot
atomgit-bot
10月18日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
atomgit-bot
atomgit-bot
10月18日 评论:

AtomGit AI 助手使用指南

在 PR 评论中使用命令即可触发。支持在普通评论和代码行评论中使用。

功能 命令 说明
代码审查 /ai review 检查代码质量、潜在问题、安全风险
PR 摘要 /ai summary 生成 PR 变更内容的结构化摘要
代码解释 /ai explain 解释代码变更的逻辑和意图
自由提问 @atomgit-bot <问题> 询问关于本 PR 的任何问题
帮助 /ai help 显示此帮助信息

免责声明

AI 助手可能存在误判,请结合自身判断。可以对评论点 👍 或 👎 帮助我们改进。

likedislike
不准确?
OopenJiuwen-bot成员
10月18日 添加了label:sig/sig-agent-protocol
此处折叠了45条消息 查看更多
openJiuwen-bot成员
17 天前 评论:

Review Code Feedback

  • The label lgtm-mingo007, approved was added to this pull request. It means that mingo007 reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
yutaoJustinBieber1223yutaoJustinBieber1223成员
17 天前 解决了最后一个问题
OopenJiuwen-bot成员
17 天前 关闭了关联的issue
OopenJiuwen-bot成员
17 天前 合入了pull request
OopenJiuwen-bot成员
17 天前 删除了label:ci-successful