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(ui): serialize control stop with service lock

cyhc7cdd27305d4
diff --git a/tests/test_ui_server_logs.py b/tests/test_ui_server_logs.py
index ff5f6ed38..dda7bd52e 100644
--- a/tests/test_ui_server_logs.py
+++ b/tests/test_ui_server_logs.py
@@ -249,6 +249,25 @@ def test_control_start_reuses_running_service_without_stop(monkeypatch, tmp_path
assert payload["status"]["service_pid"] == 12345
+def test_control_stop_uses_locked_service_stop(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ paths.ensure_data_dirs()
+ runtime.write_status("running", detail="running", service_pid=12345, ui_pid=67890)
+ paths.get_runtime_pid_path().write_text("12345", encoding="utf-8")
+ calls = []
+
+ monkeypatch.setattr(runtime, "pid_alive", lambda pid: pid == 12345)
+ monkeypatch.setattr(runtime, "stop_service", lambda: calls.append("stop_service") or True)
+ monkeypatch.setattr(runtime, "stop_process", lambda pid_path: calls.append(("stop_process", pid_path)) or True)
+
+ client = app.test_client()
+ response = client.post("/control", json={"action": "stop"}, headers=csrf_headers(client))
+
+ assert response.status_code == 200
+ assert calls == ["stop_service"]
+ assert response.get_json()["status"]["state"] == "stopped"
+
+
def test_control_restart_schedules_restart_job(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
paths.ensure_data_dirs()
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index fa845a7dd..0b62385dc 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -121,7 +121,10 @@ def _stop_runtime_process_or_error(pid_path: Path, label: str) -> tuple[bool, st
from vibe import runtime
was_running = _runtime_pid_file_points_to_live_process(pid_path)
- stopped = runtime.stop_process(pid_path)
+ if pid_path == paths.get_runtime_pid_path():
+ stopped = runtime.stop_service()
+ else:
+ stopped = runtime.stop_process(pid_path)
if was_running and stopped is False:
return False, f"{label} did not stop"
return True, None