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): preserve gateway recovery paths

cyh9175e01d30a8
diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.py
index 52507e0e6..1974940b7 100644
--- a/tests/test_model_hub_runtime.py
+++ b/tests/test_model_hub_runtime.py
@@ -3172,6 +3172,115 @@ def test_runtime_start_consults_install_owner_before_starting(
asyncio.run(run())
+def test_runtime_start_continues_after_server_owned_installation(
+ tmp_path: Path,
+) -> None:
+ class BlockingInstaller(EngineRuntimeManager):
+ def __init__(self, runtime_dir: Path) -> None:
+ super().__init__(runtime_dir=runtime_dir, offline=True)
+ self.release = threading.Event()
+ self.started = threading.Event()
+ self.binary = runtime_dir / "installed-engine"
+
+ def ensure(
+ self,
+ *,
+ force: bool = False,
+ expected_target=None,
+ on_resolved=None,
+ ):
+ del force
+ assert expected_target is None
+ assert on_resolved is not None
+ on_resolved(RUNTIME_INSTALL_TARGET)
+ self.started.set()
+ assert self.release.wait(timeout=2)
+ self.binary.parent.mkdir(parents=True, exist_ok=True)
+ self.binary.write_bytes(b"verified fixture")
+ return {
+ "ok": True,
+ "changed": True,
+ "path": str(self.binary),
+ "install_dir": str(self.binary.parent),
+ "version": "v7.2.95",
+ }
+
+ def resolve_engine_path(self):
+ return self.binary if self.binary.is_file() else None
+
+ def status(self):
+ installed = self.resolve_engine_path() is not None
+ return {
+ "installed": installed,
+ "version": "v7.2.95" if installed else None,
+ "install_dir": str(self.binary.parent),
+ "platform": self.host_platform(),
+ "reason": None,
+ }
+
+ class Supervisor:
+ def __init__(self, installer: BlockingInstaller) -> None:
+ self.installer = installer
+ self.state_store = EngineStateStore(tmp_path / "state")
+ self.start_calls = 0
+
+ def status(self):
+ installed = self.installer.resolve_engine_path() is not None
+ return {
+ "host_platform": self.installer.host_platform(),
+ "status": {
+ "health": "ok" if self.start_calls else (
+ "not_started" if installed else "not_installed"
+ ),
+ "installed_version": "v7.2.95" if installed else None,
+ "verified": installed,
+ "listening": {"host": "127.0.0.1", "port": 15220}
+ if self.start_calls
+ else None,
+ "last_check": None,
+ "error_key": None,
+ },
+ }
+
+ def restart_if_running(self) -> None:
+ return None
+
+ def note_installation_settled(self) -> None:
+ return None
+
+ def ensure_running(self) -> None:
+ self.start_calls += 1
+
+ async def run() -> None:
+ installer = BlockingInstaller(tmp_path / "runtime")
+ supervisor = Supervisor(installer)
+ adapter = CLIProxyEngineAdapter(
+ supervisor=supervisor, # type: ignore[arg-type]
+ state_store=supervisor.state_store,
+ )
+
+ installing = await adapter.install()
+ assert installing.health is EngineHealth.INSTALLING
+ assert await asyncio.to_thread(installer.started.wait, 2)
+
+ deferred = await adapter.start()
+ assert deferred.health is EngineHealth.INSTALLING
+ assert supervisor.start_calls == 0
+
+ installer.release.set()
+ for _ in range(100):
+ settled = await adapter.status()
+ if settled.health is EngineHealth.OK:
+ break
+ await asyncio.sleep(0.01)
+ else:
+ raise AssertionError("runtime did not start after installation")
+
+ assert supervisor.start_calls == 1
+
+ asyncio.run(run())
+
+
def test_runtime_install_failure_persists_closed_error_key(tmp_path: Path) -> None:
class FailedInstaller(EngineRuntimeManager):
def __init__(self, runtime_dir: Path) -> None:
diff --git a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
index b7f38ca6d..c00a6d4e6 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
@@ -274,18 +274,14 @@ describe('SettingsModelsPage surface branches', () => {
expect(await screen.findAllByRole('tab')).toHaveLength(3);
});
- it('keeps the persisted gateway switch on while its process is unavailable', async () => {
+ it('keeps routing controls available while an enabled gateway process is unavailable', async () => {
const unavailable = {
...runtime,
enabled: true,
status: { ...runtime.status, health: 'down' as const },
};
- vi.spyOn(modelsApi, 'listSources').mockResolvedValue([]);
- vi.spyOn(modelsApi, 'listAgents').mockResolvedValue([
- directAgent('claude'),
- directAgent('codex'),
- directAgent('opencode'),
- ]);
+ vi.spyOn(modelsApi, 'listSources').mockResolvedValue([retainedSource]);
+ vi.spyOn(modelsApi, 'listAgents').mockResolvedValue([takeoverAgent]);
vi.spyOn(modelsApi, 'getRuntimeStatus').mockResolvedValue(unavailable);
vi.spyOn(modelsApi, 'listEvents').mockResolvedValue([]);
@@ -297,10 +293,12 @@ describe('SettingsModelsPage surface branches', () => {
</ToastProvider>,
);
- const toggle = await screen.findByRole('switch', { name: /Turn model gateway off|关闭模型网关/i });
+ const toggle = await screen.findByRole('switch', { name: /Switch codex to Direct|请先将 codex 切换为直连/i });
expect(toggle.getAttribute('aria-checked')).toBe('true');
- expect(await screen.findByText(/^Model gateway is enabled but unavailable$|^模型网关已开启,但当前不可用$/i)).toBeTruthy();
- expect(screen.queryAllByRole('tab')).toHaveLength(0);
+ expect((toggle as HTMLButtonElement).disabled).toBe(true);
+ expect(await screen.findByText('Retained source')).toBeTruthy();
+ expect(screen.getByRole('button', { name: /^Switch to direct$|^切换到直连$/i })).toBeTruthy();
+ expect(screen.queryAllByRole('tab')).toHaveLength(3);
});
it('still allows persisted enablement to be turned off on an unsupported host', async () => {
diff --git a/ui/src/components/settings/models/SettingsModelsPage.tsx b/ui/src/components/settings/models/SettingsModelsPage.tsx
index 4d956212b..4f1f81087 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.tsx
@@ -453,7 +453,9 @@ export const SettingsModelsPage: React.FC = () => {
const runtimeEnabled = retainedRuntime !== null
&& (retainedRuntime.enabled ?? runtimeIsRunning(retainedRuntime))
&& runtimeRead.kind !== 'unread';
- const runtimeConfigurationVisible = runtimeRunning && !stoppingRuntime;
+ const runtimeConfigurationVisible = (
+ runtimeRunning || (runtimeEnabled && runtimeHealth !== 'installing')
+ ) && !stoppingRuntime;
React.useEffect(() => {
const runtimeCanRecover = runtimeRead.kind === 'unread'
|| (runtimeRead.kind === 'degraded' && runtimeRead.cause === 'read_failed')
diff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.py
index 3270e7d35..da5059d57 100644
--- a/vibe/model_hub_runtime/adapter.py
+++ b/vibe/model_hub_runtime/adapter.py
@@ -570,6 +570,7 @@ class CLIProxyEngineAdapter:
self._install_task: asyncio.Task[None] | None = None
self._install_admission: asyncio.Future[EngineStatus] | None = None
self._install_owner_active = False
+ self._start_after_install_task: asyncio.Task[None] | None = None
self._installation_stopping = False
self._oauth_flows: dict[str, _OAuthFlow] = {}
self._active_oauth_providers: set[str] = set()
@@ -674,6 +675,29 @@ class CLIProxyEngineAdapter:
except Exception: # noqa: BLE001
logger.exception("Model Hub runtime install task failed")
+ def _start_after_install_done(self, task: asyncio.Task[None]) -> None:
+ if self._start_after_install_task is task:
+ self._start_after_install_task = None
+ try:
+ task.result()
+ except asyncio.CancelledError:
+ return
+ except Exception: # noqa: BLE001
+ logger.exception("Model Hub runtime start after installation failed")
+
+ async def _start_after_install(self, install_task: asyncio.Task[None]) -> None:
+ await asyncio.shield(install_task)
+ async with self._installation_lock:
+ if self._installation_stopping:
+ return
+ status = await self.status()
+ if status.health in {
+ EngineHealth.INSTALLING,
+ EngineHealth.NOT_INSTALLED,
+ }:
+ return
+ await asyncio.to_thread(self.supervisor.ensure_running)
+
async def _run_installation(
self,
*,
@@ -873,6 +897,16 @@ class CLIProxyEngineAdapter:
async with self._installation_lock:
status = await self.status()
if status.health is EngineHealth.INSTALLING:
+ install_task = self._install_task
+ if install_task is not None and not install_task.done():
+ start_task = self._start_after_install_task
+ if start_task is None or start_task.done():
+ start_task = asyncio.create_task(
+ self._start_after_install(install_task),
+ name="model-hub-runtime-start-after-install",
+ )
+ self._start_after_install_task = start_task
+ start_task.add_done_callback(self._start_after_install_done)
return status
await asyncio.to_thread(self.supervisor.ensure_running)
return await self.status()
@@ -889,6 +923,7 @@ class CLIProxyEngineAdapter:
async with self._installation_lock:
self._installation_stopping = True
install_task = self._install_task
+ start_after_install_task = self._start_after_install_task
if install_task is not None:
try:
await asyncio.shield(install_task)
@@ -897,6 +932,14 @@ class CLIProxyEngineAdapter:
raise
except Exception: # noqa: BLE001
pass
+ if start_after_install_task is not None:
+ try:
+ await asyncio.shield(start_after_install_task)
+ except asyncio.CancelledError:
+ if not start_after_install_task.cancelled():
+ raise
+ except Exception: # noqa: BLE001
+ pass
await asyncio.to_thread(self.supervisor.stop)
async def status(self) -> EngineStatus: