-
Notifications
You must be signed in to change notification settings - Fork 57
fix(workspaces): preserve file workspace memberships on PUT and PATCH #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
paultranvan
merged 2 commits into
dev
from
fix/workspace-membership-lost-on-file-replace
Mar 17, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard workspace restoration on partition moves, and keep it best-effort.
workspace_idshere are captured from the original partition, butopenrag/routers/indexer.pyLines 339-346 allow PATCH to move the file to a different partition. Re-adding those IDs on Lines 205-208 would recreateworkspace_filesrows for workspaces that still belong to the old partition, and any exception here currently makes the PATCH fail after the file has already been reindexed successfully.Proposed fix
# Snapshot workspace memberships before deletion so they can be restored. workspace_ids = await vectordb.get_file_workspaces.remote(file_id, partition) await self.delete_file(file_id, partition) await vectordb.async_add_documents.remote(docs, user=user) # Restore workspace memberships that existed before the delete. - if workspace_ids: - await asyncio.gather( - *[vectordb.add_files_to_workspace.remote(ws_id, [file_id]) for ws_id in workspace_ids] - ) - log.debug("Restored workspace memberships after metadata update.", workspace_ids=workspace_ids) + target_partition = metadata.get("partition", partition) + if workspace_ids and target_partition == partition: + try: + await asyncio.gather( + *[vectordb.add_files_to_workspace.remote(ws_id, [file_id]) for ws_id in workspace_ids] + ) + log.debug( + "Restored workspace memberships after metadata update.", + workspace_ids=workspace_ids, + ) + except Exception as ws_err: + log.warning( + "Failed to restore workspace memberships after metadata update.", + error=str(ws_err), + workspace_ids=workspace_ids, + ) + elif workspace_ids: + log.info( + "Skipping workspace restoration because the file moved to a different partition.", + old_partition=partition, + new_partition=target_partition, + workspace_ids=workspace_ids, + )Based on learnings: workspace association is a best-effort metadata step and failures should be logged without turning a successfully indexed file into a failed operation.
🤖 Prompt for AI Agents