Skip to content

feat(cli): correct secondary-limit backoff and retry-after handling in run_gh #705

Closed

Description

@dan-petty

Context & Rationale

run_gh (src/devops_cli/github/rate_limiter.py:1646) is already the single gh seam, with quota-derived pacing, a read cache and a retry loop. calculate_backoff_delay (:1013) never checks remaining: whenever a future reset is tracked it sleeps until the primary reset, and one almost always is, because missing or stale state is refreshed before a request is paced (:711). Otherwise it retries after 2 to 5 s with no secondary floor. Retry-After is never parsed (:562), and the only tracked-reset test (tests/test_github_rate_limiter.py:791) uses remaining=0. AGENTS.md's 'Zero Bare gh Invocations' claims jittered secondary backoff, and nothing enforces its bare-gh ban. The httpx2 GraphQL path raises on 403/429 (graphql.py:780). vibes records a 20-PR triage stalled for an hour by a retry loop.

Scope & Deliverables

  • Context & Rationale*: run_gh (src/devops_cli/github/rate_limiter.py:1646) is already the single gh seam, with quota-derived pacing, a read cache and a retry loop. calculate_backoff_delay (:1013) never checks remaining: whenever a future reset is tracked it sleeps until the primary reset, and one almost always is, because missing or stale state is refreshed before a request is paced (:711). Otherwise it retries after 2 to 5 s with no secondary floor. Retry-After is never parsed (:562), and the only tracked-reset test (tests/test_github_rate_limiter.py:791) uses remaining=0. AGENTS.md's 'Zero Bare gh Invocations' claims jittered secondary backoff, and nothing enforces its bare-gh ban. The httpx2 GraphQL path raises on 403/429 (graphql.py:780). vibes records a 20-PR triage stalled for an hour by a retry loop.
  • Deliverable*: PR1 (the P0): classify primary (remaining zero), secondary and Retry-After. Wait for the reset only on a primary limit. On a secondary limit wait a configured floor (default 60 s, PyGithub GithubRetry's DEFAULT_SECONDARY_RATE_WAIT, as client.py:42 gets), then tenacity wait_random_exponential under a local cap. Return a server Retry-After unchanged. Declare tenacity in pyproject.toml (today only transitive), and do not reuse pydantic_ai's wait_retry_after, which clamps. Add throttle and wait counters to the persisted quota meta (_save_disk_quota) so devops gh rate-limit, a separate process, shows them. Correct the AGENTS.md sentence. P1 follow-ups: route GraphQL 403/429 through the same classifier via the existing HTTPX2TenacityTransport seam, and add an AST invariant to tests/test_architectural_invariants.py allowlisting only devcontainer.py's gh auth token and gh auth login --with-token (credential migration, no API quota). P2: replace ratelimit (:54) and the hardcoded AsyncLimiter(max_rate=60, time_period=60) (:650), both contradicting the docstring at :6, with one configured pyrate-limiter ceiling (sync and async). Pre-flight bulk budgeting stays with Proportional API Rate Budgeting & GraphQL Circuit Breaker Guard.
  • Constraint*: Clamping to min(retry_after, cap) retries early and turns a primary limit into a secondary one; sleeping silently through the primary window looks like a hang. When the required wait exceeds a configured maximum, raise GitHubRateLimitError stating the wait and reset time, as GithubRetry's max_rate_limit_wait does when set (it defaults to None). Two tests pin both halves: a server Retry-After is returned unchanged, and the local cap bounds only the client's own growth; the remaining=0 test keeps passing. The invariant must be AST-based: grep flags docstrings and cannot tell whether a command list reaches run_gh or a raw subprocess.
  • Measured*: uv run python probe/rewrite_backoff.py: after update_quota('core', remaining=4999, limit=5000, reset_epoch=now+3000), calculate_backoff_delay on a secondary-limit message returns 3000.0 s. Same probe with no tracked quota: attempt 1 waits 2.2–3.0 s, attempt 2 waits 4.2–5.0 s. grep -n -A6 '^name = "ratelimit"' uv.lock: 2.2.1, upload-time 2018-12-17.
  • Source*: vibes observations/devops-cli/06-rate-limits-and-anti-brittle-heuristics.md, vibes examples/fastmcp-token-bucket-gateway/README.md, vibes examples/fastmcp-token-bucket-gateway/gateway.py, vibes examples/fastmcp-token-bucket-gateway/test_gateway.py

Strategic Alignment

  • Milestone: v0.2.24 (Reactive Workstation Command Center, Interactive TUI & Unified Operations Hub)
  • Roadmap Reference: docs/ROADMAP.md

Activity

  1. added this to the v0.2.24 milestone on Sep 28, 2026
  2. added
    type/feature
    scope/cli
    priority/p0-critical
    on Sep 28, 2026
  3. dan-petty commented on Sep 28, 2026

    @dan-petty
    OwnerAuthor

    Resolved and verified via PR #714 into release/v0.2.24 (commit 3359e36).

  4. added a commit that references this issue on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p0-criticalscope/clitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions