Skip to content

fix: inject X-Fusion-Route header + separate gateway/MLX API key layers (#52) - #53

Merged
dahai80 merged 1 commit into
mainfrom
fix/issue-52-mlx-route-header-key-layering
Aug 5, 2026
Merged

dahai80 merged 1 commit into
mainfrom
fix/issue-52-mlx-route-header-key-layering

Conversation

@dahai80

@dahai80 dahai80 commented Aug 5, 2026

Copy link
Copy Markdown
Owner

修复 D1 P0 阻断缺陷 — 本地推理全量 401/403

Closes #52

根因 (均在 fusion-code 侧)

  1. 未注入 X-Fusion-Route 头: fusion-mlx route_guard (feat(bench): count silent-stream retries per task #343/Headless runs give up on 529 after 3 retries while claude code retries ~10 — workers die in transient capacity cascades #349) Phase 2 默认 enforce,缺失该头 → 403。
  2. API key 层级错配: 把 MLX 层 key (FUSION_MLX_API_KEY) 当 Bearer 发给 gateway 层;gateway 有独立 key 体系 → 401。

修复

  • getMlxAuthHeaders() 统一注入 X-Fusion-Route 头 (默认 local,可经 FUSION_ROUTE_HEADER 覆盖),覆盖全部 8 处请求点。
  • 新增 isGatewayBaseUrl() + getGatewayApiKey():经 gateway (11432) 时用 FUSION_GATEWAY_API_KEY,直连 MLX (11434) 时用 FUSION_MLX_API_KEY。
  • checkFusionMlxHealth() 区分 401/403 并输出诊断引导 (兼修 D2)。
  • mlxFetchWithRetry() 401/403 不再静默。

实测验证

路径 Headers 结果
gateway 11432 + gateway key X-Fusion-Route: local + Bearer fg-demo-key-change-me available: true ✅
MLX 直连 11434 + MLX key X-Fusion-Route: local + Bearer dahai168 55 模型 ✅

回归

  • tsc 0 error
  • 320 单元测试 pass / 0 fail
  • 无新增 lint (新代码 biome-clean)

配置提示

用户经 gateway 时须设 FUSION_GATEWAY_API_KEY 为 gateway config 的 key,而非 FUSION_MLX_API_KEY。

🤖 Generated with Claude Code

…rs (#52)

D1 P0: 本地推理全量 401/403。fusion-mlx route_guard (#343/#349) Phase 2
默认 enforce,缺失 X-Fusion-Route 头的请求被 403 拒绝;且 fusion-code 把
MLX 层 key (FUSION_MLX_API_KEY) 当 Bearer 发给 gateway 层,gateway 有独立
key 体系 → 401。

修复:
- getMlxAuthHeaders() 统一注入 X-Fusion-Route 头 (默认 local,可经
  FUSION_ROUTE_HEADER 覆盖),覆盖全部 8 处请求点。
- 新增 isGatewayBaseUrl() + getGatewayApiKey():经 gateway (11432) 时用
  FUSION_GATEWAY_API_KEY,直连 MLX (11434) 时用 FUSION_MLX_API_KEY。
- checkFusionMlxHealth() 区分 401 (鉴权失败) / 403 (route 头缺失),
  输出明确诊断引导 (兼修 D2)。
- mlxFetchWithRetry() 401/403 不再静默,输出层级与 key 检查提示。

验证:
- gateway 路径 (X-Fusion-Route: local + Bearer fg-demo-key-change-me)
  → available:true
- MLX 直连路径 (X-Fusion-Route: local + Bearer dahai168) → 返回 55 模型
- tsc 0 error / 320 单元测试 pass / 无新增 lint

Co-Authored-By: Claude <[email protected]>
@dahai80
dahai80 merged commit 00957f7 into main Aug 5, 2026
1 check passed
@dahai80
dahai80 deleted the fix/issue-52-mlx-route-header-key-layering branch August 5, 2026 10:04
dahai80 added a commit that referenced this pull request Aug 30, 2026
…1 slice #53)

Extract handleQueuedCommandOnCancel useCallback body (~17 LOC) from REPL.tsx
into src/screens/handleQueuedCommandCancelCheck.ts as
createHandleQueuedCommandOnCancel(ctx) (curried factory). Restore queued
command on permission-cancel: popAllEditable -> set input text + prompt mode
+ restore images to pastedContents. deps (inputValue/setInputValue/
setInputMode/setPastedContents) via ctx. Remove REPL sole-user import
popAllEditable.

REPL 5341->5333 (-8). Gates: typecheck 0 / 921 tests / biome new-file /
build:dev.

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…slice #55)

resetLoadingState useCallback body 外移 to resetLoadingStateCheck.ts
(INLINE-CALLBACK curried-factory, like #46/#49/#50/#53).
12 deps via ctx; setIsExternalLoading/setUserInputOnProcessing are useCallback
wrappers (narrowed to exact signatures, not Dispatch); responseLengthRef/
apiMetricsRef refs via ctx; endInteractionSpan + clearSpeculativeChecks
imported directly (REPL sole-use imports removed). useCallback thin shell
remains in REPL (hook rules). byte-identical. gates 0/921/clean/build:dev.
REPL 5309→5303 (−6 net).

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

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

1 participant