Repository navigation
Conversation
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Tip: cubic could auto-approve low-risk PRs like this, if it thinks it's safe to merge. Learn more
Re-trigger cubic
kodjima33
left a comment
There was a problem hiding this comment.
Backend hardening bug fix with regression test; matches established pattern. (auto-review)
f28eed9 to
9aa8d0d
Compare
|
Hi @ZachL111 — thank you for finding and writing up this async/resource correctness issue. We consolidated this set into a smaller aggregate PR so the fixes share infrastructure and are easier to maintain/review: #8364. Your original discovery, reproduction details, and candidate fix are credited in the new PR body and commit metadata. I’m closing this individual PR as superseded by #8364, not because the issue is invalid. Thanks again for surfacing it. |
|
Hey @ZachL111 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! 💜 |
## Summary This aggregates ZachL111's async/resource correctness fixes into one maintained PR: - Offload synchronous Firestore/database reads from async code with `utils.executors.run_blocking(..., db_executor, ...)` in app integrations, notification memories, and the fair-use classifier. - Make the Gmail retrieval path async end-to-end: the tool is async, message list/fetch Google API calls are awaited, and auth refresh goes through a shared `retry_on_auth_async` helper beside the existing sync helper. - Add the missing `asyncio` import in `routers/agent_tools.py` and verify changed modules with a static undefined-name check. - Ensure speech-profile matching closes the uploaded audio file handle deterministically. - Teach `scan_async_blockers.py` that work wrapped by repository `run_blocking` is executor-offloaded. - Add a focused async/resource regression test module to the backend test runner. 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 -v` - `uv 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.py` - `uv 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` <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/8364?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. -->
Supersedes BasedHardware#8268, BasedHardware#8274, BasedHardware#8296, BasedHardware#8300, BasedHardware#8314, BasedHardware#8323. Original issue discovery, reproductions, and candidate fixes by @ZachL111. Co-authored-by: ZachL111 <[email protected]>
Summary
get_relevant_memoriesinbackend/utils/llm/notifications.pyis anasync defthat calls the sync, Firestore-backedget_memoriesdirectly. Firestore's sync SDK is blocking, so every call stalls the whole event loop while the read runs, which freezes health checks, HPA scaling, and all other in-flight requests on that worker. This wraps the read inawait run_blocking(db_executor, get_memories, uid, limit)so the blocking call runs on thedb_executorpool instead of on the loop. This is a proactive hardening change; there is no filed GitHub issue for it.Root cause
In
backend/utils/llm/notifications.py,get_relevant_memoriesis async but calls the sync read inline:get_memoriescomes fromdatabase.memoriesand uses the synchronous Firestore client. Calling it directly insideasync defblocks the event loop for the duration of the Firestore round trip. The repo's async rules require offloading blocking DB calls viarun_blockingon the right pool (db_executorfor Firestore/Redis CRUD), and this one was never offloaded. It runs inside the notification flows (generate_notification_message,generate_credit_limit_notification), so the stall lands in paths that also do LLM work.Fix
Offload the read to the
db_executorpool withrun_blocking, and import the two helpers fromutils.executors:The return value is unchanged, locked memories are still filtered out, and the result is identical for valid input. The read just no longer runs on the event loop.
Testing
New
backend/tests/unit/test_notifications_memories_async.py(registered intest.sh). The module pulls in heavy LLM and Firestore siblings, so the test keepsutils.llmandutils.executorsas real packages and stubs only the heavy leaf modules (clients,usage_tracker,database.memories), then importsnotificationsand callsget_relevant_memoriesdirectly.run_blockingis patched withcreate=Trueso the pre-fix absence of the offload surfaces as a clean assertion failure rather than a patch error. The cases check thatrun_blockingis called exactly once, that the function handed to it isget_memories, thatdb_executoris passed as the pool, thatuidandlimitare forwarded positionally (default 100 and an explicit 50), and that locked memories are filtered from the result. Verified red to green: the test fails on current main and passes with this change.PR status check
No open PR changes this logic. The offload added here does not appear anywhere in this file's history, so it is not a previously reverted fix being resubmitted. No filed GitHub issue matches.