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): bind UI to wildcard when tunnel is enabled

cyha5204af53be9
diff --git a/tests/test_remote_access_vibe_cloud.py b/tests/test_remote_access_vibe_cloud.py
index 624ea7edb..bd4342101 100644
--- a/tests/test_remote_access_vibe_cloud.py
+++ b/tests/test_remote_access_vibe_cloud.py
@@ -858,3 +858,67 @@ def test_start_clears_previous_cloudflared_logs_before_spawn(monkeypatch, tmp_pa
assert result["ok"] is True
assert result["started"] is True
+
+
+def test_effective_ui_bind_host_uses_setup_host_when_tunnel_disabled() -> None:
+ config = _config()
+ config.remote_access.vibe_cloud.enabled = False
+ config.ui.setup_host = "100.97.103.112"
+
+ assert runtime.effective_ui_bind_host(config) == "100.97.103.112"
+
+
+def test_effective_ui_bind_host_overrides_to_wildcard_when_tunnel_enabled() -> None:
+ config = _config()
+ assert config.remote_access.vibe_cloud.enabled is True
+ config.ui.setup_host = "100.97.103.112"
+
+ assert runtime.effective_ui_bind_host(config) == "0.0.0.0"
+
+
+def test_effective_ui_bind_host_preserves_loopback_when_tunnel_disabled() -> None:
+ config = _config()
+ config.remote_access.vibe_cloud.enabled = False
+ config.ui.setup_host = "127.0.0.1"
+
+ assert runtime.effective_ui_bind_host(config) == "127.0.0.1"
+
+
+def test_effective_ui_bind_host_falls_back_to_loopback_when_setup_host_blank() -> None:
+ config = _config()
+ config.remote_access.vibe_cloud.enabled = False
+ config.ui.setup_host = ""
+
+ assert runtime.effective_ui_bind_host(config) == "127.0.0.1"
+
+
+def test_effective_ui_bind_host_uses_v6_wildcard_for_ipv6_setup_host() -> None:
+ config = _config()
+ assert config.remote_access.vibe_cloud.enabled is True
+ config.ui.setup_host = "::"
+
+ assert runtime.effective_ui_bind_host(config) == "::"
+
+
+def test_effective_ui_bind_host_uses_v6_wildcard_for_bracketed_ipv6_loopback() -> None:
+ config = _config()
+ assert config.remote_access.vibe_cloud.enabled is True
+ config.ui.setup_host = "[::1]"
+
+ assert runtime.effective_ui_bind_host(config) == "::"
+
+
+def test_effective_ui_bind_host_prefers_requested_host_over_persisted_setup_host() -> None:
+ config = _config()
+ config.remote_access.vibe_cloud.enabled = False
+ config.ui.setup_host = "127.0.0.1"
+
+ assert runtime.effective_ui_bind_host(config, requested_host="192.168.1.10") == "192.168.1.10"
+
+
+def test_effective_ui_bind_host_requested_host_yields_to_tunnel_override() -> None:
+ config = _config()
+ assert config.remote_access.vibe_cloud.enabled is True
+ config.ui.setup_host = "127.0.0.1"
+
+ assert runtime.effective_ui_bind_host(config, requested_host="100.97.103.112") == "0.0.0.0"
diff --git a/tests/test_ui_server_reload.py b/tests/test_ui_server_reload.py
new file mode 100644
index 000000000..eda8000e6
--- /dev/null
+++ b/tests/test_ui_server_reload.py
@@ -0,0 +1,105 @@
+from __future__ import annotations
+
+import threading
+
+from config.v2_config import (
+ AgentsConfig,
+ PlatformsConfig,
+ RemoteAccessConfig,
+ RuntimeConfig,
+ SlackConfig,
+ UiConfig,
+ V2Config,
+)
+from vibe import runtime
+from vibe.ui_server import app
+
+from tests.ui_server_test_helpers import csrf_headers
+
+
+def _config_with_tunnel(enabled: bool, setup_host: str = "127.0.0.1") -> V2Config:
+ config = V2Config(
+ mode="self_host",
+ version="v2",
+ platform="slack",
+ platforms=PlatformsConfig(enabled=["slack"], primary="slack"),
+ slack=SlackConfig(bot_token=""),
+ runtime=RuntimeConfig(default_cwd="."),
+ agents=AgentsConfig(),
+ ui=UiConfig(setup_host=setup_host),
+ remote_access=RemoteAccessConfig(),
+ )
+ config.remote_access.vibe_cloud.enabled = enabled
+ return config
+
+
+class _NoopThread:
+ def __init__(self, target=None, args=(), kwargs=None, **_extra):
+ self._target = target
+ self._args = args
+ self._kwargs = kwargs or {}
+
+ def start(self) -> None:
+ # Skip the actual subprocess respawn; the unit test only asserts
+ # the bind host computed before the thread is started.
+ return None
+
+
+def test_ui_reload_overrides_bind_host_when_tunnel_enabled(monkeypatch):
+ captured_calls: list[dict] = []
+ original = runtime.effective_ui_bind_host
+
+ def _spy(config, requested_host=None):
+ captured_calls.append({"config": config, "requested_host": requested_host})
+ return original(config, requested_host=requested_host)
+
+ monkeypatch.setattr(runtime, "effective_ui_bind_host", _spy)
+ monkeypatch.setattr(V2Config, "load", classmethod(lambda cls: _config_with_tunnel(enabled=True)))
+ monkeypatch.setattr(threading, "Thread", _NoopThread)
+
+ client = app.test_client()
+ response = client.post(
+ "/ui/reload",
+ json={"host": "100.97.103.112", "port": 5123},
+ headers=csrf_headers(client, "http://127.0.0.1:5123"),
+ base_url="http://127.0.0.1:5123",
+ )
+
+ assert response.status_code == 200
+ body = response.get_json()
+ assert body["ok"] is True
+ # Response echoes the user-facing host (what the browser should redirect to).
+ assert body["host"] == "100.97.103.112"
+ assert body["port"] == 5123
+
+ assert captured_calls, "effective_ui_bind_host was not invoked"
+ call = captured_calls[-1]
+ assert call["requested_host"] == "100.97.103.112"
+ assert call["config"].remote_access.vibe_cloud.enabled is True
+
+
+def test_ui_reload_uses_requested_host_when_tunnel_disabled(monkeypatch):
+ captured: dict = {}
+
+ original = runtime.effective_ui_bind_host
+
+ def _spy(config, requested_host=None):
+ captured["requested_host"] = requested_host
+ captured["enabled"] = config.remote_access.vibe_cloud.enabled
+ return original(config, requested_host=requested_host)
+
+ monkeypatch.setattr(runtime, "effective_ui_bind_host", _spy)
+ monkeypatch.setattr(V2Config, "load", classmethod(lambda cls: _config_with_tunnel(enabled=False)))
+ monkeypatch.setattr(threading, "Thread", _NoopThread)
+
+ client = app.test_client()
+ response = client.post(
+ "/ui/reload",
+ json={"host": "192.168.1.5", "port": 6000},
+ headers=csrf_headers(client, "http://127.0.0.1:5123"),
+ base_url="http://127.0.0.1:5123",
+ )
+
+ assert response.status_code == 200
+ assert captured["requested_host"] == "192.168.1.5"
+ assert captured["enabled"] is False
diff --git a/vibe/cli.py b/vibe/cli.py
index 1b1070f4f..66949d572 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -1829,7 +1829,8 @@ def cmd_vibe():
_write_status("starting")
service_pid = runtime.start_service()
- ui_pid = runtime.start_ui(config.ui.setup_host, config.ui.setup_port)
+ bind_host = runtime.effective_ui_bind_host(config)
+ ui_pid = runtime.start_ui(bind_host, config.ui.setup_port)
runtime.write_status("running", "pid={}".format(service_pid), service_pid, ui_pid)
ui_url = "http://{}:{}".format(config.ui.setup_host, config.ui.setup_port)
diff --git a/vibe/runtime.py b/vibe/runtime.py
index f7e111ed8..86c7801a2 100644
--- a/vibe/runtime.py
+++ b/vibe/runtime.py
@@ -398,6 +398,38 @@ def start_service():
)
+def effective_ui_bind_host(config: V2Config, requested_host: str | None = None) -> str:
+ """Resolve the host the UI server should bind to.
+
+ When the Vibe Cloud tunnel is enabled, bind to a wildcard so the local
+ ``cloudflared`` origin (which dials ``127.0.0.1``/``[::1]``) can reach the
+ UI no matter which interface IP the user typed into ``ui.setup_host``
+ (loopback, Tailscale CGNAT, LAN). The host-trust middleware in
+ ``ui_server`` still rejects untrusted peers, so widening the bind does
+ not widen exposure.
+
+ Why: If the user binds to a Tailscale or LAN IP and then enables the
+ tunnel, ``cloudflared`` cannot reach the UI on its loopback origin and
+ every public request returns 502.
+
+ ``requested_host`` lets callers (e.g. the ``/ui/reload`` endpoint)
+ propagate the host from the inbound request without persisting it first;
+ when omitted we fall back to ``config.ui.setup_host``.
+ """
+ setup_host = (requested_host if requested_host is not None else config.ui.setup_host) or "127.0.0.1"
+ cloud = getattr(getattr(config, "remote_access", None), "vibe_cloud", None)
+ if cloud is not None and cloud.enabled:
+ # Pick the wildcard family that matches the user's intent so an
+ # IPv6-only setup_host stays reachable on v6.
+ normalized = setup_host.strip()
+ if normalized.startswith("[") and normalized.endswith("]"):
+ normalized = normalized[1:-1]
+ if normalized in {"::", "::0"} or ":" in normalized:
+ return "::"
+ return "0.0.0.0"
+ return setup_host
+
+
def start_ui(host, port):
command = "from vibe.ui_server import run_ui_server; run_ui_server('{}', {})".format(host, port)
return spawn_background(
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index f38937dce..7dfb069f1 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -907,6 +907,15 @@ def ui_reload():
status = runtime.read_status()
+ try:
+ current_config = V2Config.load()
+ except Exception:
+ current_config = None
+ if current_config is not None:
+ bind_host = runtime.effective_ui_bind_host(current_config, requested_host=host)
+ else:
+ bind_host = host
+
def _restart():
global _server
import subprocess
@@ -915,7 +924,7 @@ def ui_reload():
from config import paths as config_paths
working_dir = get_working_dir()
- command = f"from vibe.ui_server import run_ui_server; run_ui_server('{host}', {port})"
+ command = f"from vibe.ui_server import run_ui_server; run_ui_server('{bind_host}', {port})"
stdout_path = config_paths.get_runtime_dir() / "ui_stdout.log"
stderr_path = config_paths.get_runtime_dir() / "ui_stderr.log"
stdout = stdout_path.open("ab")