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(watch): clamp action polling by request count

cyhec2d63488fe8
diff --git a/skills/background-watch-hook/scripts/wait_action.py b/skills/background-watch-hook/scripts/wait_action.py
index 1d7ae166c..4ed2ce37b 100755
--- a/skills/background-watch-hook/scripts/wait_action.py
+++ b/skills/background-watch-hook/scripts/wait_action.py
@@ -214,19 +214,7 @@ def main() -> int:
success_conclusions = _parse_success_conclusions(args.success_conclusion)
start = time.monotonic()
selected: dict[str, dict[str, Any] | None] = {workflow: None for workflow in args.workflow}
-
- if token is None:
- unauthenticated_min = min_interval_for_unauthenticated(1, bootstrap_requests=1)
- 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
+ first_successful_fetch = True
print(
(
@@ -241,7 +229,7 @@ def main() -> int:
first_poll = poll_attempt == 0
poll_attempt += 1
try:
- runs, _request_count = _fetch_workflow_runs(
+ runs, request_count = _fetch_workflow_runs(
args.repo,
token,
branch=args.branch,
@@ -271,6 +259,33 @@ def main() -> int:
except Exception as err: # noqa: BLE001
print(f"Polling failed: {err}", file=sys.stderr)
runs = []
+ request_count = 0
+
+ if token is None and request_count > 0:
+ bootstrap_requests = request_count if first_successful_fetch else 0
+ unauthenticated_min = min_interval_for_unauthenticated(
+ request_count,
+ bootstrap_requests=bootstrap_requests,
+ )
+ target_interval = max(base_interval, unauthenticated_min)
+ if target_interval != effective_interval:
+ direction = "increasing" if target_interval > effective_interval else "reducing"
+ print(
+ (
+ "GitHub unauthenticated polling uses %s request(s) per poll plus "
+ "%s bootstrap request(s); %s interval from %.1fs to %.1fs."
+ )
+ % (
+ request_count,
+ bootstrap_requests,
+ direction,
+ effective_interval,
+ target_interval,
+ ),
+ file=sys.stderr,
+ )
+ effective_interval = target_interval
+ first_successful_fetch = False
if runs:
selected = _select_latest_runs_by_workflow(
diff --git a/tests/test_wait_for_github_action_runs.py b/tests/test_wait_for_github_action_runs.py
index 60ce687fd..9c256fc02 100644
--- a/tests/test_wait_for_github_action_runs.py
+++ b/tests/test_wait_for_github_action_runs.py
@@ -242,6 +242,79 @@ def test_main_requires_authentication_by_default() -> None:
assert rc == 2
+def test_main_uses_real_request_count_for_unauthenticated_interval() -> None:
+ module = _load_module()
+ calls = 0
+ sleep_intervals: list[float] = []
+
+ def _fake_fetch_workflow_runs(repo, token, *, branch=None, head_sha=None, max_pages=3):
+ nonlocal calls
+ calls += 1
+ if calls == 1:
+ return (
+ [
+ {
+ "id": 1,
+ "name": "CI",
+ "head_sha": "abc123",
+ "head_branch": "main",
+ "status": "in_progress",
+ "conclusion": None,
+ }
+ ],
+ 3,
+ )
+ return (
+ [
+ {
+ "id": 1,
+ "name": "CI",
+ "head_sha": "abc123",
+ "head_branch": "main",
+ "status": "completed",
+ "conclusion": "success",
+ "html_url": "https://github.com/example/actions/runs/1",
+ }
+ ],
+ 3,
+ )
+
+ def _fake_sleep(seconds):
+ sleep_intervals.append(seconds)
+
+ stdout = io.StringIO()
+ with (
+ patch.object(module, "get_token", return_value=None),
+ patch.object(module, "_fetch_workflow_runs", side_effect=_fake_fetch_workflow_runs),
+ patch.object(module, "min_interval_for_unauthenticated", return_value=240.0) as min_interval,
+ patch.object(module.time, "sleep", side_effect=_fake_sleep),
+ patch(
+ "sys.argv",
+ [
+ "wait_action.py",
+ "--repo",
+ "cyhhao/sub2api",
+ "--branch",
+ "main",
+ "--sha",
+ "abc123",
+ "--workflow",
+ "CI",
+ "--interval",
+ "1",
+ "--allow-unauthenticated",
+ ],
+ ),
+ redirect_stdout(stdout),
+ ):
+ rc = module.main()
+
+ assert rc == 0
+ min_interval.assert_any_call(3, bootstrap_requests=3)
+ assert sleep_intervals == [240.0]
+ assert "GitHub Actions success" in stdout.getvalue()
+
+
def test_main_retryable_startup_http_error_returns_retry_code() -> None:
module = _load_module()
err = urllib.error.HTTPError(