feat(coderd/externalauth/gitprovider): use conditional requests for GitHub JSON reads - #27628
Merged
johnstcn merged 1 commit intoJul 30, 2026
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
Author
|
recheck |
cdrci2
added a commit
to coder/cla
that referenced
this pull request
Jul 29, 2026
johnstcn
approved these changes
Jul 29, 2026
Contributor
Author
|
Thanks for the review, @johnstcn! 🙏 The two red checks look like unrelated CI flakes rather than anything from this (Go-only) change:
Would you mind re-running those two jobs when you get a chance? Happy to rebase if you'd prefer. Thanks again! |
Member
The chat-diff-status gitsync worker polls open pull requests on a short interval, re-fetching full JSON bodies for pull requests that have not changed. Add an in-memory, concurrency-safe LRU cache of ETags and response bodies and issue `If-None-Match` on GitHub JSON reads so that unchanged resources return `304 Not Modified` instead of a full body. 304 responses are cheaper and do not count against the primary REST rate limit. The cache is keyed by request URL plus a hash of the token so a cached response for one token is never served under another, and it is bounded by entry count and per-body size to cap memory use. Co-authored-by: Copilot <[email protected]> Copilot-Session: 4959e1f9-f8e6-4e97-a487-f395a0123c79
joshfree
force-pushed
the
josh/gitprovider-etag-conditional-requests
branch
from
July 30, 2026 14:19
688f25e to
e9449ff
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #27627.
What
The chat diff-status gitsync worker polls open pull requests on a fixed 10s interval and re-downloads the full JSON body every tick, even when nothing changed, because the GitHub client never sends
If-None-Match/ ETag.This adds a small, concurrency-safe, bounded in-memory ETag+body cache (
coderd/externalauth/gitprovider/conditional.go) and wires it intogithubProvider.decodeJSON. When an ETag is cached for a request, we sendIf-None-Match; on304 Not Modifiedwe decode the cached body; on200we cache{etag, body}when an ETag is present and the body is under a size cap.Why
304responses do not count against GitHub's primary rate limit, but full200s do. Today every unchanged poll burns quota that the same token also needs for interactive Git and API operations, so busy instances can hit rate-limit errors and stalls elsewhere. Unchanged PRs now revalidate for free with no behavior change; only genuine changes transfer a body.Details
decodeJSON; the raw-diff path (fetchDiff, up toMaxDiffSize) is intentionally left out to avoid caching large bodies.Tests
TestConditionalRequestReuseingithub_test.gocovers:NotModifiedReusesCachedBody— a warm poll sendsIf-None-Matchwith the prior ETag and reuses the cached body on304, yielding the same result with exactly two upstream requests.DifferentTokenDoesNotShareCache— a different token never sends another token's cached ETag.