[PR #23044] fix(backend): clear orphaned Redis task IDs on startup and explicit stop (#22525) #42623

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

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/23044
Author: @snesan821
Created: 3/25/2026
Status: 🔄 Open

Base: devHead: main


📝 Commits (1)

  • c092420 fix(backend): clear orphaned Redis task IDs on startup and explicit stop (#22525)

📊 Changes

2 files changed (+56 additions, -0 deletions)

View changed files

📝 backend/open_webui/main.py (+4 -0)
📝 backend/open_webui/tasks.py (+52 -0)

📄 Description

fix(backend): clear orphaned Redis task IDs on startup and explicit stop (#22525)

Description

This PR resolves a critical state-synchronization bug where generation tasks orphaned by a server restart would "brick" the UI in a permanent loading state. By implementing a startup cleanup routine and hardening the manual stop endpoint, we ensure Redis and in-memory state stay consistent even after crashes or rollouts.

Added

  • clear_all_tasks() function in backend/open_webui/tasks.py to handle bulk cleanup of Redis hash keys (REDIS_TASKS_KEY) and set patterns (REDIS_ITEM_TASKS_KEY:*).

Changed

  • lifespan handler in backend/open_webui/main.py now calls clear_all_tasks on startup to ensure a clean slate.
  • stop_task in backend/open_webui/tasks.py now explicitly deletes keys from Redis and local dictionaries instead of relying on background worker callbacks which may be dead.

Fixed

  • Fixed #22525: Orphaned task IDs in Redis causing permanent loading spinners in the sidebar and chat view.
  • Improved stop_task reliability by adding byte-decoding for Redis values and idempotent deletion logic.

Pull Request Checklist

  • Target branch: Verify that the pull request targets the dev branch.
  • Description: Concise description provided above.
  • Changelog: Entry added below.
  • Documentation: N/A (Internal backend fix).
  • Dependencies: No new dependencies.
  • Testing: Verified that orphaned tasks are cleared on startup and manual "Stop" now effectively unfreezes the UI.
  • Agentic AI Code: Code has undergone manual human review and syntax validation.
  • Code review: Self-review performed; Ruff linting passed.
  • Git Hygiene: Atomic change; rebased on latest code.

Changelog Entry

Fixed

  • Resolved issue #22525 where server restarts left orphaned generation tasks in Redis, causing the UI to hang indefinitely.

Additional Information

  • Issue handled: When the server restarts, background workers die before cleaning up their task IDs. The /stop endpoint previously only sent an abort signal; if no worker was alive to receive it, the Redis key stayed forever. This fix adds a "Hard Delete" to the stop command and a "Flush on Boot" to the server.

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/23044 **Author:** [@snesan821](https://github.com/snesan821) **Created:** 3/25/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `main` --- ### 📝 Commits (1) - [`c092420`](https://github.com/open-webui/open-webui/commit/c0924206d775b8837247759032c0fb730f73cb46) fix(backend): clear orphaned Redis task IDs on startup and explicit stop (#22525) ### 📊 Changes **2 files changed** (+56 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/main.py` (+4 -0) 📝 `backend/open_webui/tasks.py` (+52 -0) </details> ### 📄 Description # fix(backend): clear orphaned Redis task IDs on startup and explicit stop (#22525) ### Description This PR resolves a critical state-synchronization bug where generation tasks orphaned by a server restart would "brick" the UI in a permanent loading state. By implementing a startup cleanup routine and hardening the manual stop endpoint, we ensure Redis and in-memory state stay consistent even after crashes or rollouts. ### Added - `clear_all_tasks()` function in `backend/open_webui/tasks.py` to handle bulk cleanup of Redis hash keys (`REDIS_TASKS_KEY`) and set patterns (`REDIS_ITEM_TASKS_KEY:*`). ### Changed - `lifespan` handler in `backend/open_webui/main.py` now calls `clear_all_tasks` on startup to ensure a clean slate. - `stop_task` in `backend/open_webui/tasks.py` now explicitly deletes keys from Redis and local dictionaries instead of relying on background worker callbacks which may be dead. ### Fixed - Fixed #22525: Orphaned task IDs in Redis causing permanent loading spinners in the sidebar and chat view. - Improved `stop_task` reliability by adding byte-decoding for Redis values and idempotent deletion logic. --- # Pull Request Checklist - [x] **Target branch:** Verify that the pull request targets the `dev` branch. - [x] **Description:** Concise description provided above. - [x] **Changelog:** Entry added below. - [x] **Documentation:** N/A (Internal backend fix). - [x] **Dependencies:** No new dependencies. - [x] **Testing:** Verified that orphaned tasks are cleared on startup and manual "Stop" now effectively unfreezes the UI. - [x] **Agentic AI Code:** Code has undergone manual human review and syntax validation. - [x] **Code review:** Self-review performed; Ruff linting passed. - [x] **Git Hygiene:** Atomic change; rebased on latest code. # Changelog Entry ### Fixed - Resolved issue #22525 where server restarts left orphaned generation tasks in Redis, causing the UI to hang indefinitely. --- ### Additional Information - **Issue handled:** When the server restarts, background workers die before cleaning up their task IDs. The `/stop` endpoint previously only sent an abort signal; if no worker was alive to receive it, the Redis key stayed forever. This fix adds a "Hard Delete" to the stop command and a "Flush on Boot" to the server. ### Contributor License Agreement - [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:27:15 -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#42623