Skip to main content

Module github_rate_limit

Module github_rate_limit 

Source
Expand description

GitHub API rate-limit resolution for the daemon’s budget monitor (#1375).

The engine half of the rate-limit view, mirroring the crate::pr_status engine / crate::daemon::services::worktrees adapter split: this module is pure resolution — run gh api rate_limit, parse the reply, compute per-resource used-percentage — and knows nothing about the daemon, the socket, or the tray. The adapter owns the poll loop and surfaces the cached snapshot.

§Why this exists

The daemon’s worktrees PR-badge poller (crate::pr_status) shells out to gh, spending the same GitHub API budget as every other tool sharing the user’s gh token. When that consumption spikes the budget silently drains to zero and rate-limits gh machine-wide, with no visibility until commands start failing. This module lets the daemon watch the trend and warn before exhaustion.

§Why polling it is free

GitHub documents GET /rate_limit as not counting against your rate limit (confirmed empirically: consecutive gh api rate_limit calls leave core.used flat). So this monitor adds zero cost to the very budget it watches — the poller can run on a fixed cadence without a budget concern of its own.

§No credential enters the daemon

Resolution shells out to gh api rate_limit, so the GitHub token stays inside gh where the user already put it — exactly as the PR poller does (ADR-0050), following ADR-0003’s “shell out to gh/git for GitHub operations”.

Structs§

RateLimitCache
The poller-written, status/menu-read rate-limit snapshot cache.
RateLimitResource
One resource’s budget usage, parsed from a /rate_limit resources.<name> object.
RateLimitSnapshot
A parsed gh api rate_limit snapshot: the resources this monitor surfaces.

Constants§

WARN_PERCENT
The used-percentage at or above which a resource is treated as “high”.

Functions§

format_reset_utc
Formats a unix epoch as a HH:MMZ UTC clock time, e.g. 06:50Z. A zero or unparseable epoch renders ??:??Z rather than a misleading 00:00Z.
resolve_rate_limit_with
Resolves the current rate-limit snapshot in one gh api rate_limit call, using the gh at bin.