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(restart): keep full scope for manual restart buttons + block overlapping restarts
cyhe97ce9bd8188
diff --git a/tests/test_ui_server_logs.py b/tests/test_ui_server_logs.pyindex 19cd52ca2..79c09e270 100644--- a/tests/test_ui_server_logs.py+++ b/tests/test_ui_server_logs.py@@ -291,10 +291,40 @@ def test_control_restart_schedules_restart_job(monkeypatch, tmp_path):assert payload["ok"] is Trueassert payload["restart"]["job_id"] == "job123"assert runtime.read_status()["state"] == "restarting"- # A Web-UI restart defaults to service-only so the Web UI process survives.- assert calls == [{"delay_seconds": 0.0, "trigger": "web-ui", "scope": "service"}]+ # Default is a FULL restart (the manual Dashboard / Service restart buttons+ # send no scope and expect both processes to come back).+ assert calls == [{"delay_seconds": 0.0, "trigger": "web-ui", "scope": "all"}]- # An explicit scope:"all" still requests a full restart (e.g. UI port change).+ # The platform-config flow opts into a service-only restart (keep the Web UI).calls.clear()- client.post("/api/control", json={"action": "restart", "scope": "all"}, headers=csrf_headers(client))- assert calls == [{"delay_seconds": 0.0, "trigger": "web-ui", "scope": "all"}]+ client.post("/api/control", json={"action": "restart", "scope": "service"}, headers=csrf_headers(client))+ assert calls == [{"delay_seconds": 0.0, "trigger": "web-ui", "scope": "service"}]+++def test_control_restart_rejects_overlapping_restart(monkeypatch, tmp_path):+ """A restart already in flight (live supervisor) blocks a second one so two+ jobs can't race on the same pid files + lock."""+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ from vibe.ui_server import app+ import vibe.restart_supervisor as restart_supervisor++ paths.ensure_data_dirs()+ # Seed a live, in-flight restart status (this test process is the "supervisor").+ runtime.write_json(+ runtime.get_restart_status_path(),+ {"state": "running", "supervisor_pid": os.getpid(), "job_id": "inflight"},+ )++ calls = []+ monkeypatch.setattr(+ restart_supervisor,+ "schedule_restart",+ lambda **kwargs: calls.append(kwargs) or {"job_id": "x", "state": "scheduled"},+ )++ client = app.test_client()+ response = client.post("/api/control", json={"action": "restart"}, headers=csrf_headers(client))++ assert response.status_code == 409+ assert response.get_json()["code"] == "restart_in_progress"+ assert calls == [] # no second job scheduleddiff --git a/ui/src/components/settings/SettingsPlatformsPage.tsx b/ui/src/components/settings/SettingsPlatformsPage.tsxindex 4218a5834..5ad3df53d 100644--- a/ui/src/components/settings/SettingsPlatformsPage.tsx+++ b/ui/src/components/settings/SettingsPlatformsPage.tsx@@ -107,6 +107,25 @@ export const SettingsPlatformsPage: React.FC = () => {// Persist the enabled set and restart. ``primary`` is intentionally omitted:// the backend normalizes it from ``enabled`` (first enabled, or the workbench// when empty), so the UI never chooses or sends one.+ // Restart only the service (scope:'service') so the open Web UI survives the+ // config change. A "restart_in_progress" rejection is NOT a failure: the+ // config is already saved and the in-flight restart will pick it up, so show+ // a neutral notice. Returns true when the change is applied or queued.+ const requestServiceRestart = async (): Promise<boolean> => {+ try {+ await control('restart', { scope: 'service' });+ showToast(t('platform.restartedSuccess'), 'success');+ return true;+ } catch (e) {+ if ((e as { code?: string })?.code === 'restart_in_progress') {+ showToast(t('platform.restartInProgress'), 'warning');+ return true;+ }+ showToast(t('platform.restartFailed'), 'error');+ return false;+ }+ };+const persistEnabled = async (nextEnabled: string[]) => {setRestartPhase('saving');try {@@ -117,12 +136,7 @@ export const SettingsPlatformsPage: React.FC = () => {return false;}setRestartPhase('restarting');- try {- await control('restart');- showToast(t('platform.restartedSuccess'), 'success');- } catch {- showToast(t('platform.restartFailed'), 'error');- }+ await requestServiceRestart();return true;} finally {setRestartPhase('idle');@@ -198,12 +212,13 @@ export const SettingsPlatformsPage: React.FC = () => {setRestartPhase('restarting');try {await saveConfig({ ...savedConfig, platforms: { enabled: nextEnabled } });- await control('restart');- showToast(t('platform.restartedSuccess'), 'success');- setRevealed((prev) => prev.filter((p) => p !== platform));- setOpenConfig((prev) => (prev === platform ? null : prev));} catch {showToast(t('platform.restartFailed'), 'error');+ return;+ }+ if (await requestServiceRestart()) {+ setRevealed((prev) => prev.filter((p) => p !== platform));+ setOpenConfig((prev) => (prev === platform ? null : prev));}} finally {setRestartPhase('idle');diff --git a/ui/src/context/StatusContext.tsx b/ui/src/context/StatusContext.tsxindex 669e2483d..2836a58e4 100644--- a/ui/src/context/StatusContext.tsx+++ b/ui/src/context/StatusContext.tsx@@ -80,8 +80,15 @@ export const StatusProvider: React.FC<{ children: React.ReactNode }> = ({ childr});if (!res.ok) {// Surface non-2xx responses as rejections so callers do not mistake a- // failed restart/start for success and emit positive UI feedback.- throw new Error(`Control action ${action} failed with status ${res.status}`);+ // failed restart/start for success and emit positive UI feedback. Carry+ // the server ``code`` (e.g. "restart_in_progress") so callers can react+ // specifically instead of only showing a generic failure.+ const body = await res.json().catch(() => ({}));+ const err = new Error(`Control action ${action} failed with status ${res.status}`) as Error & {+ code?: string;+ };+ err.code = body?.code;+ throw err;}await refreshStatus();// A restart bounces the service (and this UI server), so the next poll maydiff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 362211b8c..f67ae1ed2 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -741,6 +741,7 @@"restartingService": "Restarting service to apply changes...","restartedSuccess": "Configuration applied and service restarted","restartFailed": "Configuration saved, but service restart failed",+ "restartInProgress": "A restart is already in progress. Your change is saved and will apply once it finishes.","credentialSetupTitle": "{{platform}} workspace setup","credentialSetupSubtitle": "Configure the selected platform directly here, then validate credentials before enabling groups.","stepCreateApp": "Create platform app",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex b05fa75fe..722951188 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -741,6 +741,7 @@"restartingService": "正在重启服务以使配置生效...","restartedSuccess": "配置已应用,服务已重启","restartFailed": "配置已保存,但服务重启失败",+ "restartInProgress": "服务正在重启,更改已保存,将在重启完成后生效。","credentialSetupTitle": "{{platform}} 工作区设置","credentialSetupSubtitle": "在这里直接配置选中平台,并在启用群组前验证凭证。","stepCreateApp": "创建平台应用",diff --git a/vibe/ui_server.py b/vibe/ui_server.pyindex 10a313ec2..8f5345fe5 100644--- a/vibe/ui_server.py+++ b/vibe/ui_server.py@@ -2179,12 +2179,33 @@ def control():_stop_opencode_server()runtime.write_status("stopped", "stopped", None, status.get("ui_pid"))elif action == "restart":- # Default to a SERVICE-ONLY restart: a Web-UI-triggered restart (e.g. a- # config change) must not tear down the Web UI process the user is- # looking at. A caller can still request a full restart with- # ``scope: "all"`` (e.g. a UI host/port change that needs the UI server- # itself to come back up).- scope = payload.get("scope") if payload.get("scope") in ("all", "service") else "service"+ # Scope defaults to "all" (full restart) so the manual Dashboard /+ # Settings → Service restart buttons keep restarting BOTH processes+ # (a UI host/port change needs the UI server itself to come back up).+ # Only the platform-config flow opts into "service" (keep the Web UI up).+ scope = payload.get("scope") if payload.get("scope") in ("all", "service") else "all"+ # Reject overlapping restarts: a service-only restart leaves the Web UI+ # up, so a user (or another tab) could fire a second restart while the+ # first supervisor is still bouncing the service — two jobs would race+ # on the same pid files + lock. Block while one is genuinely in flight+ # (a stale status whose supervisor pid is dead does NOT block).+ restart_status = runtime.read_json(runtime.get_restart_status_path()) or {}+ sup_pid = restart_status.get("supervisor_pid")+ if restart_status.get("state") in ("scheduled", "running") and (+ sup_pid is None or runtime.pid_alive(sup_pid)+ ):+ return (+ jsonify(+ {+ "ok": False,+ "action": action,+ "error": "a restart is already in progress",+ "code": "restart_in_progress",+ "status": runtime.read_status(),+ }+ ),+ 409,+ )runtime.write_status("restarting", "restarting", status.get("service_pid"), status.get("ui_pid"))result = schedule_restart(delay_seconds=0.0, trigger="web-ui", scope=scope)return jsonify({"ok": True, "action": action, "restart": result, "status": runtime.read_status()})