Conversation
When a GitHub API call returns 401 (e.g. due to clock skew, early token revocation, or network delays), force-refresh the token and retry once. Changes: - Add forceRefreshClient to bypass both in-memory and file caches - Add withFreshClient wrapper that catches 401 and retries with fresh token - Refactor updateCommitStatus and checkExistingStatus to use withFreshClient - Add token validation to FakeGithubApi mock server (unique tokens, expiry tracking, clock skew simulation via expiration offset) - Add '# github token expiration offset N' test directive - Add golden test for 401 retry scenario
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
CI runs are getting long enough that GitHub App installation tokens (1-hour lifetime) expire mid-build. The existing proactive refresh mechanism checks
expiresAtbefore each API call, but doesn't handle cases where GitHub rejects a token the client still considers valid (clock skew, early revocation, network delays).This PR adds reactive token refresh: when any GitHub API call returns 401, force-refresh the token and retry once.
Changes
src/CommitStatus.hsforceRefreshClient— acquires the file lock and always refreshes the token, bypassing both in-memory and file cacheswithFreshClient— callsgetClient, executes the request; if response is 401, logs a warning, callsforceRefreshClient, and retries onceupdateCommitStatusandcheckExistingStatusto usewithFreshClienttest/FakeGithubApi.hstokenExpirationOffsetto simulate clock skew (server reports a longer-than-actual token lifetime)test/Spec.hs# github token expiration offset Ntest directiveNew test:
test/t/slow/github-token-retry-on-401withFreshClientcatches the 401, force-refreshes, and retries successfullyTesting
All existing GitHub tests continue to pass. New test verified: