[PR #17587] [CLOSED] feat: use RedisDict for MODELS state when Redis is available #47527

Closed
opened 2026-04-29 22:48:04 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/17587
Author: @acwoo97
Created: 9/19/2025
Status: Closed

Base: devHead: feat/models-in-multi-instance


📝 Commits (1)

  • 90d0cda feat(models): use RedisDict for MODELS state when Redis is available

📊 Changes

3 files changed (+29 additions, -5 deletions)

View changed files

📝 backend/open_webui/main.py (+12 -3)
📝 backend/open_webui/socket/utils.py (+10 -0)
📝 backend/open_webui/utils/models.py (+7 -2)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

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

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

  • Introduced Redis-backed storage for application models (MODELS) to replace the in-memory dictionary when REDIS_URL is configured.
  • Motivation: ensure model state is properly synchronized across multiple instances in distributed deployments, as local in-memory state does not propagate.
  • Implemented replace_all in RedisDict using Redis pipelines for atomic operations, preventing potential race conditions between DELETE and HSET.

Added

  • RedisDict.replace_all(mapping) method with pipeline support (pipe.delete + pipe.hset + pipe.execute), ensuring atomic replacement of all model entries.

Changed

  • app.state.MODELS initialization now conditionally uses RedisDict instead of plain {} when Redis is available.
  • Model updates now call RedisDict.replace_all if using Redis storage, ensuring full state synchronization across instances.

Deprecated

  • None

Removed

  • Previous approach of using only in-memory dict to manage models.

Fixed

  • Fixed issue where model state changes were not propagated across multiple instances, leading to inconsistent application state.

Security

  • None

Breaking Changes

  • BREAKING CHANGE: In environments where Redis is enabled, app.state.MODELS is now backed by Redis instead of an in-memory dict, potentially changing persistence and runtime behavior.

Additional Information

  • Implemented Redis pipelines in replace_all to ensure atomic state replacement and avoid transient states during delete/set operations.
  • Maintains backward compatibility by falling back to an in-memory dict if no Redis connection is configured.
  • Related motivation: prevent model state desynchronization in multi-instance deployments.

Screenshots or Videos

  • N/A

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.


🔄 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/17587 **Author:** [@acwoo97](https://github.com/acwoo97) **Created:** 9/19/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feat/models-in-multi-instance` --- ### 📝 Commits (1) - [`90d0cda`](https://github.com/open-webui/open-webui/commit/90d0cda3604dd33d7c082b98e69231a2a2abdbbf) feat(models): use RedisDict for MODELS state when Redis is available ### 📊 Changes **3 files changed** (+29 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/main.py` (+12 -3) 📝 `backend/open_webui/socket/utils.py` (+10 -0) 📝 `backend/open_webui/utils/models.py` (+7 -2) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [ ] **Target branch:** Please verify that the pull request targets the `dev` branch. - [ ] **Description:** Provide a concise description of the changes made in this pull request. - [ ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [ ] **Testing:** Have you written and run sufficient tests to validate the changes? - [ ] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [ ] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description - Introduced Redis-backed storage for application models (`MODELS`) to replace the in-memory dictionary when `REDIS_URL` is configured. - Motivation: ensure model state is properly synchronized across multiple instances in distributed deployments, as local in-memory state does not propagate. - Implemented `replace_all` in `RedisDict` using Redis pipelines for atomic operations, preventing potential race conditions between `DELETE` and `HSET`. ### Added - `RedisDict.replace_all(mapping)` method with pipeline support (`pipe.delete` + `pipe.hset` + `pipe.execute`), ensuring atomic replacement of all model entries. ### Changed - `app.state.MODELS` initialization now conditionally uses `RedisDict` instead of plain `{}` when Redis is available. - Model updates now call `RedisDict.replace_all` if using Redis storage, ensuring full state synchronization across instances. ### Deprecated - None ### Removed - Previous approach of using only in-memory `dict` to manage models. ### Fixed - Fixed issue where model state changes were not propagated across multiple instances, leading to inconsistent application state. ### Security - None ### Breaking Changes - **BREAKING CHANGE**: In environments where Redis is enabled, `app.state.MODELS` is now backed by Redis instead of an in-memory dict, potentially changing persistence and runtime behavior. --- ### Additional Information - Implemented Redis pipelines in `replace_all` to ensure atomic state replacement and avoid transient states during delete/set operations. - Maintains backward compatibility by falling back to an in-memory dict if no Redis connection is configured. - Related motivation: prevent model state desynchronization in multi-instance deployments. ### Screenshots or Videos - N/A ### 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. --- <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-29 22:48:04 -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#47527