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.

feat(model-hub): prefer responses for xai and pin auto-detect order (#1937)

Max84fd281028eb
diff --git a/docs/plans/model-hub-subscription-vendors.md b/docs/plans/model-hub-subscription-vendors.md
index c7740489f..22a71caba 100644
--- a/docs/plans/model-hub-subscription-vendors.md
+++ b/docs/plans/model-hub-subscription-vendors.md
@@ -123,11 +123,16 @@ The native upstream differs per vendor — Gemini's own wire format, Moonshot's
OpenAI-compatible endpoint, xAI's Responses API — and for gemini it is not in
Avibe's `SOURCE_PROTOCOLS` vocabulary at all. The pin therefore names the
**served** surface rather than the upstream one, and picking the surface the
-gateway's engine client already speaks is what makes all three converge. Each
-pin equals what `api_key_vendors.json` pins for the same vendor id: one
-vendor, one protocol, whichever channel holds the credential. Keep the two
-tables in agreement — a subscription pinned against its api-key sibling would
-need `_validate_source_target` taught about a second pin.
+gateway's engine client already speaks is what makes all three converge.
+
+This table is independent of `api_key_vendors.json`, and since 2026-09-08 the
+two disagree for `xai`: the catalog pins the protocol Avibe speaks to a
+vendor's *public* API with a key it holds, while this one names the surface the
+engine serves a credential it holds itself. Nothing reconciles them when a
+Source is projected. `_validate_source_target` reads no protocol pin at all
+now, from either table — it asks only whether the Source's upstream can be
+resolved, which is the one question the renderer downstream of it asks — so
+each pin is admitted on its own terms.
**Semantics.** These rungs prove no response shape. Reachability and
authentication follow the engine-managed flow that just completed: the engine
diff --git a/docs/plans/model-hub-vendor-preset-protocol.md b/docs/plans/model-hub-vendor-preset-protocol.md
index c415fc612..0c79aa904 100644
--- a/docs/plans/model-hub-vendor-preset-protocol.md
+++ b/docs/plans/model-hub-vendor-preset-protocol.md
@@ -49,6 +49,17 @@ contract_version bump). Dialog badges are local form state. After save,
`Source.vendor` is the catalog id (`deepseek`, not `custom`), which is
enough for source-detail identity.
+**The ladder is the only owner (amended 2026-09-08).** A rung's verdict is
+reached once, when the Source is saved, and nothing re-derives it afterwards.
+The engine projection used to re-check a stored Source's `protocol` against its
+vendor's current catalog pin, which contradicted the ladder twice: rung 2 can
+legitimately prove a protocol the pin does not name, and a pin is mutable
+product data, so repinning a vendor between releases retroactively invalidated
+the Sources that vendor's own earlier pin had admitted. `_validate_source_target`
+now asks only what the renderer downstream of it asks — can this Source's
+upstream be resolved — so a pin is read where a protocol is *decided* and never
+where one is replayed.
+
## First-wave catalog
Authoritative table, shipped as `vibe/data/api_key_vendors.json`. Vendor
@@ -68,7 +79,7 @@ prefix map in `vibe/data/model_vendors.json` is a different document
| `openrouter` | OpenRouter | `https://openrouter.ai/api/v1` | `openai_chat` |
| `groq` | Groq | `https://api.groq.com/openai/v1` | `openai_chat` |
| `mistral` | Mistral | `https://api.mistral.ai/v1` | `openai_chat` |
-| `xai` | xAI | `https://api.x.ai/v1` | `openai_chat` |
+| `xai` | xAI | `https://api.x.ai/v1` | `openai_responses` |
| `together` | Together | `https://api.together.xyz/v1` | `openai_chat` |
| `fireworks` | Fireworks | `https://api.fireworks.ai/inference/v1` | `openai_chat` |
diff --git a/tests/fixtures/model_hub_source_edit_validation.json b/tests/fixtures/model_hub_source_edit_validation.json
index 8f58b7616..df850585c 100644
--- a/tests/fixtures/model_hub_source_edit_validation.json
+++ b/tests/fixtures/model_hub_source_edit_validation.json
@@ -116,19 +116,19 @@
"id": "anthropic_openai_responses",
"vendor": "anthropic",
"protocol": "openai_responses",
- "server_valid": false
+ "server_valid": true
},
{
"id": "anthropic_openai_chat",
"vendor": "anthropic",
"protocol": "openai_chat",
- "server_valid": false
+ "server_valid": true
},
{
"id": "openai_anthropic",
"vendor": "openai",
"protocol": "anthropic",
- "server_valid": false
+ "server_valid": true
},
{
"id": "openai_openai_responses",
@@ -146,7 +146,7 @@
"id": "codex_anthropic",
"vendor": "codex",
"protocol": "anthropic",
- "server_valid": false
+ "server_valid": true
},
{
"id": "codex_openai_responses",
@@ -158,7 +158,25 @@
"id": "codex_openai_chat",
"vendor": "codex",
"protocol": "openai_chat",
- "server_valid": false
+ "server_valid": true
+ },
+ {
+ "id": "xai_anthropic",
+ "vendor": "xai",
+ "protocol": "anthropic",
+ "server_valid": true
+ },
+ {
+ "id": "xai_openai_responses",
+ "vendor": "xai",
+ "protocol": "openai_responses",
+ "server_valid": true
+ },
+ {
+ "id": "xai_openai_chat",
+ "vendor": "xai",
+ "protocol": "openai_chat",
+ "server_valid": true
},
{
"id": "custom_anthropic",
diff --git a/tests/test_model_hub_api.py b/tests/test_model_hub_api.py
index 2741d14a2..2c2bfa40c 100644
--- a/tests/test_model_hub_api.py
+++ b/tests/test_model_hub_api.py
@@ -8504,11 +8504,33 @@ def test_source_edit_validation_contract_fixture(tmp_path, field, case):
)
def test_source_empty_target_contract_fixture(case):
if case["server_valid"]:
- _validate_source_target(case["vendor"], case["protocol"], None)
+ _validate_source_target(case["vendor"], case["protocol"], None, credential_kind="api_key")
return
with pytest.raises(EngineStateError):
- _validate_source_target(case["vendor"], case["protocol"], None)
+ _validate_source_target(case["vendor"], case["protocol"], None, credential_kind="api_key")
+
+
+def test_an_emptied_endpoint_is_judged_by_the_vendor_alone():
+ """Whether an emptied endpoint is admissible cannot depend on the protocol.
+
+ An emptied endpoint asks one question — does this runtime have an upstream to
+ reach the vendor over — and the answer is the official URL the shipped catalog
+ holds for it. Which protocols that vendor may be added as is the create path's
+ proof ladder to decide, and it decided when the Source was saved. A verdict
+ that also read the vendor's current protocol pin would revisit that decision on
+ every projection, so repinning a vendor between releases would invalidate the
+ Sources its own earlier pin admitted.
+
+ Asserted as agreement across each vendor's rows rather than by naming the
+ protocols, so a fourth protocol joins the property instead of escaping it.
+ """
+
+ by_vendor: dict[str, set[bool]] = {}
+ for case in SOURCE_EDIT_VALIDATION_CASES["empty_targets"]:
+ by_vendor.setdefault(case["vendor"], set()).add(case["server_valid"])
+ assert by_vendor
+ assert {vendor: verdicts for vendor, verdicts in by_vendor.items() if len(verdicts) != 1} == {}
def test_source_display_names_reject_credential_material(tmp_path):
diff --git a/tests/test_model_hub_config.py b/tests/test_model_hub_config.py
index f21d8a862..f8760991e 100644
--- a/tests/test_model_hub_config.py
+++ b/tests/test_model_hub_config.py
@@ -30,7 +30,7 @@ from config.v2_config import (
V2Config,
is_model_hub_enabled,
)
-from core.handlers.model_hub.service import CONTRACT_VERSION
+from core.handlers.model_hub.service import CONTRACT_VERSION, ModelHubService
from core.services.settings import default_config
from core.handlers.model_hub.adapter import (
DiscoveredModel,
@@ -104,6 +104,24 @@ def test_protocol_vocabulary_matches_authority_and_rejects_removed_alias():
ModelHubSourceConfig.from_payload(example)
+def test_auto_detect_asks_for_responses_before_chat():
+ """Auto-detect reaches a Responses implementation before the chat fallback.
+
+ OpenAI has signalled Chat Completions is legacy, so a compat provider that
+ genuinely implements Responses should be detected as one rather than get
+ labelled by the older surface it also still serves. Elimination consumes
+ this sequence pairwise, so the relative position is a contract rather than
+ an accident of how the tuple was typed: asserting it here makes a reorder a
+ deliberate change instead of a silent one. The whole vocabulary is asserted
+ to stay in the sequence so a protocol cannot drop out of detection either.
+ """
+
+ auto_sequence = ModelHubService._observation_protocols("custom", {})
+ assert set(auto_sequence) == set(SOURCE_PROTOCOLS)
+ assert len(auto_sequence) == len(set(auto_sequence))
+ assert auto_sequence.index("openai_responses") < auto_sequence.index("openai_chat")
+
+
def test_unsaved_observation_schema_closes_all_terminal_shapes():
schema = _schema("observation-result.schema.json")
assert schema["properties"]["contract_version"]["const"] == 10
diff --git a/tests/test_model_hub_l3.py b/tests/test_model_hub_l3.py
index 5cf6c5320..6cf4d15de 100644
--- a/tests/test_model_hub_l3.py
+++ b/tests/test_model_hub_l3.py
@@ -45,6 +45,7 @@ from core.handlers.model_hub.adapter import (
RawCallOutcome,
RawOutcomeKind,
SOURCE_PROTOCOLS,
+ SourceBinding,
)
from core.handlers.model_hub.classification import ResolutionDecision, classify_outcome
from core.handlers.model_hub.events import (
@@ -116,7 +117,6 @@ from vibe.model_hub_runtime.adapter import (
from vibe.model_hub_runtime.api_key_vendors import (
api_key_vendor_catalog,
catalog_api_key_vendor_label,
- pinned_api_key_protocol,
)
from vibe.model_hub_runtime.client import EngineClientError, probe_models
from vibe.model_hub_runtime.state import EngineStateStore
@@ -7467,16 +7467,48 @@ def test_hub_subscription_observation_binds_on_the_engine_declared_protocol(
@pytest.mark.parametrize("vendor", sorted(_HUB_SUBSCRIPTION_PROTOCOLS))
-def test_hub_subscription_pin_agrees_with_the_same_vendors_api_key_pin(vendor: str) -> None:
- """One vendor, one protocol, whichever channel holds the credential.
+def test_hub_subscription_projects_on_its_pin_whatever_the_api_key_pin_is(
+ tmp_path: Path,
+ vendor: str,
+) -> None:
+ """A pinned subscription projects on its own protocol, with no base URL.
- `_validate_source_target` admits a Source with no base URL by consulting the
- api-key catalog pin, so a subscription pinned to a protocol its api-key
- sibling contradicts would need that validator taught about a second pin.
- Asserting the agreement here is cheaper than carrying that second pin.
+ The engine holds the credential and serves it on the surface this table
+ names, so nothing about the projection depends on the api-key catalog: that
+ describes the other channel, Avibe calling the vendor's public API with a
+ key it holds, and the two may legitimately disagree for one vendor id.
+ Seeding the whole pin table asserts every row projects on its own terms
+ rather than by agreeing with its sibling — and because the projection is
+ atomic, a row that stopped being admissible would take every other Source
+ down with it rather than fail alone.
"""
- assert hub_subscription_serving_protocol(vendor) == pinned_api_key_protocol(vendor)
+ state_store = EngineStateStore(tmp_path / "engine-state")
+ credential_ref = state_store.bind_oauth_credential(
+ "src_hubsubscript",
+ vendor,
+ f"{vendor}-test.json",
+ )
+ protocol = hub_subscription_serving_protocol(vendor)
+ assert protocol in SOURCE_PROTOCOLS
+
+ projected = state_store.sync_sources(
+ [
+ SourceBinding(
+ source_id="src_hubsubscript",
+ vendor=vendor,
+ protocol=protocol,
+ base_url=None,
+ credential_ref=credential_ref,
+ allowed_origins=("main",),
+ model_ids=(f"{vendor}-model",),
+ )
+ ]
+ )
+
+ assert [(record.vendor, record.protocol, record.base_url) for record in projected] == [
+ (vendor, protocol, None)
+ ]
@pytest.mark.parametrize("vendor", sorted(_OAUTH_ENDPOINTS))
diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.py
index dacc14890..aeb50fad8 100644
--- a/tests/test_model_hub_runtime.py
+++ b/tests/test_model_hub_runtime.py
@@ -1781,6 +1781,55 @@ def test_state_rejects_unsafe_inputs_and_auth_permissions(tmp_path: Path) -> Non
assert stat.S_IMODE(auth_file.stat().st_mode) == 0o600
+def test_a_persisted_key_source_survives_a_repin_of_its_vendor(tmp_path: Path) -> None:
+ """A stored api-key Source is judged by its upstream, not by today's pin.
+
+ A released Avibe persisted api-key Sources whose Base URL the user left empty:
+ their upstream is the official URL their vendor's catalog row holds, which is
+ why the runtime keeps a fallback for it. A row's ``protocol`` is product data
+ that moves between releases — `xai` moved from `openai_chat` to
+ `openai_responses` — and moving it must not retroactively invalidate the
+ Sources the earlier value admitted. The projection is atomic, so a Source that
+ stopped being admissible would take every other Source down with it rather
+ than fail alone.
+
+ Seeded from the catalog on the one protocol each row does *not* pin, so the
+ property covers every vendor rather than the row that happened to move, and a
+ vendor added or repinned later is covered without editing this test.
+ """
+
+ store = EngineStateStore(tmp_path / "state")
+ store.prepare_instance("install-repin")
+ bindings = []
+ for index, entry in enumerate(api_key_vendor_catalog()):
+ off_pin_protocol = next(
+ protocol for protocol in SOURCE_PROTOCOLS if protocol != entry.protocol
+ )
+ credential_ref = store.store_api_key(
+ "secret",
+ vendor=entry.id,
+ protocol=off_pin_protocol,
+ base_url=None,
+ )
+ bindings.append(
+ SourceBinding(
+ source_id=f"src_repin{index:08d}",
+ vendor=entry.id,
+ protocol=off_pin_protocol,
+ base_url=None,
+ credential_ref=credential_ref,
+ allowed_origins=("main",),
+ model_ids=(f"{entry.id}-model",),
+ )
+ )
+
+ projected = store.sync_sources(bindings)
+
+ assert [(record.vendor, record.protocol, record.base_url) for record in projected] == [
+ (binding.vendor, binding.protocol, None) for binding in bindings
+ ]
+
+
def test_source_record_requires_valid_reasoning_state() -> None:
payload = {
"source_id": "src_fixture123",
diff --git a/vibe/data/api_key_vendors.json b/vibe/data/api_key_vendors.json
index b76a556db..09c55af3b 100644
--- a/vibe/data/api_key_vendors.json
+++ b/vibe/data/api_key_vendors.json
@@ -15,7 +15,7 @@
"id": "xai",
"label": "xAI",
"official_base_url": "https://api.x.ai/v1",
- "protocol": "openai_chat"
+ "protocol": "openai_responses"
},
{
"id": "gemini",
diff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.py
index ce9d1d3c4..c6420cc8f 100644
--- a/vibe/model_hub_runtime/adapter.py
+++ b/vibe/model_hub_runtime/adapter.py
@@ -109,12 +109,13 @@ _OAUTH_ENDPOINTS = {
# the executor sends to `/responses`
# (`internal/runtime/executor/xai_executor_execute.go:45`).
#
-# All three land on `openai_chat`, which is also what the api-key catalog pins
-# for the same three vendor ids — one vendor, one protocol, whichever channel
-# holds the credential. That agreement is what lets `_validate_source_target`
-# admit these Sources without a base URL, so keep the two tables consistent: a
-# subscription pinned to a protocol its api-key sibling contradicts would need
-# that validator taught about a second pin.
+# All three land on `openai_chat`. This table is not required to agree with
+# `vibe/data/api_key_vendors.json`, and for `xai` it no longer does: that catalog
+# pins the protocol Avibe speaks to a vendor's *public* API with a key it holds,
+# while this one names the surface the engine serves a credential it holds
+# itself. The engine reaches xAI's Responses API from either, so the api-key
+# channel is pinned to the surface OpenAI is steering the ecosystem toward and
+# this one keeps the surface the shipped grant path was verified on.
_HUB_SUBSCRIPTION_PROTOCOLS = {
"gemini": "openai_chat",
"kimi": "openai_chat",
diff --git a/vibe/model_hub_runtime/state.py b/vibe/model_hub_runtime/state.py
index 62e779c87..5a3a81d77 100644
--- a/vibe/model_hub_runtime/state.py
+++ b/vibe/model_hub_runtime/state.py
@@ -13,7 +13,7 @@ from typing import Any, Sequence
from config.atomic_io import write_atomic
from config.v2_config import normalize_model_hub_base_url
-from vibe.model_hub_runtime.api_key_vendors import pinned_api_key_protocol
+from vibe.model_hub_runtime.api_key_vendors import official_api_key_base_url
logger = logging.getLogger(__name__)
@@ -236,7 +236,12 @@ class EngineStateStore:
raise EngineStateError("unsupported source protocol")
vendor = str(binding.vendor).strip().lower()
base_url = _validated_base_url(binding.base_url)
- _validate_source_target(vendor, protocol, base_url)
+ _validate_source_target(
+ vendor,
+ protocol,
+ base_url,
+ credential_kind=credential["kind"],
+ )
if credential["kind"] == "api_key":
if (
credential.get("vendor") != vendor
@@ -596,26 +601,49 @@ def _validated_base_url(value: str | None) -> str | None:
raise EngineStateError("invalid source base URL")
-def _validate_source_target(vendor: str, protocol: str, base_url: str | None) -> None:
- pinned_protocol = pinned_api_key_protocol(vendor)
- if (
- protocol == "anthropic"
- and base_url is None
- and vendor != "anthropic"
- and pinned_protocol != "anthropic"
- ):
- raise EngineStateError("Anthropic-compatible source requires a base URL")
- if (
- protocol == "openai_responses"
- and base_url is None
- and vendor not in {"openai", "codex"}
- and pinned_protocol != "openai_responses"
- ):
- raise EngineStateError("Responses API source requires a base URL")
- if (
- protocol == "openai_chat"
- and base_url is None
- and vendor != "openai"
- and pinned_protocol != "openai_chat"
- ):
- raise EngineStateError("OpenAI-compatible source requires a base URL")
+# `_append_source` raises these same three strings when it reaches a Source whose
+# upstream it cannot resolve. The check below is the earlier refusal of that one
+# condition, so it answers with the message the renderer would have.
+_MISSING_BASE_URL_ERRORS = {
+ "anthropic": "Anthropic-compatible source requires a base URL",
+ "openai_responses": "Responses API source requires a base URL",
+ "openai_chat": "OpenAI-compatible source requires a base URL",
+}
+
+
+def _validate_source_target(
+ vendor: str,
+ protocol: str,
+ base_url: str | None,
+ *,
+ credential_kind: str,
+) -> None:
+ """Reject a Source whose upstream this runtime cannot resolve.
+
+ This asks exactly what `_append_source` asks when it renders the YAML: an
+ api-key Source is reachable over its own ``base_url``, or over the official
+ one the shipped catalog holds for its vendor, and over nothing else.
+
+ It deliberately does not compare the Source's protocol against that vendor's
+ catalog pin. Which protocols a vendor may be added as belongs to the create
+ path's proof ladder — a catalog pin, a client declaration on `custom`, or a
+ protocol-shaped response — and that decision was made when the Source was
+ saved. Re-deciding it here would judge a stored Source by a pin that can
+ change under it: a vendor repinned between releases would retroactively
+ invalidate the Sources its own earlier pin admitted. Since `sync_sources`
+ replaces the whole projection atomically, that verdict is not private to the
+ Source it falls on — it would take every other Source down with it.
+
+ An engine-held credential has no upstream to resolve at all: the auth file
+ stays inside the engine, `_append_source` returns before rendering it, and
+ `sync_sources` already requires ``base_url is None``. The requirement does
+ not reach it.
+ """
+
+ if credential_kind != "api_key":
+ return
+ if base_url is not None:
+ return
+ if official_api_key_base_url(vendor) is not None:
+ return
+ raise EngineStateError(_MISSING_BASE_URL_ERRORS[protocol])