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
feat(model-hub): start Vibey on a model as soon as a source is placed (#2505)
Call White60fd6ab0e94d
diff --git a/core/controller.py b/core/controller.pyindex 5b48a9e16..c62dde2d9 100644--- a/core/controller.py+++ b/core/controller.py@@ -417,6 +417,19 @@ class Controller:user_context=instance_owner_context(),)+ async def _start_vibey_without_a_model(self) -> None:+ """Start a Vibey with nothing to run on, once a models.dev copy can describe a starting model.++ Only while the built-in Agent has no model: a person who emptied Vibey's list keeps+ the Agent's model, so this never replaces a choice; it only makes an unrunnable+ Agent runnable, as ``_reconcile_vibey_agent_model`` does.+ """++ vibey = self.vibe_agent_store.get_builtin_default_agent_for_backend("vibey", enabled_only=False)+ if vibey is None or str(vibey.model or "").strip():+ return+ await self.model_hub_service.start_vibey_without_models()+async def _model_hub_catalog_changed(self, backend: str) -> None:"""Follow a committed Model Hub catalog change for one backend."""@@ -441,7 +454,12 @@ class Controller:await adopt_catalog()async def _seed_vibey_model_supply(self) -> None:- """Seed Vibey's Model Hub entry from existing Sources, then reconcile its built-in Agent's model."""+ """Seed Vibey's Model Hub entry from existing Sources, then reconcile its built-in Agent's model.++ A Vibey an earlier seed left with nothing to run on (an earlier build's empty seed,+ or one that ran without a models.dev copy) starts here too, not only on the next+ snapshot reconcile.+ """model_hub_service = getattr(self, "model_hub_service", None)if model_hub_service is None:@@ -450,6 +468,10 @@ class Controller:await model_hub_service.seed_vibey_supply()except Exception:logger.warning("Vibey starting model supply failed", exc_info=True)+ try:+ await self._start_vibey_without_a_model()+ except Exception:+ logger.warning("Vibey's starting model failed at startup", exc_info=True)try:self._reconcile_vibey_agent_model()except Exception:@@ -2714,6 +2736,13 @@ class Controller:"Model Hub models.dev limit backfill failed after snapshot refresh",exc_info=True,)+ try:+ await self._start_vibey_without_a_model()+ except Exception:+ logger.warning(+ "Vibey's starting model failed after snapshot refresh",+ exc_info=True,+ )finally:self._model_hub_snapshot_reconcile_task = Noneif (diff --git a/core/handlers/model_hub/service.py b/core/handlers/model_hub/service.pyindex 4d52afde1..7971e2640 100644--- a/core/handlers/model_hub/service.py+++ b/core/handlers/model_hub/service.py@@ -277,6 +277,27 @@ _MODELS_DEV_CANDIDATE_FIELDS = ()+def _described_as_fit_for_agent_turns(match: Mapping[str, Any]) -> bool:+ """models.dev says the model takes text and tool calls and answers in text: the least an Agent's turn needs."""++ return (+ match.get("supports_tools") is True+ and "text" in (match.get("input_modalities") or ())+ and "text" in (match.get("output_modalities") or ())+ )+++def _described_as_unfit_for_agent_turns(match: Mapping[str, Any]) -> bool:+ """models.dev says the model takes no tool calls, or takes or answers in something other than text."""++ if match.get("supports_tools") is False:+ return True+ return any(+ bool(modalities) and "text" not in modalities+ for modalities in (match.get("input_modalities") or (), match.get("output_modalities") or ())+ )++AGENT_CHAIN_CONTRACT_VERSION = 11PROBE_RESULT_CONTRACT_VERSION = 11_SOURCE_DISCOVERY_TIMEOUT_SECONDS = 15@@ -5488,8 +5509,10 @@ class ModelHubService:Its Sources are every existing one this backend may use, placed as anewly created Source would be. Its models are the built-in Agents'selections, in order, that one of those Sources lists, each added as the- picker adds a provider model; none qualifying leaves the list empty- rather than picking one. The seed counts only once it has placed a+ picker adds a provider model. With none qualifying, Vibey starts on one+ model the Sources list (``_vibey_starting_model``), so a new install's+ default Agent can run once setup places a Source; a model nothing can+ describe leaves the list empty. The seed counts only once it has placed aSource: until then the entry stays pending, so the first Source the useradds still brings every Source and the starting models with it. Eachmutation that adds Sources seeds after its Sources are final, so one@@ -5535,12 +5558,50 @@ class ModelHubService:described = self._models_dev_descriptions(model_ids)rows = []for model_id in model_ids:- candidate = self._provider_candidate(config, "vibey", model_id, described.get(model_id))+ match = described.get(model_id)+ # A selection is a person's choice for a native Agent: only a description+ # that rules out an Agent's turn keeps it from starting Vibey.+ if match is not None and _described_as_unfit_for_agent_turns(match):+ continue+ candidate = self._provider_candidate(config, "vibey", model_id, match)if candidate is not None:rows.append(candidate[0])+ if not rows:+ starting = self._vibey_starting_model(config)+ rows = [starting] if starting is not None else []agent.models = rowsreturn True+ def _vibey_starting_model(self, config: ModelHubConfig) -> ModelHubBackendModelConfig | None:+ """The one model a seed with no qualifying selection starts Vibey on, or ``None``.++ The first model, in Vibey's Source order and then each Source's own+ inventory order, that models.dev describes (by the exact match the+ picker's candidates use) as taking tool calls and producing text: the+ least an Agent's turn needs. A model models.dev does not know is never+ guessed at, so an inventory it cannot describe starts Vibey with none.+ """++ source_by_id = {source.id: source for source in config.sources}+ listed = list(+ dict.fromkeys(+ model.id+ for source_id in config.agents["vibey"].sources.order+ if (source := source_by_id.get(source_id)) is not None+ for model in source.models+ if not model.retired+ )+ )+ described = self._models_dev_descriptions(listed)+ for model_id in listed:+ match = described.get(model_id)+ if match is None or not _described_as_fit_for_agent_turns(match):+ continue+ candidate = self._provider_candidate(config, "vibey", model_id, match)+ if candidate is not None:+ return candidate[0]+ return None+async def _announce_vibey_seed(self) -> None:"""Announce a committed seed as the Vibey catalog change it is.@@ -5585,6 +5646,37 @@ class ModelHubService:await self._announce_vibey_seed()return [model.id for model in config.agents["vibey"].models]+ async def start_vibey_without_models(self) -> list[str]:+ """Start a seeded Vibey whose catalog is still empty on its starting model; the ids it took.++ A seed that found nothing describable leaves the catalog empty. The snapshot+ reconcile calls this, when a models.dev copy arrives and on its cadence, and+ only while Vibey's built-in Agent has no model, so whatever later makes a+ listed model describable (the copy, or a Source added since) starts a Vibey+ nothing was ever chosen for. A catalog a person emptied records its removals,+ so it is theirs and stays empty.+ """++ async with self._mutation_lock:+ previous = self.store.load()+ vibey = previous.agents["vibey"]+ if previous.vibey_supply_pending or vibey.models or vibey.removed_model_ids:+ return []+ starting = self._vibey_starting_model(previous)+ if starting is None:+ return []+ config = self._clone_config(previous)+ config.agents["vibey"].models = [starting]+ try:+ # As for the seed, an engine that is not up must not undo the start: the+ # config is saved first, and the Agent still has to hear about it.+ await self._commit_synced(previous, config, rollback_on_sync_failure=False)+ except ModelHubError:+ if not self.store.load().agents["vibey"].models:+ raise+ await self._announce_vibey_seed()+ return [starting.id]+def _ensure_models_dev_copy(self) -> None:"""Fetch models.dev in the foreground, bounded, when no copy is cached.diff --git a/docs/INSTALL_FOR_AI.md b/docs/INSTALL_FOR_AI.mdindex 650836e51..b2903e0a9 100644--- a/docs/INSTALL_FOR_AI.md+++ b/docs/INSTALL_FOR_AI.md@@ -123,7 +123,7 @@ the wizard confirms application and an available Agent before completing setup.Pending application, uncertain keychain auth, or a failed start stays recoverableon this screen. For OpenCode, if the Agent's provider is unconnected or its exactmodel is absent from that provider's merged native/custom catalog, choose a-compatible model in the inline recovery and apply it explicitly. The wizard never chooses a model or changes an existing usable default silently.+compatible model in the inline recovery and apply it explicitly. The wizard never changes an existing usable default silently, and it picks no model for an assistant except Vibey's starting model: the first tool-capable text model the sources list, in their order and then each source's own model order, which the user can change.IM is optional for a fresh installation. Configure Slack, Discord, Telegram,WeChat, or Lark / Feishu later in Settings. Existing enabled but incomplete IMdiff --git a/docs/plans/model-hub-contracts/vibey-consumer.md b/docs/plans/model-hub-contracts/vibey-consumer.mdindex aced54ca7..bd883d7a6 100644--- a/docs/plans/model-hub-contracts/vibey-consumer.md+++ b/docs/plans/model-hub-contracts/vibey-consumer.md@@ -25,8 +25,24 @@ subscription joins it whether or not a starting model matches, ahead of the APIkeys), and its catalog becomes the models the built-inClaude, Codex, and OpenCode Agents run, in that order, that one of those Sourceslists, deduplicated and added as the picker adds a provider model (models.dev-metadata included). None qualifying leaves the catalog empty; no model is picked-on the user's behalf. A Vibey Agent without a model cannot run a turn, so the+metadata included). A selection that models.dev explicitly describes as taking+no tool calls, or as taking or producing no text, does not qualify; one it does not know still+does, being a person's own choice for a native Agent. With none qualifying, the+seed starts Vibey on one model, so a new install's default Agent can run once+setup places a Source. That model is the+first one, in Vibey's Source order and then each Source's own non-retired+inventory order, that models.dev describes, by the picker's exact match, as+taking text and tool calls and producing text. A model models.dev does not know is never+guessed at: with none described that way, the catalog stays empty and the setup+card offers the pick. A Vibey left with nothing to run on is healed by the+snapshot reconcile that also backfills MH-LIMITS-001, which runs when a copy+arrives and on the controller's cadence, and at every start, so a Vibey an earlier+build seeded empty starts on the first upgraded start. While Vibey's catalog is empty, records+no removal, and its built-in Agent has no model, it starts on the same rule's+model, whether a new copy or a later Source made one describable. Nothing was+ever chosen for that Vibey, so this is its start, not a re-seed. An Agent that+has a model, or a list a person emptied, is that person's choice and is never+overridden. A Vibey Agent without a model cannot run a turn, so thebuilt-in one takes its catalog's first model while it has none: one controllerrule, decided under the Agent store's write lock so a chosen model stands, runon every Vibey catalog change (`_refresh_backend_catalog`, which each seed also@@ -198,6 +214,10 @@ The header needs no upstream credentials and is never forwarded upstream.- Starting supply (MH-VIBEY-007): an unrelated write keeps the unseeded row absent;the seed places existing Sources for Vibey alone and keeps only routable Agentmodels; a second start leaves the persisted row, including removed Sources, alone.+ With no qualifying selection, the seed starts Vibey on the first listed model+ models.dev describes as tool-capable with text output; a selection models.dev+ rules out does not start it; nothing describable leaves the catalog empty, and+ a copy that arrives later starts it unless its built-in Agent already has a model.- Real loopback gateway requests through the existing service, with hermetic enginefixtures: primary protocol resolution, cross-protocol failover, non-ASCII origin,slow Anthropic resolution, buffered/streamed bodies, and concurrent requests.diff --git a/tests/scenarios/auth_setup/catalog.yaml b/tests/scenarios/auth_setup/catalog.yamlindex bbb7f599f..4a2c32067 100644--- a/tests/scenarios/auth_setup/catalog.yaml+++ b/tests/scenarios/auth_setup/catalog.yaml@@ -548,4 +548,19 @@ scenarios:test: tests/e2e/test_model_hub_engine_contract.py::test_oauth_callback_forwarder_is_loopback_only_and_optionalsupporting_tests:- tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_hub_oauth_mispaste_stays_recoverable_and_schemeless_address_signs_in+ - id: AUTH-SETUP-131+ name: A source that lists no built-in Agent's model still leaves Vibey runnable, and setup completes on it without a pick+ status: covered+ kind: happy_path+ layer: scenario+ backend: vibey+ test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_vibey_starts_on_a_sources_tool_capable_model_and_setup_completes_without_a_pick+ # The scenario owns the server boundary setup's providers screen calls: the add-source+ # route, the seed it runs, the Vibey catalog change it announces, the controller's+ # reconciliation of the built-in Agent's model, the runnable named route the entry+ # gate admits, and completion. The browser side, which keeps a recorded default that+ # can run, is the supporting tests below.+ supporting_tests:+ - ui/src/components/onboarding/entryGate.test.ts+ - tests/test_model_hub_vibey_consumer.pynext_priority: []diff --git a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py b/tests/scenarios/auth_setup/test_auth_setup_scenarios.pyindex d909d0cd3..91b584b53 100644--- a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py+++ b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py@@ -4681,6 +4681,75 @@ def test_builtin_vibey_model_pick_completes_setup_without_a_cli(monkeypatch, tmpagents.close()+def test_vibey_starts_on_a_sources_tool_capable_model_and_setup_completes_without_a_pick(monkeypatch, tmp_path):+ """AUTH-SETUP-131: add source -> seed -> catalog change -> Agent model -> runnable route -> completion.++ The setup's first source lists no model a built-in Agent runs, yet the built-in Vibey+ Agent can run as soon as it is placed: the seed starts Vibey on the first listed model+ models.dev describes as taking tool calls and answering in text, announces the catalog+ change, and the controller gives the Agent that model. Setup then completes on the+ Vibey default with no pick. Every step is the HTTP route setup calls, and the Hub+ service is wired to the real Agent store and catalog-change handler as the controller+ wires them.+ """+ from core.controller import Controller+ from core.vibe_agents import VibeAgentStore+ from tests.test_model_hub_api import _service++ monkeypatch.setenv("VIBE_MODEL_HUB_ENABLED", "1")+ V2Config.default().save()+ service, store, _adapter = _service(tmp_path / "hub")+ # The fake upstream lists claude-opus-4-6 then claude-sonnet-4-6; models.dev knows only the second.+ service.models_dev_catalog = lambda: {"anthropic": {"name": "Anthropic", "models": {+ "claude-sonnet-4-6": {"name": "Claude Sonnet 4.6", "tool_call": True,+ "modalities": {"input": ["text"], "output": ["text"]}},+ }}}+ agents = VibeAgentStore()+ controller = Controller.__new__(Controller)+ controller.config = V2Config.load()+ controller.vibe_agent_store = agents+ controller.model_hub_service = service+ service.builtin_agent_models_override = controller._builtin_agent_models+ service.backend_catalog_changed = controller._model_hub_catalog_changed+ service.named_agents_override = lambda backend: [+ (agent.name, agent.model)+ for agent in agents.list_agents(include_disabled=False)+ if agent.backend == backend+ ]+ monkeypatch.setattr(ui_server, "_model_hub_service", lambda: service)+ client = app.test_client()+ headers = csrf_headers(client)+ try:+ vibey = next(row for row in client.get("/api/agents").get_json()["agents"] if row["backend"] == "vibey")+ assert vibey["model"] is None+ # A new install records the built-in Agent as its default.+ recorded = client.post("/api/agents/default", json={"name": vibey["name"]}, headers=headers)+ assert recorded.status_code == 200, recorded.get_json()++ created = client.post(+ "/api/models/sources",+ json={"kind": "api_key", "vendor": "anthropic", "key": "sk-test-auth-setup-anthropic"},+ headers=headers,+ )+ assert created.status_code == 201, created.get_json()++ # No pick: the seed chose the first describable tool-capable model and the Agent took it.+ assert agents.require(vibey["name"]).model == "claude-sonnet-4-6"+ supply = next(row for row in client.get("/api/models/agents").get_json()["agents"] if row["backend"] == "vibey")+ assert [row["id"] for row in supply["catalog_models"]] == ["claude-sonnet-4-6"]+ route = next(row for row in supply["named_agents"] if row["name"] == vibey["name"])+ assert route["effective_model_id"] == "claude-sonnet-4-6"+ assert route["supply_status"] in {"ok", "degraded"}+ assert route["route_reason"] != "route_unconfigured"++ completed = client.post("/api/config", json={"setup_completed": True}, headers=headers)+ assert completed.status_code == 200, completed.get_json()+ assert V2Config.load().setup_completed+ assert agents.get_default_agent().name == vibey["name"]+ finally:+ agents.close()++@pytest.mark.parametrize("setup_host", ["192.0.2.5", "fd00::1", "2001:db8::5", "[2001:db8::5]"])async def test_cloud_pairing_origin_reaches_effective_ui_listener(monkeypatch, setup_host):"""Scenario: AUTH-SETUP-907 — every origin consumer reaches the widened UI bind."""diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex 79800a71a..2ca4f922a 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -146,6 +146,8 @@ scenarios:test: tests/test_model_hub_vibey_consumer.py::test_vibey_agent_predating_its_supply_starts_with_the_users_providers_and_modelsrelated_tests:- tests/test_model_hub_vibey_consumer.py::test_fresh_install_seeds_vibey_with_its_first_source+ - tests/test_model_hub_vibey_consumer.py::test_a_seed_with_no_qualifying_selection_starts_vibey_on_a_tool_capable_model+ - tests/test_vibey_backend_registration.py::test_vibey_starts_once_a_models_dev_copy_describes_a_listed_model- tests/test_model_hub_native_takeover.py::test_takeover_seeds_a_pending_vibey_entry_from_its_whole_batch- tests/test_vibey_backend_registration.py::test_vibey_agent_runs_its_catalogs_first_model_until_it_has_one- tests/test_vibey_backend_registration.py::test_a_lost_vibey_model_hand_off_heals_on_the_next_startdiff --git a/tests/test_model_hub_vibey_consumer.py b/tests/test_model_hub_vibey_consumer.pyindex 164c801fc..3141e857c 100644--- a/tests/test_model_hub_vibey_consumer.py+++ b/tests/test_model_hub_vibey_consumer.py@@ -775,6 +775,55 @@ async def test_fresh_install_seeds_vibey_with_its_first_source(tmp_path, first,assert announced == ["vibey"]+TOOL_CATALOG = {"relay": {"name": "Relay", "models": {+ "embed-1": {"name": "Embed 1", "tool_call": False, "modalities": {"input": ["text"], "output": ["text"]}},+ "draw-1": {"name": "Draw 1", "tool_call": True, "modalities": {"input": ["text"], "output": ["image"]}},+ "chat-1": {"name": "Chat 1", "tool_call": True, "modalities": {"input": ["text"], "output": ["text"]},+ "limit": {"context": 200_000, "output": 32_000}},+ "chat-2": {"name": "Chat 2", "tool_call": True, "modalities": {"input": ["text"], "output": ["text"]}},+ "see-1": {"name": "See 1", "tool_call": True, "modalities": {"input": ["image"], "output": ["text"]}},+}}}++[email protected](("selections", "sources", "seeded"), [+ # The first listed model that takes text and tool calls and answers in text, past the ones that do not.+ ([("codex", "gpt-6-astra")], [("src_seedrelay001", ("embed-1", "draw-1", "see-1", "unknown-1", "chat-1", "chat-2"))], ["chat-1"]),+ # Sources the user already had are read in Vibey's Source order, each in its own inventory order.+ ([("codex", "gpt-6-astra")], [("src_seedrelay001", ("unknown-1", "embed-1")), ("src_seedrelay002", ("chat-2", "chat-1"))], ["chat-2"]),+ # A model models.dev cannot describe is never guessed at.+ ([("codex", "gpt-6-astra")], [("src_seedrelay001", ("unknown-1", "unknown-2"))], []),+ # A native Agent's selection that models.dev rules out for an Agent's turn does not start Vibey;+ # one it does not know still does, being that person's own choice.+ ([("codex", "embed-1"), ("opencode", "custom/draw-1"), ("claude", "see-1")],+ [("src_seedrelay001", ("embed-1", "draw-1", "see-1", "chat-2"))], ["chat-2"]),+ ([("codex", "unknown-1")], [("src_seedrelay001", ("unknown-1", "chat-2"))], ["unknown-1"]),+])+async def test_a_seed_with_no_qualifying_selection_starts_vibey_on_a_tool_capable_model(+ tmp_path, selections, sources, seeded,+):+ """MH-VIBEY-007: a new install's default Agent can run once setup places a Source.++ No built-in Agent's model is listed by these Sources, so the seed starts+ Vibey on one model they do list, by a rule a person can predict.+ """+ payload = ModelHubConfig().to_payload()+ payload["sources"] = [+ _seed_source(source_id, day, *model_ids, vendor="custom", protocol="openai_chat").to_payload()+ for day, (source_id, model_ids) in enumerate(sources, start=1)+ ]+ service, store, _announced = _seed_service(tmp_path, payload, selections)+ service.models_dev_catalog = lambda: TOOL_CATALOG++ assert await service.seed_vibey_supply() == seeded++ vibey = store.payload["agents"]["vibey"]+ assert [model["id"] for model in vibey["models"]] == seeded+ if seeded == ["chat-1"]:+ [row] = vibey["models"]+ assert (row["origin"], row["display_name"], row["context_window"]) == ("provider", "Chat 1", 200_000)++@pytest.mark.asyncioasync def test_the_first_source_seed_fetches_a_models_dev_copy_when_none_is_cached(tmp_path, monkeypatch):"""MH-VIBEY-007: seeded rows keep the metadata they are written with.diff --git a/tests/test_vibey_backend_registration.py b/tests/test_vibey_backend_registration.pyindex 2cde00ad6..fbdbb8912 100644--- a/tests/test_vibey_backend_registration.py+++ b/tests/test_vibey_backend_registration.py@@ -6,7 +6,7 @@ import asyncioimport jsonfrom pathlib import Pathfrom types import SimpleNamespace-from unittest.mock import AsyncMock+from unittest.mock import AsyncMock, patchimport pytestfrom sqlalchemy.exc import OperationalError@@ -294,8 +294,8 @@ async def test_a_starting_model_needs_a_source_that_lists_it(tmp_path, sqlite_db"""MH-VIBEY-007: a Source's inventory, not a route, decides a starting model.An Anthropic key could pass any model id through, but it lists only Claude- models: the Codex Agent's ``gpt-6-astra`` is no starting model for Avibe,- and the Avibe Agent stays without a model rather than routing it there.+ models: the Codex Agent's ``gpt-6-astra`` is no starting model for Avibe.+ The Avibe Agent starts on a model the Source lists instead of routing it there."""from config.v2_config import ModelHubConfigfrom tests.test_model_hub_l3 import _service, _source@@ -306,6 +306,11 @@ async def test_a_starting_model_needs_a_source_that_lists_it(tmp_path, sqlite_dbstore.update("codex", model="gpt-6-astra")service = _service(tmp_path, sources=[])service.store.config = ModelHubConfig()+ # A fixed models.dev copy: the seed must never reach the network.+ service.models_dev_catalog = lambda: {"anthropic": {"name": "Anthropic", "models": {+ "claude-opus-5-5": {"name": "Claude Opus 5.5", "tool_call": True,+ "modalities": {"input": ["text"], "output": ["text"]}},+ }}}controller = Controller.__new__(Controller)controller.vibe_agent_store = storecontroller.model_hub_service = service@@ -319,8 +324,110 @@ async def test_a_starting_model_needs_a_source_that_lists_it(tmp_path, sqlite_dbawait service._commit_new_source_locked(anthropic)vibey = service.store.load().agents["vibey"]- assert (vibey.sources.order, vibey.models) == ([anthropic.id], [])+ assert (vibey.sources.order, [model.id for model in vibey.models]) == ([anthropic.id], ["claude-opus-5-5"])+ assert store.get("vibey").model == "claude-opus-5-5"+ finally:+ store.close()+++ ("person_chose", "person_emptied", "engine_up"),+ [(False, False, True), (True, False, True), (False, True, True), (False, False, False)],+)+async def test_vibey_starts_once_a_models_dev_copy_describes_a_listed_model(+ tmp_path, sqlite_db_factory, person_chose, person_emptied, engine_up,+):+ """MH-VIBEY-007: a seed that ran with no models.dev copy heals when a copy arrives.++ With no copy to describe the Source's models, the seed leaves Vibey's catalog empty.+ Once a copy arrives, Vibey starts on its starting model, but only while its built-in+ Agent has no model and nobody emptied its list: a person's choice always stands.+ """+ from config.v2_config import ModelHubConfig+ from tests.test_model_hub_l3 import _service, _source++ store = VibeAgentStore(sqlite_db_factory(tmp_path / "agents.sqlite"))+ try:+ store.ensure_builtin_default_agents(["codex", "vibey"])+ store.update("codex", model="gpt-6-astra")+ service = _service(tmp_path, sources=[])+ service.store.config = ModelHubConfig()+ copy_on_disk: dict = {}+ service.models_dev_catalog = lambda: copy_on_disk+ controller = Controller.__new__(Controller)+ controller.vibe_agent_store = store+ controller.model_hub_service = service+ service.builtin_agent_models_override = controller._builtin_agent_models+ service.backend_catalog_changed = controller._model_hub_catalog_changed+ # A model only Vibey would run, so starting on it adds the Source's route target and syncs the engine.+ relay = _source("src_relay0001", "Relay", vendor="custom", protocol="openai_chat", model_id="relay-tools-1")++ with patch("vibe.models_dev_catalog.load_models_dev_catalog", side_effect=OSError("offline")):+ async with service._mutation_lock:+ await service._commit_new_source_locked(relay)+ assert service.store.load().agents["vibey"].models == []assert store.get("vibey").model is None+ if person_chose:+ store.update("vibey", model="relay-tools-1")+ if person_emptied:+ # The person added the model and removed it again: the empty list is theirs.+ service.store.config.agents["vibey"].removed_model_ids = ["relay-tools-1"]++ copy_on_disk.update({"relay": {"name": "Relay", "models": {+ "relay-tools-1": {"name": "Relay Tools 1", "tool_call": True,+ "modalities": {"input": ["text"], "output": ["text"]}},+ }}})+ if not engine_up:+ from core.handlers.model_hub.service import ModelHubError++ # The start is saved before the engine syncs, so the Agent hears of it even when the sync fails.+ service.adapter.sync_sources = AsyncMock(side_effect=ModelHubError("engine_down", status=503))+ await controller._start_vibey_without_a_model()++ started = [model.id for model in service.store.load().agents["vibey"].models]+ assert started == ([] if person_chose or person_emptied else ["relay-tools-1"])+ assert store.get("vibey").model == (None if person_emptied else "relay-tools-1")+ finally:+ store.close()+++async def test_an_rc1_vibey_left_empty_starts_at_the_first_upgraded_start(tmp_path, sqlite_db_factory):+ """MH-VIBEY-007: a Vibey an earlier build seeded empty starts at the next start.++ gh-v3.2.0rc1 seeded Vibey from a Source listing no built-in Agent's model and left its+ catalog empty. The seed is spent, so the upgraded start does not run it again; it starts+ that Vibey from the cached models.dev copy instead of waiting for a later refresh.+ """+ from config.v2_config import ModelHubConfig+ from tests.test_model_hub_l3 import _service, _source++ store = VibeAgentStore(sqlite_db_factory(tmp_path / "agents.sqlite"))+ try:+ store.ensure_builtin_default_agents(["vibey"])+ relay = _source("src_relay0001", "Relay", vendor="custom", protocol="openai_chat", model_id="relay-tools-1")+ # The persisted shape rc1 left: Vibey seeded (no longer pending), its Source placed, its catalog empty.+ config = ModelHubConfig(sources=[relay])+ config.agents["vibey"].sources.order = [relay.id]+ config = ModelHubConfig.from_payload(config.to_payload())+ assert not config.vibey_supply_pending and config.agents["vibey"].models == []+ service = _service(tmp_path, sources=[])+ service.store.config = config+ service.models_dev_catalog = lambda: {"relay": {"name": "Relay", "models": {+ "relay-tools-1": {"name": "Relay Tools 1", "tool_call": True,+ "modalities": {"input": ["text"], "output": ["text"]}},+ }}}+ controller = Controller.__new__(Controller)+ controller.vibe_agent_store = store+ controller.model_hub_service = service+ service.builtin_agent_models_override = controller._builtin_agent_models+ service.backend_catalog_changed = controller._model_hub_catalog_changed++ await controller._seed_vibey_model_supply()++ assert [model.id for model in service.store.load().agents["vibey"].models] == ["relay-tools-1"]+ assert store.get("vibey").model == "relay-tools-1"finally:store.close()