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(remote-access): decouple config save from reconcile

cyhfa62ba68bdf1
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 35541acbe..b882fc0d1 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from config.v2_config import AgentsConfig, PlatformsConfig, RemoteAccessConfig, RuntimeConfig, SlackConfig, UiConfig, V2Config
from tests.ui_server_test_helpers import csrf_headers
+from vibe import api
from vibe import remote_access
from vibe import ui_server
from vibe.ui_server import app
@@ -127,6 +128,49 @@ def test_config_post_rotates_session_secret_when_remote_access_is_disabled(monke
assert saved.remote_access.vibe_cloud.session_secret != old_secret
+def test_config_post_skips_reconcile_when_remote_access_is_unchanged(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ client = app.test_client()
+ reconcile_calls = []
+
+ monkeypatch.setattr(remote_access, "reconcile", lambda next_config: reconcile_calls.append(next_config) or {"ok": True})
+
+ response = client.post(
+ "/config",
+ json=api.config_to_payload(config),
+ headers=csrf_headers(client, "http://127.0.0.1:5123"),
+ base_url="http://127.0.0.1:5123",
+ )
+
+ assert response.status_code == 200
+ assert reconcile_calls == []
+
+
+def test_config_post_returns_saved_config_when_remote_reconcile_fails(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ old_secret = config.remote_access.vibe_cloud.session_secret
+ client = app.test_client()
+
+ monkeypatch.setattr(remote_access, "reconcile", lambda next_config: {"ok": False, "error": "cloudflared_stop_failed"})
+
+ response = client.post(
+ "/config",
+ json={"remote_access": {"vibe_cloud": {"enabled": False}}},
+ headers=csrf_headers(client, "http://127.0.0.1:5123"),
+ base_url="http://127.0.0.1:5123",
+ )
+ saved = V2Config.load()
+ body = response.get_json()
+
+ assert response.status_code == 200
+ assert body["remote_access_runtime"]["ok"] is False
+ assert body["remote_access_runtime"]["error"] == "cloudflared_stop_failed"
+ assert saved.remote_access.vibe_cloud.enabled is False
+ assert saved.remote_access.vibe_cloud.session_secret != old_secret
+
+
def test_remote_callback_rejects_nonce_mismatch(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
config = _save_config(tmp_path)
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 8688d12de..073ddc96c 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -215,6 +215,21 @@ def _is_remote_access_request(config: V2Config) -> bool:
return bool(public_host and _normalized_host(request.host) == public_host)
+def _remote_access_snapshot(config: V2Config) -> dict[str, Any]:
+ return {
+ "provider": config.remote_access.provider,
+ "vibe_cloud": config.remote_access.vibe_cloud.__dict__.copy(),
+ }
+
+
+def _remote_access_settings_changed(previous: V2Config | None, current: V2Config, payload: dict) -> bool:
+ if "remote_access" not in payload:
+ return False
+ if previous is None:
+ return bool(_remote_access_snapshot(current)["vibe_cloud"].get("enabled"))
+ return _remote_access_snapshot(previous) != _remote_access_snapshot(current)
+
+
def _should_rotate_remote_session_secret(previous: V2Config | None, current: V2Config, payload: dict) -> bool:
if "remote_access" not in payload or previous is None:
return False
@@ -569,13 +584,15 @@ def config_post():
payload = request.json or {}
previous_config = _load_remote_access_config() if "remote_access" in payload else None
config = api.save_config(payload)
- if "remote_access" in payload:
+ remote_access_runtime = None
+ if _remote_access_settings_changed(previous_config, config, payload):
if _should_rotate_remote_session_secret(previous_config, config, payload):
remote_access.rotate_session_secret(config)
- result = remote_access.reconcile(config)
- if result.get("ok") is False:
- return jsonify({"ok": False, "error": result.get("error", "remote_access_reconcile_failed"), "remote_access": result, "config": api.config_to_payload(config)}), 500
- return jsonify(api.config_to_payload(config))
+ remote_access_runtime = remote_access.reconcile(config)
+ response_payload = api.config_to_payload(config)
+ if remote_access_runtime is not None:
+ response_payload["remote_access_runtime"] = remote_access_runtime
+ return jsonify(response_payload)
@app.route("/remote-access/status", methods=["GET"])