Skip to content

[dogfood][devin-swe2] fix(backend): keep the picked file name on chat uploads - #15207

Closed
Git-on-my-level wants to merge 1 commit into
BasedHardware:mainfrom
Git-on-my-level:dogfood/devin-swe2-chat-upload-filename
Closed

Git-on-my-level wants to merge 1 commit into
BasedHardware:mainfrom
Git-on-my-level:dogfood/devin-swe2-chat-upload-filename

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #15179.

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}", and FileChatTool.upload sent that temp path 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) now accepts the caller's picked name and sends it as the multipart filename (the SDK's (name, fileobj) form), so the provider record and result["file_name"] both carry the original name. The v1/v2 handlers pass their already-sanitized safe_suffix (Path(file.filename).name), and upload re-takes Path(file_name).name defensively. No file_name → unchanged behavior.

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_filename.py — 3 pass with the fix.
  • Same file on the unfixed tree (git stash): fails with assert 'c5b12e30b2c9…d00_photo.png' == 'photo.png' — reproduces the issue exactly.
  • 70 related chat-file tests pass (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 preflight local lane: clean except this declaration, which this body provides.

Failure-Class: none

Review in cubic

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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Superseded by #15336, which keeps this PR's production fix (the (Path(file_name).name, f) tuple form to openai.files.create so the provider record itself is photo.png, routes passing safe_suffix) and pairs it with the stronger test file from #15210 (both routes, image + document, provider-double sabotage, fallback, path-strip). Closing this dogfood comparison draft as superseded; #15179 stays open until #15336 merges.

@github-actions

Copy link
Copy Markdown
Contributor

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:

  • 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!

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. -->
lukiod pushed a commit to lukiod/omi that referenced this pull request Sep 21, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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)

1 participant