[PR #24100] fix: Task generation (title, tags, etc.) failing for direct connection chats #43135

Open
opened 2026-04-25 14:49:21 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24100
Author: @champumbc
Created: 4/24/2026
Status: 🔄 Open

Base: devHead: fix/direct-connection-task-generation


📝 Commits (1)

  • d827039 Fix task generation (title, tags, etc.) failing for direct connection chats

📊 Changes

2 files changed (+94 additions, -97 deletions)

View changed files

📝 backend/open_webui/routers/tasks.py (+78 -97)
📝 backend/open_webui/utils/middleware.py (+16 -0)

📄 Description

Pull Request Checklist

Before submitting, make sure you've checked the following:

  • Target branch: Verify that the pull request targets the dev branch.
  • Description: Provided below.
  • Changelog: Included below.
  • Documentation: No user-facing configuration changes; existing ENABLE_DIRECT_CONNECTIONS and TASK_MODEL settings work correctly after this fix.
  • Dependencies: No new or changed dependencies.
  • Testing: Manually tested on a production AWS Fargate deployment (3 ECS tasks, Aurora PostgreSQL, ALB) with 28 models via LiteLLM gateway. Before/after results documented below.
  • Agentic AI Code: Code was authored with AI assistance (Claude Code) and has been thoroughly reviewed and manually tested by a human on a live production deployment.
  • Code review: Self-reviewed. Changes are minimal and targeted.
  • Design & Architecture: No new settings, no architectural changes. Fixes existing code paths to work as intended.
  • Git Hygiene: Single atomic commit, rebased on dev.
  • Title Prefix: fix:

Changelog Entry

Description

When ENABLE_DIRECT_CONNECTIONS=true and users chat via their own API keys, all background task generation (auto-title, tags, follow-ups, emoji, etc.) fails with either a 404 or TypeError: 'NoneType' object is not callable. This PR fixes two related code paths so the configured server-side task model is used correctly.

Fixed

  • Task generation endpoints (/api/v1/tasks/*/completions) no longer return 404 when the chat model is from a direct connection and a server-side task model is configured
  • Background task handler (background_tasks_handler) no longer crashes with TypeError when generating titles/tags after a direct connection chat completion

Additional Information

Two root causes addressed:

  1. HTTP endpoint path (tasks.py): The model existence check validated the chat model against request.app.state.MODELS before get_task_model_id() could resolve to the configured task model. Direct connection models aren't in the server's MODELS registry, so this raised a 404 — even though the configured task model was available. Fix: Task endpoints now always use request.app.state.MODELS and validate the resolved task_model_id after get_task_model_id() runs.

  2. Internal middleware path (middleware.py): After a chat completion, background_tasks_handler called generate_title/generate_chat_tags with the original request that still had request.state.direct = True. This routed task generation through generate_direct_chat_completion, which required an active WebSocket session unavailable in the background task context — causing event_caller to be None. Fix: background_tasks_handler temporarily clears request.state.direct so task generation routes through the standard server-side path, then restores the original state.

Error traceback (before fix):

middleware.py:5020 → await background_tasks_handler(ctx)
  middleware.py:3112 → res = await generate_title(request, {...}, user)
    tasks.py:220     → return await generate_direct_chat_completion(...)
      chat.py:140    → res = await event_caller({...})
TypeError: 'NoneType' object is not callable

Screenshots or Videos

Before fix — server logs show TypeError on every chat via direct connection:

ERROR | open_webui.routers.tasks:generate_title:222 - Exception occurred
  File "/app/backend/open_webui/utils/middleware.py", line 5020, in response_handler
TypeError: 'NoneType' object is not callable
ERROR | open_webui.routers.tasks:generate_chat_tags:358 - Error generating chat completion: 'NoneType' object is not callable

After fix — title generation succeeds, zero errors:

INFO | "POST /api/v1/tasks/title/completions HTTP/1.1" 200

(No TypeError or 404 errors in logs after deploying the patched image to production)

Test environment:

  • Open WebUI v0.9.2 on AWS Fargate (ARM64), 3 ECS tasks
  • ENABLE_DIRECT_CONNECTIONS=true, ENABLE_OLLAMA_API=False
  • Server-level OpenAI connection via LiteLLM gateway (28 models)
  • Task Model set to "Amazon Nova Micro" in Admin Settings
  • Users chatting via direct connections to Claude, GPT, Gemini, and other models

Contributor License Agreement


🔄 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/24100 **Author:** [@champumbc](https://github.com/champumbc) **Created:** 4/24/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/direct-connection-task-generation` --- ### 📝 Commits (1) - [`d827039`](https://github.com/open-webui/open-webui/commit/d827039b1ba7777d25fae5e416eee9ad4727b99d) Fix task generation (title, tags, etc.) failing for direct connection chats ### 📊 Changes **2 files changed** (+94 additions, -97 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/tasks.py` (+78 -97) 📝 `backend/open_webui/utils/middleware.py` (+16 -0) </details> ### 📄 Description <!-- ⚠️ CRITICAL CHECKS FOR CONTRIBUTORS (READ, DON'T DELETE) ⚠️ 1. Target the `dev` branch. PRs targeting `main` will be automatically closed. 2. Do NOT delete the CLA section at the bottom. It is required for the bot to accept your PR. --> # Pull Request Checklist **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Verify that the pull request targets the `dev` branch. - [x] **Description:** Provided below. - [x] **Changelog:** Included below. - [ ] **Documentation:** No user-facing configuration changes; existing `ENABLE_DIRECT_CONNECTIONS` and `TASK_MODEL` settings work correctly after this fix. - [x] **Dependencies:** No new or changed dependencies. - [x] **Testing:** Manually tested on a production AWS Fargate deployment (3 ECS tasks, Aurora PostgreSQL, ALB) with 28 models via LiteLLM gateway. Before/after results documented below. - [x] **Agentic AI Code:** Code was authored with AI assistance (Claude Code) and has been thoroughly reviewed and manually tested by a human on a live production deployment. - [x] **Code review:** Self-reviewed. Changes are minimal and targeted. - [x] **Design & Architecture:** No new settings, no architectural changes. Fixes existing code paths to work as intended. - [x] **Git Hygiene:** Single atomic commit, rebased on `dev`. - [x] **Title Prefix:** `fix:` # Changelog Entry ### Description When `ENABLE_DIRECT_CONNECTIONS=true` and users chat via their own API keys, all background task generation (auto-title, tags, follow-ups, emoji, etc.) fails with either a 404 or `TypeError: 'NoneType' object is not callable`. This PR fixes two related code paths so the configured server-side task model is used correctly. ### Fixed - Task generation endpoints (`/api/v1/tasks/*/completions`) no longer return 404 when the chat model is from a direct connection and a server-side task model is configured - Background task handler (`background_tasks_handler`) no longer crashes with `TypeError` when generating titles/tags after a direct connection chat completion --- ### Additional Information **Two root causes addressed:** 1. **HTTP endpoint path (`tasks.py`):** The model existence check validated the *chat* model against `request.app.state.MODELS` before `get_task_model_id()` could resolve to the configured task model. Direct connection models aren't in the server's MODELS registry, so this raised a 404 — even though the configured task model was available. **Fix:** Task endpoints now always use `request.app.state.MODELS` and validate the resolved `task_model_id` after `get_task_model_id()` runs. 2. **Internal middleware path (`middleware.py`):** After a chat completion, `background_tasks_handler` called `generate_title`/`generate_chat_tags` with the original request that still had `request.state.direct = True`. This routed task generation through `generate_direct_chat_completion`, which required an active WebSocket session unavailable in the background task context — causing `event_caller` to be `None`. **Fix:** `background_tasks_handler` temporarily clears `request.state.direct` so task generation routes through the standard server-side path, then restores the original state. **Error traceback (before fix):** ``` middleware.py:5020 → await background_tasks_handler(ctx) middleware.py:3112 → res = await generate_title(request, {...}, user) tasks.py:220 → return await generate_direct_chat_completion(...) chat.py:140 → res = await event_caller({...}) TypeError: 'NoneType' object is not callable ``` - Related issues: #24092, #24095 ### Screenshots or Videos **Before fix** — server logs show TypeError on every chat via direct connection: ``` ERROR | open_webui.routers.tasks:generate_title:222 - Exception occurred File "/app/backend/open_webui/utils/middleware.py", line 5020, in response_handler TypeError: 'NoneType' object is not callable ERROR | open_webui.routers.tasks:generate_chat_tags:358 - Error generating chat completion: 'NoneType' object is not callable ``` **After fix** — title generation succeeds, zero errors: ``` INFO | "POST /api/v1/tasks/title/completions HTTP/1.1" 200 ``` (No TypeError or 404 errors in logs after deploying the patched image to production) **Test environment:** - Open WebUI v0.9.2 on AWS Fargate (ARM64), 3 ECS tasks - `ENABLE_DIRECT_CONNECTIONS=true`, `ENABLE_OLLAMA_API=False` - Server-level OpenAI connection via LiteLLM gateway (28 models) - Task Model set to "Amazon Nova Micro" in Admin Settings - Users chatting via direct connections to Claude, GPT, Gemini, and other models ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 --> - [x] 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. --- <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-04-25 14:49:21 -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#43135