Skip to content

fix(config): clear stale baseUrl when switching away from custom provider#222

Merged
404-Page-Found merged 4 commits into
404-PF:mainfrom
c436zhan:fix/config-set-clear-stale-baseurl
Jul 13, 2026
Merged

fix(config): clear stale baseUrl when switching away from custom provider#222
404-Page-Found merged 4 commits into
404-PF:mainfrom
c436zhan:fix/config-set-clear-stale-baseurl

Conversation

@c436zhan

@c436zhan c436zhan commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Switching from the custom provider (__custom__) to a built-in provider via config set provider <builtin> left the previous baseUrl in the config file. That stale URL continued to override the built-in provider's endpoint, so requests were sent to the wrong place.

Root cause

updateConfigField in src/commands/config.ts used { ...config, [key]: value }, which updated only the requested key and preserved everything else, including baseUrl.

Changes

  • src/commands/config.ts: when key === 'provider' and the new value is not __custom__, also set baseUrl to undefined so the built-in provider's default endpoint is used.
  • tests/config-command.test.mjs: add two regression tests:
    1. switching from __custom__ to openai clears baseUrl
    2. switching from openai to __custom__ preserves the existing baseUrl

Testing

  • npm run build — compiles cleanly
  • node --test tests/config-command.test.mjs — 26 tests: 24 pass (2 pre-existing unrelated JSON-output failures)
  • npm run format:check — no formatting issues in changed files

Compatibility

No breaking changes. Users who previously had a stale baseUrl after switching providers will now get the correct built-in endpoint. Users who intentionally set baseUrl on a built-in provider and then switch to another built-in will also have it cleared, which is the desired behavior per the issue.

Fixes #202

Summary by CodeRabbit

  • New Features
    • Improved custom provider configuration behavior, including consistent API key environment handling.
    • Configuration JSON now outputs normalized provider identifiers.
  • Bug Fixes
    • Provider changes now correctly clear or preserve baseUrl as appropriate (e.g., switching away from or to the custom provider).
    • Updated initialization and API key checks to use centralized provider constants.
  • Tests
    • Updated config --json expectations for normalized provider values.
    • Added tests covering baseUrl clearing/preservation across provider changes.

@c436zhan c436zhan requested a review from 404-Page-Found as a code owner July 13, 2026 02:21
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0674332e-dca0-4b03-9a03-f6fa569ea2e9

📥 Commits

Reviewing files that changed from the base of the PR and between 705685c and 6c8998b.

📒 Files selected for processing (6)
  • src/commands/config.ts
  • src/commands/init.ts
  • src/llm/client.ts
  • src/providers/index.ts
  • src/providers/registry.ts
  • tests/config-command.test.mjs
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

The project is ESM-only: use .js extensions in local imports and keep verbatimModuleSyntax-compatible TypeScript imports (for example, import type for type-only imports).

Files:

  • src/providers/registry.ts
  • src/providers/index.ts
  • src/llm/client.ts
  • src/commands/config.ts
  • src/commands/init.ts
src/providers/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

All LLM provider implementations must conform to the shared Provider interface and integrate with the provider abstraction used by the factory/registry system.

Files:

  • src/providers/registry.ts
  • src/providers/index.ts
tests/**/*.mjs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.mjs: Use Node.js built-in node:test for test files in tests/ and tests/e2e/; do not use Jest or Mocha.
Write test assertions with node:assert/strict in test files under tests/ and tests/e2e/.

Files:

  • tests/config-command.test.mjs
src/{history,llm}/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Recent commit history should be stored as JSONL, analyzed by buildProfile() for commit-style patterns, and injected into prompts as style guidance.

Files:

  • src/llm/client.ts
🔇 Additional comments (6)
src/providers/registry.ts (1)

3-5: LGTM!

src/providers/index.ts (1)

6-14: LGTM!

src/commands/config.ts (1)

11-13: LGTM!

Also applies to: 91-110, 194-215

tests/config-command.test.mjs (1)

188-188: LGTM!

Also applies to: 209-209, 303-349

src/commands/init.ts (1)

3-20: LGTM!

Also applies to: 54-54, 75-75, 94-94, 129-133, 236-236, 295-295

src/llm/client.ts (1)

2-10: LGTM!

Also applies to: 26-26


📝 Walkthrough

Walkthrough

Centralizes custom-provider constants, updates initialization and LLM client handling, and makes config set provider clear or preserve baseUrl according to the selected provider. Tests assert normalized provider values and switching behavior.

Changes

Custom provider configuration

Layer / File(s) Summary
Centralize provider constants
src/providers/registry.ts, src/providers/index.ts
Defines and re-exports the custom provider key and API-key environment constant.
Apply provider-aware config updates
src/commands/config.ts, tests/config-command.test.mjs
Provider changes clear baseUrl for built-in providers, preserve it for the custom provider, and validate normalized JSON output.
Use constants across provider flows
src/commands/init.ts, src/llm/client.ts
Initialization and API-key validation use centralized custom-provider identifiers and environment names.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: bug

Poem

A rabbit hops where providers change,
Clearing stale URLs from the range.
Custom paths keep their chosen trail,
Shared constants guide the sail.
Tests cheer: the config is right! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: clearing stale baseUrl when switching away from the custom provider.
Linked Issues check ✅ Passed The code clears baseUrl when provider changes from custom to a built-in provider and preserves it for custom, matching issue #202.
Out of Scope Changes check ✅ Passed The provider constant refactors, client/init updates, and test adjustments all support the provider-switch fix and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@404-Page-Found

Copy link
Copy Markdown
Contributor

@c436zhan please resolve the merge conflicts

…ider

When a user switches from the custom provider (__custom__) to a
built-in provider via , the previous
custom baseUrl was left in the config file and continued to override
the built-in provider's endpoint.

Change updateConfigField so that setting the provider to any built-in
also clears baseUrl, while preserving baseUrl when switching to the
custom provider.

Fixes 404-PF#202
@c436zhan c436zhan force-pushed the fix/config-set-clear-stale-baseurl branch from f3ae4b8 to fae80dd Compare July 13, 2026 02:35

@404-Page-Found 404-Page-Found left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR Review: #222 — fix(config): clear stale baseUrl when switching away from custom provider

Summary

This PR fixes issue #202: when switching from the custom provider (__custom__) to a built-in provider via config set provider <builtin>, the previously stored baseUrl was left in the config file and continued to override the built-in provider default endpoint. The fix adds a targeted conditional in updateConfigField that clears baseUrl when switching to a non-custom provider. Two regression tests are included.

Strengths

  • Minimal, focused fix — The change is surgically targeted at the exact root cause in updateConfigField (config.ts:86-91). No unnecessary refactoring.
  • Correct test coverage — Both tests cover the exact regression and its inverse, using the existing withTempHome/writeConfig test infrastructure.
  • Well-documented — The PR description clearly explains the root cause, the fix, and the testing performed.
  • No breaking changes — Existing users with stale baseUrl will now correctly use built-in endpoints; users who intentionally set baseUrl on a built-in before switching to another built-in will also get it cleared, which is correct behavior.

Issues Found

🔴 Critical — None.

🟡 Suggestions

  1. CUSTOM_PROVIDER_KEY is duplicated across 4 filessrc/commands/config.ts:14, src/providers/index.ts:10, src/commands/init.ts:9, and hard-coded \__custom__\' in src/llm/client.ts:9. If this sentinel value ever changes, all four must be updated. Consider exporting it from a single location (e.g., src/types.ts or src/providers/registry.ts).

  2. apiKey is not cleared alongside baseUrl — When switching from __custom__ to a built-in provider, baseUrl is cleared but apiKey persists. Built-in providers resolve their API keys from environment variables (OPENAI_API_KEY, etc.), so the stored apiKey becomes orphaned. This is harmless but could confuse users who run config and see an API key that is not being used. Consider clearing apiKey too when switching to a non-custom provider — or at minimum, document why it is preserved.

  3. Domain-specific logic in a generic updaterupdateConfigField now has provider-aware branching. If more provider-specific fields are added in the future (e.g., customHeaders, apiVersion), this function will grow increasingly coupled. A future refactor could move this to a providerSwitchCleanup helper, but for now it is acceptable.

🟢 Nitpicks

  1. The diff uses tab indentation while the rest of the file uses 2-space — The new lines in updateConfigField appear to use tabs (\t). Prettier is configured with "tabWidth": 2 and no useTabs. If this passes format:check, it may just be a rendering artifact in the diff, but worth double-checking.

  2. Test could explicitly verify config.baseUrl === undefined — The current assertion assert.equal(config.baseUrl, undefined) is correct, but adding a comment like // not present in saved JSON would clarify intent for future readers.

Testing Assessment

The two new tests cover the core regression scenarios:

  • ✅ Custom → built-in clears baseUrl
  • ✅ Built-in → custom preserves baseUrl

Missing but not blocking:

  • Built-in → built-in with existing baseUrl (should clear) — implied by the fix but not explicitly tested
  • Verification that commit-echo suggest actually uses the correct endpoint after the switch (integration test territory)

Verdict

Approve with suggestions — The fix is correct, minimal, and well-tested. The CUSTOM_PROVIDER_KEY duplication and apiKey persistence are worth addressing but not blockers.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/commands/config.ts`:
- Around line 194-195: Remove the redundant parse in the config-setting flow by
extracting a pure validation helper from parseConfigSetValue, such as
validateConfigSetValue, and use it in the try-catch around the command handler
while keeping updateConfigFromRawValue responsible for the single actual parse
and update.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 51f9db8c-1939-4d25-a9c5-d530ee5f24f1

📥 Commits

Reviewing files that changed from the base of the PR and between 705685c and b741187.

📒 Files selected for processing (6)
  • src/commands/config.ts
  • src/commands/init.ts
  • src/llm/client.ts
  • src/providers/index.ts
  • src/providers/registry.ts
  • tests/config-command.test.mjs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

The project is ESM-only: use .js extensions in local imports and keep verbatimModuleSyntax-compatible TypeScript imports (for example, import type for type-only imports).

Files:

  • src/providers/registry.ts
  • src/llm/client.ts
  • src/providers/index.ts
  • src/commands/init.ts
  • src/commands/config.ts
src/providers/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

All LLM provider implementations must conform to the shared Provider interface and integrate with the provider abstraction used by the factory/registry system.

Files:

  • src/providers/registry.ts
  • src/providers/index.ts
tests/**/*.mjs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.mjs: Use Node.js built-in node:test for test files in tests/ and tests/e2e/; do not use Jest or Mocha.
Write test assertions with node:assert/strict in test files under tests/ and tests/e2e/.

Files:

  • tests/config-command.test.mjs
src/{history,llm}/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Recent commit history should be stored as JSONL, analyzed by buildProfile() for commit-style patterns, and injected into prompts as style guidance.

Files:

  • src/llm/client.ts
🔇 Additional comments (7)
src/providers/registry.ts (1)

3-5: LGTM!

src/providers/index.ts (1)

6-14: LGTM!

src/commands/config.ts (1)

91-110: LGTM!

tests/config-command.test.mjs (2)

188-188: LGTM!

Also applies to: 209-209


303-349: LGTM!

src/commands/init.ts (1)

3-20: LGTM!

Also applies to: 54-54, 75-75, 94-94, 129-133, 236-236, 295-295

src/llm/client.ts (1)

2-10: LGTM!

Also applies to: 26-26

Comment thread src/commands/config.ts Outdated
@404-Page-Found

Copy link
Copy Markdown
Contributor

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@404-Page-Found 404-Page-Found left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@404-Page-Found 404-Page-Found merged commit c7ea3e9 into 404-PF:main Jul 13, 2026
1 check 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.

[Config] Switching away from the custom provider via config set leaves stale baseUrl behind

2 participants