Repository navigation
fix(backend): offload chat quota release off the event loop (#15966) - #16028
Merged
kodjima33 merged 1 commit intoSep 22, 2026
Merged
Conversation
_release_chat_quota_question_best_effort ran a synchronous Firestore transaction (release_chat_quota_question) directly on the event loop from an async generator (generate_stream in /v2/messages), blocking all concurrent requests on that worker for the transaction's duration. It fires exactly when a provider call already failed, i.e. under load. Route it through await run_blocking(db_executor, ...), matching every other Firestore/Redis call in this same function (db_executor is already used at lines 624, 638, 968, 1025, 1055, ...).
kodjima33
deleted the
watchdog/issue-15966-chat-quota-release-event-loop
branch
September 22, 2026 22:17
This was referenced Oct 1, 2026
Git-on-my-level
added a commit
that referenced
this pull request
Oct 1, 2026
…ponses (#20168) What: `POST /v1/oauth/token` reflected raw Firebase verification exceptions (`InvalidIdTokenError` details, cert fetch URLs, key IDs, claim state) directly into HTTP 401 response bodies. Unauthenticated surface: any caller can submit a malformed token and read internal verification traces. Why: Internal error-detail leakage on an auth endpoint; real (if minor) security hygiene issue, not template hardening against impossible inputs. Risk: Low — error *bodies* become static strings; status codes unchanged; detail preserved in server logs. Solution: Log exception detail server-side (`logger.warning` / `logger.error`), return static 401 messages. Regression tests assert the leak strings no longer appear in the raised HTTPException. Cherry-picked from #16029 by @Mateidslx (code + regression tests as authored; verified the leak still exists on current `main` before re-landing). Original bounty proposal #16028 is declined per the maintainer's standing bounty-policy ruling; the fix lands here with credit. Verification evidence: - `backend/.venv/bin/python -m pytest tests/unit/test_oauth_firebase_error_sanitization.py` — 2 passed (both tests fail on unpatched `main` code, pass with this diff) - `scripts/pr-preflight --pr-body-file` passes with the citations below Invariants: INV-DATA-1 Failure-Class: none --- *by AI on behalf of David — if you need David's attention urgently, please @Git-on-my-level and escalate with `need human response`.* <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/20168?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. -->
rahul24
pushed a commit
to rahul24/milo
that referenced
this pull request
Oct 1, 2026
…ponses The oauth_token exchange endpoint reflected raw Firebase verification exceptions (InvalidIdTokenError details, cert fetch URLs, key IDs, claim state) directly into HTTP 401 response bodies. Moves the detail to server-side logging (warning/error) and returns static messages. Cherry-picked from BasedHardware#16029 by @Mateidslx (code + regression tests as authored there; verified against current main — the leak is still present). Original bounty proposal BasedHardware#16028 declined; this lands the fix under the maintainer account instead. Verification: backend/.venv pytest tests/unit/test_oauth_firebase_error_sanitization.py — 2 passed. Failure-Class: none
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
_release_chat_quota_question_best_effortinbackend/routers/chat.pyran a synchronous Firestore transaction (llm_usage_db.release_chat_quota_question) directly on the event loop, from theasync def generate_stream()generator behind/v2/messages. It fires on the terminal-failure path (provider error, empty answer) — i.e. exactly when a provider is already failing and the pod is under load — and pins the whole worker's event loop for the transaction's duration, stalling every other concurrent request on it.defcalling the sync Firestore client directly, unlike its sibling_record_chat_quota_question_best_effortpath and every other Firestore/Redis call in the same function (chat_tz,process_message,is_trial_paywalled,resolve_voice_message_language, ...), which already go throughawait run_blocking(db_executor, ...)._release_chat_quota_question_best_effortasync defand offloaded the call viaawait run_blocking(db_executor, llm_usage_db.release_chat_quota_question, uid, idempotency_key), matching the established pattern in this exact file (backend/AGENTS.md"Async I/O (3-Lane Architecture)" — Lane 2 executors,db_executorfor Firestore/Redis CRUD). Updated both call sites toawaitit.Testing
black --line-length 120 --skip-string-normalization --check backend/routers/chat.py— passes.python backend/scripts/scan_async_blockers.py --dirs routers utils— 0 findings.pytest backend/tests/unit/test_chat_quota_release.py backend/tests/unit/test_chat_quota_offload.py backend/tests/unit/test_chat_quota_counting_router.py backend/tests/unit/test_chat_quota.py— 35 passed, includingtest_v2_messages_records_failure_when_the_production_stream_errors, which exercises the exactexcept Exceptionrelease path this change touches.Failure-Class: none
🤖 automated by hourly watchdog — tested and merged