Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(model_hub): leave the rename to the layer that can prove it
cyhaac5ffbb5ca3
diff --git a/config/v2_config.py b/config/v2_config.pyindex e143d07d8..5a50548a1 100644--- a/config/v2_config.py+++ b/config/v2_config.py@@ -800,153 +800,8 @@ def _migrate_opencode_active_turn_timeout_on_load(payload: dict) -> dict:return migrated-def _migrate_model_hub_credential_addresses(payload: dict) -> dict:- """Drop credential addresses from model names an earlier release stored.-- The engine addresses a credential through the model field of one outbound- request, so a call spells its target ``<source prefix>/<model>``. Releases- before this one persisted what the engine's management API answered with,- which is already addressed, so a stored inventory id could carry the address- of the credential that served it. Composition then addressed it a second- time and the engine refused the call, and resolution — which compares a- menu id against an inventory id literally — matched nothing either.-- A bounded repair rather than a rule in the admission path. Discovery now- removes the address of the credential it is discovering, at the boundary- where the address enters, so no newly written file carries one; what remains- is files already written, and this is the compatibility boundary that reads- them. Nothing here is claimed about a name a caller sends afterwards.-- Only rows discovery produced are touched. Those are the only rows an address- could have reached, and it means a model a person added by hand is never- renamed, however it is spelled. A config file records no prefix to compare- against — that lives with the credential — so the address is recognised by- its minted shape, which is safe exactly because of that provenance limit.-- Unwrapping can land a discovered row on a name a manual row already holds,- which is the shape left behind when someone added the bare name by hand to- work around this bug. The manual row wins: it carries a display name,- reasoning efforts, and a provenance a person chose, and the discovered row- duplicates an identity rather than adding one. Next discovery re-attaches- upstream metadata to the surviving row.-- Any shape this cannot read is returned untouched, so the strict parse that- follows still reports it rather than having it quietly repaired here.- """-- model_hub = payload.get("model_hub")- if not isinstance(model_hub, dict):- return payload- raw_sources = model_hub.get("sources")- if not isinstance(raw_sources, list):- return payload-- from core.handlers.model_hub.identifiers import model_id_without_credential_address-- healed_sources: list[dict] = []- # Per Source, the addressed spellings this repair renamed and what each- # became. A route hop is rewritten only if it names one of these, so a hop- # is never redirected to a model this file does not show it already meant.- renamed: dict[str, dict[str, str]] = {}- changed = False- for source in raw_sources:- if not isinstance(source, dict):- return payload- models = source.get("models")- source_id = source.get("id")- if not isinstance(models, list) or not isinstance(source_id, str):- healed_sources.append(source)- continue- # Which rows this repair moves, and which names it is not moving. Read- # before anything is rewritten, because a name a row already holds- # outranks one this repair would move onto it however the file orders- # the two — a manual row a person added by hand to work around this- # bug most of all.- settled: dict[str, str] = {}- held: set[str] = set()- for model in models:- if not isinstance(model, dict):- return payload- model_id = model.get("id")- if not isinstance(model_id, str) or not model_id:- continue- identity = (- model_id_without_credential_address(model_id)- if model.get("origin") == "discovered"- else model_id- )- if identity == model_id:- held.add(model_id)- else:- settled[model_id] = identity-- healed_models: list[dict] = []- moved: set[str] = set()- for model in models:- model_id = model.get("id")- identity = settled.get(model_id) if isinstance(model_id, str) else None- if identity is None:- # Untouched, including a row this file lists twice: a duplicate- # this repair did not create is still the strict parse's to report.- healed_models.append(model)- continue- changed = True- if identity in held or identity in moved:- continue- moved.add(identity)- healed_models.append({**model, "id": identity})- if settled:- renamed[source_id] = settled- healed_sources.append({**source, "models": healed_models})-- if not changed:- return payload-- healed_hub = {**model_hub, "sources": healed_sources}- agents = model_hub.get("agents")- if isinstance(agents, dict):- healed_agents: dict[str, object] = {}- for backend, agent in agents.items():- routes = agent.get("routes") if isinstance(agent, dict) else None- if not isinstance(routes, dict):- healed_agents[backend] = agent- continue- healed_routes: dict[str, object] = {}- for requested, route in routes.items():- hops = route.get("hops") if isinstance(route, dict) else None- if not isinstance(hops, list):- healed_routes[requested] = route- continue- healed_hops: list[object] = []- # Which hop already holds each pair, and whether this repair is- # what put it there. A hop is dropped only where renaming is- # what made the two identical; a route that already listed one- # hop twice still reaches the strict parse that refuses it.- settled_hops: dict[tuple[str, str], bool] = {}- for hop in hops:- if isinstance(hop, dict):- source_id = hop.get("source_id")- model_id = hop.get("model_id")- if isinstance(source_id, str) and isinstance(model_id, str):- identity = renamed.get(source_id, {}).get(model_id)- if identity is not None:- hop = {**hop, "model_id": identity}- model_id = identity- earlier = settled_hops.get((source_id, model_id))- if earlier is not None and (identity is not None or earlier):- continue- settled_hops[(source_id, model_id)] = identity is not None- healed_hops.append(hop)- healed_routes[requested] = {**route, "hops": healed_hops}- healed_agents[backend] = {**agent, "routes": healed_routes}- healed_hub["agents"] = healed_agents-- return {**payload, "model_hub": healed_hub}--def _migrate_config_payload_on_load(payload: dict) -> tuple[dict, bool, tuple[str, ...]]:migrated, changed, warnings = _migrate_legacy_model_hub_payload(payload)- migrated = _migrate_model_hub_credential_addresses(migrated)migrated, catalog_changed, catalog_warnings = _migrate_legacy_opencode_catalog(migrated)model_hub_changed = changed or catalog_changed or migrated.get("model_hub") != payload.get("model_hub")migrated = _migrate_opencode_active_turn_timeout_on_load(migrated)diff --git a/docs/plans/model-hub-credential-address-repair.md b/docs/plans/model-hub-credential-address-repair.mdnew file mode 100644index 000000000..bd5f9ce32--- /dev/null+++ b/docs/plans/model-hub-credential-address-repair.md@@ -0,0 +1,156 @@+# Repairing model ids an earlier release stored with a credential address++## Background++The engine reaches one credential through the **model field of one outbound+request** and through no other field, so a call spells its target+`<source prefix>/<model>`. That prefix (`avibe-` + twelve random bytes) addresses+a credential. It is not part of what the model is called.++Releases before PR #2099 persisted what the engine's management API answered+with — names the engine had *already* addressed — so a stored inventory id could+carry the address of the credential that served it. `invoke` then addressed it a+second time (`client.py:368` composes unconditionally) and the engine answered+`model_not_found`; independently, `matching_v1_model_id` compares a menu id+against `source.models[].id` literally, so an addressed row matched no route+target and every hop through it was refused as `mapping_target_unavailable`.++PR #2099 closed the boundary the address enters through:++- **Discovery** (`vibe/model_hub_runtime/adapter.py`) removes the address of the+ credential it is discovering, compared literally against that credential's own+ prefix. Nothing newly written carries one.+- **Engine state records** (`vibe/model_hub_runtime/state.py`) heal against their+ own `SourceRecord.prefix`, re-keying `model_reasoning_efforts` with the ids.++What remains is **files already written**. This document is the design for+repairing those.++## Why the config layer is the wrong place++PR #2099 first attempted the repair at the config load seam+(`_migrate_model_hub_credential_addresses`), and review rejected it twice for+two reasons that are both structural, not fixable by a better heuristic:++1. **The config layer cannot prove ownership.** `ModelHubSourceConfig`+ (`config/v2_config.py:3020`) has no prefix field; `credential_metadata` lives+ only in `vibe/model_hub_runtime/state.py`. A repair there can only recognise+ an address by its *minted spelling*, which means renaming any upstream+ identity that happens to be spelled that way. Provenance narrows the blast+ radius but does not close it: a `discovered` row on a passthrough source is+ whatever upstream named it.+2. **An id is a join key, and config sees only part of the join.** The same id+ appears in the source inventory, route hops, **route keys**, the persisted+ backend menu rows (`ModelHubBackendModelConfig`), `removed_model_ids`,+ per-source reasoning maps, engine state records, and usage ledger keys.+ `agent_model_candidates` (`service.py:4289`) derives `provider`-origin picker+ candidates directly from source model ids, so an addressed id can structurally+ reach the persisted menu and a route key. A migration that renames the+ inventory row alone leaves every other position naming something gone.++So the repair needs both halves that the config layer lacks: the credential+(to prove the prefix) and the service (to move every position together).++## Functional relief that already exists++An affected user is not stuck waiting for this. Once #2099 lands, one **refresh+models** on the Source re-discovers through the fixed boundary and+`_apply_discovered_models` (`service.py:1904`) replaces the inventory rows with+bare-named ones. What refresh does not do is move a route hop or a route key+that already points at an addressed spelling — those are the positions this+repair owns.++## Design++### Where it runs++A service-level repair, invoked once per Source from the runtime, not a+config-load rewrite. Shape:++```+ModelHubService.repair_credential_addresses(source_id) -> RepairOutcome+```++The runtime resolves the owning prefix through the existing+`credential_metadata(...)["prefix"]`, exactly as discovery does, and hands the+service a **proven** prefix. A Source whose credential no longer resolves is+skipped and reported — never guessed at.++### What it rewrites, in one transaction++Given `(source_id, prefix)`, build the rename map from the source's own rows —+`{stored_id: model_id_without_credential_address(stored_id, prefix)}`, keeping+only entries that actually changed — then apply it to every position in one+config write:++| Position | Rule |+| --- | --- |+| `source.models[].id` | Renamed. A row landing on a name another row already holds is dropped; the holder keeps its display name, reasoning efforts, and provenance. |+| `source.models[].reasoning_efforts` and the engine record's `model_reasoning_efforts` | Follow their row. |+| Route **hops** (`hop.source_id == source_id`) | Renamed only where the map has the spelling. Two hops collapsing onto one pair are merged; a route left with zero hops keeps its key and reports the ordinary unavailable-target path. |+| Route **keys** (menu ids a route is keyed by) | Renamed only when the key matches a renamed id *and* no route already exists under the bare name; otherwise the routes are merged hop-wise, bare-name-first. |+| Backend menu rows (`ModelHubBackendModelConfig`) | Renamed only for rows whose origin is `provider` (the origin `agent_model_candidates` produces from inventory) and whose id matches a renamed id. `builtin` / `models_dev` / `manual` rows are never touched. |+| `removed_model_ids` | Renamed, so a model the user hid stays hidden. |+| Usage ledger keys | **Not** rewritten. See below. |++Everything is computed first and written once, so a partial rename cannot be+persisted.++### The ledger is deliberately excluded++An addressed inventory id cannot have produced a ledger row: composition is+unconditional, so such a call went out double-addressed and came back an error+envelope; `TurnExecution.reached_model` classifies that as having reached no+model (`turn_gateway.py:226-267`), `owes_metering` is then False (`:280-282`),+and `_record_usage` returns before writing (`:1169`). Verified against the live+local regression ledger: 31 rows, 10 distinct model ids, **zero** addressed —+while `gpt-5.6-luna` / `gpt-5.6-terra`, whose inventory rows *were* addressed on+that host, already metered under their bare names.++Falsifiable claim: a usage row whose `model_id` matches `avibe-[0-9a-f]{24}/…`+on an upgrading installation. If one turns up, `usage_summary`'s label join+orphans it and a ledger re-key joins this design.++### When it is triggered++Preference order, cheapest first:++1. **On Source refresh / reachability check** — the runtime already holds the+ credential there, so the repair costs one extra config write and only on a+ Source that actually has addressed rows.+2. **On engine start, per bound Source** — covers a user who never clicks+ refresh. Guarded by a fast "does any row carry the minted shape" pre-check so+ the common case does no work.++Not a config-load migration, and not a one-shot script: it must run where the+credential is resolvable.++### Reporting++The outcome is reported, not silent: the number of rows, hops, keys, and menu+rows moved, per Source, in the runtime log, and a Source whose credential could+not be resolved is named so the user can reconnect it.++## Validation plan++- Unit: rename map built from a proven prefix; foreign address left alone;+ upstream slashes (`x-ai/grok-4.6-latest`, `anthropic/claude-sonnet-4`,+ `accounts/fireworks/models/…`) left alone; row-collision precedence; hop+ merge; route-key merge; menu row renamed only for `provider` origin;+ `removed_model_ids` followed.+- Property: a repaired config must serialize to one this product loads again —+ the failure mode is writing a surviving name twice and refusing the file on+ the next load.+- Integration: a source whose credential does not resolve is skipped whole, and+ its config bytes are unchanged.+- Regression (local Incus only): load a snapshot of an affected `config.json` ++ `sources.json`, refresh the Source, and confirm the six subscription models+ become selectable and invocable end to end.++## Out of scope++- Any change to `client.py:368` / `modules/agents/model_hub.py` composition. The+ outbound request is where the address belongs — it is the envelope, written at+ the moment of sending.+- Any change to `normalized_model_id` / `usage_ledger_key`.+- Widening `source_supports_passthrough`.diff --git a/tests/test_model_hub_credential_address.py b/tests/test_model_hub_credential_address.pyindex 67c760e70..1a593593a 100644--- a/tests/test_model_hub_credential_address.py+++ b/tests/test_model_hub_credential_address.py@@ -9,9 +9,12 @@ file an earlier release wrote with one still loads.The address is removed where its owner is known, so what gets removed is acredential's own address and never a name that merely looks like one. Discovery-knows the credential it is discovering, an engine record names the prefix it is-addressed by, and a config file — which records no prefix at all — is repaired-once on load, for the rows discovery produced, by the minted spelling.+knows the credential it is discovering and an engine record names the prefix it+is addressed by. A config file names no prefix, so the config layer renames+nothing: it stores the name it is given, and a file an earlier release addressed+is repaired by the runtime, which holds the credential and can move an id in+every place it is a join key at once. See+``docs/plans/model-hub-credential-address-repair.md``."""import copy@@ -118,6 +121,70 @@ def test_discovery_drops_the_address_the_engine_answers_with() -> None:assert models[0].supported_parameters == ("reasoning",)+def test_discovery_coalesces_two_rows_the_engine_answers_for_one_model() -> None:+ """Removing an address can land two of the engine's rows on one name.++ The inventory holds one row per name, so the rows are coalesced rather than+ the later one dropped. What the engine reported about a model may not depend+ on which position it reported it in — and the inventory writer refuses a+ duplicate outright, so dropping one silently is not an option either.+ """++ models = _discovered_models(+ {+ "models": [+ {"id": f"{ADDRESS}/gpt-5.5", "supported_parameters": ["reasoning"]},+ {"id": "gpt-5.5", "supported_parameters": ["tools", "reasoning"]},+ ]+ },+ ADDRESS,+ )++ assert [model.id for model in models] == ["gpt-5.5"]+ assert models[0].supported_parameters == ("reasoning", "tools")+++def test_discovery_keeps_metadata_only_a_later_row_carries() -> None:+ """Order decides nothing: the row that knew something is the one believed."""++ models = _discovered_models(+ {+ "models": [+ {"id": f"{ADDRESS}/gpt-5.5"},+ {"id": "gpt-5.5", "supported_parameters": ["reasoning"]},+ ]+ },+ ADDRESS,+ )++ assert [(model.id, model.supported_parameters) for model in models] == [+ ("gpt-5.5", ("reasoning",))+ ]+++def test_discovery_leaves_a_name_the_engine_listed_twice_to_its_first_answer() -> None:+ """Coalescing is for the merge this boundary makes, not for the engine's own.++ One spelling listed twice is the engine contradicting itself, and the first+ answer has always been the one kept. Removing an address does not change+ that; it only means two names the engine kept apart can now meet.+ """++ models = _discovered_models(+ {+ "models": [+ {"id": "gpt-5.5", "supported_parameters": ["reasoning"]},+ {"id": "gpt-5.5", "supported_parameters": ["tools"]},+ ]+ },+ ADDRESS,+ )++ assert [(model.id, model.supported_parameters) for model in models] == [+ ("gpt-5.5", ("reasoning",))+ ]++def test_discovery_keeps_a_name_it_cannot_prove_is_an_address() -> None:models = _discovered_models({"models": [{"id": f"{OTHER_ADDRESS}/gpt-5.5"}, {"id": "x-ai/grok-4.6-latest"}]},@@ -251,115 +318,32 @@ def _config_payload(models: list[dict], hops: list[dict] | None = None) -> dict:return payload-def _load(tmp_path, payload: dict) -> V2Config:- config_path = tmp_path / "config.json"- config_path.write_text(json.dumps(payload, ensure_ascii=False), encoding="utf-8")- return V2Config.load(config_path=config_path)---def test_a_file_an_earlier_release_addressed_loads_without_the_address(tmp_path) -> None:- """One repair on load, for a file written before discovery stopped storing one."""-- loaded = _load(- tmp_path,- _config_payload(- [_model_payload(f"{ADDRESS}/gpt-5.5"), _model_payload(f"{ADDRESS}/gpt-6-astra")],- [{"source_id": SOURCE_ID, "model_id": f"{ADDRESS}/gpt-5.5"}],- ),- )-- assert loaded.load_warnings == ()- assert [model.id for model in loaded.model_hub.sources[0].models] == ["gpt-5.5", "gpt-6-astra"]- hops = loaded.model_hub.agents["claude"].routes["claude-opus-4-6"].hops- assert [hop.model_id for hop in hops] == ["gpt-5.5"]---def test_a_model_a_person_added_keeps_the_name_they_gave_it(tmp_path) -> None:- """Only discovery could have stored an address, so only its rows are repaired.-- A hand-added model spelled like an address is a name someone chose. Renaming- it would point the row at a model the source may not serve at all.- """-- loaded = _load(tmp_path, _config_payload([_model_payload(f"{ADDRESS}/gpt-5.5", "manual")]))-- assert [model.id for model in loaded.model_hub.sources[0].models] == [f"{ADDRESS}/gpt-5.5"]---def test_a_repaired_row_yields_to_the_manual_row_already_holding_its_name(tmp_path) -> None:- """The shape left behind by working around this bug by hand.-- Both rows name one model once the address is gone. The manual row is the one- a person made — it carries their display name and their provenance — and the- discovered row adds no identity the surviving row does not already have.- """-- loaded = _load(- tmp_path,- _config_payload(- [- _model_payload(f"{ADDRESS}/gpt-5.5"),- _model_payload("gpt-5.5", "manual", display_name="Added by hand"),- ]- ),- )-- assert loaded.load_warnings == ()- models = loaded.model_hub.sources[0].models- assert [(model.id, model.provenance, model.display_name) for model in models] == [- ("gpt-5.5", "manual", "Added by hand")- ]-+def test_the_config_layer_stores_the_name_it_is_given(tmp_path) -> None:+ """Config renames nothing — not what a caller sends, not what a file holds.-def test_two_spellings_of_one_hop_collapse_onto_the_model_they_now_name(tmp_path) -> None:- loaded = _load(- tmp_path,- _config_payload(- [_model_payload(f"{ADDRESS}/gpt-5.5"), _model_payload("gpt-5.5")],- [- {"source_id": SOURCE_ID, "model_id": f"{ADDRESS}/gpt-5.5"},- {"source_id": SOURCE_ID, "model_id": "gpt-5.5"},- ],- ),- )+ A config file names no prefix, so this layer cannot prove which segment of a+ model id addresses a credential; it would have to guess from the spelling,+ and a guess renames an upstream identity that happens to be spelled like+ one. An id is also the join key across the inventory, route hops, route+ keys, the backend menus, and the engine records — so renaming one from here+ moves it in a single place and leaves every other naming something gone.- assert loaded.load_warnings == ()- assert [model.id for model in loaded.model_hub.sources[0].models] == ["gpt-5.5"]- hops = loaded.model_hub.agents["claude"].routes["claude-opus-4-6"].hops- assert [(hop.source_id, hop.model_id) for hop in hops] == [(SOURCE_ID, "gpt-5.5")]---def test_a_hop_this_repair_did_not_rename_is_left_where_it_points(tmp_path) -> None:- """A hop follows its source's rows; it is never redirected on its own.-- Nothing in the file shows this hop meant ``gpt-5.5``: the source holds no row- that was renamed to it. Rewriting the hop anyway would move a route to a- model on a guess, so the hop stays and the ordinary unavailable-target path- reports it.+ Repair belongs where both are answerable: the runtime holds the credential,+ and the service writes every one of those collections together. Until then+ an addressed row loads exactly as written, and one refresh of its Source+ replaces it."""- loaded = _load(- tmp_path,- _config_payload(- [_model_payload(f"{ADDRESS}/gpt-6-astra")],- [{"source_id": SOURCE_ID, "model_id": f"{ADDRESS}/gpt-5.5"}],- ),- )-- assert [model.id for model in loaded.model_hub.sources[0].models] == ["gpt-6-astra"]- hops = loaded.model_hub.agents["claude"].routes["claude-opus-4-6"].hops- assert [(hop.source_id, hop.model_id) for hop in hops] == [(SOURCE_ID, f"{ADDRESS}/gpt-5.5")]---def test_a_file_carrying_no_address_is_not_rewritten(tmp_path) -> None:- """The repair is a repair: a file with nothing to fix is left byte for byte."""-config_path = tmp_path / "config.json"config_path.write_text(json.dumps(_config_payload(- [_model_payload("gpt-5.5"), _model_payload("x-ai/grok-4.6-latest")],- [{"source_id": SOURCE_ID, "model_id": "x-ai/grok-4.6-latest"}],+ [+ _model_payload(f"{ADDRESS}/gpt-5.5"),+ _model_payload(f"{ADDRESS}/gpt-6-astra", "manual"),+ _model_payload("x-ai/grok-4.6-latest"),+ ],+ [{"source_id": SOURCE_ID, "model_id": f"{ADDRESS}/gpt-5.5"}],),ensure_ascii=False,),@@ -369,40 +353,12 @@ def test_a_file_carrying_no_address_is_not_rewritten(tmp_path) -> None:loaded = V2Config.load(config_path=config_path)+ assert loaded.load_warnings == ()assert config_path.read_bytes() == originalassert [model.id for model in loaded.model_hub.sources[0].models] == [- "gpt-5.5",+ f"{ADDRESS}/gpt-5.5",+ f"{ADDRESS}/gpt-6-astra","x-ai/grok-4.6-latest",]---def test_a_repaired_config_serializes_to_one_this_product_loads_again(tmp_path) -> None:- """The terminal property: repairing may not produce a file that will not load.-- Collapsing two spellings into one identity is where that could break — write- the surviving name twice and the next load refuses the file it just wrote.- """-- loaded = _load(- tmp_path,- _config_payload(- [_model_payload(f"{ADDRESS}/gpt-5.5"), _model_payload("gpt-5.5")],- [- {"source_id": SOURCE_ID, "model_id": f"{ADDRESS}/gpt-5.5"},- {"source_id": SOURCE_ID, "model_id": "gpt-5.5"},- ],- ),- )- rewritten = tmp_path / "rewritten.json"- rewritten.write_text(- json.dumps(- api.config_to_payload(loaded, include_secrets=True, include_internal=True),- ensure_ascii=False,- ),- encoding="utf-8",- )-- reloaded = V2Config.load(config_path=rewritten)-- assert reloaded.load_warnings == ()- assert reloaded.model_hub.to_payload() == loaded.model_hub.to_payload()+ hops = loaded.model_hub.agents["claude"].routes["claude-opus-4-6"].hops+ assert [(hop.source_id, hop.model_id) for hop in hops] == [(SOURCE_ID, f"{ADDRESS}/gpt-5.5")]diff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.pyindex 3588404c4..dcac0dbeb 100644--- a/vibe/model_hub_runtime/adapter.py+++ b/vibe/model_hub_runtime/adapter.py@@ -2915,33 +2915,53 @@ def _discovered_models(models = payload.get("models")if not isinstance(models, list):return ()- result: list[DiscoveredModel] = []- seen: set[str] = set()+ coalesced: dict[str, tuple[str, ...] | None] = {}+ # Which spellings the engine used for each name, so a row it listed twice+ # under one name stays distinguishable from two rows that became one here.+ spellings: dict[str, set[str]] = {}for item in models:value = item.get("id") or item.get("alias") or item.get("name") if isinstance(item, dict) else itemif not isinstance(value, str) or not value:continue+ answered = value# This is the one place an address enters the product: the engine answers# with the name it addresses this credential by. It is removed here, at# that boundary, rather than by every later reader of the inventory — and# only the address of the credential being discovered, so a model whose# own name is spelled like one is left as upstream named it.value = model_id_without_credential_address(value, prefix)- if not value or value in seen:+ if not value:continue- seen.add(value)supported_parameters = Noneif isinstance(item, dict) and isinstance(item.get("supported_parameters"), list):parameters = item["supported_parameters"]if all(isinstance(parameter, str) and parameter for parameter in parameters):supported_parameters = tuple(dict.fromkeys(parameters))- result.append(- DiscoveredModel(- id=value,- supported_parameters=supported_parameters,- )- )- return tuple(result)+ if value not in coalesced:+ coalesced[value] = supported_parameters+ spellings[value] = {answered}+ continue+ if answered in spellings[value]:+ # The engine listed one name twice and said different things about+ # it. That is the engine contradicting itself and the first answer+ # has always been the one kept.+ continue+ # Two names the engine kept apart, landing on one only because the+ # address came off. The inventory holds one row per name, so the rows+ # are coalesced rather than the later one dropped: this merge is ours,+ # and nothing the engine said may be lost to the order it said it in.+ spellings[value].add(answered)+ held = coalesced[value]+ if supported_parameters is None:+ continue+ if held is None:+ coalesced[value] = supported_parameters+ continue+ coalesced[value] = tuple(dict.fromkeys(held + supported_parameters))+ return tuple(+ DiscoveredModel(id=model_id, supported_parameters=parameters)+ for model_id, parameters in coalesced.items()+ )_adapter: CLIProxyEngineAdapter | None = None