Repository navigation
Background channel tasks: off-loop sessions, burst-safe webhooks - #532
Open
chattermate wants to merge 6 commits into
Open
chattermate wants to merge 6 commits into
chattermate wants to merge 6 commits into
Conversation
Channel message, interaction and status handlers and the Slack Home/ assistant events opened SessionLocal() on the event loop. The loop-safe pool keeps that from freezing the server, but in a burst it refuses them at once, dropping the reply to an inbound message. session_off_loop() makes them wait their turn in a checkout thread instead. Signed-off-by: Runix <admin@chattermate.chat>
Background tasks now share session_off_loop's slots with requests, so holding one through an extension, app, platform or Slack call slowed the dashboard during webhook bursts. Each task reads what it needs, then release_connection()s before waiting on anything outside. Also ports the ticket email-reply task, which still opened SessionLocal() on the event loop, and adds tests that each wait happens with the slot free and that a receipt queues for a slot rather than failing. The shared test helper moves to tests/session_db.py. Signed-off-by: Runix <admin@chattermate.chat>
A new customer's profile fetch released the session before the session and config reads, sending those back to the event loop. It now runs after setup. app_claims and the ticket email-reply task also give the slot back before their outside calls. Signed-off-by: Runix <admin@chattermate.chat>
A webhook route held its request session (and off-loop slot) until its background task finished, while that task waited for a slot of its own: ten webhooks at once took every slot and froze the backend. Webhook routes now close their session when the endpoint returns (webhook_db). Channel tasks also ran unbounded, so a burst used up the pool from the event loop and refused most of them. They now queue for one of MAX_CONCURRENT_CHANNEL_TASKS places (default 4). Adds e2e/scripts/channel-burst.mjs to the nightly burst variant: 100 WhatsApp messages and 200 receipts at once must all be answered without the API stalling. On main the API stalls 6-7s under it. Signed-off-by: Runix <admin@chattermate.chat>
One account whose AI provider hangs could take every place and keep every other business's messages waiting. Also names LOOP_OVERFLOW so a test can hold the task limit to the pool budget, and the channel burst now counts button replies and fails on any pool-full warning. Signed-off-by: Runix <admin@chattermate.chat>
chattermate
force-pushed
the
feature/background-tasks-off-loop
branch
from
November 30, 2026 17:32
7c2a8df to
8adab52
Compare
Signed-off-by: Runix <admin@chattermate.chat>
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.
Channel webhook background tasks (inbound messages, delivery receipts, interactions, the Slack Home and assistant events, ticket email replies) opened
SessionLocal()on the event loop. In a burst, the loop-safe pool refused them, so customers didn't get replies. This PR also stops a burst stalling the dashboard.session_off_loop(), and callrelease_connection()before any outside call (extensions, the app handler, the profile fetch, Slack).webhook_db, a function-scopedget_db, so the request's session is closed before its background tasks run. Before this, a request held its slot while its own task waited for one; ten webhooks at once froze the backend.MAX_CONCURRENT_CHANNEL_TASKSplaces (default 4, at most half for any one account), so a burst queues instead of running the pool dry.e2e/scripts/channel-burst.mjs, added to the nightlyburstvariant: 100 WhatsApp messages and 200 receipts at once must all be answered, with no API stall and no pool-full warning. On main the API stalls 6–7s and the pool overflows; on this branch it's under 0.5s, with no warnings.tests/socket_db.pyis nowtests/session_db.py, with a genericserve_session_off_loophelper.Tested: backend suite (OSS); channels, integrations, team and tickets e2e specs; both burst scripts.