Skip to content

fix(backend): offload the pusher webhook lookup off the event loop - #15291

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/backend-offload-pusher-webhook
Sep 21, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/backend-offload-pusher-webhook

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15290

One line: get_audio_bytes_webhook_seconds now goes through await run_blocking(db_executor, ...), matching the three lines directly below it in the same block.

db_executor is the pool the adjacent calls already use, and pusher.py already imports both names.

Tests: backend/tests/unit/test_pusher_webhook_lookup_offload.py. It asserts the handler is async, that the lookup is not called directly, that it is offloaded through an awaited run_blocking on db_executor, and that the two adjacent lookups stay offloaded, so the guard also catches someone removing their offload later.

Verification:

$ cd backend && BACKEND_UNIT_TEST_FILE_LIST=<new file> bash test.sh
4 passed in 0.07s

Five existing tests monkeypatch this symbol on the pusher module with a plain lambda uid: None. That keeps working, because run_blocking resolves the module global at call time and runs it in a thread, but I ran them rather than assuming:

$ BACKEND_UNIT_TEST_FILE_LIST=<the 4 files that patch it> bash test.sh
19 passed / 2 passed / 14 passed / 108 passed, exit 0

The 59 pusher, webhook, listen and trigger suites give an identical result on this branch and on c385444b72: the same two files fail on both (test_verify_pusher_config_references.py, test_verify_pusher_promotion_evidence.py, which check rendered k8s manifests and fail locally for environment reasons), and nothing else.

With routers/pusher.py reverted to its state on main and the test kept, 2 of the 4 fail; the two that still pass are the handler-is-async check and the adjacent-lookups check, both true on main.

pusher.py does not change line count.

Product invariants affected

none

Failure class (fixes)

Failure-Class: none

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Nice catch, and a clean fix — verified on the current head.

backend/routers/pusher.py — the one-line change is correct and consistent. get_audio_bytes_webhook_seconds (backend/utils/webhooks.py:431) is a plain def doing up to two synchronous Redis reads (user_webhook_status_db, then get_user_webhook_db when the webhook is toggled on), and it ran directly on the event loop in _websocket_util_trigger after websocket.accept() — so a Redis slow period or failover stalled the pod's loop and every already-connected audio stream on it stopped draining. Every other caller of those two lookups in utils/webhooks.py already goes through await run_blocking(db_executor, ...); this brings the last unoffloaded one in the hot path into line, matching the three adjacent lookups right below it. An AST pass over the handler at this head shows no remaining direct sync DB/Redis calls in it.

backend/tests/unit/test_pusher_webhook_lookup_offload.py — the structural guard is a good idea: asserting the handler is async, that the lookup is never invoked directly, that it goes through an awaited run_blocking on db_executor, and that the two adjacent lookups stay offloaded means the original omission can't quietly come back. The note about the five existing suites that monkeypatch this symbol also checks out — run_blocking resolves the module global at call time, so thread-offloaded patched lambdas behave the same.

Checks all green on this head (Backend Hermetic Merge Gate, Backend unit suite, Listen Pusher Stack Gauntlet, Hermetic Backend E2E, Hygiene, Formatting).

Leaving formal approval to the maintainers; from an automated review standpoint this looks merge-ready as-is.

🤖 Automated review on behalf of the maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Sep 20, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_audio_bytes_webhook_seconds in the pusher webhook handler now goes through run_blocking on db_executor, matching the three adjacent lookups in the same block that were already offloaded (Fixes #15290), closing the last blocking DB call in that handler. AST-guard test + full pusher/webhook suite green. Confidence 5/5.

@kodjima33
kodjima33 merged commit 779326f into BasedHardware:main Sep 21, 2026
51 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pusher trigger WebSocket reads the webhook config on the event loop

3 participants