fix: preserve explicit startup provider selection#468
fix: preserve explicit startup provider selection#468gnanam1990 wants to merge 4 commits intomainfrom
Conversation
a0a0606 to
65dd19c
Compare
|
Reporter validation update: the affected user tested the PR and confirmed it is now working fine.\n\nIssue comment: #464 (comment) |
|
one more eyes when you can bro @Vasanthdev2004 |
Vasanthdev2004
left a comment
There was a problem hiding this comment.
Rechecked the current head 65dd19cf87718e6ee1beb03c833bebad2daf96eb against current origin/main.
The branch does fix the original GitHub-onboarding precedence issue for the specific --provider openai path it targets, and the focused tests/build/smoke are green. I still can't approve because there are two provider-selection regressions in the generalized fix.
-
src/utils/managedEnv.ts:87-95,src/utils/managedEnv.ts:146-166,src/utils/providerEnvSelection.ts:22-31,src/utils/providerEnvSelection.ts:40-54
filterSettingsEnvForExplicitProvider()is documented/tested as an explicit-CLI-provider filter, but it also treats any already-presentCLAUDE_CODE_USE_*flag inprocess.envas "explicit".Because
applySafeConfigEnvironmentVariables()applies settings sources sequentially, that inverts source precedence:- an earlier settings source can set
CLAUDE_CODE_USE_GITHUB=1 - a later settings source trying to switch to OpenAI/another provider gets stripped instead of winning
Direct helper-level repro I verified locally on this head:
processEnv = { CLAUDE_CODE_USE_GITHUB: '1' }env = { CLAUDE_CODE_USE_OPENAI: '1', OPENAI_MODEL: 'gpt-4o', OTHER: 'keep-me' }filterSettingsEnvForExplicitProvider(env, processEnv)returns only{ OTHER: 'keep-me' }
So this no longer means "explicit CLI provider wins"; it means "whichever provider flag got applied first wins", which is a real precedence regression.
- an earlier settings source can set
-
src/utils/providerFlag.ts:85-86,src/utils/providerProfile.ts:407-422,src/utils/providerProfile.ts:669-672
--provider anthropicis still not treated as an explicit startup selection by the saved-profile startup path.The branch records
CLAUDE_CODE_EXPLICIT_PROVIDER=anthropic, butbuildStartupEnvFromProfile()still decides explicit-provider intent only fromCLAUDE_CODE_USE_*flags /CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED. Since anthropic clears allCLAUDE_CODE_USE_*flags, a persisted GitHub/OpenAI profile can still override the user's explicit CLI choice.Direct repro I verified locally on this head:
- call
applyProviderFlag('anthropic', []) - call
buildStartupEnvFromProfile()with a persisted GitHub profile - result is not the original
process.env; it comes back withCLAUDE_CODE_USE_OPENAI='1'andOPENAI_MODEL='github:copilot'
So an explicit
--provider anthropicstartup can still be pulled back into the persisted profile path. - call
Non-blocking note:
src/screens/REPL.tsxnow delays startup checks until the prompt is empty, not merely idle, which may be stricter than intended, but I am not blocking on that without a clearer product regression repro.
What I verified on this head:
bun test src/utils/providerFlag.test.ts src/utils/providerEnvSelection.test.ts src/screens/replStartupGates.test.ts-> 31 passbun run build-> successbun run smoke-> success- direct repro of the settings-source precedence regression above
- direct repro that explicit
--provider anthropicis overridden by a persisted GitHub profile
I would not merge this until the filtering is limited to truly explicit startup provider intent, and --provider anthropic is treated as explicit by the saved-profile startup path too.
|
Thanks for the detailed recheck. I pushed a narrow follow-up that addresses both provider-selection regressions you called out. What changed:
Added regression coverage for both cases:
Local verification:
I also rechecked the two direct repro paths locally:
|
Vasanthdev2004
left a comment
There was a problem hiding this comment.
Rechecked the current head 139610950c6f9bf4bab32e7779fa7c4d5d331253 against current origin/main.
The latest push fixes the two blockers I raised on the previous head:
- settings-source precedence is no longer inverted by plain
CLAUDE_CODE_USE_*flags buildStartupEnvFromProfile()now preserves explicit--provider anthropic
I still can't approve because there is one remaining explicit-provider regression on the current startup path.
-
src/utils/providerFlag.ts:85-86,src/utils/managedEnv.ts:183-185,src/utils/providerProfiles.ts:255-265,417-433
--provider anthropicis still overridden by an active saved provider profile during startup.The new
CLAUDE_CODE_EXPLICIT_PROVIDERmarker is respected by:filterSettingsEnvForExplicitProvider()buildStartupEnvFromProfile()
But
applySafeConfigEnvironmentVariables()still callsapplyActiveProviderProfileFromConfig(), and that path only guards onhasProviderSelectionFlags(processEnv), which still ignoresCLAUDE_CODE_EXPLICIT_PROVIDER.Direct repro I verified locally on this head:
- call
applyProviderFlag('anthropic', []) - call
applyActiveProviderProfileFromConfig()with an active GitHub profile config - result:
- returned profile id is
gh CLAUDE_CODE_USE_OPENAI='1'OPENAI_MODEL='github:copilot'
- returned profile id is
So explicit startup intent is still not preserved end-to-end: it survives the saved-profile bootstrap path, but it is still clobbered by the later active-profile application path.
Non-blocking note:
src/screens/REPL.tsx:1336-1352now waits forpromptTypingSuppressionActive === false, and that helper stays true for any non-empty draft, not just active typing. I did not block on this without a clearer user-facing regression repro, but the behavior is stricter than "wait until startup is idle" suggests.
What I verified on this head:
bun test src/utils/providerFlag.test.ts src/utils/providerEnvSelection.test.ts src/utils/providerProfile.test.ts src/screens/replStartupGates.test.ts-> 71 passbun run build-> successbun run smoke-> success- direct repro that
filterSettingsEnvForExplicitProvider()now preserves later settings-source precedence - direct repro that
buildStartupEnvFromProfile()preserves explicit anthropic startup intent - direct repro that
applyActiveProviderProfileFromConfig()still overrides explicit--provider anthropic
I would not merge this until the active-profile application path also treats CLAUDE_CODE_EXPLICIT_PROVIDER as explicit startup intent.
|
@Vasanthdev2004 I pushed one more narrow follow-up for the remaining active-profile path on the latest head:
This updates Local recheck on this head:
When you have a moment, could you please re-review the latest commit? |
Vasanthdev2004
left a comment
There was a problem hiding this comment.
Rechecked the current head b2cabdd950eeee5ed0f9c50d42f63e963e04201e against current origin/main.
The latest push fixes the previous blocker I raised:
- active provider profiles now respect
CLAUDE_CODE_EXPLICIT_PROVIDER, so explicit--provider anthropicstartup intent is preserved end-to-end
I still can't approve because there is one remaining explicit-provider regression in the generalized fix.
-
src/utils/providerFlag.ts:118-123,src/utils/providerEnvSelection.ts:39-55,src/utils/managedEnv.ts:87-95,140-166
--provider ollamais still overridable by settings-sourced OpenAI routing env, so the new ?explicit provider? path does not actually preserve Ollama startup intent.applyProviderFlag('ollama', ...)encodes Ollama as:CLAUDE_CODE_USE_OPENAI=1OPENAI_BASE_URL=http://localhost:11434/v1OPENAI_API_KEY=ollama
But
filterSettingsEnvForExplicitProvider()only strips provider flags plus a GitHub-model special case. It does not strip OpenAI routing env for explicit non-GitHub OpenAI-compatible providers like Ollama.Direct repro I verified locally on this head:
- call
applyProviderFlag('ollama', []) - then filter settings env containing:
OPENAI_BASE_URL='https://api.openai.com/v1'OPENAI_MODEL='gpt-4o'OPENAI_API_KEY='sk-test'
filterSettingsEnvForExplicitProvider(...)returns those values unchanged
Since
applySafeConfigEnvironmentVariables()merges filtered settings env afterward, a user launching with--provider ollamacan still be rerouted back to a remote OpenAI endpoint from trusted settings. That means the branch still does not preserve explicit startup provider intent for all supported providers; it currently special-cases GitHub/Anthropic but leaves Ollama exposed.
Non-blocking note:
- I could not reproduce a user-facing startup-check regression, but the REPL change still waits for
promptTypingSuppressionActive === false, which is stricter than just ?wait until startup is idle?. I am not blocking on that without a clearer symptom repro.
What I verified on this head:
bun test src/utils/providerFlag.test.ts src/utils/providerEnvSelection.test.ts src/utils/providerProfile.test.ts src/utils/providerProfiles.test.ts src/screens/replStartupGates.test.ts-> 71 pass- direct repro that
applyActiveProviderProfileFromConfig()no longer overrides explicit--provider anthropic - direct repro that explicit
--provider ollamastill allowsOPENAI_BASE_URL/OPENAI_MODEL/OPENAI_API_KEYfrom settings through the filter - current GitHub Actions checks on this head are green
I would not merge this until explicit-provider filtering also protects Ollama/OpenAI-compatible startup intent, not just GitHub-model and anthropic paths.
|
Thanks again for the careful rechecks. I pushed one more narrow follow-up for the remaining Ollama path on the latest head:
This closes the last explicit-provider override you called out:
Local recheck on this head:
I also rechecked the direct repros locally:
One small request for future rounds: if possible, it would really help to include all identified blockers in a single review pass when they’re visible together. That makes it easier to address the full provider-precedence surface in one try and reduces the back-and-forth on adjacent startup paths. When you have a moment, could you please re-review the latest commit? |
Vasanthdev2004
left a comment
There was a problem hiding this comment.
No blocking findings on the current head b5dbb71a4431b249d1e64e2a42c5d50c17e31eac relative to current origin/main.
What I verified:
bun test src/utils/providerFlag.test.ts src/utils/providerEnvSelection.test.ts src/utils/providerProfile.test.ts src/utils/providerProfiles.test.ts src/screens/replStartupGates.test.ts- direct repro that explicit
--provider ollamanow strips settings-sourcedOPENAI_BASE_URL/OPENAI_MODEL/OPENAI_API_KEY - direct repro that
applyActiveProviderProfileFromConfig()no longer overrides explicit--provider anthropic bun run buildbun run smoke- current GitHub Actions checks on this head are all green
Non-blocking note:
src/screens/REPL.tsxstill waits forpromptTypingSuppressionActive === false, which means background startup checks are delayed while any non-empty draft remains in the prompt. I did not find a clear product regression from that on this branch, but it is a behavior change worth keeping an eye on.
Summary
--providerstartup selection take precedence over persisted GitHub onboarding state.--provider openai.Root Cause
This issue turned out to be a combination of two older bug paths:
CLAUDE_CODE_USE_GITHUB=1OPENAI_MODEL=github:copilotOn later launches,
--providerwas applied early, but settings hydration could still reapply GitHub provider state afterward.REPL startup checks were still running immediately on mount, which matches the known startup freeze family from earlier reports.
In practice, this could leave users stuck reopening in GitHub Models mode and then hitting a launch-time freeze path.
What Changed
--provideris used.github:copilotmodel state when the explicit provider is not GitHub.performStartupChecks()until after the initial prompt suppression window so startup work does not land in the first input window.Test Plan
npx bun test src/utils/providerFlag.test.ts src/utils/providerEnvSelection.test.ts src/screens/replStartupGates.test.tsnpx bun testnpx bun run smokenode dist/cli.mjs --provider openaiProvider OpenAIModel gpt-4oEndpoint https://api.openai.com/v1Notes