Skip to content

fix(backend): keep the picked file name on chat uploads - #14970

Closed
jitendravjh wants to merge 1 commit into
BasedHardware:mainfrom
jitendravjh:fix/chat-image-thumbnails
Closed

jitendravjh wants to merge 1 commit into
BasedHardware:mainfrom
jitendravjh:fix/chat-image-thumbnails

Conversation

@jitendravjh

@jitendravjh jitendravjh commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15179

Chat file uploads now save the name the user picked instead of the temp name with the uuid prefix, on both /v1/files and /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

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and upload_file_chat_v1 (/v1/files) now collect result["thumbnail"] (the temp-dir path that utils/other/chat_file.py actually writes to since #6804) and upload from those paths. The old code passed bare thumbnail_names while storage.upload_multi_chat_files prefixed them with ./, pointing at the server CWD where thumbnails no longer exist — which matches the #14969 symptom. Temp cleanup moved to Path(thumb_path).unlink(missing_ok=True), so it no longer silently skips. Both routes fixed identically.
  • backend/utils/other/storage.py — upload_multi_chat_files now takes real paths and derives the blob key with os.path.basename(file_path). Since the router already sanitizes uploads with Path(filename).name, the basename keeps GCS keys under {uid}/ and blocks any stray path separator from escaping the user prefix. os is 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.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Sep 20, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #14969, chat image thumbnails upload from correct temp path, scoped, test added. 5/5.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Verified on db53c5bf1091.

Leaving this open as the unique remaining-hole vehicle (backend/routers/chat.py, backend/tests/unit/test_chat_image_thumbnail_upload.py, backend/utils/other/storage.py). unique chat thumbnail temp-path hole+tests remaining but 0 CI.

Not approving: hosted CI has not gone green on this SHA. kodjima APPROVE is not a merge. I am not merging.

@jitendravjh
jitendravjh force-pushed the fix/chat-image-thumbnails branch from 11423c0 to 686e79b Compare September 21, 2026 01:44
Git-on-my-level added a commit that referenced this pull request Sep 21, 2026
## 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. -->
@Git-on-my-level Git-on-my-level added the superseded Superseded by a newer change on main label Sep 21, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

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:

  • backend/routers/chat.py — upload_file_chat (/v2/files) and upload_file_chat_v1 (/v1/files) both switch FileChat.name from result.get("file_name") (which openai.files.create echoes back from the {uuid}_ temp handle) to safe_suffix, the traversal-sanitized basename of the file the user picked. That is precisely the [Bounty proposal] fix(backend): chat file uploads show a uuid in the file name ($25 proposed) #15179 defect, fixed at the right layer.
  • backend/tests/unit/test_chat_file_upload_name.py — solid regression test: the real router driven over the shared _chat_router_test_harness client with the provider upload and storage stubbed, asserting both routes return photo.png. It fails on pre-fix main and passes on this head, and it follows the house pattern from test_chat_file_upload_unsupported.py.

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 need human response.

@github-actions

Copy link
Copy Markdown
Contributor

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:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution superseded Superseded by a newer change on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] fix(backend): chat file uploads show a uuid in the file name ($25 proposed)

4 participants