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): fail fast before waiting

cyhb5b079629a84
diff --git a/skills/background-watch-hook/scripts/wait_for_github_pr_activity.py b/skills/background-watch-hook/scripts/wait_for_github_pr_activity.py
index 60806bad6..d80a15c20 100755
--- a/skills/background-watch-hook/scripts/wait_for_github_pr_activity.py
+++ b/skills/background-watch-hook/scripts/wait_for_github_pr_activity.py
@@ -13,6 +13,7 @@ import time
import urllib.error
import urllib.parse
import urllib.request
+from math import ceil
from typing import Any
@@ -39,10 +40,9 @@ def _get_token() -> str | None:
return token or None
-def _min_interval_for_unauthenticated() -> float:
- # Each poll performs three API requests. Keep unauthenticated usage at or below
- # GitHub's 60 requests/hour ceiling with a small safety margin.
- return 180.0
+def _min_interval_for_unauthenticated(requests_per_poll: int) -> float:
+ # Keep unauthenticated usage at or below GitHub's 60 requests/hour ceiling.
+ return float(max(requests_per_poll, 1) * 60)
def _github_get(url: str, token: str | None) -> Any:
@@ -137,6 +137,13 @@ def _fetch_state(repo: str, pr_number: int, token: str | None) -> dict[str, list
}
+def _requests_per_poll(state: dict[str, list[dict[str, Any]]]) -> int:
+ requests = 0
+ for key in ("reviews", "review_comments", "issue_comments"):
+ requests += max(1, ceil(len(state[key]) / 100))
+ return requests
+
+
def _render_activity(
*,
repo: str,
@@ -215,18 +222,6 @@ def main() -> int:
return 2
effective_interval = max(args.interval, 1.0)
- if token is None:
- unauthenticated_min = _min_interval_for_unauthenticated()
- if effective_interval < unauthenticated_min:
- print(
- (
- "No GitHub token detected; clamping polling interval from %.1fs to %.1fs "
- "to avoid unauthenticated rate-limit lockout."
- )
- % (effective_interval, unauthenticated_min),
- file=sys.stderr,
- )
- effective_interval = unauthenticated_min
start = time.monotonic()
@@ -239,6 +234,20 @@ def main() -> int:
print(f"Failed to fetch initial PR state: {err}", file=sys.stderr)
return 1
+ if token is None:
+ requests_per_poll = _requests_per_poll(state)
+ unauthenticated_min = _min_interval_for_unauthenticated(requests_per_poll)
+ if effective_interval < unauthenticated_min:
+ print(
+ (
+ "No GitHub token detected; clamping polling interval from %.1fs to %.1fs "
+ "for %s request(s) per poll to avoid unauthenticated rate-limit lockout."
+ )
+ % (effective_interval, unauthenticated_min, requests_per_poll),
+ file=sys.stderr,
+ )
+ effective_interval = unauthenticated_min
+
review_cursor = (
args.since_review_id
if args.since_review_id is not None
@@ -301,6 +310,20 @@ def main() -> int:
print(f"Polling failed: {err}", file=sys.stderr)
continue
+ if token is None:
+ requests_per_poll = _requests_per_poll(state)
+ unauthenticated_min = _min_interval_for_unauthenticated(requests_per_poll)
+ if effective_interval < unauthenticated_min:
+ print(
+ (
+ "GitHub unauthenticated polling now needs %.1fs minimum for %s request(s) "
+ "per poll; increasing interval."
+ )
+ % (unauthenticated_min, requests_per_poll),
+ file=sys.stderr,
+ )
+ effective_interval = unauthenticated_min
+
output, review_cursor, review_comment_cursor, issue_comment_cursor = _render_activity(
repo=args.repo,
pr_number=args.pr,
diff --git a/skills/background-watch-hook/scripts/watch_then_hook.sh b/skills/background-watch-hook/scripts/watch_then_hook.sh
index 8b6b1cbf1..3e222a3f2 100755
--- a/skills/background-watch-hook/scripts/watch_then_hook.sh
+++ b/skills/background-watch-hook/scripts/watch_then_hook.sh
@@ -91,6 +91,11 @@ if [[ $# -eq 0 ]]; then
exit 2
fi
+if [[ -n "$post_to" && "$post_to" != "thread" && "$post_to" != "channel" ]]; then
+ echo "--post-to must be either 'thread' or 'channel'" >&2
+ exit 2
+fi
+
if [[ -n "$post_to" && -n "$deliver_key" ]]; then
echo "--post-to and --deliver-key are mutually exclusive" >&2
exit 2
@@ -176,6 +181,8 @@ _run_hook_command() {
"$hook_cmd_prefix" "${hook_args[@]}"
}
+hook_runner="$(_resolve_hook_command)"
+
set +e
"$@" >"$output_file"
waiter_status=$?
@@ -207,7 +214,6 @@ fi
fi
} >"$prompt_file"
-hook_runner="$(_resolve_hook_command)"
hook_args=(hook send --session-key "$session_key" --prompt-file "$prompt_file")
if [[ -n "$post_to" ]]; then
hook_args+=(--post-to "$post_to")