Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

fix(model_hub): let a Source holding both spellings still reach the engine

cyh14690b8c2519
diff --git a/tests/test_model_hub_credential_address.py b/tests/test_model_hub_credential_address.py
index 1a593593a..d0b020560 100644
--- a/tests/test_model_hub_credential_address.py
+++ b/tests/test_model_hub_credential_address.py
@@ -30,8 +30,9 @@ from core.handlers.model_hub.identifiers import (
)
from core.services.settings import default_config
from vibe import api
+from core.handlers.model_hub.adapter import SourceBinding
from vibe.model_hub_runtime.adapter import _discovered_models
-from vibe.model_hub_runtime.state import EngineStateError, SourceRecord
+from vibe.model_hub_runtime.state import EngineStateError, EngineStateStore, SourceRecord
ADDRESS = "avibe-dc0395516c77a0ee4e62e01e"
# Minted the same way, for some other credential. Nothing here may treat the two
@@ -277,6 +278,80 @@ def test_engine_record_still_refuses_an_unreadable_reasoning_map() -> None:
)
+def _bound_store(tmp_path) -> tuple[EngineStateStore, str]:
+ store = EngineStateStore(tmp_path / "state")
+ store.prepare_instance("install-1")
+ (store.auth_dir / "claude-account.json").write_text("{}", encoding="utf-8")
+ credential_ref = store.bind_oauth_credential(
+ "src_fixture123",
+ "anthropic",
+ "claude-account.json",
+ )
+ return store, credential_ref
+
+
+def _sync_binding(credential_ref: str, **overrides: object) -> SourceBinding:
+ payload = {
+ "source_id": "src_fixture123",
+ "vendor": "anthropic",
+ "protocol": "anthropic",
+ "base_url": None,
+ "credential_ref": credential_ref,
+ "allowed_origins": ("claude",),
+ "model_ids": ("gpt-5.5",),
+ }
+ payload.update(overrides)
+ return SourceBinding(**payload) # type: ignore[arg-type]
+
+
+def test_a_source_holding_both_spellings_still_reaches_the_engine(tmp_path) -> None:
+ """Config keeps both spellings, so the engine projection must survive them.
+
+ A Source whose file still carries an addressed row next to the bare name
+ projects one reasoning entry per row, and both name one model once the
+ address is gone. Refusing that pair would abort the whole sync and leave the
+ engine holding nothing — so it collapses onto the first, exactly as the
+ model ids beside it and a stored record on load already do.
+ """
+
+ store, credential_ref = _bound_store(tmp_path)
+ # The address this credential is actually reached by, which is the only one
+ # the projection removes.
+ address = store.credential_metadata(credential_ref)["prefix"]
+
+ records = store.sync_sources(
+ [
+ _sync_binding(
+ credential_ref,
+ model_ids=(f"{address}/gpt-5.5", "gpt-5.5"),
+ model_reasoning_efforts=(
+ (f"{address}/gpt-5.5", ("high",)),
+ ("gpt-5.5", ()),
+ ),
+ )
+ ]
+ )
+
+ assert records[0].model_ids == ("gpt-5.5",)
+ assert records[0].model_reasoning_efforts == (("gpt-5.5", ("high",)),)
+
+
+def test_one_model_named_twice_by_one_spelling_is_still_refused(tmp_path) -> None:
+ """Collapsing absorbs the merge this layer makes, not a caller's own repeat."""
+
+ store, credential_ref = _bound_store(tmp_path)
+
+ with pytest.raises(EngineStateError, match="duplicate reasoning model id"):
+ store.sync_sources(
+ [
+ _sync_binding(
+ credential_ref,
+ model_reasoning_efforts=(("gpt-5.5", ("high",)), ("gpt-5.5", ("low",))),
+ )
+ ]
+ )
+
+
SOURCE_ID = "src_fixture123"
diff --git a/vibe/model_hub_runtime/state.py b/vibe/model_hub_runtime/state.py
index b9b4296e8..148705294 100644
--- a/vibe/model_hub_runtime/state.py
+++ b/vibe/model_hub_runtime/state.py
@@ -616,19 +616,30 @@ class EngineStateStore:
if any(not isinstance(model, str) or not model or model != model.strip() for model in route_model_ids):
raise EngineStateError("invalid route model id")
reasoning_by_model: dict[str, tuple[str, ...]] = {}
+ # Which spelling each entry arrived under. A caller naming one
+ # model twice is still refused, but two names that meet only
+ # because the address came off collapse onto the first — the
+ # same collision ``model_ids`` above absorbs, and the same one a
+ # stored record absorbs on load. A Source may legitimately hold
+ # both spellings until its rows are repaired, and refusing the
+ # pair here would leave the engine unsynchronized instead.
+ spellings: dict[str, str] = {}
for model_id, efforts in binding.model_reasoning_efforts:
- normalized_model_id = model_id_without_credential_address(
- str(model_id).strip(), prefix
- )
+ answered = str(model_id).strip()
+ normalized_model_id = model_id_without_credential_address(answered, prefix)
if not normalized_model_id or normalized_model_id not in model_ids:
raise EngineStateError("reasoning model id is not registered")
- if normalized_model_id in reasoning_by_model:
- raise EngineStateError("duplicate reasoning model id")
normalized_efforts = tuple(
dict.fromkeys(str(effort).strip() for effort in efforts)
)
if any(not effort for effort in normalized_efforts):
raise EngineStateError("reasoning effort cannot be empty")
+ held = spellings.get(normalized_model_id)
+ if held is not None:
+ if held == answered:
+ raise EngineStateError("duplicate reasoning model id")
+ continue
+ spellings[normalized_model_id] = answered
reasoning_by_model[normalized_model_id] = normalized_efforts
records.append(
SourceRecord(