jcode icon indicating copy to clipboard operation
jcode copied to clipboard

Auth login can change the provider of later fresh daemon sessions

Open ianalitis opened this issue 3 months ago • 0 comments

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_change applies provider activation after auth changes.
  • activate_provider_runtime writes JCODE_RUNTIME_PROVIDER, JCODE_ACTIVE_PROVIDER, and JCODE_INITIAL_PROVIDER_EXPLICIT into the daemon process environment.
  • Fresh provider startup/selection consumes those process-global values before the configured default: startup.rs, selection.rs.

Reproduction shape

  1. Start a shared Jcode server with provider/model A configured as the default.
  2. Authenticate provider B through the server auth lifecycle.
  3. Leave existing sessions untouched.
  4. Create a fresh session without an explicit provider override.
  5. 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:

  1. starts with an explicit configured default,
  2. performs an auth change for a different provider,
  3. creates a fresh session/runtime,
  4. 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.

ianalitis avatar Aug 30 '26 19:08 ianalitis