scm-github plugin (32K lines) shells out to the gh CLI for all GitHub interactions — PR creation, CI checks, reviews, merge readiness. With multiple agents running in parallel, the 5,000 requests/hour limit is exhausted. No caching, no request coordination, no graceful degradation.| Scenario | Estimated API Calls |
|---|---|
| Single agent session (spawn, work, PR) | ~50-100 calls |
| 5 parallel agents | ~250-500 calls |
| Dashboard polling (5s interval, 10 sessions) | ~720/hr per metric |
| CI status checks (per PR) | ~60/hr per PR |
| Total (5 agents + dashboard) | ~2,000-4,000/hr |
scm-github/src/index.ts (32,165 bytes) — uses gh CLI via execFile() with 30s timeout and 10MB buffergh api, gh pr, gh issue commandstracker-github — separate plugin, also calls GitHub for issue trackinggh calls for PR/CI statuspackages/integration/ does NOT exist — there's no shared GitHub access layergh CLI manages its own auth and rate limiting, but AO has no visibility into it. Multiple plugins spawn independent gh processes with no coordination. When rate-limited, gh returns errors that AO doesn't handle gracefully. The fix requires either: (a) wrapping gh calls through a coordinator, or (b) migrating to Octokit for proper header-based rate limit tracking.Two approaches — choose based on scope appetite:
gh CLI (lower effort, faster)gh executor — all gh calls go through a single queue in packages/core/gh api rate_limit periodically to know remaining budgetgh command outputs with TTL. PR data (1min), CI status (15s), issue data (5min)gh CLI with Octokit in scm-github — direct HTTP with header-based rate limit tracking@octokit/plugin-throttling — built-in retry on 403/429 with backoffIf-None-Match headers. 304 responses don't count against limitX-RateLimit-Remaining from every responseexecFile("gh", ...) for every API callgh) for quick wins. Plan Option B (Octokit migration) as a separate task — it's a bigger refactor of the 32K-line scm-github plugin but gives proper rate limit control.| Source | What to learn |
|---|---|
| GitHub REST API Rate Limits | Official docs on limits, headers, best practices. Conditional requests are key. |
| Octokit + plugin-throttling | @octokit/plugin-throttling — handles 403 retries and abuse detection. Useful if migrating from gh CLI to Octokit (Option B). |
scm-github/src/index.ts | 32,165 bytes. Uses execFile("gh", [...]) for all GitHub calls. This is the primary consumer to wrap or migrate. |
tracker-github plugin | Second GitHub consumer — polls for issue updates. Also needs to route through centralized layer. |
packages/core/src/session-manager.ts | 82K bytes. Triggers GitHub calls for PR status, CI checks. Polling frequency is configurable but defaults are aggressive. |
gh CLI UsageGrep scm-github/src/index.ts and tracker-github for all execFile/execCli calls. Map which gh subcommands are used, how often, and from where. The file uses a helper execCli(bin, args, cwd) with 30s timeout.
gh ExecutorBuild packages/core/src/gh-executor.ts. All gh CLI calls route through this. Tracks rate limit via periodic gh api rate_limit checks. Queues requests by priority.
interface GhExecutor {
exec(args: string[], opts: { priority: 'high' | 'medium' | 'low'; cwd?: string }): Promise<string>;
getRemainingBudget(): { remaining: number; resetAt: Date };
getCacheStats(): { hits: number; misses: number };
}
In-memory LRU cache keyed by gh command + args. Cache stdout output with TTL per command type:
const CACHE_TTL = {
'gh api repos/*/issues': 5 * 60 * 1000, // 5 min
'gh pr view': 60 * 1000, // 1 min
'gh pr checks': 15 * 1000, // 15 sec
'gh api repos/*/commits': 10 * 60 * 1000, // 10 min
};
Priority queue with 3 levels: high (user-initiated: spawn, merge, PR create), medium (dashboard refresh), low (background polling, CI status checks). When remaining budget < 20%, pause low-priority requests. When < 5%, pause medium too.
Replace all execCli("gh", [...]) calls in scm-github/src/index.ts (32K lines) with ghExecutor.exec([...], { priority }). Biggest change — every function that calls gh needs to specify its priority level and accept cached responses.
Same treatment — route through centralized executor. Tracker polls frequently for issue updates; make it use cached responses and lower priority.
Show remaining API budget in dashboard header. Color-coded: green (>50%), yellow (20-50%), red (<20%). Click to expand and see per-consumer breakdown.
When rate-limited: show stale cached data with a "last updated X min ago" badge. Queue requests for when limit resets. Never show a raw 403 error to the user. Log rate limit events for debugging.