Repository navigation
[dogfood][devin-swe2] fix(backend): keep the picked file name on chat uploads - #15207
Git-on-my-level wants to merge 1 commit into
Conversation
Both /v1/files and /v2/files stage uploads under a uuid-prefixed temp
path, and FileChatTool.upload sent that path to the provider, so the
stored FileChat.name became "<uuid>_photo.png" instead of "photo.png".
FileChatTool.upload now takes the caller's picked file_name and sends it
as the multipart filename, so the provider record and the saved chat
file both carry the original name.
Verified: backend/.venv pytest tests/unit/test_chat_file_upload_filename.py
fails on the unfixed tree ("<uuid>_photo.png" != "photo.png") and passes
with the fix; 70 related chat-file tests pass.
Failure-Class: none
Co-authored-by: multica-agent <[email protected]>
|
Superseded by #15336, which keeps this PR's production fix (the |
|
Hey @Git-on-my-level 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
## 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`) as `FileChat.name` instead of the name the user picked. Both `POST /v1/files` and `POST /v2/files` stage bytes under `Path(tempfile.gettempdir()) / f"{uuid.hex}_{safe_suffix}"` for path-traversal safety, and `FileChatTool.upload` sent that temp handle to `openai.files.create`, so the provider echoed the temp basename back into `response.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 and `result["file_name"]` follows it. The v1/v2 handlers pass their already-sanitized `safe_suffix` (`Path(file.filename).name`), and `upload` re-takes `Path(file_name).name` defensively, so a directory-carrying picked name (`../../photo.txt`) reduces to its basename. No `file_name` → unchanged behavior for direct callers. Differs from #14970, which overrode `FileChat.name` at 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). - Same file on the unfixed tree (`git stash` of the two production files): 5 fail, reproducing the issue exactly (`assert '96b2a5a72e49…_photo.png' == 'photo.png'` on the provider double; `TypeError` on the direct kwarg tests). - 75 related chat-file / upload-security tests pass (`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-preflight` with this body: clean. ## Product invariants affected none Failure-Class: none <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/15336?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
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 (BasedHardware#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 BasedHardware#15207 and BasedHardware#15210. Failure-Class: none
Summary
Fixes #15179.
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}", andFileChatTool.uploadsent that temp path 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)now accepts the caller's picked name and sends it as the multipart filename (the SDK's(name, fileobj)form), so the provider record andresult["file_name"]both carry the original name. The v1/v2 handlers pass their already-sanitizedsafe_suffix(Path(file.filename).name), anduploadre-takesPath(file_name).namedefensively. Nofile_name→ unchanged behavior.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_filename.py— 3 pass with the fix.git stash): fails withassert 'c5b12e30b2c9…d00_photo.png' == 'photo.png'— reproduces the issue exactly.test_chat_file_upload_unsupported,test_chat_file_completions,test_chat_file_gateway_surface,test_file_upload_endpoint_security,test_file_upload_security, vision/stream variants).make preflightlocal lane: clean except this declaration, which this body provides.Failure-Class: none