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): avoid orphaned pending restart markers

cyh650b141e298f
diff --git a/tests/test_ui_server_fastapi.py b/tests/test_ui_server_fastapi.py
index 66b72bd34..ca0ba597b 100644
--- a/tests/test_ui_server_fastapi.py
+++ b/tests/test_ui_server_fastapi.py
@@ -525,6 +525,35 @@ def test_config_restart_fallback_marks_pending_restart_when_restart_in_flight(mo
assert pending["scope"] == "service"
+def test_config_restart_fallback_schedules_when_in_flight_finishes_after_marker(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ from vibe import restart_supervisor
+ from vibe import runtime
+
+ runtime.get_restart_status_path().parent.mkdir(parents=True, exist_ok=True)
+ restart_status = {
+ "ok": None,
+ "state": "running",
+ "job_id": "job-in-flight",
+ "supervisor_pid": 4242,
+ }
+ runtime.write_json(runtime.get_restart_status_path(), restart_status)
+ in_flight_results = iter([True, False])
+ scheduled: list[dict] = []
+
+ monkeypatch.setattr(ui_server, "_restart_in_flight", lambda: next(in_flight_results))
+ monkeypatch.setattr(restart_supervisor, "schedule_restart", lambda **kwargs: scheduled.append(kwargs) or {"job_id": "followup"})
+ monkeypatch.setattr(runtime, "read_status", lambda: {"service_pid": 11, "ui_pid": 22})
+
+ result = ui_server._schedule_service_restart_for_config_fallback()
+
+ assert result["ok"] is True
+ assert result["code"] == "restart_scheduled_after_in_flight_finished"
+ assert result["restart"] == {"job_id": "followup"}
+ assert scheduled == [{"delay_seconds": 0.0, "trigger": "web-ui-config", "scope": "service"}]
+ assert runtime.read_json(restart_supervisor._pending_restart_path()) is None
+
+
def test_static_ui_assets_use_cache_headers(monkeypatch, tmp_path):
ui_dist = tmp_path / "dist"
assets_dir = ui_dist / "assets"
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 9368da55a..6b7e6f5e1 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -2233,24 +2233,40 @@ def _schedule_service_restart_for_config_fallback() -> dict[str, Any]:
from vibe import runtime
from vibe.restart_supervisor import mark_pending_restart, schedule_restart
+ def _schedule_restart() -> dict[str, Any]:
+ status = runtime.read_status()
+ runtime.write_status("restarting", "restarting", status.get("service_pid"), status.get("ui_pid"))
+ return schedule_restart(delay_seconds=0.0, trigger="web-ui-config", scope="service")
+
with _RESTART_CONTROL_LOCK:
- restart_status = runtime.read_json(runtime.get_restart_status_path()) or {}
if _restart_in_flight():
+ restart_status = runtime.read_json(runtime.get_restart_status_path()) or {}
pending = mark_pending_restart(
trigger="web-ui-config-pending",
scope="service",
reason="restart_in_progress",
restart_job_id=restart_status.get("job_id"),
)
+ if not _restart_in_flight():
+ try:
+ from vibe.restart_supervisor import _pending_restart_path
+
+ _pending_restart_path().unlink(missing_ok=True)
+ except OSError:
+ logger.debug("Failed to remove stale pending restart marker", exc_info=True)
+ restart = _schedule_restart()
+ return {
+ "ok": True,
+ "restart": restart,
+ "code": "restart_scheduled_after_in_flight_finished",
+ }
return {
"ok": True,
"pending_restart": pending,
"restart": restart_status,
"code": "restart_pending_after_in_progress",
}
- status = runtime.read_status()
- runtime.write_status("restarting", "restarting", status.get("service_pid"), status.get("ui_pid"))
- restart = schedule_restart(delay_seconds=0.0, trigger="web-ui-config", scope="service")
+ restart = _schedule_restart()
return {"ok": True, "restart": restart}