Auth login can change the provider of later fresh daemon sessions
Summary
A successful provider login in the shared server can mutate process-global provider-selection environment variables. A later fresh session can therefore inherit the most recently authenticated provider instead of the configured default provider.
Existing peer sessions appear to remain pinned, but fresh-session isolation is not preserved.
Why this matters
Authentication state and provider selection are separate trust boundaries. Logging into a provider should make credentials available, not silently change which provider future sessions use. In a long-lived multi-session daemon this can route prompts, tools, and data to an unintended vendor.
Source trace
Audited at 008abc44b1653efa65ccf98acb3b7236ce8507e6:
activate_auth_changeapplies provider activation after auth changes.activate_provider_runtimewritesJCODE_RUNTIME_PROVIDER,JCODE_ACTIVE_PROVIDER, andJCODE_INITIAL_PROVIDER_EXPLICITinto the daemon process environment.- Fresh provider startup/selection consumes those process-global values before the configured default:
startup.rs,selection.rs.
Reproduction shape
- Start a shared Jcode server with provider/model A configured as the default.
- Authenticate provider B through the server auth lifecycle.
- Leave existing sessions untouched.
- Create a fresh session without an explicit provider override.
- Observe that the new runtime can select provider B through the daemon-global activation variables rather than provider A from configuration.
The existing server test around auth-driven model switching covers an already-running peer session, but not a fresh runtime created after the auth mutation.
Expected behavior
- Login refreshes provider credential availability.
- Existing and future sessions retain their explicit or configured provider selection.
- Provider changes occur only through an explicit session/server selection action.
- Any fallback is visible and recorded, not inferred from the last login.
Suggested regression
Add a shared-server test that:
- starts with an explicit configured default,
- performs an auth change for a different provider,
- creates a fresh session/runtime,
- asserts the fresh session still uses the configured default.
A likely fix is to stop representing auth activation as process-global provider-selection environment state, or to scope that activation to the session that explicitly requested a provider change.