Roo-Code/apps/cli/src
Chris Estreich aa49871a5d
fix(cli): resolve race condition causing provider switch during mode changes (#11205)
When using slash commands with `mode:` frontmatter (e.g., `/cli-release`
with `mode: code`), the CLI would fail with "Could not resolve
authentication method" from the Anthropic SDK, even when using a
non-Anthropic provider like `--provider roo`.

Root cause: In `markWebviewReady()`, the `webviewDidLaunch` message was
sent before `updateSettings`, creating a race condition. The
`webviewDidLaunch` handler's "first-time init" sync would read
`getState()` before CLI-provided settings were applied to the context
proxy. Since `getState()` defaults `apiProvider` to "anthropic" when
unset, this default was saved to the provider profile. When a slash
command triggered `handleModeSwitch()`, it found this corrupted profile
with `apiProvider: "anthropic"` (but no API key) and activated it,
overwriting the CLI's working roo provider configuration.

Fix:
1. Reorder `markWebviewReady()` to send `updateSettings` before
   `webviewDidLaunch`, ensuring the context proxy has CLI-provided
   values when the initialization handler runs.
2. Guard the first-time init sync with `checkExistKey(apiConfiguration)`
   to prevent saving a profile with only the default "anthropic"
   fallback and no actual API keys configured.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 18:26:41 -08:00
..
__tests__ More file organization for the cli (#10599) 2026-01-09 23:22:51 -08:00
agent fix(cli): resolve race condition causing provider switch during mode changes (#11205) 2026-02-04 18:26:41 -08:00
commands Roo Code CLI v0.0.50 (#11204) 2026-02-04 18:14:15 -08:00
lib feat(cli): improve dev experience and roo provider API key support (#11203) 2026-02-04 16:17:29 -08:00
types Roo Code CLI v0.0.50 (#11204) 2026-02-04 18:14:15 -08:00
ui refactor: replace fetch_instructions with skill tool and built-in skills (#11084) 2026-01-29 12:47:36 -07:00
index.ts Roo Code CLI v0.0.50 (#11204) 2026-02-04 18:14:15 -08:00