mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 02:48:13 -05:00
[PR #24100] fix: Task generation (title, tags, etc.) failing for direct connection chats #43135
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/24100
Author: @champumbc
Created: 4/24/2026
Status: 🔄 Open
Base:
dev← Head:fix/direct-connection-task-generation📝 Commits (1)
d827039Fix 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:
devbranch.ENABLE_DIRECT_CONNECTIONSandTASK_MODELsettings work correctly after this fix.dev.fix:Changelog Entry
Description
When
ENABLE_DIRECT_CONNECTIONS=trueand users chat via their own API keys, all background task generation (auto-title, tags, follow-ups, emoji, etc.) fails with either a 404 orTypeError: 'NoneType' object is not callable. This PR fixes two related code paths so the configured server-side task model is used correctly.Fixed
/api/v1/tasks/*/completions) no longer return 404 when the chat model is from a direct connection and a server-side task model is configuredbackground_tasks_handler) no longer crashes withTypeErrorwhen generating titles/tags after a direct connection chat completionAdditional Information
Two root causes addressed:
HTTP endpoint path (
tasks.py): The model existence check validated the chat model againstrequest.app.state.MODELSbeforeget_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 userequest.app.state.MODELSand validate the resolvedtask_model_idafterget_task_model_id()runs.Internal middleware path (
middleware.py): After a chat completion,background_tasks_handlercalledgenerate_title/generate_chat_tagswith the original request that still hadrequest.state.direct = True. This routed task generation throughgenerate_direct_chat_completion, which required an active WebSocket session unavailable in the background task context — causingevent_callerto beNone. Fix:background_tasks_handlertemporarily clearsrequest.state.directso task generation routes through the standard server-side path, then restores the original state.Error traceback (before fix):
Screenshots or Videos
Before fix — server logs show TypeError on every chat via direct connection:
After fix — title generation succeeds, zero errors:
(No TypeError or 404 errors in logs after deploying the patched image to production)
Test environment:
ENABLE_DIRECT_CONNECTIONS=true,ENABLE_OLLAMA_API=FalseContributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.