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(watch): preserve zero settings and kill cancelled waiters
cyh0baed63a4436
diff --git a/core/watches.py b/core/watches.pyindex 0b0411060..b15110d1f 100644--- a/core/watches.py+++ b/core/watches.py@@ -30,6 +30,12 @@ def _path_signature(path: Path) -> Optional[tuple[int, int, int]]:return (stat.st_mtime_ns, stat.st_size, stat.st_ino)+def _payload_float(payload: dict[str, Any], key: str, default: float) -> float:+ if key not in payload or payload.get(key) is None:+ return default+ return float(payload[key])++@dataclassclass ManagedWatch:id: str@@ -69,10 +75,10 @@ class ManagedWatch:prefix=(str(payload["prefix"]).strip() if payload.get("prefix") else None) or None,cwd=(str(payload["cwd"]).strip() if payload.get("cwd") else None) or None,mode=str(payload.get("mode") or "once"),- timeout_seconds=float(payload.get("timeout_seconds") or 21600.0),- lifetime_timeout_seconds=float(payload.get("lifetime_timeout_seconds") or 0.0),+ timeout_seconds=_payload_float(payload, "timeout_seconds", 21600.0),+ lifetime_timeout_seconds=_payload_float(payload, "lifetime_timeout_seconds", 0.0),retry_exit_codes=[int(code) for code in (payload.get("retry_exit_codes") or [1])],- retry_delay_seconds=float(payload.get("retry_delay_seconds") or 30.0),+ retry_delay_seconds=_payload_float(payload, "retry_delay_seconds", 30.0),post_to=payload.get("post_to"),deliver_key=payload.get("deliver_key"),enabled=bool(payload.get("enabled", True)),@@ -465,6 +471,10 @@ class ManagedWatchService:else:stdout, stderr = await process.communicate()timed_out = False+ except asyncio.CancelledError:+ process.kill()+ await process.communicate()+ raiseexcept asyncio.TimeoutError:process.kill()stdout, stderr = await process.communicate()diff --git a/tests/test_watches.py b/tests/test_watches.pyindex c6f3bcb11..0c2efb136 100644--- a/tests/test_watches.py+++ b/tests/test_watches.py@@ -2,10 +2,13 @@ from __future__ import annotationsimport asyncioimport json+import osimport sysfrom pathlib import Pathfrom types import SimpleNamespace+import pytest+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))from core.scheduled_tasks import TaskExecutionStore@@ -42,6 +45,33 @@ def test_managed_watch_store_round_trip(tmp_path: Path) -> None:assert saved.post_to == "channel"+def test_managed_watch_store_preserves_zero_values_on_reload(tmp_path: Path) -> None:+ store = ManagedWatchStore(tmp_path / "watches.json")+ watch = store.add_watch(+ name="Watch Zero",+ session_key="slack::channel::C123",+ command=["python3", "wait.py"],+ shell_command=None,+ prefix=None,+ cwd=None,+ mode="forever",+ timeout_seconds=0,+ lifetime_timeout_seconds=0,+ retry_exit_codes=[1],+ retry_delay_seconds=0,+ post_to=None,+ deliver_key=None,+ )++ reloaded = ManagedWatchStore(store.path)+ saved = reloaded.get_watch(watch.id)++ assert saved is not None+ assert saved.timeout_seconds == 0+ assert saved.lifetime_timeout_seconds == 0+ assert saved.retry_delay_seconds == 0++def test_managed_watch_service_once_success_enqueues_hook_and_disables(tmp_path: Path) -> None:store = ManagedWatchStore(tmp_path / "watches.json")request_store = TaskExecutionStore(tmp_path / "task_requests")@@ -129,3 +159,47 @@ def test_managed_watch_service_forever_timeout_is_silent_per_cycle(tmp_path: Patassert saved is not Noneassert saved.enabled is Trueassert saved.last_exit_code == 124+++def test_managed_watch_service_stop_terminates_running_waiter(tmp_path: Path) -> None:+ store = ManagedWatchStore(tmp_path / "watches.json")+ request_store = TaskExecutionStore(tmp_path / "task_requests")+ runtime_store = WatchRuntimeStateStore(tmp_path / "watch_runtime.json")+ watch = store.add_watch(+ name="Wait forever",+ session_key="slack::channel::C123",+ command=["python3", "-c", "import time; time.sleep(30)"],+ shell_command=None,+ prefix=None,+ cwd=None,+ mode="forever",+ timeout_seconds=0,+ lifetime_timeout_seconds=0,+ retry_exit_codes=[1],+ retry_delay_seconds=0.01,+ post_to=None,+ deliver_key=None,+ )+ service = ManagedWatchService(+ controller=SimpleNamespace(),+ store=store,+ request_store=request_store,+ runtime_store=runtime_store,+ )++ async def _run() -> int:+ service.start()+ for _ in range(100):+ pid = service._active_pids.get(watch.id)+ if pid:+ break+ await asyncio.sleep(0.02)+ else:+ raise AssertionError("waiter pid was never recorded")+ await service.stop()+ return pid++ pid = asyncio.run(_run())++ with pytest.raises(ProcessLookupError):+ os.kill(pid, 0)