[PR #24831] [CLOSED] fix: auto-link files to Knowledge Collection after processing completes #131544

Closed
opened 2026-05-21 17:10:38 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24831
Author: @kindredzhang
Created: 5/17/2026
Status: Closed

Base: devHead: fix/knowledge-upload-24807


📝 Commits (1)

  • 2c75d4b fix: auto-link files to Knowledge Collection after processing completes

📊 Changes

1 file changed (+15 additions, -0 deletions)

View changed files

📝 backend/open_webui/routers/files.py (+15 -0)

📄 Description

Pull Request Checklist

  • Linked Issue/Discussion: Closes #24807
  • Target branch: dev
  • Description: Concise description down below.
  • Changelog: Added at the bottom.
  • Documentation: N/A — backend behavior fix, no new user-facing API or config.
  • Dependencies: N/A — no new dependencies.
  • Testing: Locally verified with pytest; backend logic confirmed correct.
  • Agentic AI Code: Human reviewed and manually verified.
  • Code review: Performed self-review.
  • Design & Architecture: Minimal, targeted fix; no new settings or state introduced.
  • Git Hygiene: Single atomic commit.
  • Title Prefix: fix

Description

When a file is uploaded to a Knowledge Collection, the final linking step previously depended on the frontend calling POST /knowledge/{id}/file/add after the SSE processing stream completed. If the user navigated away before that call fired, the file was processed successfully but permanently orphaned — visible in Global Files but absent from the Knowledge Collection.

This change moves the linking operation server-side, inside process_uploaded_file(), after process_file() finishes. The upload request already carries knowledge_id in file metadata, so the backend has all the information needed to complete the association without any frontend participation.

The existing frontend code in KnowledgeBase.svelte still calls addFileHandler() after upload — for Knowledge Collection uploads this becomes a duplicate call, but Knowledges.add_file_to_knowledge_by_id() is idempotent (DB insert is a no-op on duplicate), so no harm is done.

Validation

ruff format --check backend/open_webui/routers/files.py

ruff check backend/open_webui/routers/files.py


Changelog Entry

Fixed

  • Knowledge upload can leave processed files unlinked when user navigates away before the final linking request fires. Linking is now completed server-side during process_uploaded_file(), removing the dependence on the frontend maintaining an active SSE connection.

Screenshots or Videos

Not applicable; backend behavior fix, no UI change.


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/24831 **Author:** [@kindredzhang](https://github.com/kindredzhang) **Created:** 5/17/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix/knowledge-upload-24807` --- ### 📝 Commits (1) - [`2c75d4b`](https://github.com/open-webui/open-webui/commit/2c75d4bf355b77f52a32d0f449bf661eca1c70b6) fix: auto-link files to Knowledge Collection after processing completes ### 📊 Changes **1 file changed** (+15 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/files.py` (+15 -0) </details> ### 📄 Description # Pull Request Checklist - [x] **Linked Issue/Discussion:** `Closes #24807` - [x] **Target branch:** `dev` - [x] **Description:** Concise description down below. - [x] **Changelog:** Added at the bottom. - [x] **Documentation:** N/A — backend behavior fix, no new user-facing API or config. - [x] **Dependencies:** N/A — no new dependencies. - [x] **Testing:** Locally verified with pytest; backend logic confirmed correct. - [x] **Agentic AI Code:** Human reviewed and manually verified. - [x] **Code review:** Performed self-review. - [x] **Design & Architecture:** Minimal, targeted fix; no new settings or state introduced. - [x] **Git Hygiene:** Single atomic commit. - [x] **Title Prefix:** `fix` --- ## Description When a file is uploaded to a Knowledge Collection, the final linking step previously depended on the frontend calling `POST /knowledge/{id}/file/add` after the SSE processing stream completed. If the user navigated away before that call fired, the file was processed successfully but permanently orphaned — visible in Global Files but absent from the Knowledge Collection. This change moves the linking operation server-side, inside `process_uploaded_file()`, after `process_file()` finishes. The upload request already carries `knowledge_id` in file metadata, so the backend has all the information needed to complete the association without any frontend participation. The existing frontend code in `KnowledgeBase.svelte` still calls `addFileHandler()` after upload — for Knowledge Collection uploads this becomes a duplicate call, but `Knowledges.add_file_to_knowledge_by_id()` is idempotent (DB insert is a no-op on duplicate), so no harm is done. ## Validation ```bash ruff format --check backend/open_webui/routers/files.py ruff check backend/open_webui/routers/files.py ``` --- ## Changelog Entry ### Fixed - Knowledge upload can leave processed files unlinked when user navigates away before the final linking request fires. Linking is now completed server-side during `process_uploaded_file()`, removing the dependence on the frontend maintaining an active SSE connection. --- ## Screenshots or Videos Not applicable; backend behavior fix, no UI change. --- ## 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:10:38 -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#131544