Roo-Code/apps/cli/src/agent
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__ fix(cli): fix quiet mode tests by capturing console before host creation (#10827) 2026-01-18 10:07:49 -08:00
agent-state.ts More file organization for the cli (#10599) 2026-01-09 23:22:51 -08:00
ask-dispatcher.ts Roo Code CLI v0.0.50 (#11204) 2026-02-04 18:14:15 -08:00
events.ts Some cleanup in ExtensionHost (#10600) 2026-01-10 02:29:33 -08:00
extension-client.ts Some cleanup in ExtensionHost (#10600) 2026-01-10 02:29:33 -08:00
extension-host.ts fix(cli): resolve race condition causing provider switch during mode changes (#11205) 2026-02-04 18:26:41 -08:00
index.ts Support different cli output formats: text, json, streaming json (#10812) 2026-01-18 09:19:08 -08:00
json-event-emitter.ts Support different cli output formats: text, json, streaming json (#10812) 2026-01-18 09:19:08 -08:00
message-processor.ts Some cleanup in ExtensionHost (#10600) 2026-01-10 02:29:33 -08:00
output-manager.ts More file organization for the cli (#10599) 2026-01-09 23:22:51 -08:00
prompt-manager.ts More file organization for the cli (#10599) 2026-01-09 23:22:51 -08:00
state-store.ts Some cleanup in ExtensionHost (#10600) 2026-01-10 02:29:33 -08:00