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): preserve live connector state

cyh1639dcc102cb
diff --git a/tests/test_remote_access_vibe_cloud.py b/tests/test_remote_access_vibe_cloud.py
index 67887397e..e11db5eee 100644
--- a/tests/test_remote_access_vibe_cloud.py
+++ b/tests/test_remote_access_vibe_cloud.py
@@ -217,6 +217,28 @@ def test_cloudflared_pid_detection_handles_posix_quoted_paths_with_single_quotes
assert remote_access._is_cloudflared_pid(123) is True
+def test_cloudflared_pid_detection_handles_unquoted_paths_with_spaces(monkeypatch) -> None:
+ monkeypatch.setattr(runtime, "pid_alive", lambda pid: pid == 123)
+ monkeypatch.setattr(
+ runtime,
+ "get_process_command",
+ lambda pid: "/tmp/Vibe Tools/cloudflared tunnel --no-autoupdate run",
+ )
+
+ assert remote_access._is_cloudflared_pid(123) is True
+
+
+def test_cloudflared_pid_detection_rejects_non_cloudflared_paths(monkeypatch) -> None:
+ monkeypatch.setattr(runtime, "pid_alive", lambda pid: pid == 123)
+ monkeypatch.setattr(
+ runtime,
+ "get_process_command",
+ lambda pid: "/tmp/Vibe Tools/not-cloudflared tunnel --no-autoupdate run",
+ )
+
+ assert remote_access._cloudflared_pid_state(123) == "other"
+
+
def test_stop_preserves_pid_file_when_process_stop_fails(monkeypatch, tmp_path) -> None:
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
pid = 123
@@ -236,6 +258,25 @@ def test_stop_preserves_pid_file_when_process_stop_fails(monkeypatch, tmp_path)
assert remote_access._state_path().exists()
+def test_stop_preserves_pid_file_when_stop_reports_success_but_process_survives(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: "cloudflared tunnel run")
+ monkeypatch.setattr(runtime, "stop_pid", lambda candidate, timeout=8: True)
+
+ result = remote_access.stop()
+
+ assert result["ok"] is False
+ assert result["error"] == "cloudflared_stop_failed"
+ assert remote_access._pid_path().read_text(encoding="utf-8") == str(pid)
+ 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
diff --git a/vibe/remote_access.py b/vibe/remote_access.py
index 598537784..eda5d71a0 100644
--- a/vibe/remote_access.py
+++ b/vibe/remote_access.py
@@ -169,6 +169,31 @@ def _is_cloudflared_pid(pid: int | None) -> bool:
return _cloudflared_pid_state(pid) == "cloudflared"
+def _is_cloudflared_executable(value: str) -> bool:
+ executable = value.strip().strip("\"'")
+ 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"}
+
+
+def _command_starts_with_cloudflared(command: str) -> bool:
+ command = command.strip()
+ for posix in (True, False):
+ try:
+ parts = shlex.split(command, posix=posix)
+ except ValueError:
+ continue
+ if parts and _is_cloudflared_executable(parts[0]):
+ return True
+
+ lower_command = command.lower()
+ for marker in (" tunnel ", " tunnel", " --", " access ", " service ", " update ", " version"):
+ marker_index = lower_command.find(marker)
+ if marker_index > 0 and _is_cloudflared_executable(command[:marker_index]):
+ return True
+ return _is_cloudflared_executable(command)
+
+
def _cloudflared_pid_state(pid: int | None) -> str:
if not pid or not runtime.pid_alive(pid):
return "dead"
@@ -178,17 +203,7 @@ def _cloudflared_pid_state(pid: int | None) -> str:
return "unknown"
if not command:
return "unknown"
- try:
- parts = shlex.split(command.strip(), posix=True)
- except ValueError:
- try:
- parts = shlex.split(command.strip(), posix=False)
- except ValueError:
- parts = command.strip().split()
- executable = parts[0].strip("\"'") if parts else ""
- executable_name = Path(executable).name.lower()
- windows_name = ntpath.basename(executable).lower()
- if executable_name in {"cloudflared", "cloudflared.exe"} or windows_name in {"cloudflared", "cloudflared.exe"}:
+ if _command_starts_with_cloudflared(command):
return "cloudflared"
return "other"
@@ -273,6 +288,9 @@ def stop(config: V2Config | None = None) -> dict[str, Any]:
return {**status(config), "ok": True, "stopped": False, "stale_pid": True}
stopped = runtime.stop_pid(pid, timeout=8) if pid is not None else False
if stopped:
+ post_stop_state = _cloudflared_pid_state(pid)
+ if post_stop_state in {"cloudflared", "unknown"}:
+ return {**status(config), "ok": False, "error": "cloudflared_stop_failed", "stopped": False}
_pid_path().unlink(missing_ok=True)
_state_path().unlink(missing_ok=True)
if pid is not None and not stopped and _is_cloudflared_pid(pid):