Fix duplicate gateway upload filenames#2789
Open
ZenCGL wants to merge 2 commits intobytedance:mainfrom
Open
Conversation
Fix duplicate gateway upload filenames
Collaborator
|
@ZenCGL, thanks for your contribution. Please create a GitHub issue for the bug you found. |
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents silent overwrites when a single multipart upload request contains multiple parts with the same filename by ensuring per-request filename uniqueness and exposing the original name when auto-renaming occurs.
Changes:
- Deduplicate filenames within
POST /api/threads/{thread_id}/uploadsusingclaim_unique_filename(...)and track seen names per request. - Include
original_filenamein the upload response when a file is renamed due to duplication. - Add a regression test and update backend docs to describe the new auto-rename behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| backend/app/gateway/routers/uploads.py | Tracks per-request seen filenames and auto-renames duplicates; adds original_filename in response when renamed. |
| backend/tests/test_uploads_router.py | Adds regression test ensuring duplicate form filenames persist as distinct files with preserved contents. |
| backend/README.md | Documents auto-renaming behavior for duplicate filenames in a single upload request. |
| backend/CLAUDE.md | Notes the duplicate-filename auto-rename behavior in the file upload feature description. |
Comment on lines
+71
to
+75
| with ( | ||
| patch.object(uploads, "get_uploads_dir", return_value=thread_uploads_dir), | ||
| patch.object(uploads, "ensure_uploads_dir", return_value=thread_uploads_dir), | ||
| patch.object(uploads, "get_sandbox_provider", return_value=provider), | ||
| ): |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Description
claim_unique_filenamehelper to auto-rename duplicate filenames within a singlePOST /api/threads/{thread_id}/uploadsrequest by adding_Nsuffixes and track them with aseen_filenamesset so later parts do not truncate earlier ones in the same request (app/gateway/routers/uploads.py).original_filenamein the upload response when a part was renamed so callers/agents can see the original basename (app/gateway/routers/uploads.py).test_upload_files_auto_renames_duplicate_form_filenamesproving two form parts nameddata.txtare persisted asdata.txtanddata_1.txtwith preserved contents (tests/test_uploads_router.py).backend/README.md,backend/CLAUDE.md).Testing
cd backend && PYTHONPATH=. uv run pytest tests/test_uploads_router.py -q, all tests passed (29 passed).cd backend && uv run ruff check app/gateway/routers/uploads.py tests/test_uploads_router.pyand fixed import ordering; final check passed.Fixes #2795 -