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(skills): normalize timeout comparisons

cyhfd7353936cd3
diff --git a/skills/background-watch-hook/scripts/watch_github_pr_then_hook.sh b/skills/background-watch-hook/scripts/watch_github_pr_then_hook.sh
index eb89465b2..2103f397c 100755
--- a/skills/background-watch-hook/scripts/watch_github_pr_then_hook.sh
+++ b/skills/background-watch-hook/scripts/watch_github_pr_then_hook.sh
@@ -59,6 +59,21 @@ hook_bin=""
hook_cmd=""
timeout_exit_code=""
+normalize_nonnegative_number() {
+ python3 - "$1" <<'PY'
+import math
+import sys
+
+value = float(sys.argv[1])
+if not math.isfinite(value) or value < 0:
+ raise SystemExit(1)
+if value.is_integer():
+ print(int(value))
+else:
+ print(value)
+PY
+}
+
while [[ $# -gt 0 ]]; do
case "$1" in
--session-key)
@@ -168,6 +183,18 @@ if [[ -n "$timeout_exit_code" && "$timeout_exit_code" != "124" ]]; then
exit 2
fi
+if [[ -z "$timeout" ]]; then
+ timeout="21600"
+fi
+if ! timeout="$(normalize_nonnegative_number "$timeout")"; then
+ echo "--timeout must be a finite number >= 0" >&2
+ exit 2
+fi
+if ! lifetime_timeout="$(normalize_nonnegative_number "$lifetime_timeout")"; then
+ echo "--lifetime-timeout must be a finite number >= 0" >&2
+ exit 2
+fi
+
if [[ "$forever" -ne 1 && "$lifetime_timeout" != "0" ]]; then
echo "--lifetime-timeout requires --forever" >&2
exit 2
@@ -183,10 +210,6 @@ if [[ ! -x "$WAITER" ]]; then
exit 127
fi
-if [[ -z "$timeout" ]]; then
- timeout="21600"
-fi
-
if [[ -z "$prefix" ]]; then
prefix="GitHub PR #$pr has new review activity. Fetch the latest review state, summarize actionable items, and continue handling them if needed."
fi
diff --git a/skills/background-watch-hook/scripts/watch_then_hook.sh b/skills/background-watch-hook/scripts/watch_then_hook.sh
index 949459725..38fdfc2e2 100755
--- a/skills/background-watch-hook/scripts/watch_then_hook.sh
+++ b/skills/background-watch-hook/scripts/watch_then_hook.sh
@@ -40,6 +40,21 @@ hook_bin="${VIBE_HOOK_BIN:-}"
hook_cmd_override="${VIBE_HOOK_CMD:-}"
timeout_exit_code=124
+normalize_nonnegative_number() {
+ python3 - "$1" <<'PY'
+import math
+import sys
+
+value = float(sys.argv[1])
+if not math.isfinite(value) or value < 0:
+ raise SystemExit(1)
+if value.is_integer():
+ print(int(value))
+else:
+ print(value)
+PY
+}
+
while [[ $# -gt 0 ]]; do
case "$1" in
--session-key)
@@ -120,6 +135,11 @@ if [[ -n "$post_to" && -n "$deliver_key" ]]; then
exit 2
fi
+if ! timeout_seconds="$(normalize_nonnegative_number "$timeout_seconds")"; then
+ echo "--timeout must be a finite number >= 0" >&2
+ exit 2
+fi
+
script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
output_file="$(mktemp)"
diff --git a/tests/test_background_watch_hook_scripts.py b/tests/test_background_watch_hook_scripts.py
index 44adbcfed..f4ae916f6 100644
--- a/tests/test_background_watch_hook_scripts.py
+++ b/tests/test_background_watch_hook_scripts.py
@@ -307,6 +307,127 @@ PY
assert payload["args"][:2] == ["hook", "send"]
+def test_watch_then_hook_treats_timeout_zero_point_zero_as_no_timeout(tmp_path: Path) -> None:
+ source_script = (
+ Path(__file__).resolve().parents[1]
+ / "skills"
+ / "background-watch-hook"
+ / "scripts"
+ / "watch_then_hook.sh"
+ )
+ script_dir = tmp_path / "scripts"
+ script_dir.mkdir()
+
+ watch_script = script_dir / "watch_then_hook.sh"
+ shutil.copy2(source_script, watch_script)
+ watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)
+
+ hook_calls = tmp_path / "hook-calls.jsonl"
+ fake_hook = tmp_path / "fake-hook"
+ fake_hook.write_text(
+ f"""#!/usr/bin/env bash
+set -euo pipefail
+
+if [[ "${{1:-}}" == "hook" && "${{2:-}}" == "send" && "${{3:-}}" == "--help" ]]; then
+ echo "--session-key"
+ echo "Queue one asynchronous turn"
+ exit 0
+fi
+
+python3 - <<'PY' "{str(hook_calls)}" "$@"
+import json
+import sys
+from pathlib import Path
+
+path = Path(sys.argv[1])
+args = sys.argv[2:]
+with path.open("a", encoding="utf-8") as handle:
+ handle.write(json.dumps({{"args": args}}) + "\\n")
+PY
+""",
+ encoding="utf-8",
+ )
+ fake_hook.chmod(fake_hook.stat().st_mode | stat.S_IXUSR)
+
+ result = subprocess.run(
+ [
+ "bash",
+ str(watch_script),
+ "--foreground",
+ "--session-key",
+ "slack::channel::C123",
+ "--hook-bin",
+ str(fake_hook),
+ "--timeout",
+ "0.0",
+ "--",
+ "bash",
+ "-lc",
+ "sleep 0.05; echo waiter output",
+ ],
+ cwd=tmp_path,
+ capture_output=True,
+ text=True,
+ check=False,
+ timeout=10,
+ env={**os.environ, "PATH": os.environ.get("PATH", "")},
+ )
+
+ assert result.returncode == 0, result.stderr
+ payload = json.loads(hook_calls.read_text(encoding="utf-8").splitlines()[-1])
+ assert payload["args"][:2] == ["hook", "send"]
+
+
+def test_forever_watch_accepts_lifetime_timeout_zero_point_zero_without_forever_error(tmp_path: Path) -> None:
+ source_script = (
+ Path(__file__).resolve().parents[1]
+ / "skills"
+ / "background-watch-hook"
+ / "scripts"
+ / "watch_github_pr_then_hook.sh"
+ )
+ script_dir = tmp_path / "scripts"
+ script_dir.mkdir()
+
+ watch_script = script_dir / "watch_github_pr_then_hook.sh"
+ shutil.copy2(source_script, watch_script)
+ watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)
+
+ _make_executable(
+ script_dir / "watch_then_hook.sh",
+ "#!/usr/bin/env bash\nset -euo pipefail\nexit 0\n",
+ )
+ _make_executable(
+ script_dir / "wait_for_github_pr_activity.py",
+ "#!/usr/bin/env python3\nprint('done')\n",
+ )
+
+ result = subprocess.run(
+ [
+ "bash",
+ str(watch_script),
+ "--foreground",
+ "--session-key",
+ "slack::channel::C123",
+ "--repo",
+ "cyhhao/vibe-remote",
+ "--pr",
+ "153",
+ "--lifetime-timeout",
+ "0.0",
+ ],
+ cwd=tmp_path,
+ capture_output=True,
+ text=True,
+ check=False,
+ timeout=10,
+ env={**os.environ, "PATH": os.environ.get("PATH", "")},
+ )
+
+ assert result.returncode == 0, result.stderr
+ assert "--lifetime-timeout requires --forever" not in result.stderr
+
+
def test_forever_watch_exits_on_non_retryable_cycle_failure(tmp_path: Path) -> None:
source_script = (
Path(__file__).resolve().parents[1]