Skip to main content

Module github_counters

Module github_counters 

Source
Expand description

A DaemonService that periodically logs a summary of omni-dev’s GitHub API-call counters (#1387), and surfaces them in daemon status.

The counters themselves are recorded by crate::github_metrics::run_gh at every gh call site (across the daemon and one-shot CLI processes) as kind: "gh" request-log records. This service just reads them back and emits a tracing summary at three points, so there is a periodic footprint in the log and a clean before/after marker across restarts without anyone running a command:

  • ~5s after startup — a baseline once the pollers have come up.
  • every 10 minutes thereafter — a background task on a private CancellationToken, mirroring the worktrees poller shape.
  • once on shutdown — from shutdown, the deterministic, awaited flush that registry.shutdown_all() drives after the accept loop drains. That single hook covers SIGTERM / SIGINT / SIGHUP and the built-in shutdown op, since all of them funnel through the one shared token that ends the accept loop.

Every emission is best-effort and cheap, however large the request log has grown (it is unbounded unless rotation or prune is opted into). The service keeps a running IncrementalCounts from the moment it starts, so each summary reads only the records appended since the previous one, never the log’s history (#2132). A log that is replaced or truncated underneath it (prune, rotation) is rescanned once, from its first byte.

Shutdown never waits on a scan beyond SHUTDOWN_SCAN_BUDGET. A blocking thread cannot be cancelled from outside, and the runtime waits for one before the process may exit, so the scan itself polls a stop condition before every line: shutdown cancels it for every scan already in flight, and gives the final summary a deadline. A summary cut short says so rather than reporting a partial count as complete.

Structs§

GithubCountersService
Periodically logs, and reports on demand, the GitHub API-call counters.