After crash, the active_chat_tasks check returns true for chats with dead tasks
Solution
Startup cleanup: Clear all Redis task records when the application starts (since no tasks can survive a restart)
TTL for item task sets: Add 24-hour TTL to item task sets for automatic cleanup
Logging: Log how many stale tasks were cleaned on startup
Changes
backend/open_webui/tasks.py:
Add clear_all_redis_tasks() function
Add REDIS_TASK_TTL constant (24 hours)
Add TTL to item task sets in redis_save_task()
backend/open_webui/main.py:
Import and call clear_all_redis_tasks() in lifespan
Testing
Manual testing: After a crash, restart clears stale tasks
Unit tests: Existing task tests continue to pass
Checklist
Code changes are minimal and focused
No breaking changes to existing functionality
Includes logging for debugging
Fixes the reported issue
🔄 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/23058
**Author:** [@yang1002378395-cmyk](https://github.com/yang1002378395-cmyk)
**Created:** 3/26/2026
**Status:** ❌ Closed
**Base:** `main` ← **Head:** `fix-redis-task-ttl`
---
### 📝 Commits (2)
- [`efb0f9a`](https://github.com/open-webui/open-webui/commit/efb0f9a6f29ce9afa1ee50b7e6bb3d628e636fd2) fix: add pagination to chat list endpoints to prevent OOM
- [`db10981`](https://github.com/open-webui/open-webui/commit/db10981fbcbdbe204008d1b4e7378d4a839e0c8d) fix: clear stale Redis tasks on startup
### 📊 Changes
**4 files changed** (+68 additions, -15 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/main.py` (+3 -0)
📝 `backend/open_webui/models/chats.py` (+19 -9)
📝 `backend/open_webui/routers/chats.py` (+15 -6)
📝 `backend/open_webui/tasks.py` (+31 -0)
</details>
### 📄 Description
## Problem
After a server crash or unclean shutdown, Redis task records persist indefinitely, causing the error:
```
'Chat already has a task in progress'
```
This prevents users from generating titles until the Redis records are manually cleared.
Fixes #22525
## Root Cause
1. Task records stored in Redis have no TTL
2. No startup cleanup to remove stale records
3. After crash, the `active_chat_tasks` check returns true for chats with dead tasks
## Solution
1. **Startup cleanup**: Clear all Redis task records when the application starts (since no tasks can survive a restart)
2. **TTL for item task sets**: Add 24-hour TTL to item task sets for automatic cleanup
3. **Logging**: Log how many stale tasks were cleaned on startup
## Changes
- `backend/open_webui/tasks.py`:
- Add `clear_all_redis_tasks()` function
- Add `REDIS_TASK_TTL` constant (24 hours)
- Add TTL to item task sets in `redis_save_task()`
- `backend/open_webui/main.py`:
- Import and call `clear_all_redis_tasks()` in lifespan
## Testing
- Manual testing: After a crash, restart clears stale tasks
- Unit tests: Existing task tests continue to pass
## Checklist
- [x] Code changes are minimal and focused
- [x] No breaking changes to existing functionality
- [x] Includes logging for debugging
- [x] Fixes the reported issue
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23058
Author: @yang1002378395-cmyk
Created: 3/26/2026
Status: ❌ Closed
Base:
main← Head:fix-redis-task-ttl📝 Commits (2)
efb0f9afix: add pagination to chat list endpoints to prevent OOMdb10981fix: clear stale Redis tasks on startup📊 Changes
4 files changed (+68 additions, -15 deletions)
View changed files
📝
backend/open_webui/main.py(+3 -0)📝
backend/open_webui/models/chats.py(+19 -9)📝
backend/open_webui/routers/chats.py(+15 -6)📝
backend/open_webui/tasks.py(+31 -0)📄 Description
Problem
After a server crash or unclean shutdown, Redis task records persist indefinitely, causing the error:
This prevents users from generating titles until the Redis records are manually cleared.
Fixes #22525
Root Cause
active_chat_taskscheck returns true for chats with dead tasksSolution
Startup cleanup: Clear all Redis task records when the application starts (since no tasks can survive a restart)
TTL for item task sets: Add 24-hour TTL to item task sets for automatic cleanup
Logging: Log how many stale tasks were cleaned on startup
Changes
backend/open_webui/tasks.py:clear_all_redis_tasks()functionREDIS_TASK_TTLconstant (24 hours)redis_save_task()backend/open_webui/main.py:clear_all_redis_tasks()in lifespanTesting
Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.