Skip to content

bug: 本地推理全量 401/403 — fusion-mlx-adapter 未注入 X-Fusion-Route 且 key 层级错配 #52

Closed

Description

@dahai80

现象

fusion-code v0.4.13 默认 provider (fusionMlx) 通过 gateway (127.0.0.1:11432) 调用本地推理,所有请求返回 401/403,本地推理完全不可用。这是 fusion "local-first" 默认路径,对外发布后无 cloud key 的用户开箱即坏。

根因 (fusion-code 侧,双重)

1. 未注入 X-Fusion-Route 头

fusion-mlx 在 #343/#349 已将 X-Fusion-Route 头校验设为 Phase 2 默认 enforce (见 fusion_mlx/middleware/route_guard.py)。缺失该头的请求被 403 拒绝。gateway 正常会注入此头,但 fusion-code 直连 MLX 或经 gateway 转发时,自身未携带该头。

src/services/api/fusion-mlx-adapter.ts 中 getMlxAuthHeaders() 只构造 Authorization,从未添加 X-Fusion-Route:

function getMlxAuthHeaders(): Record<string, string> {
    const apiKey = getMlxApiKey();
    if (!apiKey) return {};
    return { Authorization: `Bearer ${apiKey}` };
}

2. API key 层级错配

fusion-code 把 FUSION_MLX_API_KEY (MLX 层 key, 如 dahai168) 作为 Bearer 发给 gateway 层。gateway 有独立的 key 体系 (fusion-gateway/config.yaml 的 auth.api_keys, 如 fg-demo-key-change-me / fg-master-key-change-me),不认 MLX key → 401。

实测矩阵 (curl 直连)

目标 Header 状态码
MLX 11434 正确 key, 无 route 头 Authorization: Bearer dahai168 403 ❌
MLX 11434 正确 key, 有 route 头 Authorization: Bearer dahai168 + X-Fusion-Route: local 200 ✅
Gateway 11432 用 MLX key (层级错配) Authorization: Bearer dahai168 + X-Fusion-Route: local 401 ❌
Gateway 11432 用 gateway key (正确层级) Authorization: Bearer fg-demo-key-change-me + X-Fusion-Route: local 200 ✅

影响等级

P0 阻断。默认 provider 路径不可用 → 阻断 v0.4.13 对外发布 (见 ~/fusion/validation/validation-code-result1.md 门禁 G6/G11 未通过)。

复现

# fusion-mlx 已启动,gateway 已启动 (11432 占用)
FUSION_MLX_API_KEY=dahai168 ./fusion-code
# 进入 REPL 发送任意消息 → 401/403,本地推理失败

建议修复方向 (待讨论)

  1. 注入 X-Fusion-Route: getMlxAuthHeaders() 增加 X-Fusion-Route: local (或可配置值),与 fusion-mlx route_guard Phase 2 对齐。
  2. 区分 gateway key 与 MLX key: 经 gateway 时使用 gateway 层 key (FUSION_GATEWAY_API_KEY),直连 MLX 时使用 FUSION_MLX_API_KEY;不要把 MLX key 当 gateway key 用。
  3. 401/403 明确引导: 持续 401/403 时输出诊断 (而非静默重试 3 次),提示用户检查 key 与 route 头配置。

关联

环境

  • fusion-code v0.4.13
  • fusion-mlx (route_guard Phase 2 enforce 默认开)
  • fusion-gateway (config.yaml api_keys: fg-demo-key-change-me / fg-admin-key / fg-master-key-change-me)

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions