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): let a Vibey call after a failover take the new Source (#2860)
Call Whiteb159b019c0bb
diff --git a/core/handlers/model_hub/turn_gateway.py b/core/handlers/model_hub/turn_gateway.pyindex c690ba75c..42dfdd88d 100644--- a/core/handlers/model_hub/turn_gateway.py+++ b/core/handlers/model_hub/turn_gateway.py@@ -570,12 +570,26 @@ class ModelHubTurnGateway:raise ModelHubError("mapping_target_unavailable", status=409)if backend == "vibey" and turn_id:# The caller may read EOF before the previous handler's owned- # teardown exits. Drain already-settled responses, not live model- # work; the registry still refuses any remaining overlap.+ # teardown exits, and Vibey stops reading at the stream's terminal+ # event, which this gateway forwards before the upstream's EOF and+ # before it settles the call. Drain responses whose protocol terminal+ # was forwarded or whose upstream stream has ended, not live model+ # work: a next call that resolves to another Source (the last call+ # failed over) may only replace the turn's route once the previous+ # one is released. The wait is bounded; the registry still refuses+ # any remaining overlap.finishing = [owned.done for owned in self._turn_requests.get(turn_id, ())if owned.execution is not None- and (owned.execution.settlement_recorded or owned.execution.terminal_fact_committed)+ and (+ owned.execution.completed_at is not None+ or (+ owned.execution.wire_state is not None+ and owned.execution.wire_state.terminal_outcome is not None+ )+ or owned.execution.settlement_recorded+ or owned.execution.terminal_fact_committed+ )]if finishing:await asyncio.wait(finishing, timeout=self._transport_timeout)diff --git a/modules/agents/vibey/errors.py b/modules/agents/vibey/errors.pyindex 1484a5764..744b95bb4 100644--- a/modules/agents/vibey/errors.py+++ b/modules/agents/vibey/errors.py@@ -47,6 +47,9 @@ _KIND_KEYS: dict[str, str] = {"stream_cleanup": "internal",# A context row this build cannot read (a shape it no longer accepts): the session cannot continue."TranscriptError": "historyUnreadable",+ # Model Hub could not route a later model call of the Turn. A refusal that explains itself (no Source, all cooling+ # down) shows its own copy first (``_preflight``); this names the rest instead of calling it an internal error.+ "ModelHubError": "modelHubRoute",# The loop refuses a route that declares no tool support before any request."UnsupportedModelRoute": "toolsUnsupported",# A provider answer the canonical transcript cannot hold.diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex 1833e0352..2e25b4aae 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -648,6 +648,12 @@ scenarios:test: tests/test_model_hub_vibey_consumer.py::test_sequential_vibey_retry_replaces_route_and_retains_served_provenancerelated_tests:- tests/test_model_hub_vibey_consumer.py::test_vibey_route_replacement_refuses_overlap_without_poisoning_current_request+ - id: MH-VIBEY-010+ name: A Vibey call that failed over to another Source does not refuse the Turn's next call while it settles+ status: covered+ kind: recovery+ layer: contract+ test: tests/test_model_hub_vibey_consumer.py::test_the_next_vibey_call_takes_the_failed_over_source_while_the_last_call_settles- id: MH-VIBEY-008name: Every Vibey resolution names its Turn, so each Turn on its Session's service-lifetime scope keeps exact provenancestatus: covereddiff --git a/tests/test_model_hub_vibey_consumer.py b/tests/test_model_hub_vibey_consumer.pyindex a6b204c98..83d4bc9d6 100644--- a/tests/test_model_hub_vibey_consumer.py+++ b/tests/test_model_hub_vibey_consumer.py@@ -649,6 +649,80 @@ async def test_a_finished_turns_request_is_never_credited_to_the_next_turn_on_itawait gateway.close()+class _SettlingLiveHandle(LiveInvokeHandle):+ """A stream whose terminal frame was already forwarded, while the call has not finished.++ ``held`` names what is still outstanding: the upstream's EOF after the terminal frame, or+ the call's settlement (its outcome) after EOF.+ """++ def __init__(self, outcome, chunks, *, held):+ self.settle = asyncio.Event()+ self._held = held+ super().__init__(outcome, chunks)++ async def _iterate(self, chunks):+ for chunk in chunks:+ yield chunk+ if self._held == "eof":+ await self.settle.wait()++ async def outcome(self):+ if self._held == "settlement":+ await self.settle.wait()+ return self._outcome++[email protected]("held", ["eof", "settlement"])+async def test_the_next_vibey_call_takes_the_failed_over_source_while_the_last_call_settles(tmp_path, held):+ """MH-VIBEY-010: a call that failed over to another Source does not refuse the turn's next call.++ Vibey stops reading a stream at its terminal event and resolves its next call at once, while the+ gateway may still await the upstream's EOF or settle the last call. When that call failed over (its first Source now cooling+ down), the next resolution names the other Source and replaces the turn's route; that waits for the+ finished call instead of refusing the turn as overlapping live work.+ """+ primary = _source("src_primary01", "Primary", vendor="openai", protocol="openai_responses", model_id="gpt-x")+ fallback = _source("src_fallback01", "Fallback", vendor="openai", protocol="openai_responses", model_id="gpt-x")+ answer = _body("openai_responses", True)+ settling = _SettlingLiveHandle(+ _outcome(RawOutcomeKind.SUCCESS, source_id=fallback.id, stream_started=True), (answer,), held=held,+ )+ service = _vibey_service(tmp_path, [primary, fallback], handles=[+ InvokeHandle(_outcome(RawOutcomeKind.HTTP_ERROR, status=503, code="server_error", source_id=primary.id)),+ settling,+ ])+ gateway = ModelHubTurnGateway(service)+ router = ModelHubRuntimeRouter(service=service, turn_gateway=gateway)+ turn_id = "turn-failed-over"+ try:+ first = await router.resolve_hop("menu-alias", process_scope="vibey:test", turn_id=turn_id)+ assert first["source_id"] == primary.id+ async with aiohttp.ClientSession() as client:+ async with client.post(+ f'{first["base_url"]}/responses',+ headers={"Authorization": f'Bearer {first["token"]}', **first["request_headers"]},+ json={"model": first["runtime_model"], "stream": True, "input": "hi"},+ ) as response:+ assert _served_hop(response)["source"] == fallback.id+ received = b""+ while b"response.completed" not in received:+ received += await response.content.readany()+ # The terminal event is in: the next call resolves while this one still settles.+ following = asyncio.create_task(+ router.resolve_hop("menu-alias", process_scope="vibey:test", turn_id=turn_id)+ )+ await asyncio.sleep(0.05)+ settling.settle.set()+ second = await asyncio.wait_for(following, timeout=5)+ await response.read()+ assert second["source_id"] == fallback.id+ finally:+ settling.settle.set()+ await gateway.close()++@pytest.mark.asyncioasync def test_vibey_route_replacement_refuses_overlap_without_poisoning_current_request(tmp_path):"""MH-VIBEY-006: a new launch cannot take an in-flight request's turn identity."""diff --git a/tests/test_vibey_agent.py b/tests/test_vibey_agent.pyindex ce33fe740..a40832668 100644--- a/tests/test_vibey_agent.py+++ b/tests/test_vibey_agent.py@@ -1212,6 +1212,8 @@ def test_an_unclassified_provider_failure_and_an_unexpected_exception_each_say_wassert error_key("unknown") == "vibeyAgent.error.unclassified"# Any kind outside the named set is the class of an exception the loop did not expect.assert error_key("HookStateError") == "vibeyAgent.error.internal"+ # A Model Hub routing refusal with no copy of its own says it is one, not an internal error.+ assert error_key("ModelHubError") == "vibeyAgent.error.modelHubRoute"assert error_key(None, reason="error") == "vibeyAgent.error.generic"diff --git a/vibe/i18n/en.json b/vibe/i18n/en.jsonindex 3c201dc1b..b59cf50aa 100644--- a/vibe/i18n/en.json+++ b/vibe/i18n/en.json@@ -1801,6 +1801,7 @@"unclassified": "The request to the model failed with an error {backend} could not classify. Try again, or choose another model.","outputLimit": "The model reached its output limit before producing a usable answer or tool call. Ask for smaller steps, or choose a model with a larger output limit.","internal": "{backend} stopped because of an internal error. Try again; if it happens again, the service log names the cause.",+ "modelHubRoute": "Model Hub could not route this step of {backend} to a model. Try again; if it happens again, the service log names the cause.","historyUnreadable": "This session's history can't be loaded, so {backend} can't continue it. Start a new session with /new.","generic": "{backend}'s run failed."}diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.jsonindex 2cd264957..4ef3a96fb 100644--- a/vibe/i18n/zh.json+++ b/vibe/i18n/zh.json@@ -1801,6 +1801,7 @@"unclassified": "请求模型时出现了 {backend} 无法归类的错误。可以重试,或换一个模型。","outputLimit": "模型在生成可用的答案或工具调用前达到了输出上限。请让它分成更小的步骤,或换用输出上限更大的模型。","internal": "{backend} 因内部错误而停止。可以重试;如果再次出现,服务日志里记录了原因。",+ "modelHubRoute": "Model Hub 没能为 {backend} 的这一步选定模型路由。可以重试;如果再次出现,服务日志里记录了原因。","historyUnreadable": "这个会话的历史记录无法加载,{backend} 无法继续它。请发送 /new 开始一个新会话。","generic": "{backend} 运行失败。"}