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(pr-delivery-loop): keep a forever PR watch alive through transient startup failures
Maxc0fce19e2733
diff --git a/.agents/skills/pr-delivery-loop/scripts/_github_wait_common.py b/.agents/skills/pr-delivery-loop/scripts/_github_wait_common.pyindex 5804c54df..1491ac9cd 100644--- a/.agents/skills/pr-delivery-loop/scripts/_github_wait_common.py+++ b/.agents/skills/pr-delivery-loop/scripts/_github_wait_common.py@@ -3,6 +3,7 @@from __future__ import annotations+import http.clientimport jsonimport mathimport os@@ -114,6 +115,13 @@ def _classify_github_exception(if isinstance(err, (urllib.error.URLError, TimeoutError, ConnectionError, OSError)):reason = str(getattr(err, "reason", err))return GitHubTransientError(f"GitHub network failure: {reason}")+ # `http.client` raises `HTTPException`, not `OSError`, when the transport+ # breaks mid-body: a large PR truncated by the peer surfaces as+ # `IncompleteRead`. It is a network failure like any other, and classifying it+ # terminal killed forever watches on a connection glitch they should have+ # simply re-polled through.+ if isinstance(err, http.client.HTTPException):+ return GitHubTransientError(f"GitHub network failure: {type(err).__name__}: {err}")return GitHubTerminalError(f"Unexpected GitHub request failure ({type(err).__name__}): {err}")diff --git a/.agents/skills/pr-delivery-loop/scripts/wait_pr.py b/.agents/skills/pr-delivery-loop/scripts/wait_pr.pyindex 07ae82d0e..5cebd12bc 100755--- a/.agents/skills/pr-delivery-loop/scripts/wait_pr.py+++ b/.agents/skills/pr-delivery-loop/scripts/wait_pr.py@@ -30,10 +30,12 @@ from _github_wait_common import ( # noqa: E402filter_new,get_token,GitHubProtocolError,+ GitHubRequestError,GitHubRequestResult,github_get,github_graphql,github_request,+ InitialRequestRetriesExhausted,LAST_DELIVERY_ENV,list_paginated,list_paginated_with_count,@@ -43,6 +45,7 @@ from _github_wait_common import ( # noqa: E402requests_per_poll,resolve_authenticated_login,ResponseCache,+ RETRY_EXIT_CODE,retry_initial_request,squash,WATCH_ID_ENV,@@ -878,6 +881,21 @@ def _write_new_pr_cursor_output(path: str | None, *, pr_cursor: int) -> None:json.dump({"pr_cursor": pr_cursor}, handle)+def _startup_failure_exit_code(error: GitHubRequestError) -> int:+ """How a failure *before* the first poll should end this run.++ Nothing has been observed yet, so no activity is lost by ending the run early.+ A transient failure that merely outlasted the bounded startup retries -- a+ truncated body on a large PR, a blip in the network -- must therefore exit+ ``RETRY_EXIT_CODE`` so a ``--forever`` watch re-arms itself instead of dying+ and leaving the PR unwatched until somebody notices. Genuinely terminal+ failures (a bad token, a PR that does not exist) still exit 1: retrying those+ would poll forever without ever succeeding.+ """++ return RETRY_EXIT_CODE if isinstance(error, InitialRequestRetriesExhausted) else 1++def _watch_identity(args: argparse.Namespace) -> str:"""A stable digest of the options that decide what this watch reports.@@ -1710,7 +1728,7 @@ def main() -> int:)if viewer_result.error is not None:print(f"GitHub viewer lookup failed: {viewer_result.error}", file=sys.stderr)- return 1+ return _startup_failure_exit_code(viewer_result.error)viewer_login = viewer_result.valueif not viewer_login:print(@@ -1725,7 +1743,7 @@ def main() -> int:)if target_result.error is not None:print(f"GitHub target validation failed: {target_result.error}", file=sys.stderr)- return 1+ return _startup_failure_exit_code(target_result.error)if target_result.value is None:print("GitHub target validation completed without a result", file=sys.stderr)return 1@@ -1819,7 +1837,7 @@ def main() -> int:)if initial_request.error is not None:print(f"Failed to fetch initial PR state: {initial_request.error}", file=sys.stderr)- return 1+ return _startup_failure_exit_code(initial_request.error)if initial_request.value is None:print("Initial GitHub request completed without a result", file=sys.stderr)return 1diff --git a/.agents/skills/pr-delivery-loop/tests/test_wait_pr.py b/.agents/skills/pr-delivery-loop/tests/test_wait_pr.pyindex f174dda6a..1126df973 100644--- a/.agents/skills/pr-delivery-loop/tests/test_wait_pr.py+++ b/.agents/skills/pr-delivery-loop/tests/test_wait_pr.py@@ -3,6 +3,7 @@from __future__ import annotationsimport ast+import http.clientimport importlib.utilimport jsonimport sys@@ -1069,3 +1070,43 @@ def test_github_request_taxonomy_is_the_only_exception_boundary():assert violations == []assert urlopen_sites == [(COMMON_SCRIPT.name, "_read_github_json")]+++def test_a_truncated_response_body_is_classified_transient() -> None:+ """`http.client` failures are not `OSError`, and a large PR truncates mid-body.++ Classifying `IncompleteRead` terminal killed a `--forever` watch on a+ connection glitch it should have re-polled through.+ """++ error = github_wait_common._classify_github_exception(+ http.client.IncompleteRead(b"partial", 64785)+ )++ assert error.retryable is True+ assert "IncompleteRead" in str(error)+++def test_a_protocol_violation_stays_terminal() -> None:+ error = github_wait_common._classify_github_exception(ValueError("not json"))++ assert error.retryable is False+++ ("error", "expected"),+ [+ (github_wait_common.InitialRequestRetriesExhausted("network kept failing"), 75),+ (github_wait_common.GitHubTerminalError("GitHub HTTP 404 Not Found"), 1),+ (github_wait_common.GitHubProtocolError("unexpected payload"), 1),+ ],+)+def test_startup_failures_only_re_arm_a_forever_watch_when_transient(error, expected: int) -> None:+ """Nothing was observed yet, so exiting early loses no activity.++ A transient failure that outlasted the bounded startup retries has to exit+ ``RETRY_EXIT_CODE`` or the watch dies and leaves the PR unwatched; a bad token+ or a missing PR must still exit 1 rather than poll forever.+ """++ assert wait_pr._startup_failure_exit_code(error) == expected