Skip to content
Python

Treat openai:<model> and <model> as the same model

Devika Verma6500fa0ce176
diff --git a/coworker/providers/router.py b/coworker/providers/router.py
index 4a6d7f19..4997e7e2 100644
--- a/coworker/providers/router.py
+++ b/coworker/providers/router.py
@@ -19,13 +19,37 @@ from .base import ProviderClient
from .capabilities import capabilities_for
from .registry import build_provider_client, get_descriptor
+# The provider a model id with no `provider:` prefix runs on.
+DEFAULT_PROVIDER = "openai"
+
+
+def canonical_model(model: str) -> str:
+ """The one spelling of a model id that the app compares and stores.
+
+ A prefix naming the default provider says nothing a bare id doesn't: `openai:gpt-5.5`
+ and `gpt-5.5` both run on OpenAI. The machine's model list spells OpenAI models bare,
+ while coworker manifests often write `openai:...`, so the prefix is dropped here.
+ Every other prefix (`anthropic:`, `ollama:` ...) is kept. The GUI applies the same
+ rule (`surfaces/gui/src/modelNames.ts`, `canonicalModel`).
+ """
+ model = (model or "").strip()
+ prefix = DEFAULT_PROVIDER + ":"
+ if model.startswith(prefix) and len(model) > len(prefix):
+ return model[len(prefix):]
+ return model
+
+
+def same_model(a: str, b: str) -> bool:
+ """Do two model ids name the same model (see `canonical_model`)?"""
+ return canonical_model(a) == canonical_model(b)
+
class ProviderRouter(ProviderClient):
def __init__(
self,
secrets: Any = None,
*,
- default_provider: str = "openai",
+ default_provider: str = DEFAULT_PROVIDER,
on_use: Any = None,
) -> None:
self._secrets = secrets
diff --git a/coworker/server/manager.py b/coworker/server/manager.py
index fad31df5..85dcd9fd 100644
--- a/coworker/server/manager.py
+++ b/coworker/server/manager.py
@@ -92,6 +92,7 @@ from ..providers import (
verify_provider_key,
)
from ..providers.local_server import LOCAL_SERVERS
+from ..providers.router import DEFAULT_PROVIDER, canonical_model
from ..providers.registry import CUSTOM_PROVIDERS_PROFILE, DEFAULT_OLLAMA_URL
from ..secrets import SecretStore, state_dir
from ..sessions import SessionRecord, usage_totals
@@ -4630,7 +4631,7 @@ class SessionManager:
prefix = model.split(":", 1)[0]
if get_descriptor(prefix, self.secrets) is not None:
return prefix
- return "openai"
+ return DEFAULT_PROVIDER
def _provider_configured(self, name: str) -> bool:
d = get_descriptor(name, self.secrets)
@@ -4873,11 +4874,15 @@ class SessionManager:
"""The model a session of `persona_id` runs on (spec §4). No list: the requested
model or the machine default, as before. A list: the requested model when it is
on the list, else the first entry this machine can run, else the first entry
- (unrunnable — the composer shows its honest "No model" state)."""
- allowed = self.persona_models(persona_id)
- requested = (requested or "").strip()
+ (unrunnable — the composer shows its honest "No model" state).
+
+ Ids are compared and returned in their canonical form (`canonical_model`), so a
+ list entry `openai:gpt-5.5` matches a requested `gpt-5.5`, and the session records
+ one name per model."""
+ allowed = list(dict.fromkeys(canonical_model(m) for m in self.persona_models(persona_id)))
+ requested = canonical_model(requested or "")
if not allowed:
- return requested or self.model
+ return requested or canonical_model(self.model)
if requested in allowed:
return requested
available = [m for m in allowed if self.model_selectable(m)]
@@ -4896,8 +4901,11 @@ class SessionManager:
from ..providers.matrix import model_labels
labels = model_labels()
- allowed = self.persona_models(persona_id)
- human_pick, lead_pick = (human_pick or "").strip(), (lead_pick or "").strip()
+ # Canonical ids (`canonical_model`): `openai:gpt-5.5` and `gpt-5.5` are one model,
+ # and the worker's session records it under one name.
+ allowed = list(dict.fromkeys(canonical_model(m) for m in self.persona_models(persona_id)))
+ human_pick, lead_pick = canonical_model(human_pick or ""), canonical_model(lead_pick or "")
+ lead_model = canonical_model(lead_model or "")
if human_pick and self.model_selectable(human_pick):
return human_pick, ""
if lead_pick and (not allowed or lead_pick in allowed) and self.model_selectable(lead_pick):
@@ -4905,7 +4913,7 @@ class SessionManager:
runnable = [m for m in allowed if self.model_selectable(m)]
if runnable:
return runnable[0], ""
- fallback = lead_model if lead_model and self.model_selectable(lead_model) else self.model
+ fallback = lead_model if lead_model and self.model_selectable(lead_model) else canonical_model(self.model)
if not allowed:
return fallback, ""
entry = self.personas.get(persona_id)
diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsx
index 6f65ed01..e01c86da 100644
--- a/surfaces/gui/src/App.tsx
+++ b/surfaces/gui/src/App.tsx
@@ -71,6 +71,7 @@ import { fullPersonaName, isProjectScoped } from "./personaScope";
import { baseName } from "./paths";
import { itemsFromMessages } from "./itemsFromMessages";
import { addTurnUsage, emptyUsage, teamUsage, usageFromMessages } from "./usage";
+import { canonicalModel, canonicalModels, coworkerModels } from "./modelNames";
import { streamMode } from "./streamGate";
import { InboxItemCard, approvalItemFromParked } from "./components/InboxItemCard";
import { isTauri, macosMajor, platformOS, startWindowDrag } from "./tauri";
@@ -847,16 +848,19 @@ export function App() {
// fresh draft binds to the first entry this machine can run. Availability = the
// machine's own selectable list (its keys, its Ollama); a draft on a remote machine
// asks that machine's list, like the picker already does.
- const personaModels = personaOf(agent)?.models ?? [];
+ // Ids are compared in canonical form (`canonicalModel`): a manifest's "openai:gpt-5.5"
+ // is the machine's "gpt-5.5".
+ const personaModels = canonicalModels(personaOf(agent)?.models ?? []);
const selectableModels = machine ? machineSettings?.models || [] : models;
- const pickerModels = personaModels.length ? personaModels : selectableModels;
- const unavailableModels = personaModels.filter((m) => !selectableModels.includes(m));
+ const {
+ picker: pickerModels,
+ unavailable: unavailableModels,
+ bind: personaBind,
+ } = coworkerModels(personaModels, selectableModels, model);
const selectableKey = selectableModels.join("|");
useEffect(() => {
- if (!personaModels.length || items.length > 0 || running) return;
- if (personaModels.includes(model)) return;
- const first = personaModels.find((m) => selectableModels.includes(m)) ?? personaModels[0];
- if (first) changeModel(first);
+ if (items.length > 0 || running) return;
+ if (personaBind) changeModel(personaBind);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [agent, personas, items.length, running, selectableKey]);
@@ -2493,7 +2497,7 @@ export function App() {
(machine ? (machineSettings ? machineSettings.model_ready : true) : modelReady) &&
// A coworker bound to a model this machine cannot run shows the honest
// "No model" state, whatever the machine default says.
- !(personaModels.length > 0 && unavailableModels.includes(model))
+ !(personaModels.length > 0 && unavailableModels.includes(canonicalModel(model)))
}
onConnectModel={openModelSetup}
onOpenMemory={() => openSettings("memory")}
diff --git a/surfaces/gui/src/components/connectors/ConfigurationsSection.tsx b/surfaces/gui/src/components/connectors/ConfigurationsSection.tsx
index 0983fe5f..41ab5817 100644
--- a/surfaces/gui/src/components/connectors/ConfigurationsSection.tsx
+++ b/surfaces/gui/src/components/connectors/ConfigurationsSection.tsx
@@ -18,6 +18,7 @@ import {
type Persona,
} from "../../api";
import type { SessionInfo } from "../../types";
+import { canonicalModels, sameModel } from "../../modelNames";
type SessionRow = SessionInfo;
import { FOOT, GRP, GRP_H, PILL_ACCENT, PILL_LINE, ROW, XBTN } from "./ui";
@@ -270,13 +271,21 @@ function ConfigurationDialog({
}, [machineId]);
const personaRow = personas.find((p) => p.id === persona);
// The coworker's own list when it has one, else the machine's selectable models.
- const offered = useMemo(() => (personaRow?.models?.length ? personaRow.models : selectable), [personaRow, selectable]);
+ // Ids in canonical form (`canonicalModel`): a manifest's "openai:gpt-5.5" is the
+ // machine's "gpt-5.5".
+ const offered = useMemo(
+ () => (personaRow?.models?.length ? canonicalModels(personaRow.models) : selectable),
+ [personaRow, selectable],
+ );
useEffect(() => {
// Keep the chosen models within what is offered; default to the first runnable.
- const kept = models.filter((m) => offered.includes(m));
- if (kept.length !== models.length) setModels(kept);
+ // A saved "openai:gpt-5.5" is kept under the offered spelling.
+ const kept = models
+ .map((m) => offered.find((o) => sameModel(o, m)))
+ .filter((m): m is string => !!m);
+ if (kept.join("|") !== models.join("|")) setModels(kept);
if (kept.length === 0 && offered.length) {
- const first = offered.find((m) => selectable.includes(m)) ?? offered[0];
+ const first = offered.find((m) => selectable.some((s) => sameModel(s, m))) ?? offered[0];
setModels([first]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -454,7 +463,7 @@ function ConfigurationDialog({
{offered.map((m) => {
const i = models.indexOf(m);
const on = i >= 0;
- const runnable = selectable.includes(m);
+ const runnable = selectable.some((s) => sameModel(s, m));
return (
<button
key={m}
diff --git a/surfaces/gui/src/modelNames.test.ts b/surfaces/gui/src/modelNames.test.ts
new file mode 100644
index 00000000..964fdca4
--- /dev/null
+++ b/surfaces/gui/src/modelNames.test.ts
@@ -0,0 +1,80 @@
+import { describe, expect, it } from "vitest";
+import { canonicalModel, canonicalModels, coworkerModels, sameModel } from "./modelNames";
+
+describe("canonicalModel", () => {
+ it("drops a prefix naming the default provider", () => {
+ expect(canonicalModel("openai:gpt-test-1")).toBe("gpt-test-1");
+ expect(canonicalModel("gpt-test-1")).toBe("gpt-test-1");
+ expect(canonicalModel(" openai:gpt-test-1 ")).toBe("gpt-test-1");
+ });
+
+ it("keeps every other prefix, and colons inside the name", () => {
+ expect(canonicalModel("anthropic:model-a")).toBe("anthropic:model-a");
+ expect(canonicalModel("ollama:qwen-test:32b")).toBe("ollama:qwen-test:32b");
+ expect(canonicalModel("openai-codex:gpt-test-1")).toBe("openai-codex:gpt-test-1");
+ expect(canonicalModel("openai:qwen-test:32b")).toBe("qwen-test:32b");
+ });
+
+ it("leaves an empty or prefix-only id alone", () => {
+ expect(canonicalModel("")).toBe("");
+ expect(canonicalModel("openai:")).toBe("openai:");
+ });
+});
+
+describe("sameModel", () => {
+ it("treats the prefixed and bare spellings as one model", () => {
+ expect(sameModel("openai:gpt-test-1", "gpt-test-1")).toBe(true);
+ expect(sameModel("gpt-test-1", "openai:gpt-test-1")).toBe(true);
+ });
+
+ it("tells different providers apart", () => {
+ expect(sameModel("anthropic:gpt-test-1", "gpt-test-1")).toBe(false);
+ expect(sameModel("openrouter:gpt-test-1", "openai:gpt-test-1")).toBe(false);
+ });
+});
+
+describe("canonicalModels", () => {
+ it("canonicalizes, drops duplicates and keeps order", () => {
+ expect(canonicalModels(["anthropic:model-a", "openai:gpt-test-1", "gpt-test-1", ""])).toEqual([
+ "anthropic:model-a",
+ "gpt-test-1",
+ ]);
+ });
+});
+
+describe("coworkerModels", () => {
+ const listed = ["anthropic:model-a", "openai:gpt-test-1"];
+
+ it("binds a fresh draft to the OpenAI entry on an OpenAI-only machine", () => {
+ const out = coworkerModels(listed, ["gpt-test-1", "gpt-test-2"], "gpt-test-2");
+ expect(out.picker).toEqual(["anthropic:model-a", "gpt-test-1"]);
+ expect(out.unavailable).toEqual(["anthropic:model-a"]);
+ expect(out.bind).toBe("gpt-test-1");
+ });
+
+ it("keeps a current model that is on the list, in either spelling", () => {
+ expect(coworkerModels(listed, ["gpt-test-1"], "gpt-test-1").bind).toBeNull();
+ expect(coworkerModels(listed, ["gpt-test-1"], "openai:gpt-test-1").bind).toBeNull();
+ });
+
+ it("still reports nothing runnable when only the other provider is listed", () => {
+ const out = coworkerModels(["anthropic:model-a", "anthropic:model-b"], ["gpt-test-1"], "gpt-test-1");
+ expect(out.unavailable).toEqual(["anthropic:model-a", "anthropic:model-b"]);
+ // The draft binds to the list head, which the composer shows as "No model".
+ expect(out.bind).toBe("anthropic:model-a");
+ });
+
+ it("matches a machine list that spells the model with the prefix", () => {
+ const out = coworkerModels(["gpt-test-1"], ["openai:gpt-test-1"], "");
+ expect(out.unavailable).toEqual([]);
+ expect(out.bind).toBe("gpt-test-1");
+ });
+
+ it("offers the machine's list when the coworker has none", () => {
+ expect(coworkerModels([], ["gpt-test-1", "ollama:local-test"], "gpt-test-1")).toEqual({
+ picker: ["gpt-test-1", "ollama:local-test"],
+ unavailable: [],
+ bind: null,
+ });
+ });
+});
diff --git a/surfaces/gui/src/modelNames.ts b/surfaces/gui/src/modelNames.ts
index 8a092aa6..9c79220e 100644
--- a/surfaces/gui/src/modelNames.ts
+++ b/surfaces/gui/src/modelNames.ts
@@ -16,3 +16,46 @@ export function modelHover(id: string, labels?: Record<string, string>): string
const label = labels?.[id];
return label && label !== id ? `${label} (${id})` : id;
}
+
+// One spelling per model (same rule as the server, `coworker/providers/router.py`
+// `canonical_model`). A model id with no "provider:" prefix runs on the default
+// provider, so "openai:gpt-5.5" and "gpt-5.5" are the same model. The machine's model
+// list spells OpenAI models bare; coworker manifests often write "openai:…". Compare
+// and store the bare form. Every other prefix ("anthropic:", "ollama:" …) is kept.
+export const DEFAULT_PROVIDER = "openai";
+
+export function canonicalModel(id: string): string {
+ const m = (id || "").trim();
+ const prefix = `${DEFAULT_PROVIDER}:`;
+ return m.startsWith(prefix) && m.length > prefix.length ? m.slice(prefix.length) : m;
+}
+
+export function sameModel(a: string, b: string): boolean {
+ return canonicalModel(a) === canonicalModel(b);
+}
+
+/** The list in canonical form, first spelling of each model kept, order kept. */
+export function canonicalModels(ids: string[]): string[] {
+ return Array.from(new Set(ids.map(canonicalModel).filter(Boolean)));
+}
+
+/**
+ * The composer's model choice for a coworker with a `models:` list (connectors-across-
+ * machines §4). `picker` is what the picker offers (the coworker's list, or the machine's
+ * when it has none); `unavailable` the list entries this machine can't run; `bind` the
+ * model a fresh draft should switch to, or null to keep `current`.
+ */
+export function coworkerModels(
+ personaModels: string[],
+ selectable: string[],
+ current: string,
+): { picker: string[]; unavailable: string[]; bind: string | null } {
+ const listed = canonicalModels(personaModels);
+ if (!listed.length) return { picker: selectable, unavailable: [], bind: null };
+ const runnable = new Set(selectable.map(canonicalModel));
+ const unavailable = listed.filter((m) => !runnable.has(m));
+ const bind = listed.includes(canonicalModel(current))
+ ? null
+ : (listed.find((m) => runnable.has(m)) ?? listed[0]);
+ return { picker: listed, unavailable, bind };
+}
diff --git a/tests/test_persona_models.py b/tests/test_persona_models.py
index f07e3722..67078dd3 100644
--- a/tests/test_persona_models.py
+++ b/tests/test_persona_models.py
@@ -53,14 +53,15 @@ def test_resolve_prefers_the_first_runnable_entry(tmp_path, monkeypatch):
monkeypatch.setattr(mgr, "_provider_configured", lambda name: False)
assert mgr.resolve_persona_model("ops") == "anthropic:claude-opus-4-8"
assert mgr.persona_models_available("ops") == []
- # Only OpenAI configured: the first RUNNABLE entry wins over the list head.
+ # Only OpenAI configured: the first RUNNABLE entry wins over the list head, named the
+ # way the machine's model list names it (no default-provider prefix).
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
- assert mgr.resolve_persona_model("ops") == "openai:gpt-5.5"
+ assert mgr.resolve_persona_model("ops") == "gpt-5.5"
assert mgr.persona_models_available("ops") == ["openai:gpt-5.5"]
# A requested model ON the list is honoured even when unrunnable (user's pick).
assert mgr.resolve_persona_model("ops", "anthropic:claude-opus-4-8") == "anthropic:claude-opus-4-8"
# A requested model OFF the list resolves back onto it.
- assert mgr.resolve_persona_model("ops", "ollama:llama3") == "openai:gpt-5.5"
+ assert mgr.resolve_persona_model("ops", "ollama:llama3") == "gpt-5.5"
def test_no_list_means_any_model(tmp_path, monkeypatch):
@@ -89,7 +90,7 @@ def test_new_session_binds_to_the_list(tmp_path, monkeypatch):
mgr = _mgr(tmp_path, monkeypatch)
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
engine = mgr.get_engine("s-ops", agent="ops")
- assert engine is not None and engine.model == "openai:gpt-5.5"
+ assert engine is not None and engine.model == "gpt-5.5"
plain = mgr.get_engine("s-plain", agent="cowork")
assert plain is not None and plain.model == mgr.model
@@ -100,7 +101,28 @@ def test_socket_set_model_off_the_list_resolves_onto_it(tmp_path, monkeypatch):
client = TestClient(create_app(mgr))
with client.websocket_connect("/ws/session/s-ws?agent=ops") as ws:
ready = ws.receive_json()
- assert ready["type"] == "ready" and ready["data"]["model"] == "openai:gpt-5.5"
+ assert ready["type"] == "ready" and ready["data"]["model"] == "gpt-5.5"
ws.send_json({"type": "set_model", "model": "ollama:llama3"})
# The rebind is a no-op (resolved back onto the same model): no notice frame.
- assert mgr.get_engine("s-ws").model == "openai:gpt-5.5"
+ assert mgr.get_engine("s-ws").model == "gpt-5.5"
+
+
+def test_bare_and_prefixed_spellings_are_one_model(tmp_path, monkeypatch):
+ """The machine's list says `gpt-5.5`; the manifest says `openai:gpt-5.5`. Same model:
+ a requested bare id is ON the list, and the session records the bare id."""
+ mgr = _mgr(tmp_path, monkeypatch)
+ monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
+ assert mgr.resolve_persona_model("ops", "gpt-5.5") == "gpt-5.5"
+ assert mgr.resolve_persona_model("ops", "openai:gpt-5.5") == "gpt-5.5"
+ # Other prefixes are kept as written.
+ assert mgr.resolve_persona_model("ops", "anthropic:claude-opus-4-8") == "anthropic:claude-opus-4-8"
+ assert mgr.resolve_persona_model("cowork", "openai:gpt-test-1") == "gpt-test-1"
+ assert mgr.resolve_persona_model("cowork", "ollama:qwen-test:32b") == "ollama:qwen-test:32b"
+
+
+def test_anthropic_only_list_stays_unrunnable_without_an_anthropic_key(tmp_path, monkeypatch):
+ mgr = _mgr(tmp_path, monkeypatch)
+ monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
+ monkeypatch.setattr(mgr, "persona_models", lambda pid: ["anthropic:model-a", "anthropic:model-b"])
+ assert mgr.persona_models_available("ops") == []
+ assert mgr.resolve_persona_model("ops") == "anthropic:model-a"
diff --git a/tests/test_provider_router.py b/tests/test_provider_router.py
index d0dfec33..2e0c77b3 100644
--- a/tests/test_provider_router.py
+++ b/tests/test_provider_router.py
@@ -873,3 +873,29 @@ def test_manager_azure_card_saves_endpoint_and_key_and_verifies_at_the_resource(
added = mgr.add_model("azure:gpt-5-prod")
assert added["ok"] and "azure:gpt-5-prod" in added["models"]
assert mgr._model_provider("azure:gpt-5-prod") == "azure"
+
+
+# -- one spelling per model: the default provider's prefix is dropped ----------------------
+
+
+def test_canonical_model_drops_only_the_default_providers_prefix():
+ from coworker.providers.router import canonical_model, same_model
+
+ assert canonical_model("openai:gpt-test-1") == "gpt-test-1"
+ assert canonical_model(" gpt-test-1 ") == "gpt-test-1"
+ assert canonical_model("anthropic:model-a") == "anthropic:model-a"
+ assert canonical_model("ollama:qwen-test:32b") == "ollama:qwen-test:32b"
+ assert canonical_model("openai-codex:gpt-test-1") == "openai-codex:gpt-test-1"
+ assert canonical_model("openai:") == "openai:"
+ assert canonical_model("") == ""
+ assert same_model("openai:gpt-test-1", "gpt-test-1")
+ assert not same_model("anthropic:gpt-test-1", "gpt-test-1")
+
+
+def test_canonical_model_routes_where_the_original_did():
+ from coworker.providers.router import canonical_model
+
+ router = ProviderRouter()
+ for model in ("openai:gpt-test-1", "anthropic:model-a", "ollama:qwen-test:32b"):
+ assert router._provider_name(canonical_model(model)) == router._provider_name(model)
+ assert router._bare(canonical_model(model)) == router._bare(model)
diff --git a/tests/test_worker_connectors.py b/tests/test_worker_connectors.py
index c5c9aa9f..23bfb590 100644
--- a/tests/test_worker_connectors.py
+++ b/tests/test_worker_connectors.py
@@ -476,6 +476,8 @@ async def test_background_approver_tells_the_lead_a_worker_is_waiting(manager):
def test_worker_model_prefers_the_human_then_the_recommendation_then_the_lead(manager, monkeypatch):
opus, sol, sonnet = "anthropic:claude-opus-4-8", "openai:gpt-5.6-sol", "anthropic:claude-sonnet-4-6"
assert manager.persona_models("swe-worker") == [opus, sol]
+ # A worker's model is recorded the way the machine's list names it: no `openai:`.
+ sol = "gpt-5.6-sol"
runnable = {opus, sol, sonnet}
monkeypatch.setattr(manager, "model_selectable", lambda m: m in runnable)
# The human's choice on the card wins, even outside the recommended list.
@@ -580,3 +582,15 @@ def test_the_leads_approval_card_carries_the_workers_call(manager):
# An unknown id (already cleaned up, or invented by the model) attaches nothing.
Request.arguments = {**Request.arguments, "call_id": "nope"}
assert "worker_call" not in manager.approval_prompt_data("lead-sid", Request())
+
+
+def test_worker_model_matches_the_bare_and_prefixed_spellings(manager, monkeypatch):
+ """The lead may write `openai:…` or the bare id; either is the recommended model, and
+ the worker records the bare id (one name per model in Usage)."""
+ opus = "anthropic:claude-opus-4-8"
+ monkeypatch.setattr(manager, "persona_models", lambda pid: [opus, "openai:gpt-test-1"])
+ monkeypatch.setattr(manager, "model_selectable", lambda m: m == "gpt-test-1")
+ for pick in ("gpt-test-1", "openai:gpt-test-1"):
+ assert manager.resolve_worker_model("swe-worker", lead_pick=pick) == ("gpt-test-1", "")
+ assert manager.resolve_worker_model("swe-worker") == ("gpt-test-1", "")
+ assert manager.resolve_worker_model("swe-worker", human_pick="openai:gpt-test-1") == ("gpt-test-1", "")