Repository navigation
fix: offload token persistence during async Google token refresh - #8378
Merged
Merged
Conversation
The refresh_google_token coroutine persisted the new access token via users_db.set_integration() — a synchronous Firestore write — directly on the event loop. When a Gmail request hit an expired token, the refresh path blocked concurrent chat/tool streaming until Firestore returned. Wrap the Firestore write with run_blocking(db_executor, ...) so it runs in the DB thread pool, consistent with backend async I/O rules. Verification: scan_async_blockers reports zero blocking calls for the function.
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
The async
refresh_google_tokencoroutine persisted the new access token viausers_db.set_integration()— a synchronous Firestore write — directly on the event loop. When a Gmail request hit an expired token, the refresh path blocked concurrent chat/tool streaming until Firestore returned.Wrap the Firestore write with
await run_blocking(db_executor, ...)so it runs in the DB thread pool, consistent with backend async I/O rules (AGENTS.md: "never call sync DB/storage/file functions directly inside async def").This was originally flagged as P2 by Codex review on PR #8364 (
retry_on_auth_async), but the fix targetsgoogle_utils.pywhich was not part of that PR's diff. Opening as a standalone fix.Test Plan
scan_async_blockers.pyreports zero blocking calls forrefresh_google_token