Skip to content

jcode client silently attaches to a daemon serving a different provider #184

Open

Description

@KooshaPari

Problem

A fresh Herdr-launched jcode pane that explicitly requests a provider could silently attach to an already-running daemon serving a different provider. The running daemon's identity won unconditionally, so the explicit --provider flag was discarded and the TUI header showed the wrong provider — long after the flags were gone.

Concrete failure mode: a daemon launched with --provider auto resolves to cursor/GPT-5. A later pane launched with --provider openai-compatible --model MiniMax-M3.1-Flash attaches to that daemon and is served by Cursor instead.

Root cause

There was no source-level concept of a daemon's runtime provider identity. The client had nothing canonical to compare against, so "the daemon exists" was treated as "the daemon serves what I asked for".

Fix

Introduce an explicit, canonical provider-identity contract:

  • The daemon publishes the identity it actually resolved to (never the flag it was launched with) into a sidecar file beside its socket.
  • The client derives the same canonical runtime key from its --provider value by going through login_provider_for_choice — the same target the daemon uses to build its provider — so both sides agree by construction rather than by string luck.
  • The two vocabularies genuinely diverge (ProviderChoice::ClaudeApiKey spells anthropic-api while the runtime key is claude-api; ProviderChoice::Azure spells azure while the runtime key is azure-openai), which is why the derivation goes through the shared mapping instead of comparing raw CLI spellings.

Decision matrix

Client request Daemon publishes Result
openai-compatible openai-compatible attach to shared daemon
openai-compatible cursor isolate onto a private daemon
openai-compatible auto isolate (cannot prove agreement)
openai-compatible (nothing / older daemon) isolate (cannot prove agreement)
auto anything attach (nothing was claimed)
model mismatch same provider attach, advisory note only

The model is deliberately advisory: a mismatch is surfaced as a note but never causes isolation, because we have not established that the daemon always honors --model over its profile default, and isolating on an unverified axis would spawn a private daemon on every launch.

Implementation

  • src/cli/daemon_identity.rs — new module: canonical_provider_key, attach_plan, model_advisory, running_daemon_identity, private_client_socket.
  • crates/jcode-app-core/src/server.rs — publish_socket_identity writes the resolved identity beside the socket.
  • crates/jcode-app-core/src/server/socket.rs — read_socket_identity / write_socket_identity / identity_file_for_socket.

Known limitation

ProviderChoice carries ~40 vendor spellings (lmstudio, chutes, cerebras, meta-muse, ...) that all resolve to the single runtime key openrouter. A client asking for one vendor and a daemon serving another therefore compare equal. This is an accepted imprecision at runtime-key granularity, not an oversight. Publishing the resolved vendor name is the follow-up that would close it.

Acceptance

  • Matching provider identities attach to the shared daemon.
  • Provider mismatch isolates onto a private daemon.
  • auto on either side isolates (never a false match).
  • Unknown daemon identity isolates.
  • Model mismatch is advisory and does not isolate.
  • Unit tests cover all five decision branches plus the pinned canonical key mapping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kilo-triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions