energetic_wolf_99424 (Discord #help) has one relay key that works in both
the OpenAI and the Anthropic format. They added a custom provider with it in
one format; adding a second custom provider with the same key in the other
format was refused with "<name> is already added with that key". The same
refusal blocked OpenCode Go beside OpenCode Zen with one account's key
(#3388, found by ggbdpq, verified by Edward4226).
Add's duplicate check (add in provider.go) used sameProvider, which
judges by key + host + headers only. It now also needs servesAll: the new
provider brings no API, and no address of one, that the provider already
there lacks (Chat, Responses, Anthropic and Gemini compared slot by slot
after normalize). So the same key at the same addresses is still refused
as the one already here, and another format, or another product path on
the host, is added under its own id. The GUI, the CLI (`magpie provider
add`) and the TUI all go through provider.Add, so all three are covered.
AddCopy never had the check. Two providers sharing one key already existed
(AddCopy, another host), so nothing keyed by the key (KeyID, usage by
provider id, resting) meets a new state.
Not changed: the app import still calls an entry "Already added" when the
provider there has the key at that host, even if the entry brings an API it
lacks; filed as #4904.
Run at this head (rebased on 1829cd52f), on mote:
- go test ./internal/provider -count=1: ok (191s).
- gofmt -l clean; go vet -tags nogui ./internal/provider ./internal/cli
./internal/tui ./internal/gui for darwin, linux and windows: ok.
- Before the rebase (base 07f4d46c5, same diff): go test ./internal/cli
./internal/tui ./internal/gui: tui ok; cli red only on
TestEveryRouteHasACommandOrIsNamed (#4826, checkin-account route), gui
red only on TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27).
Broken by hand: dropping `&& servesAll(...)` turns TestAddSameKeyOtherFormat
red with the reporter's refusal ("Relay is already added with that key
(relay); ...").
Not tried: the real GUI Add dialog, a real relay key in both formats, a
real OpenCode key.
Reported by energetic_wolf_99424; #3388 by ggbdpq.