Skip to content

fix(model-bridge): validate apiKey before creating OpenAI client in new-api branch#1758

Merged
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-6X
Mar 26, 2026
Merged

fix(model-bridge): validate apiKey before creating OpenAI client in new-api branch#1758
piorpua merged 1 commit intomainfrom
fix/sentry-ELECTRON-6X

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Validate actualApiKey before constructing new OpenAI() in the isNewApiPlatform branch to prevent unhandled "Missing credentials" rejection
  • Add unit tests covering empty and undefined apiKey for the new-api platform path

Changes

src/process/bridge/modelBridge.ts

  • Add early return with user-friendly error when actualApiKey is falsy in the isNewApiPlatform code path (mirrors existing guard at line 361 for the general OpenAI path)

tests/unit/bridge/modelBridge.test.ts

  • Add 2 tests: empty string apiKey and undefined apiKey for platform: 'new-api'

Related Issue

Closes #1757

Sentry: ELECTRON-6X — 7080 occurrences, regressed

Verification

  • Process: main (unit tests only, no CDP)
  • Unit tests: PASS (5/5 in modelBridge.test.ts)
  • Type check: PASS
  • Lint: PASS (0 errors)

Test Plan

  • Unit tests verify empty apiKey returns { success: false } for new-api platform
  • Unit tests verify undefined apiKey returns { success: false } for new-api platform
  • Existing tests still pass (no regression)
  • Type check passes

@kaizhou-lab kaizhou-lab marked this pull request as ready for review March 26, 2026 12:55
@kaizhou-lab kaizhou-lab force-pushed the fix/sentry-ELECTRON-6X branch from da72d65 to 5b4d724 Compare March 26, 2026 13:07
…ew-api branch

The isNewApiPlatform code path created a new OpenAI client without
checking if actualApiKey was truthy, causing an unhandled
"Missing credentials" rejection (ELECTRON-6X, 7080 occurrences).

Add an early return with a user-friendly error message, matching
the existing guard on the general OpenAI path. Add unit tests
covering empty and undefined apiKey for the new-api platform.
@kaizhou-lab kaizhou-lab force-pushed the fix/sentry-ELECTRON-6X branch from 5b4d724 to 2d94752 Compare March 26, 2026 13:18
@piorpua piorpua added the bot:reviewing Review in progress (mutex) label Mar 26, 2026
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 26, 2026

Code Review:fix(model-bridge): validate apiKey before creating OpenAI client in new-api branch (#1758)

变更概述

本 PR 针对 Sentry 问题 ELECTRON-6X(7080 次出现)进行修复:在 new-api 平台的代码路径中,创建 OpenAI 客户端之前增加了 actualApiKey 空值校验,防止因 API key 为空而触发未处理的 "Missing credentials" 异常。同时新增了 2 个单元测试覆盖空字符串和 undefined 两种场景。


方案评估

结论:✅ 方案合理

修复方案直接镜像了第 365-368 行已有的通用 OpenAI 路径守卫逻辑,做到了代码一致性。使用 !actualApiKey 可同时拦截 undefinednull 和空字符串三种情形,完整覆盖了 Sentry 中的失败场景。无过度工程化,无设计盲点。


问题清单

未发现任何问题。

Lint 基准说明:oxlint 输出的 27 条警告全部来自文件中已有代码(no-await-in-loopno-explicit-anyno-map-spread 等),本 PR 新增代码未引入任何新的 lint 警告。


汇总

# 严重级别 文件 问题

结论

批准合并 — 修复精准,测试覆盖完整,与项目已有守卫模式高度一致,无任何阻塞性问题。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 26, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua merged commit 8bb93b7 into main Mar 26, 2026
17 checks passed
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(model-bridge): unhandled 'Missing credentials' error in new-api platform path

2 participants