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(remote-access): fail closed on uncertain routing state
cyh2fab813c71d8
diff --git a/tests/test_remote_access_vibe_cloud.py b/tests/test_remote_access_vibe_cloud.pyindex bd65dcb70..804ca2669 100644--- a/tests/test_remote_access_vibe_cloud.py+++ b/tests/test_remote_access_vibe_cloud.py@@ -150,7 +150,8 @@ def test_stop_preserves_pid_file_when_process_stop_fails(monkeypatch, tmp_path)remote_access._pid_path().write_text(str(pid), encoding="utf-8")remote_access._state_path().write_text('{"pid": 123}', encoding="utf-8")- monkeypatch.setattr(remote_access, "_is_cloudflared_pid", lambda candidate: candidate == pid)+ monkeypatch.setattr(runtime, "pid_alive", lambda candidate: candidate == pid)+ monkeypatch.setattr(runtime, "get_process_command", lambda candidate: "cloudflared tunnel run")monkeypatch.setattr(runtime, "stop_pid", lambda candidate, timeout=8: False)result = remote_access.stop()@@ -161,6 +162,50 @@ def test_stop_preserves_pid_file_when_process_stop_fails(monkeypatch, tmp_path)assert remote_access._state_path().exists()+def test_status_preserves_pid_file_when_process_command_is_unknown(monkeypatch, tmp_path) -> None:+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ pid = 123+ remote_access._pid_path().parent.mkdir(parents=True, exist_ok=True)+ remote_access._pid_path().write_text(str(pid), encoding="utf-8")+ remote_access._state_path().write_text('{"pid": 123}', encoding="utf-8")++ monkeypatch.setattr(runtime, "pid_alive", lambda candidate: candidate == pid)+ monkeypatch.setattr(runtime, "get_process_command", lambda candidate: None)++ result = remote_access.status(_config())++ assert result["running"] is False+ assert result["pid"] == pid+ assert result["pid_state"] == "unknown"+ assert remote_access._pid_path().read_text(encoding="utf-8") == str(pid)+ assert remote_access._state_path().exists()+++def test_start_refuses_duplicate_connector_when_process_command_is_unknown(monkeypatch, tmp_path) -> None:+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ pid = 123+ config = _config()+ config.remote_access.vibe_cloud.tunnel_token = "tunnel-token"+ remote_access._pid_path().parent.mkdir(parents=True, exist_ok=True)+ remote_access._pid_path().write_text(str(pid), encoding="utf-8")+ remote_access._state_path().write_text('{"pid": 123}', encoding="utf-8")+ spawn_calls = []++ monkeypatch.setattr(runtime, "pid_alive", lambda candidate: candidate == pid)+ monkeypatch.setattr(runtime, "get_process_command", lambda candidate: None)+ monkeypatch.setattr(remote_access, "_resolve_binary", lambda cfg: "/usr/local/bin/cloudflared")+ monkeypatch.setattr(remote_access, "_version", lambda path: "cloudflared test")+ monkeypatch.setattr(runtime, "spawn_background", lambda *args, **kwargs: spawn_calls.append(args) or 456)++ result = remote_access.start(config)++ assert result["ok"] is False+ assert result["error"] == "cloudflared_process_unknown"+ assert spawn_calls == []+ assert remote_access._pid_path().read_text(encoding="utf-8") == str(pid)+ assert remote_access._state_path().exists()++def test_start_returns_failure_when_remote_access_is_disabled(monkeypatch, tmp_path) -> None:monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))config = _config()diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.pyindex e8bbe134c..2f0502545 100644--- a/tests/test_ui_remote_access_auth.py+++ b/tests/test_ui_remote_access_auth.py@@ -106,6 +106,18 @@ def test_remote_host_fails_closed_when_disabled_but_hostname_still_matches(monkeassert response.get_json()["error"] == "remote_access_disabled"+def test_remote_host_fails_closed_when_public_url_is_invalid(monkeypatch, tmp_path):+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))+ config = _save_config(tmp_path)+ config.remote_access.vibe_cloud.public_url = "alex.avibe.bot"+ config.save()++ response = app.test_client().get("/dashboard", base_url="https://alex.avibe.bot", follow_redirects=False)++ assert response.status_code == 503+ assert response.get_json()["error"] == "remote_access_public_url_invalid"++def test_config_post_rotates_session_secret_when_remote_access_is_disabled(monkeypatch, tmp_path):monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))config = _save_config(tmp_path)diff --git a/vibe/remote_access.py b/vibe/remote_access.pyindex 4ea57ae02..110127ab4 100644--- a/vibe/remote_access.py+++ b/vibe/remote_access.py@@ -154,9 +154,18 @@ def _read_pid() -> int | None:def _is_cloudflared_pid(pid: int | None) -> bool:+ return _cloudflared_pid_state(pid) == "cloudflared"+++def _cloudflared_pid_state(pid: int | None) -> str:if not pid or not runtime.pid_alive(pid):- return False- command = runtime.get_process_command(pid) or ""+ return "dead"+ try:+ command = runtime.get_process_command(pid)+ except Exception:+ return "unknown"+ if not command:+ return "unknown"try:parts = shlex.split(command.strip(), posix=False)except ValueError:@@ -164,7 +173,9 @@ def _is_cloudflared_pid(pid: int | None) -> bool:executable = parts[0].strip("\"'") if parts else ""executable_name = Path(executable).name.lower()windows_name = ntpath.basename(executable).lower()- return executable_name in {"cloudflared", "cloudflared.exe"} or windows_name in {"cloudflared", "cloudflared.exe"}+ if executable_name in {"cloudflared", "cloudflared.exe"} or windows_name in {"cloudflared", "cloudflared.exe"}:+ return "cloudflared"+ return "other"def _write_state(pid: int, config: V2Config, binary: str) -> None:@@ -209,8 +220,9 @@ def status(config: V2Config | None = None) -> dict[str, Any]:except Exception:config = Nonepid = _read_pid()- running = _is_cloudflared_pid(pid)- if pid and not running:+ pid_state = _cloudflared_pid_state(pid)+ running = pid_state == "cloudflared"+ if pid and pid_state in {"dead", "other"}:_pid_path().unlink(missing_ok=True)_state_path().unlink(missing_ok=True)cloud = getattr(getattr(config, "remote_access", None), "vibe_cloud", None) if config else None@@ -222,7 +234,8 @@ def status(config: V2Config | None = None) -> dict[str, Any]:"public_url": getattr(cloud, "public_url", "") if cloud else "","paired": bool(getattr(cloud, "instance_id", "") and getattr(cloud, "tunnel_token", "")) if cloud else False,"running": running,- "pid": pid if running else None,+ "pid": pid if running or pid_state == "unknown" else None,+ "pid_state": pid_state,"binary_found": bool(binary),"binary_path": binary,"binary_version": _version(binary) if binary else None,@@ -232,7 +245,10 @@ def status(config: V2Config | None = None) -> dict[str, Any]:def stop() -> dict[str, Any]:with _CONNECTOR_LOCK:pid = _read_pid()- if pid is not None and not _is_cloudflared_pid(pid):+ pid_state = _cloudflared_pid_state(pid)+ if pid is not None and pid_state == "unknown":+ return {**status(), "ok": False, "error": "cloudflared_process_unknown", "stopped": False}+ if pid is not None and pid_state in {"dead", "other"}:_pid_path().unlink(missing_ok=True)_state_path().unlink(missing_ok=True)return {**status(), "ok": True, "stopped": False, "stale_pid": True}@@ -267,6 +283,8 @@ def start(config: V2Config | None = None) -> dict[str, Any]:return {**status(config), **install_result}binary = str(install_result["path"])current = status(config)+ if current.get("pid_state") == "unknown":+ return {**current, "ok": False, "error": "cloudflared_process_unknown", "started": False}if current.get("running"):running_sig = _running_signature(current.get("pid"))desired_sig = _runtime_signature(config, binary)diff --git a/vibe/ui_server.py b/vibe/ui_server.pyindex dfe61c7d8..6bc3b0100 100644--- a/vibe/ui_server.py+++ b/vibe/ui_server.py@@ -208,11 +208,25 @@ def _normalized_host(value: str | None) -> str:def _is_remote_access_request(config: V2Config) -> bool:- cloud = config.remote_access.vibe_cloud- if not cloud.public_url:+ public_host = _remote_access_public_host(config)+ if not public_host:return False- public_host = _normalized_host(urlparse(cloud.public_url).netloc)- return bool(public_host and _normalized_host(request.host) == public_host)+ return _normalized_host(request.host) == public_host+++def _remote_access_public_host(config: V2Config) -> str | None:+ public_url = (config.remote_access.vibe_cloud.public_url or "").strip()+ if not public_url:+ return ""+ parsed = urlparse(public_url)+ if parsed.scheme not in {"http", "https"} or not parsed.netloc:+ return None+ return _normalized_host(parsed.netloc)+++def _remote_access_public_url_invalid(config: V2Config) -> bool:+ cloud = config.remote_access.vibe_cloud+ return bool(cloud.enabled and cloud.public_url and _remote_access_public_host(config) is None)def _remote_access_snapshot(config: V2Config) -> dict[str, Any]:@@ -324,6 +338,8 @@ def enforce_remote_access_cookie():if _is_local_request_host():return Nonereturn jsonify({"ok": False, "error": "remote_access_config_unavailable"}), 503+ if _remote_access_public_url_invalid(config) and not _is_local_request_host():+ return jsonify({"ok": False, "error": "remote_access_public_url_invalid"}), 503if not _is_remote_access_request(config) or _remote_auth_exempt_path():return Nonefrom vibe import remote_access