Skip to content

[dogfood][zcode] fix(backend): keep the picked file name on chat uploads - #15210

Closed
Git-on-my-level wants to merge 1 commit into
mainfrom
agent/m5-mbp-zcode-glm-5-3/da591abd03c6
Closed

Git-on-my-level wants to merge 1 commit into
mainfrom
agent/m5-mbp-zcode-glm-5-3/da591abd03c6

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Dogfood comparison branch (agent: zcode). Reported in #15179; independent implementation alongside open PR #14970 — not for merge as-is.

What

Chat file uploads saved the backend temp file's name (ef0c40fc9b98...47d_photo.png) instead of the name the user picked (photo.png). Both /v1/files and /v2/files stream each upload through a uuid-named temp file for path-traversal safety, openai.files.create echoes that temp name back as response.filename, and the routes stored it verbatim as FileChat.name.

Change

The fix lives in FileChatTool.upload, the path both routes share: it now takes the picked name and reports its basename (directory component stripped), falling back to the provider filename for direct callers with no picked name. Both routes pass the multipart file.filename through, so the picked name survives to the response and the persisted doc by construction.

Test

tests/unit/test_chat_file_upload_keeps_picked_name.py drives both routes over HTTP with a provider double that echoes the temp-file name exactly like production. On main it fails with the uuid-prefixed name stored (cde1fd8b..._brief.pdf != brief.pdf); with the fix the answer and the chat_db.add_multi_files payload keep the picked name. Covers the image path (thumbnail branch) and the document path, the no-picked-name fallback, and directory stripping.

Product invariants affected

none

Failure class (fixes)

Failure-Class: none

Review in cubic

The /v1/files and /v2/files routes stream each upload through a
uuid-named temp file for path-traversal safety, and openai.files.create
echoes that temp name back as response.filename. Storing it verbatim
made the saved FileChat (and the chat UI) show
'ef0c40fc...47d_photo.png' instead of 'photo.png' (#15179).

FileChatTool.upload, the path both routes share, now takes the picked
name and reports its basename, so both endpoints keep it by
construction; direct callers without a picked name still fall back to
the provider filename.

Regression: tests/unit/test_chat_file_upload_keeps_picked_name.py
drives both routes with a provider double that echoes the temp-file
name exactly like production; on main it fails with the uuid-prefixed
name stored.

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 test coverage (both /v1/files and /v2/files, image + document, a provider double that faithfully answers a bare handle with the uuid temp basename, basename/path-strip of user-picked names, fallback when file_name is omitted, real utils.other.chat_file under the harness) and adopts the stronger production fix from #15207: the picked name travels to openai.files.create as the SDK's (filename, fileobj) tuple, so the provider record itself is photo.png, not only the local FileChat.name. 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.

1 participant