[PR #24936] [CLOSED] fix: prevent orphaned knowledge files by ensuring atomic upload-process-link chain #131601

Closed
opened 2026-05-21 17:18:22 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24936
Author: @paulxg12
Created: 5/20/2026
Status: Closed

Base: devHead: fix/orphaned-knowledge-files


📝 Commits (1)

  • 1d7a2ea fix: prevent orphaned knowledge files by ensuring atomic upload-process-link chain

📊 Changes

1 file changed (+26 additions, -4 deletions)

View changed files

📝 backend/open_webui/routers/knowledge.py (+26 -4)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.

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

  • Linked Issue/Discussion: This PR references an existing Issue or DiscussionCloses #24807
  • Target branch: The pull request targets the dev branch.
  • Description: A concise description of the changes is provided below.
  • Changelog: A changelog entry following Keep a Changelog format is included at the bottom.
  • Testing: Manual tests have been performed to verify the fix/feature works correctly.
  • Self-Review: A self-review of the code has been performed.
  • Git Hygiene: The PR is atomic (one logical change), rebased on dev, and contains no unrelated commits.
  • Title Prefix: fix: Bug fixes or corrections

Closes #24807

Description

Root cause: Knowledge upload pipeline did linking AFTER processing.
If user navigated away during the slow embedding step (5-60s), files
were orphaned in the vector DB with no relational record.

Fix (applied to both endpoints):

  • add_file_to_knowledge_by_id: Link file to knowledge base FIRST,
    then process. If processing fails, rollback the link.
  • add_files_to_knowledge_batch: Link all files FIRST, then process.
    If processing fails, rollback all links. After processing, unlink
    any files that failed.

Changelog

Fixed

  • Prevent orphaned knowledge files by ensuring atomic upload-process-link chain

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/24936 **Author:** [@paulxg12](https://github.com/paulxg12) **Created:** 5/20/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/orphaned-knowledge-files` --- ### 📝 Commits (1) - [`1d7a2ea`](https://github.com/open-webui/open-webui/commit/1d7a2ea215f8f67f5af911dd86cb08381f6b7e43) fix: prevent orphaned knowledge files by ensuring atomic upload-process-link chain ### 📊 Changes **1 file changed** (+26 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/knowledge.py` (+26 -4) </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 ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Linked Issue/Discussion:** This PR references an existing [Issue](https://github.com/open-webui/open-webui/issues) or [Discussion](https://github.com/open-webui/open-webui/discussions) — `Closes #24807` - [x] **Target branch:** The pull request targets the `dev` branch. - [x] **Description:** A concise description of the changes is provided below. - [x] **Changelog:** A changelog entry following [Keep a Changelog](https://keepachangelog.com/) format is included at the bottom. - [x] **Testing:** Manual tests have been performed to verify the fix/feature works correctly. - [x] **Self-Review:** A self-review of the code has been performed. - [x] **Git Hygiene:** The PR is atomic (one logical change), rebased on `dev`, and contains no unrelated commits. - [x] **Title Prefix:** fix: Bug fixes or corrections Closes #24807 ## Description **Root cause**: Knowledge upload pipeline did linking AFTER processing. If user navigated away during the slow embedding step (5-60s), files were orphaned in the vector DB with no relational record. **Fix** (applied to both endpoints): - `add_file_to_knowledge_by_id`: Link file to knowledge base FIRST, then process. If processing fails, rollback the link. - `add_files_to_knowledge_batch`: Link all files FIRST, then process. If processing fails, rollback all links. After processing, unlink any files that failed. ## Changelog ### Fixed - Prevent orphaned knowledge files by ensuring atomic upload-process-link chain ### 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-05-21 17:18:22 -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#131601