# GitHub PR Status Owns GitHub pull request data and actions for bb environments. Bundled and enabled by default. - `host.ts` batches GraphQL reads through `gh api graphql` and runs `gh pr ready|merge` in the environment's workspace on its machine. - `server.ts` resolves environments, assembles the status, serves the keyed `pullRequests` read and the `refresh`, `markReady`, `markDraft` and `merge` mutations, and registers `bb pull-request`. - `store.ts` shares snapshots, in-flight reads and pending-check timers by PR URL, and publishes only changed rows. - `persistence.ts` uses the plugin's own database through `bb.storage.database()` / `migrate()`. It stores each environment's current link (a PR URL, or known absence) and the snapshots those links reference. Snapshots no link references are deleted. Identical PR content and links do not write rows; after a restart reads see the saved rows. Set `PERSISTENCE_ENABLED` to `false` to keep everything in memory, or bump `PERSISTENCE_VERSION` when saved rows should be discarded, for example after changing how a PR row is assembled. - `app.tsx` registers the pull request segment of the composer's thread context row (`experimental_threadContextSegment`, with Mark ready and merge actions), the Info tab's Pull request row (`experimental_threadInfoRow`) and the sidebar row badge (`experimental_threadRowMetadata`). Their components, display helpers and the keyed read hook live in `ui/`. The badge sits on the row's metadata line (Organize → Rows → Metadata) and shows the current-branch PR's `#number` in the state's color (a draft's in the subtle foreground), followed by a red cross when an open or draft PR needs action (the composer's red next steps: failing checks, changes requested, conflicts, behind its base or blocked by rules) or else a yellow dot while its checks run; otherwise nothing. Its `useData` reads every listed thread, on screen or not, in one batched request. - `read-contract.ts` is the zod-free client view of `pullRequests`: the plugin id and the row tag. `contract.ts`, the public zod contract, builds on it. Core's retired sidebar shim reads through it with `pluginId: "bb--github-pr-status"`, the way any other plugin would. Plugin host calls never wake a suspended machine: reads keep the last pull request bb saw for the environment, or return `unavailable` when it has none, and actions fail with a message naming the machine. Branch discovery follows `gh pr view`: the base repository is the remote `gh` resolved (`gh repo set-default`), else `upstream`, `github`, `origin`, then any other remote, and `GH_REPO` overrides it. A branch pushed to another owner's remote matches only that owner's fork PRs; otherwise only same-repository PRs match, and the default branch ignores merged and closed PRs. Actions re-read the pull request bb already found by its URL, rediscovering the branch when that PR has merged or closed or its head branch isn't the workspace's current branch (so a fork PR with a differently named upstream branch always rediscovers), then pass the URL to `gh` so it doesn't look the PR up again. Watched open and draft PRs with any pending checks (including runs that already have a failure), unknown mergeability, a merge queue entry or auto-merge refresh about every 30 seconds. Other watched open and draft PRs refresh about every 5 minutes. Checks due within half their interval join the current tick, and the tick's loads reach each machine as one `views` call whose reads all start together, so they share GraphQL batches; changes from one tick publish as one invalidation. Merged and closed PRs do not poll. App reads answer at once from what the plugin has and refresh a stale row in the background: open and draft PRs after 30 seconds, merged and closed PRs after an hour, a "no PR" result after 5 minutes. Opening a thread, including by loading the page on it, re-checks its PR on GitHub through `refresh`, whatever the row's age; other views ask again when they first show and each time the page shows again. CLI and RPC reads wait for a row older than 10 seconds. Branch changes and turns rediscover immediately. Ref events compare the local upstream OID without fetching. Turns without a PR rediscover; known PRs recheck only after a turn that ran `gh`. Reads on each workspace host are grouped by GitHub hostname and credential (including gh profile account changes) into documents of at most 25 reads, with a 10 ms collection window. A branch lookup lists the branch's 100 newest PRs with only the fields that pick its PR (URL, state and head owner), plus full details for the newest one; only when the match is an older PR is it read again by URL. A 25-branch document costs one GraphQL point. Loads that start within 50 ms of each other (250 ms at most) reach each machine as one `views` call. Each read returns the workspace's branch and upstream OID with its result, so a load needs no other machine call; a known PR is read by URL only while the workspace is still on the branch it was found on, and is otherwise rediscovered from the current branch. Missing credentials or a sleeping host return unavailable. Rate limits pause the affected credential for at least one minute. A GitHub Enterprise server without merge queues is read without `isInMergeQueue` from then on. No credentials or ETags are persisted; measured ETag revalidation still needed two checks requests, versus one combined GraphQL request.