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(backends): dedupe concurrent install jobs

cyh4126c2e43ab4
diff --git a/tests/test_ui_server_install.py b/tests/test_ui_server_install.py
index 742ee6689..ed602901d 100644
--- a/tests/test_ui_server_install.py
+++ b/tests/test_ui_server_install.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import threading
import time
from config.v2_config import AgentsConfig, RuntimeConfig, SlackConfig, UiConfig, V2Config
@@ -139,3 +140,32 @@ def test_install_job_fails_when_runtime_refresh_fails(monkeypatch):
assert result["status"] == "failed"
assert result["ok"] is False
assert result["restart"] == {"ok": False, "message": "refresh timeout"}
+
+
+def test_install_job_dedupes_running_backend(monkeypatch):
+ calls: list[str] = []
+ release = threading.Event()
+
+ def install(name):
+ calls.append(name)
+ release.wait(timeout=1.0)
+ return {"ok": True, "message": "Installed", "output": "done", "path": "/usr/local/bin/codex"}
+
+ monkeypatch.setattr(api, "is_agent_backend", lambda name: name == "codex")
+ monkeypatch.setattr(api, "supports_runtime_refresh", lambda name: False)
+ monkeypatch.setattr(api, "install_agent", install)
+ with api._AGENT_INSTALL_JOB_LOCK:
+ api._AGENT_INSTALL_JOBS.clear()
+ api._AGENT_INSTALL_LATEST_BY_BACKEND.clear()
+
+ first = api.start_agent_install_job("codex")
+ deadline = time.time() + 1.0
+ while time.time() < deadline and not calls:
+ time.sleep(0.01)
+
+ second = api.start_agent_install_job("codex")
+ release.set()
+
+ assert second["job_id"] == first["job_id"]
+ assert second["status"] == "running"
+ assert calls == ["codex"]
diff --git a/vibe/api.py b/vibe/api.py
index 22e9a7732..e0bd55848 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -1658,6 +1658,10 @@ def start_agent_install_job(name: str) -> dict:
}
with _AGENT_INSTALL_JOB_LOCK:
_prune_agent_install_jobs(now)
+ latest_job_id = _AGENT_INSTALL_LATEST_BY_BACKEND.get(name)
+ latest_job = _AGENT_INSTALL_JOBS.get(latest_job_id or "")
+ if isinstance(latest_job, dict) and latest_job.get("status") == "running":
+ return dict(latest_job)
_AGENT_INSTALL_JOBS[job_id] = job
_AGENT_INSTALL_LATEST_BY_BACKEND[name] = job_id