Skip to content

feat(forge): GitHub rate budget, batched PR status and Todos lists - #455

Merged
simion merged 10 commits into
simion:mainfrom
wagoodman:feature/github-sync
Nov 13, 2026
Merged

simion merged 10 commits into
simion:mainfrom
wagoodman:feature/github-sync

Conversation

@wagoodman

Copy link
Copy Markdown
Contributor

Termic's background GitHub reads were one gh subprocess per task or per project, all spending from the token the user's terminal and agents also use, with no idea how much was left. With a dozen PR tasks a merge could take minutes to show, and the Todos view ran ~45 subprocesses for 15 projects.

  • background PR status is one aliased GraphQL query per host (up to 50 PRs, about 2 points), every tick
  • the Todos lists on a GitHub host are one GraphQL query (repository aliases for repo-wide lists, search aliases for personal ones)
  • a per-host rate ledger (forge_rate.rs) tracks GitHub's window apart from termic's own spend, from the x-ratelimit-* headers, the GraphQL rateLimit object, and refusals seen on the plain gh CLI
  • background work pauses on a GitHub refusal, under 15% left on the account, or past termic's 20% GraphQL share; a user action never waits on termic's budget
  • per-task fallbacks out of the batch share one budget of eight a pass, and each task gets at most one every three minutes
  • settled (merged/closed) PRs are re-checked hourly instead of taking poll slots
  • Settings > General shows the budget per host, and a top-bar pill appears only while background polling is paused
  • gh api only talks to github.com or a host gh auth status reports signed in, is killed at 45s, and refuses answers past 32 MiB

Interface changes:

  • new IPC task_pr_status_batch, project_forge_lists, forge_rate_status, and event termic://forge-rate-changed
  • task_pr_status, task_member_pr_status and task_pr_comments take a required background flag and answer null while the host is paused
  • rate-limited lookups carry retry_at
  • the pr store's refresh(id, force, background) is now refresh(id, { force, background })

Merged and closed PRs on unarchived tasks kept taking the background
poller's eight slots per tick, so open PRs waited behind them and a merge
could take several minutes to show. A PR whose live lookup is merged or
closed is now re-checked hourly (and still on focus). The remembered
snapshot does not count, so a launch still polls every task once.

Signed-off-by: Alex Goodman <[email protected]>
Termic now knows what the gh token's GitHub limits are, what is left, and
what termic itself spent this hour, per host and per feature.

- `forge_rate` keeps GitHub's window (from `x-ratelimit-*` headers and the
  GraphQL `rateLimit` object) apart from termic's own spend, since the
  token is shared with agents and the user's terminal
- background work gets a gate: held on a GitHub refusal, under 15% left
  on the account, or past termic's 20% GraphQL share
- `forge::gh_api` / `gh_graphql` run `gh api --include` and feed the
  ledger; the older `gh pr` / `gh issue` calls are charged as estimates
- new IPC `forge_rate_status` and event `termic://forge-rate-changed`
- Settings > General shows the budget per host; a top-bar pill appears
  only while background polling is paused

Signed-off-by: Alex Goodman <[email protected]>
The background poller ran one `gh pr view` per task, at most eight a
minute and one at a time, so with many PR tasks a merge could take
several minutes to show. GitHub tasks with a PR url now share one aliased
GraphQL query per host (up to 50 PRs, about 2 points), every tick.

- new IPC `task_pr_status_batch { ids, background }`
- a closed PR, a task whose branch no longer matches the PR head, or a PR
  the query cannot see still goes through the by-branch lookup, so a
  replacement PR on the same branch is found as before
- `background` skips hosts whose rate gate is closed; those tasks are left
  out of the answer and stay due
- GitLab, Azure and multi-repo tasks keep the per-task path and its
  three-minute cadence

Signed-off-by: Alex Goodman <[email protected]>
The Todos view ran one `gh issue list` / `gh pr list` per project per
list, three at a time: 45 subprocesses for 15 projects on "For me".
Every GitHub list on a host is now one GraphQL query: repo-wide lists as
`repository` aliases, personal ones (assigned, mentions, mine, review) as
`search` aliases with `repo:` qualifiers, split back out per project.

- new IPC `project_forge_lists`; GitLab, Azure and anything the query
  cannot answer keep the per-project path, three at a time
- the lists cache keys, TTL and rows are unchanged; a dialog asking for a
  list that is in the batch waits on it rather than fetching it again
- an ignored live test runs both batched queries against a signed-in gh

Signed-off-by: Alex Goodman <[email protected]>
The batched poll asks Rust's rate gate itself. The comment watcher and the
per-task fallback in the background pass did not, so they now skip GitHub
tasks while any host is paused. GitLab and Azure are unaffected.

Signed-off-by: Alex Goodman <[email protected]>
Lets a spec seed the GitHub rate ledger's mirror: no fixture repo talks
to GitHub, so nothing real would ever pause background polling.

Signed-off-by: Alex Goodman <[email protected]>
Follow-ups from review of the rate budget and the batched reads.

- a limit is `ForgeError::RateLimited`: a PR batch refused on one skips
  the host, any other batch failure answers each task with its
  `cli-unauthed` / `error` status instead of freezing it silently, and
  a Todos batch refused on a limit no longer re-asks project by project
- background work asks Rust, per host: `task_pr_status` and
  `task_pr_comments` take `background` and answer null while the task's
  host is paused; `task_pr_status_batch` drops its param and is always
  gated. The webview mirror only draws the pill now
- the rate event always goes out when a pause starts, ends or moves, so
  a budget or floor pause can no longer be throttled away
- the PR card's minute tick skips tasks the batch covers
- batch membership is tracked apart from `loading` (a forced refresh
  mid-batch is no longer dropped), a batch lands in one store write,
  and an urgent dialog no longer waits out a Todos batch
- `gh api` only talks to github.com or a host `gh auth status` lists,
  is killed at 45s, and pause, reset and cost values are clamped;
  owner/repo outside GitHub's charset takes the CLI path
- two projects on one remote both get their search list rows
- docs no longer describe the unshipped REST cap or notifications feed

Signed-off-by: Alex Goodman <[email protected]>
Covers the pill (absent, shown with its kind, gone once a pause has
passed) and Settings > General's budget block opened from it.

The rate store is held on the seed for the whole describe. The app
inherits this machine's `gh` login, so a real probe or ledger event
would otherwise replace the seed mid-case and could put a real hostname
in the screenshot.

Signed-off-by: Alex Goodman <[email protected]>
Follow-ups from review of the GitHub rate budget.

- every per-task `gh pr view` a batched pass starts (chunk fallback,
  closed or missing PR, moved branch) spends from one budget of eight,
  and each task gets one at most every three minutes. A PR in a deleted
  repo no longer costs a subprocess every pass, and the webview stamps a
  failure that lands over a good lookup instead of leaving it stalest
- a batch answer whose url is not the PR asked is not trusted or
  persisted; PR urls and slugs are validated (32-bit number, GitHub's
  charset and lengths) before they join a query
- a `gh` CLI call refused on a rate limit records the refusal, so the
  CLI path stops too; the comments REST leg goes through
  `gh api --include`, which makes the Core window and its cap real
- a task with no recorded forge is resolved from its remote before the
  gate, so GitLab and Azure tasks no longer wait on github.com
- rate-limited lookups carry `retry_at`; the webview words them itself
  (`lookupMessage`), and a pulled rate status no longer overwrites a
  newer pushed one
- a Todos chunk past the output cap is split and asked again instead of
  falling back to the uncapped CLI path
- a zero limit is ignored, resets are moved into the local clock by the
  `Date` header, the ledger uses parking_lot locks, and the rate probe
  runs at most once a minute per host
- `refresh(id, { force, background })` replaces the boolean pair; the
  board, agent spawn and blocked-card retry poll as background
- a steady poll keeps the previous lookup object, and the batch runs
  beside the per-task loop rather than ahead of it
- the pill is info-coloured and reads "GitHub polling paused"

`refresh` and `task_pr_comments` change shape (options object, a held
background call answers null), and lookups gain `retry_at`.

Signed-off-by: Alex Goodman <[email protected]>
@simion

simion commented Nov 11, 2026

Copy link
Copy Markdown
Owner

No blocking bugs, the GraphQL batching and rate ledger hold up correctly across the aliasing, chunking, and backoff paths. One minor race: concurrent pollers can each pass the per-host budget check before their cost is recorded, letting termic briefly overspend its local share, though GitHub's own limit still catches real exhaustion.

Thanks for the contribution!
— Simion's agent here, he'll take a look at this shortly.

The background poller rechecks merged and closed PRs hourly, so a
merged snapshot aged by 10 minutes was never due and the pass skipped
it. Age it by two hours instead.

Signed-off-by: Alex Goodman <[email protected]>
@simion
simion merged commit 999ef89 into simion:main Nov 13, 2026
5 of 7 checks passed
simion added a commit that referenced this pull request Nov 13, 2026
The case seeded the PR entry with loading:false, hiding a real lookup
still in flight (leaving the Git tab starts one). On Windows its git
spawn is slow enough to land inside the background pass: it landed as
raced, kept the seed but stamped fetchedAt, and the batch then dropped
its own answer as older than that landing, so the badge never moved.
Failed on every Windows run since #455 batched the background poll.

The seed now leaves loading as it is, and the case waits for no lookup
in flight before aging the entry and running the pass.

Refs #281

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@simion

simion commented Nov 17, 2026

Copy link
Copy Markdown
Owner

This is live in v1.23.0. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants