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§
- Rate
Limit Cache - The poller-written, status/menu-read rate-limit snapshot cache.
- Rate
Limit Resource - One resource’s budget usage, parsed from a
/rate_limitresources.<name>object. - Rate
Limit Snapshot - A parsed
gh api rate_limitsnapshot: 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:MMZUTC clock time, e.g.06:50Z. A zero or unparseable epoch renders??:??Zrather than a misleading00:00Z. - resolve_
rate_ limit_ with - Resolves the current rate-limit snapshot in one
gh api rate_limitcall, using theghatbin.