Repository navigation
fix(backend): keep the picked file name on chat uploads - #14970
jitendravjh wants to merge 1 commit into
Conversation
016081c to
db53c5b
Compare
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verified this end to end — thanks for the clean fix and the regression tests.
What I checked:
- backend/routers/chat.py — both
upload_file_chat(/v2/files) andupload_file_chat_v1(/v1/files) now collectresult["thumbnail"](the temp-dir path thatutils/other/chat_file.pyactually writes to since #6804) and upload from those paths. The old code passed barethumbnail_names whilestorage.upload_multi_chat_filesprefixed them with./, pointing at the server CWD where thumbnails no longer exist — which matches the #14969 symptom. Temp cleanup moved toPath(thumb_path).unlink(missing_ok=True), so it no longer silently skips. Both routes fixed identically. - backend/utils/other/storage.py —
upload_multi_chat_filesnow takes real paths and derives the blob key withos.path.basename(file_path). Since the router already sanitizes uploads withPath(filename).name, the basename keeps GCS keys under{uid}/and blocks any stray path separator from escaping the user prefix.osis already imported here. - backend/tests/unit/test_chat_image_thumbnail_upload.py — hermetic (GCS/OpenAI seams mocked, sys.modules snapshot harness), covers both routes, asserts the uploaded path and its cleanup. I ran the suite in a scratch worktree: 3/3 pass on this head, and all 3 fail against the pre-PR router/storage, so they genuinely capture the bug. The pre-existing chat upload suites still pass (27/27).
One deliberate behavior change worth a maintainer's eye: FileChat.name now uses safe_suffix (the original upload filename) instead of the provider-echoed file_name, so stored chat files keep the name the user uploaded with rather than the uuid-prefixed temp name. That's the second commit's intent and is covered by the name == 'photo.png' assertion; it is user-visible in stored chat file metadata, so a quick product sign-off alongside the merge would be good.
Fixes the #14969 symptom on both routes. Leaving the merge call to a human maintainer.
🤖 Automated review on behalf of the maintainers.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Verified on Leaving this open as the unique remaining-hole vehicle ( Not approving: hosted CI has not gone green on this SHA. kodjima APPROVE is not a merge. I am not merging. |
db53c5b to
11423c0
Compare
11423c0 to
686e79b
Compare
## 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. -->
|
Closing as superseded, with full credit for the fix — everything here has landed on main through another vehicle. What I verified on 686e79b before reaching that conclusion:
Why superseded: main landed the same fix in 6bcfe65 ("fix(backend): keep the picked file name on chat uploads", refs #15179) a few hours after this rebase. It takes the complementary approach — FileChatTool.upload now accepts file_name=safe_suffix and passes the SDK's (filename, fileobj) tuple so the provider record itself keeps the picked name, with the routes still reading result.get("file_name") — and ships its own regression suite (test_chat_file_upload_picked_name.py). With that on main, this branch's remaining diff is redundant, so closing rather than asking for yet another rebase. Thank you — the diagnosis in #15179 and the regression tests here are what made the fix straightforward to land. The proposal in #15179 stays tracked on the issue. 🤖 Automated review on behalf of the maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Hey @jitendravjh 👋 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! |
Fixes #15179
Chat file uploads now save the name the user picked instead of the temp name with the uuid prefix, on both
/v1/filesand/v2/files.Added
tests/unit/test_chat_file_upload_name.py, fails on main with the uuid prefixed name and passes now.This PR also carried a thumbnail fix earlier. That part landed on main through #15033, so the branch is rebased down to the file name fix.
Failure-Class: none