Repository navigation
fix(backend): keep the picked file name on chat uploads - #15336
Merged
Merged
Conversation
Both /v1/files and /v2/files stage each upload under a uuid temp name for path-traversal safety, and openai.files.create echoes the filename it was given back as response.filename. Sending the bare temp handle made the provider record — and the FileChat.name stored from it — carry <uuid32>_photo.png instead of photo.png (#15179). FileChatTool.upload now accepts the caller's picked name and sends the SDK's (filename, fileobj) tuple form so the provider record itself keeps the picked basename; the routes pass their already-sanitized safe_suffix, and upload re-takes Path(file_name).name defensively. No file_name means unchanged behavior for direct callers. Supersedes the dogfood comparison drafts #15207 and #15210. Failure-Class: none
This was referenced Sep 21, 2026
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.
Summary
Fixes #15179. Supersedes the dogfood comparison drafts #15207 and #15210 (best of each: the provider-record fix from the first, the stronger test file from the second).
Chat file uploads saved the backend's uuid-prefixed temp name (
ef0c40fc…_photo.png) asFileChat.nameinstead of the name the user picked. BothPOST /v1/filesandPOST /v2/filesstage bytes underPath(tempfile.gettempdir()) / f"{uuid.hex}_{safe_suffix}"for path-traversal safety, andFileChatTool.uploadsent that temp handle toopenai.files.create, so the provider echoed the temp basename back intoresponse.filename— the value stored on the chat file record.Fix at the shared upload path:
FileChatTool.upload(file_path, file_name=None)accepts the caller's picked name and sends the SDK's(filename, fileobj)tuple form, so the provider record itself carries the original name andresult["file_name"]follows it. The v1/v2 handlers pass their already-sanitizedsafe_suffix(Path(file.filename).name), anduploadre-takesPath(file_name).namedefensively, so a directory-carrying picked name (../../photo.txt) reduces to its basename. Nofile_name→ unchanged behavior for direct callers.Differs from #14970, which overrode
FileChat.nameat each call site; this fixes the name at the upload seam so the provider-side record is correct too.Verification
backend/.venv/bin/python -m pytest tests/unit/test_chat_file_upload_picked_name.py— 6 pass with the fix (both routes × image/document, provider-double sabotage, fallback, path-strip).git stashof the two production files): 5 fail, reproducing the issue exactly (assert '96b2a5a72e49…_photo.png' == 'photo.png'on the provider double;TypeErroron the direct kwarg tests).test_chat_file_upload_unsupported,test_chat_file_completions,test_chat_file_gateway_surface,test_chat_file_input_types,test_chat_file_skip_malformed,test_chat_file_vision_request,test_chat_file_vision_params,test_file_upload_endpoint_security,test_file_upload_security).scripts/pr-preflightwith this body: clean.Product invariants affected
none
Failure-Class: none