fix(tui): clear launch missing-key state when a provider switch lands on a keyed route - #6696
Merged
Merged
Conversation
… on a keyed route The reported first-launch symptom (a configured openai/gpui-fixture home opening on "Choose your model provider" with DeepSeek focused) was not a config-resolution bug. The tmux server used for the repro carries CODEWHALE_PROVIDER=deepseek and CODEWHALE_MODEL=deepseek-v4-flash in its global environment, so every new session inherited them. Config::load then resolved deepseek per the documented env > file precedence (instrumented: provider=deepseek already at load_config_from_cli_with_effective_profile). `codewhale model resolve` from a shell without those vars reported openai, which hid the difference. With the vars unset, the unmodified release build aaaadfe starts on the composer with "OpenAI-compatible · gpui-fixture". It did expose a real bug. After Esc on the recovery picker, `/provider openai` switched to a keyed route, but switch_provider never recomputed app.onboarding_needs_api_key. Only complete_provider_picker_onboarding clears it, and that runs only while onboarding == Provider. The stale true kept the footer on "model not connected" (frame.rs info_segments) and left should_adopt_live_local_ollama armed against the provider the user had just chosen. Fix: on a successful switch, set onboarding_needs_api_key from has_api_key(config) for the new route, and clear onboarding_missing_key_recovery when the key is present. The auth-failure rollback already restores the previous flag. Tests (focused, local): - new first_run_switch_to_keyed_route_clears_launch_missing_key_state (real Config::load + App::new startup with the inherited env pair, Esc, switch_provider): passes; fails without the fix at the !onboarding_needs_api_key assert. - provider_switch|switch_provider|local_ollama|missing_key|onboarding: 109 passed, 0 failed. - first_run_|provider_picker: 161 passed, 1 failed. The one failure, first_run_ollama_choice_survives_restart_from_canonical_config ("index not found"), also fails on a clean aaaadfe tree and is not touched here. - first_run_route_env_guards now also removes CODEWHALE_PROVIDER. E2E (tmux 130x40, debug build, fixture at 127.0.0.1:4880): - configured home, env clean: composer, footer "OpenAI-compatible · gpui-fixture · thinking: max". - configured home with the inherited deepseek env: picker (correct per precedence), then Esc and /provider openai: footer "OpenAI-compatible · gpt-5.6 ..." (release build: "model not connected"). - unconfigured home with local Ollama unreachable: "Choose your model provider" picker. With the live local Ollama it auto-adopts ollama/qwen3:4b, same as the release build. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014ZwqatxgVFxHvovngywnks
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause of the reported first-launch symptom
This is not a product bug. The tmux server used for the repro has
CODEWHALE_PROVIDER=deepseekandCODEWHALE_MODEL=deepseek-v4-flashin its global environment, and every new session inherits them.Config::loadthen resolves DeepSeek under the documented env > file precedence. Instrumentation showedprovider=deepseekalready atload_config_from_cli_with_effective_profile, with the env var set.codewhale model resolvefrom a shell without those vars reported openai, which hid the difference. With the vars unset, the unmodified release build aaaadfe starts on the composer withOpenAI-compatible · gpui-fixture.Real bug fixed here
After Esc on the recovery picker,
/provider openaiswitched to a keyed route, butswitch_providernever recomputedapp.onboarding_needs_api_key. Onlycomplete_provider_picker_onboardingclears it, and that runs only whileonboarding == Provider. The staletruekept the footer on "model not connected" and leftshould_adopt_live_local_ollamaarmed against the provider the user had just chosen.Fix (
crates/tui/src/tui/ui/provider_routes.rs,switch_provider): on success, setonboarding_needs_api_key = !has_api_key(config)for the new route, and clearonboarding_missing_key_recoverywhen the key is present. The auth-failure rollback already restores the previous value.Tests (focused, local)
first_run_switch_to_keyed_route_clears_launch_missing_key_stateruns the realConfig::load+App::newstartup with the inherited env pair, then Esc, thenswitch_provider. It passes with the fix and fails without it.provider_switch|switch_provider|local_ollama|missing_key|onboarding: 109 passed, 0 failed.first_run_|provider_picker: 161 passed, 1 failed. The failure,first_run_ollama_choice_survives_restart_from_canonical_config("index not found"), also fails on a clean aaaadfe tree and is not touched here.E2E (tmux 130x40, debug build, fixture at 127.0.0.1:4880)
OpenAI-compatible · gpui-fixture · thinking: max./provider openai: footerOpenAI-compatible · gpt-5.6 …. The release build showedmodel not connectedhere.Choose your model providerpicker. With a live local Ollama it auto-adoptsollama/qwen3:4b, the same as the release build.Out of scope, noted: under an env model override,
/provider openailands on the catalog default (gpt-5.6), not the file'sdefault_text_model, because the env value replaced it in memory.🤖 Generated with Claude Code
https://claude.ai/code/session_014ZwqatxgVFxHvovngywnks