fix(github): primary GraphQL limits, refused installation tokens, scan-free cache eviction
Merged
SW
1d ago+482+482+012345678901234567890123456789-81-81-01234567890123456789
What and why
- GraphQL primary limit read as a secondary one (
crates/github/src/governor.rs). GitHub answers an exhausted GraphQL primary limit with HTTP 200, aRATE_LIMITEDerror andx-ratelimit-remaining: 0. The governor treated every such answer as a secondary limit: it guessed a 60 s cooldown and cut writes to one a second for an hour. Now aRATE_LIMITEDanswer with a spent window, and no error message naming the secondary limit, counts as primary exhaustion. The graphql bucket waits untilx-ratelimit-resetand writes are left alone. Answers without the header, or with "secondary rate limit" in a message, still take the secondary path. The classification lives in a smallGraphqlLimithelper. - Refused installation tokens reused until they expire (
app.rs,credentials.rs,lib.rs). A newCredentials::invalidate(rejected)hook defaults toNone, meaning "can't mint another token, don't retry". App installations implement it by clearing the full-installation slot, but only while it still holds the refused token, so a token another request minted in the meantime is kept. On a 401,exchangeinvalidates the token and retries once. GitHub runs nothing it refuses with 401, so this is safe for writes too. The retry doesn't count against the rate-limit retries, and a second 401 is returned. MAX_WRITE_BURSTdefined twice. Now there is one definition, inpatchula-config, andpatchula-githubuses it. I picked the directiongithub → configbecause every crate that depends on github already depends on config, so nothing gains a new transitive dependency. The other direction would pull reqwest, SQLite and jsonwebtoken into config and every crate that uses it. The unusedpubconstant in github is gone.- Dead
search/branch inexchange: removed. Nothing calls search, and on an Enterprise root the branch couldn't match. The governor still keys buckets byx-ratelimit-resource. - Every HTTP cache write summed the whole
httptable (crates/cache/src/store.rs). Migration 016 adds a one-rowhttp_bytestable. It is seeded from the current sum, and AFTER INSERT/DELETE/UPDATE OF body triggers onhttpmaintain it. Several processes can share the cache file (the CLI's default directory is shared, and the cache uses WAL), so the counter lives in the database and changes inside each write's own transaction. A per-Storecounter would drift.evict()re-reads the row after each delete. A rebuilt cache after corruption recovery starts at 0 on an empty table.cache schemais now 16.
Tests
- governor: a spent GraphQL window is primary (bucket reset ≈
x-ratelimit-reset, no secondary cooldown, no write throttle). ARATE_LIMITEDanswer without a spent window, without headers, or with a secondary message stays secondary. A GraphQL answer that spends the last point without an error is not limited. - app: a refused token is minted again and the write retried (2 mints, 2 sends, and later requests keep the new token). A refused fresh token fails after one retry with no mint loop. Invalidating an already-replaced token keeps the replacement.
- cache: the counter matches
SUM(length(body))after insert, a resize through upsert, a 304 refresh, removal and eviction, including writes through a second handle on the same file. The table stays within budget over 40 puts. The migration test checks that 016 seeds the counter from existing rows.rewinddrops 016's objects. cargo test -p patchula-github -p patchula-cache, the state/derive parity tests in datasource, notes, engine and update, andcargo clippy -p patchula-github -p patchula-cache --all-targets -D warningsall pass.
State versions
crates/github/src/ is hashed by source-head, tag-catalog, tag-object and release-notes. Bumping those cascades through crates/datasource/src/ and crates/notes/src/ to catalog, catalog-controls, changelog and notes-adapter, and to the derived github-release-head, notes-adapter-listing, parsed-postgres-sgml and parsed-go-history. All are bumped by one, with their rows updated. Expect a one-time miss on those entries.
Dropped
Nothing.
Follow-ups
- The scoped (per-repository) tokens handed to tools aren't invalidated on 401. Tools use them in their own processes, so the client never sees those 401s.
- The App's own
repos/{owner}/{repo}read for scoped mints (App::repository_id) uses the installation token directly, without the 401 retry.