Skip to content

feat(ai-gateway): enforce gateway name prefixes - #3150

Merged
wklken merged 4 commits into
TencentBlueKing:masterfrom
wklken:feat/ai-gateway-name-prefix
Aug 11, 2026
Merged

feat(ai-gateway): enforce gateway name prefixes#3150
wklken merged 4 commits into
TencentBlueKing:masterfrom
wklken:feat/ai-gateway-name-prefix

Conversation

@wklken

@wklken wklken commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Description

  • require newly created AI gateways to use the bkai- prefix
  • reserve bkai- from non-AI gateway creation
  • allow bkaidev and bkaidev-* only when V1/V2 automated sync creates an AI gateway
  • preserve updates to existing gateways and document the V1/V2 naming contract

Checklist

  • 填写 PR 描述 (write PR description)
  • 代码风格检查通过 (code style check passed)
  • PR 中包含单元测试 (include unit test)
  • 单元测试通过 (unit test passed)
  • 本地开发联调环境验证通过 (local development environment verification passed)

Verification:

  • uv run make lint-check
  • uv run make test (3807 passed)
  • focused gateway-name/API tests (182 passed)

wklken added 3 commits August 11, 2026 16:45
Require new AI gateways to use the bkai- prefix and reserve that prefix from non-AI gateways.

Allow bkaidev and bkaidev-* only when V1 or V2 automated sync creates an AI gateway, while preserving updates to existing gateways.

Document the naming contract and cover Web, sync serializers, saver behavior, official gateways, and compatibility cases.
Use bkai-demo consistently in the V1 and V2 sync response examples so they match the request path and returned gateway name.
Allow the internal bkaidev name convention across Web, V1/V2 sync, and direct Saver creation through one shared validator.

Remove the source-specific flag and keep public API documentation and error messages focused on the bkai- naming rule.

@wklken wklken left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

PR #3150 合并 Review 报告(Codex + Claude 双模型汇总)

仓库: TencentBlueKing/blueking-apigateway
PR: feat(ai-gateway): enforce gateway name prefixes (#3150)
作者: wklken | 分支: feat/ai-gateway-name-prefixmaster
审查 commit: a9361f63809b21c3ed99e2276162535be0336260
模型: Codex (gpt-5.6-sol) + Claude Opus 5 [1m]

合并建议

merge after fixes — 两个模型一致认为改动方向正确、兜底点选得对(GatewaySaver._create_gateway 覆盖全部创建入口)、测试与文档同步到位,无 Critical 缺陷。但存在「意图与实现不吻合」类问题需合并前确认。


双模型一致关注点

High Issues(建议合并前修复)

H1. bkaidev* 未从非 AI 网关侧保留 → 自动化同步名可被永久抢占

  • 位置:service/gateway_name.py:29-34、相关 sync 测试
  • kind != AI 分支只拦 bkai- 前缀,对 bkaidev/bkaidev-* 完全放行。网关名全局唯一,若任何用户先建名为 bkaidev 的普通网关,V1/V2 自动化同步再建同名 AI 网关会永久失败——而这恰是本 PR 开的豁免口子。
  • 建议:将 bkaidev/bkaidev- 一并纳入「仅 AI 可用」保留前缀集合,或明确注释说明为何允许被占用。

H2. allow_bkaidev_ai_name 在 sync 入口硬编码 True,与「仅自动化同步」描述不符

  • 位置:biz/gateway/gateway.py:285apis/open/gateway/serializers.py:178apis/v2/sync/serializers.py:180
  • sync_gateway() 对所有 openapi 同步请求无条件传 True,未按 app_code 区分,实现等价于「任何有 sync 权限的应用都能创建 bkaidev* AI 网关」。文档也写成了对所有调用方公开的规则,与「专用名称」表述矛盾。
  • 建议:若只允特定应用,加 bk_app_code 白名单;若接受所有 sync 调用方,修正 PR 描述与文档措辞。

Medium Issues

  • M1(字面值泛滥/设计偏差)"bkai-""bkaidev" 直接硬编码进新模块(共 6 处),未复用既有 settings.OFFICIAL_GATEWAY_NAME_PREFIXES / RESERVED_GATEWAY_NAME_PREFIXES 机制。
  • M2:sync SLZ 与 GatewaySaver 双重校验存在冗余(Codex 认为属合理纵深保护,Claude 列为可后续清理)。
  • M3(i18n)service/gateway_name.py 三条新错误为裸中文字符串,绕过项目 gettext 机制,非中文环境固定显示中文。
  • M4(代码组织):纯字符串校验器落在 service/ 而非更通用的 common/

Low Issues

  • Django Admin 创建路径未接入新命名约束(GatewayAdmin 可绕过),属历史创建边界未被新不变量覆盖(Codex 提出)。
  • 错误文案未国际化(M3 同)。

双方一致认可(Dismissed / 合理设计)

  • 已有网关更新跳过新命名规则:create/update 已正确区分,与历史兼容一致。
  • 重复校验属合理纵深保护(覆盖 management command 等非 HTTP 入口)。
  • 无 Critical 缺陷,无会导致崩溃或数据损坏的问题。

[from openclaw-internal]

@wklken
wklken merged commit 1731cd3 into TencentBlueKing:master Aug 11, 2026
4 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.

1 participant