Repository navigation
Fix async resource boundaries - #8364
Conversation
There was a problem hiding this comment.
1 issue found across 10 files
Confidence score: 4/5
- In
backend/tests/unit/test_async_resource_correctness.py,test_speech_profile_closes_audio_file_handleleavesutils.stt.speech_profileinsys.modulesafter_load_module, which can contaminate later tests that import the same module and cause order-dependent/flaky CI failures; add teardown cleanup (e.g., remove the injected module fromsys.modules) before merging.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Git-on-my-level
left a comment
There was a problem hiding this comment.
Addressed the unresolved Cubic test-isolation comment.
Changes:
test_speech_profile_closes_audio_file_handlenow removes the manually loadedutils.stt.speech_profilemodule fromsys.modulesin afinallyblock.- Stubbed
pydublocally in the test so the focused unit file remains hermetic in a minimaluv runenvironment.
Verification:
ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run pytest tests/unit/test_async_resource_correctness.py -q→5 passed
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd7df4ed91
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address Codex P2 review comment on get_gmail_messages_tool: prepare_access() calls users_db.get_integration() (Firestore read) synchronously on the event loop since the tool became async. Offload via run_blocking(db_executor, ...) matching the pattern already used in fair_use_classifier.py, notifications.py, and app_integrations.py.
|
Offloaded Gmail access lookup from the event loop (P2 — Codex feedback)
What changed:
Verification:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 323adcb193
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed: token persistence is now offloaded to the DB executor. The sync Verification:
|
## Summary The async `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 `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 targets `google_utils.py` which was not part of that PR's diff. Opening as a standalone fix. ## Test Plan - [x] `scan_async_blockers.py` reports zero blocking calls for `refresh_google_token` - [x] Pre-commit formatting passes (black) - [ ] CI Hermetic Backend E2E passes <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/8378?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Summary
This aggregates ZachL111's async/resource correctness fixes into one maintained PR:
utils.executors.run_blocking(..., db_executor, ...)in app integrations, notification memories, and the fair-use classifier.retry_on_auth_asynchelper beside the existing sync helper.asyncioimport inrouters/agent_tools.pyand verify changed modules with a static undefined-name check.scan_async_blockers.pythat work wrapped by repositoryrun_blockingis executor-offloaded.Supersedes #8268, #8274, #8296, #8300, #8314, #8323. Original issue discovery, reproductions, and candidate fixes by @ZachL111.
Deferred: #8265, per the aggregation plan, because it mixes Firestore writes, cache work, and potentially expensive memory/LLM postprocessing and needs a fuller executor design.
Tests
uv run --with pytest --with pytest-asyncio --with httpx --with pydub pytest tests/unit/test_async_resource_correctness.py -vuv run python -m py_compile routers/agent_tools.py utils/app_integrations.py utils/llm/notifications.py utils/retrieval/tools/gmail_tools.py utils/retrieval/tools/integration_base.py utils/llm/fair_use_classifier.py utils/stt/speech_profile.py scripts/scan_async_blockers.py tests/unit/test_async_resource_correctness.pyuv run python scripts/scan_async_blockers.py --dirs routers utils(exit 0; reports 0 high network I/O / 0 file I/O / 0 no-await endpoints, plus pre-existing async helper/sync DB findings elsewhere)uv run --with pyflakes pyflakes routers/agent_tools.py utils/retrieval/tools/gmail_tools.py tests/unit/test_async_resource_correctness.py