[PR #20546] [MERGED] fix: don't pass database session to channel background tasks during LLM calls #112976

Closed
opened 2026-05-18 13:13:22 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20546
Author: @Classic298
Created: 1/10/2026
Status: Merged
Merged: 1/10/2026
Merged by: @tjbck

Base: devHead: db-perf2


📝 Commits (1)

📊 Changes

1 file changed (+4 additions, -2 deletions)

View changed files

📝 backend/open_webui/routers/channels.py (+4 -2)

📄 Description

Background tasks for channel model mentions (@mentioning a model in a channel)
were receiving the request's database session and holding it during LLM calls.

When a user @mentions a model in a channel:

  1. Request creates the message in DB (fast)
  2. Background task starts to generate LLM response
  3. Background task was passed db session from request scope
  4. Connection held for 30+ seconds during LLM generation
  5. Connection only released when background task completes

This is the same pattern fixed in auth.py - connections held during slow
external operations instead of being released immediately.

The fix removes the db parameter from background_handler. Both
model_response_handler and send_notification now manage their own short-lived
sessions internally, releasing connections immediately after each database
operation.

    BEFORE: Background task holds connection during LLM call
    ─────────────────────────────────────────────────
    │ create msg │ LLM call (30s) │ save response │
    │       CONNECTION HELD ENTIRE TIME           │
    ─────────────────────────────────────────────────

    AFTER: Each operation uses short-lived session
    ┌────────────┐                 ┌───────────────┐
    │ create msg │   LLM (30s)     │ save response │
    │    20ms    │  NO CONNECTION  │     20ms      │
    └────────────┘                 └───────────────┘

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/20546 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/10/2026 **Status:** ✅ Merged **Merged:** 1/10/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `db-perf2` --- ### 📝 Commits (1) - [`821469b`](https://github.com/open-webui/open-webui/commit/821469bbd312300f356d2febfb0a4303edf781fe) Update channels.py ### 📊 Changes **1 file changed** (+4 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/channels.py` (+4 -2) </details> ### 📄 Description Background tasks for channel model mentions (@mentioning a model in a channel) were receiving the request's database session and holding it during LLM calls. When a user @mentions a model in a channel: 1. Request creates the message in DB (fast) 2. Background task starts to generate LLM response 3. Background task was passed db session from request scope 4. Connection held for 30+ seconds during LLM generation 5. Connection only released when background task completes This is the same pattern fixed in auth.py - connections held during slow external operations instead of being released immediately. The fix removes the db parameter from background_handler. Both model_response_handler and send_notification now manage their own short-lived sessions internally, releasing connections immediately after each database operation. ``` BEFORE: Background task holds connection during LLM call ───────────────────────────────────────────────── │ create msg │ LLM call (30s) │ save response │ │ CONNECTION HELD ENTIRE TIME │ ───────────────────────────────────────────────── AFTER: Each operation uses short-lived session ┌────────────┐ ┌───────────────┐ │ create msg │ LLM (30s) │ save response │ │ 20ms │ NO CONNECTION │ 20ms │ └────────────┘ └───────────────┘ ``` ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-18 13:13:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#112976