Skip to content

fix(config): resolve (baseUrl, apiKey) as a tuple, not two independent fields#1658

Merged
esengine merged 1 commit into
mainfrom
fix/endpoint-tuple-source
May 24, 2026
Merged

fix(config): resolve (baseUrl, apiKey) as a tuple, not two independent fields#1658
esengine merged 1 commit into
mainfrom
fix/endpoint-tuple-source

Conversation

@esengine

Copy link
Copy Markdown
Owner

Summary

When a user sets a custom baseUrl + apiKey in config.json (e.g. routing DeepSeek through new-api or another proxy) but also has a stale env DEEPSEEK_API_KEY left over from a default-endpoint setup, the resolver pulled baseUrl from one source and apiKey from the other. The request hit the proxy URL with the wrong token and the API returned auth errors with no obvious cause.

Reported in #1631. Root-caused in #1577 (closed without a fix — same person hit it again).

Design

12-factor env > config precedence is conventional and worth preserving. The actual bug isn't precedence — it's that (baseUrl, apiKey) is a logical tuple but the resolver treated them as independent fields, mixing sources across the pair.

New loadEndpoint() resolves the pair atomically:

Scenario Tuple source
env DEEPSEEK_BASE_URL set env (env apiKey paired)
env unset, config has baseUrl config (config apiKey paired)
neither sets baseUrl → default endpoint env apiKey > config apiKey (unchanged)

Whichever source defines baseUrl owns apiKey too. The non-obvious branch is "config sets baseUrl" — a stale env key doesn't bleed into a custom endpoint.

Changes

  • src/config.ts — new loadEndpoint() (tuple resolver), new bridgeEndpointEnv() (mirrors resolved tuple into env for subprocess constructions); existing loadApiKey / loadBaseUrl kept as thin wrappers.
  • All 6 DeepSeekClient construction sites (acp.ts, commit.ts, desktop.ts, doctor.ts, run.ts, App.tsx, setup.ts) now pass both apiKey and baseUrl explicitly via loadEndpoint() so tuple semantics apply regardless of the client constructor's env fallback.
  • Scattered process.env.DEEPSEEK_API_KEY = loadApiKey() bridges across chat/code/run/acp/desktop replaced with bridgeEndpointEnv() — closes the "only env, never both" gap.

Test plan

  • npm run verify — 260 files / 3593 tests pass
  • 4 new test cases in tests/config.test.ts:
    • bug scenario: config tuple wins over stale env apiKey (issue 配置baseUrl不生效 #1631 repro)
    • env-baseUrl-set tuple
    • default-endpoint precedence (unchanged from pre-fix — regression check)
    • config baseUrl + missing config apiKey surfaces a clean "no key" error rather than silent wrong-key auth

Closes #1631

…t fields

When a user sets a custom baseUrl + apiKey in config.json (e.g. routing
DeepSeek through new-api or another proxy) but also has a stale env
DEEPSEEK_API_KEY left over from a default-endpoint setup, the resolver
used to pull baseUrl from one source and apiKey from the other. Result:
the request hit the proxy URL with the wrong token and the API returned
auth errors with no obvious cause. Reported in #1631, root-caused in
#1577 (closed without a fix).

- New loadEndpoint() resolves the pair atomically: whichever source
  defines baseUrl owns apiKey too. 12-factor env-first is preserved
  (env DEEPSEEK_BASE_URL takes the whole tuple), and the default-
  endpoint case still does env apiKey > config apiKey. The non-obvious
  branch is "config sets baseUrl" — config also owns the apiKey there,
  so a stale env key doesn't bleed into a custom endpoint.
- loadApiKey / loadBaseUrl kept as thin wrappers (many call sites only
  need a presence check); they now return the tuple-resolved value.
- New bridgeEndpointEnv() mirrors the resolved tuple into process.env
  so subprocess constructions and lazy DeepSeekClient instances see the
  matched pair. Replaces the scattered `process.env.DEEPSEEK_API_KEY =
  loadApiKey()` bridges across chat/code/run/acp/desktop, which all had
  the "only env, never both" gap.
- Every DeepSeekClient construction site now passes both apiKey and
  baseUrl explicitly via loadEndpoint() so the tuple semantics apply
  regardless of the client constructor's env fallback.

Tests: new cases cover the bug scenario (config tuple wins over stale
env apiKey), env-baseUrl-set tuple, default-endpoint precedence
(unchanged from pre-fix), and config baseUrl with missing apiKey
(surfaces a clean "no key" error rather than silent wrong-key auth).

Closes #1631
@esengine esengine merged commit d2b5d05 into main May 24, 2026
4 checks passed
@esengine esengine deleted the fix/endpoint-tuple-source branch May 24, 2026 06:05
esengine pushed a commit that referenced this pull request May 24, 2026
…moved, persisted usage stats, plan dispatch gate

Headline themes:
- Desktop: bundle the CLI-hosted React dashboard, retire Tauri+Preact duplicate (#1418)
- Config: drop preset abstraction; flash/pro are direct model selections (#1657, #1630)
- Stats: persist cumulative usage to session meta + auto-restore on startup (#1667, #1680, #1643, #1628)
- Plans: editMode="plan" enforced at the ToolRegistry dispatch gate (#1681); step advance fix (#1629)
- Context: fold once at turn start, drop pre-flight + byte-ceiling (#1642, #1646); collapsible compacted card (#1649)
- Subagents: per-skill flash/pro override + Settings UI (#1632)
- Desktop polish: sidebar drag-resize (#1688), responsive collapse (#1585), copy/edit overlay + msg-history nav (#1645), Esc closes modal not turn (#1685), QQ tab isolation (#1672), DiffCard for edits (#1662), theme-aware highlighting (#1655), system events toggle (#1654/#1650), macOS TCC inheritance (#1614), dashboard.enabled (#1612)
- Dashboard polish: persistent session URL (#1586, #1589, #1599), theme-aware highlighting (#1664), IME confirm-enter guard (#1689), code-fence lang fix (#1677), vendor chunk split (#1587), markdown table h-scroll (#1562)
- TUI: Alt+S input stash/recall; static history isolated from input rerenders (#1635); legacy mouse drop (#1637, #1648); multi-edit gated in review (#1647)
- Diff: SplitDiff column border holds under CJK (#1686)
- MCP: workspace roots passed to servers (#1625); codeCommand honors mcpServers (#1603)
- Config plumbing: (baseUrl, apiKey) resolved as a tuple (#1658); stale model id self-heal (#1663)

See CHANGELOG for the full list.
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.

配置baseUrl不生效

1 participant