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
Address lifecycle review feedback
cyhb7da7f515d68
diff --git a/main.py b/main.pyindex e98b70491..7c3b303c5 100644--- a/main.py+++ b/main.py@@ -69,6 +69,33 @@ def prepare_sqlite_state(config: V2Config):return ensure_sqlite_state(primary_platform=config.platform)+def _log_shutdown_signal(logger: logging.Logger, signum: int) -> None:+ try:+ logger.info(+ "Received signal %s pid=%s ppid=%s pgid=%s sid=%s",+ signum,+ os.getpid(),+ os.getppid(),+ os.getpgid(0),+ os.getsid(0),+ )+ except Exception:+ logger.info("Received signal %s", signum)+++def _log_shutdown_intent(logger: logging.Logger, signum: int) -> None:+ if signum != signal.SIGTERM or not shutdown_intent_required():+ return+ intent = consume_shutdown_intent(os.getpid(), signum)+ if intent is None:+ logger.warning(+ "No managed shutdown intent found for SIGTERM pid=%s; honoring signal",+ os.getpid(),+ )+ return+ logger.info("Accepted managed shutdown intent: %s", intent)++def main():"""Main entry point"""try:@@ -85,7 +112,7 @@ def main():logger.info("Starting vibe-remote service...")logger.info(f"Working directory: {config.runtime.default_cwd}")logger.info(- "Shutdown intent guard enabled=%s env=%s",+ "Shutdown intent diagnostics enabled=%s env=%s",shutdown_intent_required(),os.environ.get("VIBE_REQUIRE_SHUTDOWN_INTENT"),)@@ -111,28 +138,8 @@ def main():returnshutdown_initiated = Truetry:- logger.info("Received signal %s", signum)- log_process_snapshot(- logger,- f"signal-{signum}",- related_terms=(- "codex app-server",- "/codex ",- " claude",- "/vibe restart",- ".local/bin/vibe restart",- ),- )- if signum == signal.SIGTERM and shutdown_intent_required():- intent = consume_shutdown_intent(os.getpid(), signum)- if intent is None:- logger.warning(- "Ignoring unmanaged SIGTERM for pid=%s because no valid shutdown intent was present",- os.getpid(),- )- shutdown_initiated = False- return- logger.info("Accepted managed shutdown intent: %s", intent)+ _log_shutdown_signal(logger, signum)+ _log_shutdown_intent(logger, signum)logger.info("Shutting down after signal %s", signum)except Exception:passdiff --git a/tests/test_service_logging_handlers.py b/tests/test_service_logging_handlers.pyindex ef6d297ae..f642432f7 100644--- a/tests/test_service_logging_handlers.py+++ b/tests/test_service_logging_handlers.py@@ -1,6 +1,7 @@from __future__ import annotationsimport logging+import signalfrom pathlib import Pathimport main@@ -52,3 +53,27 @@ def test_start_service_disables_stdout_logging_for_background_process(monkeypatcassert captured["stderr_name"] == "service_stderr.log"assert isinstance(captured["env"], dict)assert captured["env"]["VIBE_DISABLE_STDOUT_LOGGING"] == "1"+++def test_shutdown_intent_missing_is_logged_not_ignored(monkeypatch, caplog):+ monkeypatch.setattr(main, "shutdown_intent_required", lambda: True)+ monkeypatch.setattr(main, "consume_shutdown_intent", lambda pid, signum: None)++ logger = logging.getLogger("test.shutdown")+ with caplog.at_level(logging.WARNING, logger=logger.name):+ main._log_shutdown_intent(logger, signal.SIGTERM)++ assert "honoring signal" in caplog.text+++def test_shutdown_signal_logging_is_lightweight(monkeypatch, caplog):+ monkeypatch.setattr(main.os, "getpid", lambda: 123)+ monkeypatch.setattr(main.os, "getppid", lambda: 1)+ monkeypatch.setattr(main.os, "getpgid", lambda pid: 123)+ monkeypatch.setattr(main.os, "getsid", lambda pid: 123)++ logger = logging.getLogger("test.shutdown")+ with caplog.at_level(logging.INFO, logger=logger.name):+ main._log_shutdown_signal(logger, signal.SIGTERM)++ assert "Received signal 15 pid=123 ppid=1 pgid=123 sid=123" in caplog.textdiff --git a/tests/test_vibe_cli.py b/tests/test_vibe_cli.pyindex 25b70714a..c09448e74 100644--- a/tests/test_vibe_cli.py+++ b/tests/test_vibe_cli.py@@ -431,9 +431,12 @@ def test_start_ui_replaces_stale_live_pid_when_health_check_fails(tmp_path, monkmonkeypatch.setattr(paths, "get_vibe_remote_dir", lambda: tmp_path / ".vibe_remote")runtime.ensure_dirs()paths.get_runtime_ui_pid_path().write_text("12345", encoding="utf-8")+ stopped = []monkeypatch.setattr(runtime, "pid_alive", lambda pid: pid == 12345)monkeypatch.setattr(runtime, "ui_server_healthy", lambda host, port: False)+ monkeypatch.setattr(runtime, "stop_pid", lambda pid: stopped.append(pid) or True)+ monkeypatch.setattr(runtime, "wait_for_ui_server", lambda host, port: True)def fake_spawn(args, pid_path, stdout_name, stderr_name, env=None):assert args[-1] == "from vibe.ui_server import run_ui_server; run_ui_server('127.0.0.1', 5123)"@@ -443,9 +446,22 @@ def test_start_ui_replaces_stale_live_pid_when_health_check_fails(tmp_path, monkmonkeypatch.setattr(runtime, "spawn_background", fake_spawn)assert runtime.start_ui("127.0.0.1", 5123) == 67890+ assert stopped == [12345]assert paths.get_runtime_ui_pid_path().read_text(encoding="utf-8") == "67890"+def test_start_ui_waits_for_replacement_health(tmp_path, monkeypatch):+ monkeypatch.setattr(paths, "get_vibe_remote_dir", lambda: tmp_path / ".vibe_remote")+ runtime.ensure_dirs()+ waited = []++ monkeypatch.setattr(runtime, "wait_for_ui_server", lambda host, port: waited.append((host, port)) or True)+ monkeypatch.setattr(runtime, "spawn_background", lambda *args, **kwargs: 67890)++ assert runtime.start_ui("127.0.0.1", 5123) == 67890+ assert waited == [("127.0.0.1", 5123)]++def test_ui_health_url_uses_loopback_for_wildcard_bind():assert runtime._ui_health_url("0.0.0.0", 5100) == "http://127.0.0.1:5100/health"assert runtime._ui_health_url("::", 5100) == "http://[::1]:5100/health"diff --git a/vibe/runtime.py b/vibe/runtime.pyindex 77a325609..d3a10fcc3 100644--- a/vibe/runtime.py+++ b/vibe/runtime.py@@ -489,6 +489,15 @@ def ui_server_healthy(host: str, port: int, timeout: float = 0.5) -> bool:return False+def wait_for_ui_server(host: str, port: int, timeout: float = 5.0) -> bool:+ deadline = time.monotonic() + timeout+ while time.monotonic() < deadline:+ if ui_server_healthy(host, port):+ return True+ time.sleep(0.1)+ return ui_server_healthy(host, port)++def resolve_localhost_family() -> str:"""Return the loopback family ``localhost`` actually maps to on this host.@@ -559,15 +568,25 @@ def start_ui(host, port):existing_pid = 0if existing_pid and pid_alive(existing_pid) and ui_server_healthy(host, port):return existing_pid+ if existing_pid and pid_alive(existing_pid):+ logger.warning(+ "Stopping stale UI process pid=%s because health check failed for %s",+ existing_pid,+ _ui_health_url(host, port),+ )+ stop_pid(existing_pid)pid_path.unlink(missing_ok=True)command = "from vibe.ui_server import run_ui_server; run_ui_server('{}', {})".format(host, port)- return spawn_background(+ pid = spawn_background([sys.executable, "-c", command],pid_path,"ui_stdout.log","ui_stderr.log",)+ if not wait_for_ui_server(host, port):+ logger.warning("Started UI pid=%s but health check did not pass for %s", pid, _ui_health_url(host, port))+ return piddef stop_service():