Skip to content

Host daemon PR status reads exhaust the GitHub GraphQL hourly limit #5704

Description

@amrtawfik160

What happens

On one host, the BB host daemon spends most of the GitHub GraphQL hourly allowance (5,000 points) by re-reading pull request status. When the allowance runs out, every other gh user on the host (agents opening or merging PRs, plugins) fails with GraphQL: API rate limit already exceeded.

Evidence (BB 0.45.0, Linux host, about 60 active threads across 19 GitHub repositories)

  • A 30-second process sample showed the host daemon (host-daemon/dist/daemon-bundle.mjs) running this command 22 times:
    gh pr view --json number,title,state,url,isDraft,autoMergeRequest,baseRefName,headRefName,updatedAt,statusCheckRollup,reviewDecision,reviewRequests,mergeStateStatus,mergeable
    plus several gh api graphql queries per PR for isInMergeQueue.
  • That rate is about 2,600 PR reads per hour from the daemon alone; each read costs at least 1 GraphQL point, and statusCheckRollup can cost more.
  • The GraphQL rate-limit headers on real responses fell from 4,116 to 3,709 remaining in 223 seconds (about 6,500 points per hour for the host).
  • gh api rate_limit reported a different, higher remaining value at the same moment, so tools that rely on it underestimate usage.
  • Turning a third-party plugin off did not lower the daemon's read rate.

Expected

PR status reads should stay well under the shared hourly allowance, whatever the number of threads. For example:

  1. Read only PRs of threads that are open and visible (or that changed recently).
  2. Use the REST pulls list with ETags (conditional 304 responses do not count) to detect changes, and read details only for PRs that changed.
  3. Back off when the x-ratelimit-remaining header of a GraphQL response is low, and leave a reserve for user actions (create, merge).
  4. Coalesce duplicate reads of the same PR.

Impact

Agents fail to open, check or merge PRs for the rest of the hour, and plugins that also need GitHub stop working.

Activity

  1. added theissue type on Oct 17, 2026
  2. added
    host
    github
    partial-repro
    on Oct 17, 2026
  3. bb-slop-cop commented on Oct 17, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority High · Effort Medium. Area/plugin labels: host, perf, github.
    • Reproduction and root-cause report: PARTIALLY REPRODUCED, with high confidence in the request-amplification mechanism. Reproduction label: partial-repro.
    • Root cause: The 10-second, per-environment cache does not bound aggregate traffic. Each uncached open, non-draft PR lookup runs a detail read plus a separate merge-queue query, without a shared quota cooldown.
    • Evidence: The same offline test in two clean trusted-main checkouts produced 7,200 detail reads + 7,200 queue queries for 60 environments over one simulated hour. Same-environment coalescing works; cross-environment duplication and retries after synthetic quota exhaustion reproduce. Actual GraphQL point consumption and the original request initiator remain unverified. Existing host-workspace and cache tests pass.
    • No PR: A safe shared-budget fix requires a freshness/reserve policy decision, exceeding the simple-fix gate; increasing a fixed TTL would leave traffic unbounded as environment count grows.

    AGENT GENERATED

  4. cameronm123 commented on Nov 24, 2026

    @cameronm123

    Reproduced in production on BB 0.50.1 (macOS host + 4 connected remote hosts, cameronm123). This fills in the two gaps noted in the triage report: the exact GraphQL point consumption and the request initiator.

    Measured GraphQL cost (rateLimit(dryRun: true))

    In builtin-plugins/github-pr-status/dist/host.js, kind: "branch" queries pullRequests(headRefName: ..., first: 100) with nested reviewRequests(first: 100) and commits(last: 1) { statusCheckRollup { contexts(first: 100) } }:

    Query shape Batch size Static nodeCount Measured cost
    Current (first: 100 / 100 / 100) 1 env 20,200 3 pts
    Current (first: 100 / 100 / 100) 10 envs 202,000 30 pts
    Current (first: 100 / 100 / 100) 24 envs (500k cap) 484,800 72 pts
    Tightened (first: 5 / 10 / 50) 24 envs 7,440 4 pts (18× cheaper)

    Every absent or settled environment costs 3 GraphQL points, even on main with 0 PRs.

    Root cause & request initiator on BB 0.50.1

    1. Background plugin caller + 10s non-viewer TTL (server.js → createPullRequestStore().read):
      • Browser clients (viewer: true) use staleAfterMs: 30s (open PR), 5m (absent), 1h (merged/closed).
      • Non-client callers (viewer: false, e.g. plugins calling pullRequests / environments.pullRequest like bb-sidebar's */5 * * * * auto-settle cron) hit a hardcoded 10s (1e4) TTL.
      • Every 5-minute background sweep therefore misses the cache on 100% of checked environments. In a live 5-minute sweep across 979 ready git environments (before patching bb-sidebar), bb--github-pr-status logged +1,100 handler calls and burned 1,193+ GraphQL points in ~2.5 minutes (~13,000–16,000+ pts/hr demand against the 5,000 pts/hr limit; 1.24M total calls over 95h uptime).
    2. Merged/closed PRs force branch queries (server.js → prepareLoad):
      • When isSettled(envId) is true (merged or closed), prepareLoad sets known: null, forcing a 3 pt (20,200-node) kind: "branch" query instead of a cheap URL check or skipping.
    3. No rate-limit reserve and short error backoff (host.js → flushBatch):
      • When a rate-limit error returns data: null, flushBatch only backs off for 60s (Date.now() + 6e4) instead of waiting until resetAt.
      • There is no low-water reserve (e.g. pausing background reads once rateLimit.remaining < 500) to protect interactive agent/user gh operations.

    (Also confirms the reporter's /rate_limit observation: GitHub's GraphQL rate-limiter can diverge across shards — REST gh api rate_limit reported 3,268 remaining on one shard while live POST /graphql calls hit remaining: 0 / used: 5002 on another.)

    Concrete fixes for builtin:github-pr-status

    1. Respect staleAfterMs for non-client callers (or give pullRequests an explicit fresh option instead of defaulting all viewer: false calls to a 10s TTL).
    2. Shrink branch query pagination in host.js: pullRequests(headRefName: ..., first: 5) with reviewRequests(first: 10) and contexts(first: 50) (paginating only when hasNextPage is true) cuts GraphQL point cost 18× (72 pts → 4 pts per 24-env batch).
    3. Avoid forcing known: null on every poll of settled PRs unless git refs actually changed (git-refs-changed / branch change).
    4. Add a shared low-water reserve (e.g. skip background polls when rateLimit.remaining < 500) and honor resetAt (or exponential backoff) on rate-limit errors.
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

    githubhostpartial-reproperf

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions