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): answer for the address the engine would actually compose

cyh8cb25376ccf0
diff --git a/core/handlers/model_hub/adapter.py b/core/handlers/model_hub/adapter.py
index 0cef39d58..480c1eac1 100644
--- a/core/handlers/model_hub/adapter.py
+++ b/core/handlers/model_hub/adapter.py
@@ -537,8 +537,15 @@ class EngineAdapter(Protocol):
can *prove* an id an older release stored carries one — as opposed to
guessing from its shape and renaming a vendor's own model.
- None when the credential records no address, including when it is gone.
- A caller that cannot prove ownership must leave the id alone.
+ Whichever address the engine would actually compose, however custody
+ happens to hold it: one credential records its own, another is
+ addressed by the record its Source is bound through. An implementation
+ that answers from only one of those reports no address for a Source the
+ engine addresses perfectly well.
+
+ None when nothing records an address for this credential, including
+ when it is gone. A caller that cannot prove ownership must leave the
+ id alone.
"""
...
diff --git a/docs/plans/model-hub-contracts/adapter-interface.py b/docs/plans/model-hub-contracts/adapter-interface.py
index 0cef39d58..480c1eac1 100644
--- a/docs/plans/model-hub-contracts/adapter-interface.py
+++ b/docs/plans/model-hub-contracts/adapter-interface.py
@@ -537,8 +537,15 @@ class EngineAdapter(Protocol):
can *prove* an id an older release stored carries one — as opposed to
guessing from its shape and renaming a vendor's own model.
- None when the credential records no address, including when it is gone.
- A caller that cannot prove ownership must leave the id alone.
+ Whichever address the engine would actually compose, however custody
+ happens to hold it: one credential records its own, another is
+ addressed by the record its Source is bound through. An implementation
+ that answers from only one of those reports no address for a Source the
+ engine addresses perfectly well.
+
+ None when nothing records an address for this credential, including
+ when it is gone. A caller that cannot prove ownership must leave the
+ id alone.
"""
...
diff --git a/tests/test_model_hub_credential_address.py b/tests/test_model_hub_credential_address.py
index ab2e944cc..889c0beb1 100644
--- a/tests/test_model_hub_credential_address.py
+++ b/tests/test_model_hub_credential_address.py
@@ -801,6 +801,35 @@ def test_custody_is_what_proves_an_address(tmp_path) -> None:
assert asyncio.run(adapter.credential_address("cred_absent0000")) is None
+def test_custody_answers_for_a_credential_that_records_no_address(tmp_path) -> None:
+ """An API key records no address of its own, and the engine still has one.
+
+ ``bind_source`` settles the address in two steps — the credential's own,
+ else the prefix the bound record already holds — so an answer drawn from
+ only the first reports nothing for a Source the engine addresses perfectly
+ well, and the repair declines exactly the ids that need it. Every bound
+ Source has an address; only some credentials write it down.
+ """
+
+ store = EngineStateStore(tmp_path / "state")
+ store.prepare_instance("install-1")
+ credential_ref = store.store_api_key(
+ "sk-fixture", vendor="openai", protocol="openai_chat",
+ )
+ assert "prefix" not in store.credential_metadata(credential_ref)
+ adapter = CLIProxyEngineAdapter.__new__(CLIProxyEngineAdapter)
+ adapter.state_store = store
+
+ assert asyncio.run(adapter.credential_address(credential_ref)) is None
+
+ [record] = store.sync_sources(
+ [_sync_binding(credential_ref, vendor="openai", protocol="openai_chat")]
+ )
+
+ assert asyncio.run(adapter.credential_address(credential_ref)) == record.prefix
+ assert record.prefix.startswith("avibe-")
+
+
class _AddressingAdapter(FakeAdapter):
"""An engine that knows which address belongs to which credential."""
diff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.py
index 4c6087b2a..9f9a7a654 100644
--- a/vibe/model_hub_runtime/adapter.py
+++ b/vibe/model_hub_runtime/adapter.py
@@ -1921,12 +1921,32 @@ class CLIProxyEngineAdapter:
return await asyncio.to_thread(self.state_store.credential_auth_scheme, credential_ref)
async def credential_address(self, credential_ref: str) -> str | None:
- metadata = await asyncio.to_thread(
- self.state_store.credential_metadata_if_present,
- credential_ref,
- )
+ return await asyncio.to_thread(self._credential_address, credential_ref)
+
+ def _credential_address(self, credential_ref: str) -> str | None:
+ """Settle the address the same way ``bind_source`` settles it.
+
+ Only an OAuth credential records an address of its own, and one written
+ by an older release may not have even that. Every other bound Source is
+ addressed by the prefix its record holds, which ``bind_source`` reaches
+ for next. Reading just the credential would therefore report no address
+ for a Source the engine addresses perfectly well, and the repair would
+ decline exactly the ids that need it.
+ """
+
+ metadata = self.state_store.credential_metadata_if_present(credential_ref)
prefix = (metadata or {}).get("prefix")
- return prefix if isinstance(prefix, str) and prefix else None
+ if isinstance(prefix, str) and prefix:
+ return prefix
+ record = next(
+ (
+ source
+ for source in self.state_store.list_sources()
+ if source.credential_ref == credential_ref
+ ),
+ None,
+ )
+ return record.prefix if record is not None and record.prefix else None
async def retarget_api_key_credential(
self,