Repository navigation
Serve cached gh credentials to remote sends while refreshing in the background - #5258
Merged
ymichael merged 1 commit intoOct 9, 2026
Conversation
…ackground Every send to a non-server host assembles the host environment, which forwards the server's gh login (GH_TOKEN and git identity) to that machine. The credentials were memoized for 60 seconds and then refreshed inline, so the first send after expiry waited on `gh auth token` and `gh api user` (350-820 ms of network-bound latency). The memo now supports stale-while-revalidate: once loaded, an expired value is returned immediately while one background lookup replaces it. Settings health checks still force a blocking refresh, and host connection already warms the cache through the machine environment sync. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/stop-gh-auth-lookups-on-the-send-path-for-remote-thr_bnzqa2ntm8
branch
October 9, 2026 17:11
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.
Human comments
What was wrong
Every send to a thread on a non-server host assembles that host's environment, which forwards the server's
ghlogin (GH_TOKEN, git author/committer identity). Those credentials were memoized for 60 s (5 s when empty) and then refreshed inline, so the first send after expiry blocked ongh auth tokenandgh api user— 350–820 ms of network-bound latency on the send path.What changed
apps/server/src/services/lib/async-ttl-memo.ts: new opt-instaleWhileRevalidateoption. Once a key has loaded, an expired value is returned immediately while a single background lookup replaces it; a failed background lookup leaves the stale value in place and the next call retries. Lookup start/settle logic is extracted into a sharedstart()helper. Expired entries are not pruned when the option is on (they are what gets served). Other memo callers are unaffected.apps/server/src/services/machines/git-credentials.ts: the credential cache enablesstaleWhileRevalidate.resolveGitCredentials(send path) serves cached credentials instantly;machineGitHealth(Settings health check) still forces a blocking refresh.Trade-off: after a token rotation or
gh auth login/logout, the first send after expiry still sees the previous result; the next one sees the refreshed value.No wire changes.
How you verified
async-ttl-memotest: expired value is served, only one background lookup runs, a rejected lookup keeps the stale value and is retried, success replaces it, and a forced refresh blocks and is shared with concurrent callers.git-credentialstests for the serve-stale-then-refresh behavior.pnpm exec turbo run typecheck lint --filter=@bb/serverand the two test files pass.🤖 Generated with Claude Code