Skip to content

[Due for payment 2026-11-02] Hybrid - Chat - File name is changed into "file" after edit msg offline & back online #101744

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.90-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #99385
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Pixel 7a/ Android 16
App Component: Chat Report View

Action Performed:

  1. Open Hybrid app
  2. Go to any chat
  3. Go offline
  4. Type some text, attach a csv file and send it.
  5. Long tap on sent message
  6. Select 'Edit comment'
  7. Change the text and save it
  8. Go online

Expected Result:

Verify the message keeps both the edited text and the file, and the file shows as a file rather than a link.

Actual Result:

Attachment name is changed into "file'

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7265022_1789972037997.az_recorder_20260921_130709.1.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7265022

Issue OwnerCurrent Issue Owner: @shubham1206agra

Activity

  1. applause-bot commented on Sep 21, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/e0589bce2f3a88f92dbdb896471e66ae1bd67ce01072f0b796d79e4bd66c9dc0

  2. added
    Bug
    on Sep 21, 2026
  3. MelvinBot commented on Sep 21, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    A regression from Keep a file attachment intact when its comment is edited (merged 2026-09-18) — the same PR this bug was found while QA'ing.

    The chat card shows nothing but the anchor's own text. AnchorRenderer.tsx:45 takes the first text node and BaseAnchorForAttachmentsOnly.tsx:76 renders it with no fallback. So file is already in the HTML the server sent back, and the server names the stored attachment after the uploaded file. Something changed the filename on the wire.

    Offline, the edit never sends UpdateComment. It merges into the still-queued AddTextAndAttachment, and that merge also renames the queued file — logic PR #99385 added. The rename fires whenever the draft's markdown label differs from the data-name attribute:

    src/libs/actions/Report/index.ts:3788-3792 → RequestConflictUtils.ts:316-320

    Two defects in that path:

    1. The guard is not idempotent. applyLabelToUploadingAttachmentHtml rewrites only the anchor's inner text and never touches data-name. Once a label changes, the two disagree permanently, so every later edit re-renames the queued file from whatever the label currently is. One bad label becomes sticky.
    2. The rename drops the props native uploads need. renameQueuedAttachment rebuilds the object with new File([file], name, …), which silently discards the non-standard uri and source that App attaches to file objects. prepareRequestPayload/index.native.ts:55-72 keys on source; without it the request falls into the !source branch and appends a part with no uri. This is also why the report is Android app + iOS app only — web appends the persisted File as-is and never re-reads it.

    Where my confidence stops: walking a first, text-only edit by hand, the draft label and data-name are equal, so the rename should not fire at all. Either the label diverges for a reason I could not see statically (the native live-markdown edit composer is the one link I could not inspect), or the multipart filename arrives blank and the backend falls back to the form-field name, which is literally file. Both funnel through the same new code, so the fix below covers either, but a maintainer should confirm which on a device before merging.

    Investigation details

    Why the offline case is special. editReportComment finds a queued add request and resolves the conflict as a replace instead of sending UpdateComment (Report/index.ts:3902). Online there is no queued request, so the attachment is already synced and the rename path never runs. That matches "go offline" being load-bearing in the repro.

    Why "type some text" is load-bearing too. addNewMessageWithText only contains ADD_COMMENT and ADD_TEXT_AND_ATTACHMENT (Report/index.ts:490), while RequestConflictUtils also lists ADD_ATTACHMENT (:16). An attachment with no text therefore takes the deferred-replay path instead of the merge+rename path. That asymmetry looks unintentional and is worth fixing alongside.

    Ruled out as the source of the string "file": there is no client-side default filename of file. CONST.DEFAULT_ATTACHMENT_FILENAME is chat_attachment; ATTACHMENT_FILE_TYPE.FILE only picks an icon; getFileName() only feeds the image/carousel paths; and ExpensiMark's html → markdown → html round trip preserves the anchor label verbatim. The only literal 'file' fallback in App source is the native paste handler in Composer/implementation/index.native.tsx, which always appends an extension and is not reachable from the picker repro.

    Possibly related: Chat- Attachment is empty when edit msg while file is loading — another "edit a comment while its attachment is still uploading" failure, likely from the same PR. Worth fixing together.

    What changes do you think we should make in order to solve the problem?

    1. In editReportComment, compare the draft label against the attachment tag's own visible label (the thing the draft markdown was derived from), not against data-name, and treat a missing label as "no rename". This makes the check idempotent across repeated edits.
    2. Also update data-name inside applyLabelToUploadingAttachmentHtml so the optimistic tag stays self-consistent.
    3. Harden renameQueuedAttachment: return the file unchanged when the new name is empty, and carry uri and source across the rebuild so native uploads keep working.
    4. Backstop in prepareRequestPayload/index.native.ts: never append a file part with an empty name — fall back to the basename of source. A missing multipart filename is what lets the backend name the attachment after the form field.
    5. Add ADD_ATTACHMENT to addNewMessageWithText so an attachment sent without text takes the same path.

    Regression tests to add: edit an offline attachment comment twice in a row and assert the queued file's name is unchanged both times, and assert uri/source survive renameQueuedAttachment. The existing test at tests/unit/RequestConflictUtilsTest.ts only asserts name and type.

    What alternative solutions did you explore? (Optional)

    Reverting PR #99385 and re-landing it with the rename removed. The rename only exists to make a filename change made in the editor stick; dropping it costs that one behavior and removes both defects at once. Given the PR is three days old and has produced at least two QA bugs, that may be the lower-risk option.


    💡 Suggested AI code review rule

    The second defect is a recurring, mechanically detectable pattern, so it may be worth a coding-standards rule so the AI reviewer catches the next one. Proposed for Expensify/App:

    The full rule file would go in App/.claude/skills/app-coding-standards/. If it's worth adding, a maintainer can open it there as a draft PR.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/101744) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  4. added
    External
    on Sep 21, 2026
  5. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @shubham1206agra (External)

  6. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  7. shubham1206agra commented on Sep 21, 2026

    @shubham1206agra
    Contributor

    @MelvinBot The PR was reverted and the issue is reproducible on production.

  8. mukhrr commented on Sep 21, 2026

    @mukhrr
    Contributor

    @lakchote can you pls assign me here? thanks

  9. MelvinBot commented on Sep 21, 2026

    @MelvinBot
    Contributor

    You're right, and thanks for the correction. Keep a file attachment intact when its comment is edited never reached production — production is 9.4.89-0 and contains none of that PR's files — so it cannot be the cause. Here is the real one.

    Proposal

    What is the root cause of that problem?

    react-native-nitro-fetch names an uploaded file file when the multipart part carries no filename, and on the offline path App hands it exactly that.

    1. App swaps the global fetch for nitro-fetch on native only (src/polyfills/NitroFetch.ts:7; NitroFetch.web.ts is a no-op), and HttpUtils calls bare fetch (src/libs/HttpUtils.ts:116). Production ships react-native-nitro-fetch@1.5.4.
    2. When a request was created while offline — and only then — the native payload builder re-reads the file off disk and appends a React Native File instance (src/libs/prepareRequestPayload/index.native.ts:55-71, via readFileAsync in FileUtils.ts:294-298).
    3. RN's FormData.getParts() computes the correct content-disposition header, then returns the part as {...value, headers, fieldName: name}. File.prototype.name and Blob.prototype.type are prototype getters, so the object spread drops both — only _data, source and uri survive as own properties.
    4. nitro-fetch discards part.headers for file parts and rebuilds the disposition from that spread object: fileName: part.fileName ?? part.name ?? 'file'. Both are undefined, so the part goes out as filename="file" and the attachment is stored under that name.

    Every condition in the report falls out of this:

    • Android app + iOS app only — web has no polyfill and uses the browser's FormData and fetch.
    • Offline only — an online send appends the picker's plain object, whose name and type are own properties and survive the spread.
    • A .csv — for an image the filename lives in alt/data-name behind a thumbnail, so a wrong name is invisible. Only a non-previewable file shows the anchor label.
    • No client-side source for the word file — CONST.DEFAULT_ATTACHMENT_FILENAME is chat_attachment, and the chat card renders the anchor's own text with no fallback (AnchorRenderer.tsx:42 → BaseAnchorForAttachmentsOnly.tsx:75).

    This dates to 2026-07-27, when nitro-fetch became the global fetch on native.

    One prediction to confirm first: the edit steps are probably not needed. initiatedOffline is stamped when the request is created (makeRequest.ts:78), and merging the edit into the queued AddTextAndAttachment leaves data.file untouched (RequestConflictUtils.ts:296). So offline → send a .csv → go online, with no edit at all should already name it file. Please try that. If it reproduces, the bug is wider than reported.

    Investigation details

    What I verified by reading source: the polyfill wiring and platform split; HttpUtils using bare fetch; the initiatedOffline gate; that readFileAsync produces an RN File whose only own properties are _data, source and uri; RN's spread in getParts(); nitro-fetch's 'file' default in JS and in its Kotlin and Swift uploaders; and that nothing in src/ or src/languages/en.ts emits file as a filename or label.

    The one link I could not read: that the backend names the stored attachment from the multipart filename. The observed name is exactly nitro-fetch's default and no client code produces it, but this appears to be a backend behavior, so a separate internal check would confirm it.

    Collateral from the same spread: type is dropped too, so nitro-fetch falls back to application/octet-stream for every offline-initiated attachment. If offline-uploaded files also come back with an octet-stream MIME type, that independently confirms the mechanism.

    Why this went unnoticed: RN's own multipart builder honours part.headers, so before the nitro-fetch swap the correct filename that getParts() had already computed reached the server. Only the rebuild-from-spread path loses it.

    Related issues. [Exploratory] Chat - Doc file border and download icon missing after edit comment. is the separate, still-open production bug that PR #99385 was written to fix (an edited attachment degrades to a plain link) — a different symptom in the same flow, and untouched by this. Chat - Edited file name is not saved when editing file name in offline mode is the closed prior report of the same repro shape. Attachment-Both CSV files become misaligned after editing the second CSV, Chat- Attachment is empty when edit msg while file is loading and Attachment-File becomes misaligned after renaming; LHN shows renamed file name were all marked not reproducible in production and should be resolved by the revert.

    What changes do you think we should make in order to solve the problem?

    Stop handing nitro-fetch a File instance in prepareRequestPayload/index.native.ts. The native uploader only needs a plain {uri, name, type} object, and those are own properties that survive getParts()'s spread. isFileUploadable on native already only requires a string uri, so a plain object still passes validateFormDataParameter.

    Add test coverage while you're there: the existing native test mocks readFileAsync to resolve null, so the FormData shape for the file key is never asserted. A test that runs the offline branch and asserts getParts() yields a part with the real name and MIME type would have caught this.

    What alternative solutions did you explore? (Optional)

    • Make name and type own enumerable properties on the object readFileAsync returns. Plain assignment won't work — it would throw against the getter-only prototype accessor — so it needs Object.defineProperty, which is more fragile than just not using a File.
    • Fix serializeFormData upstream so it honours part.headers instead of rebuilding the disposition. That's the correct long-term fix and helps every consumer, but it shouldn't block this one.

    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/101744) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  10. shubham1206agra commented on Sep 21, 2026

    @shubham1206agra
    Contributor

    @MelvinBot Give me a test branch please

  11. mukhrr commented on Sep 21, 2026

    @mukhrr
    Contributor

    @shubham1206agra this is what we should have fixed in original PR and not paid. I will handle this

  12. MelvinBot commented on Sep 21, 2026

    @MelvinBot
    Contributor

    Test branch is up: [Test branch] Keep an edited attachment name from collapsing to the form field name — draft, assigned to shubham1206agra, branch claude-attachmentNameResetOnOfflineEdit.

    One thing changed since my analysis: Keep a file attachment intact when its comment is edited was reverted out of main in d805f83 about half an hour ago. So on plain main this bug can't reproduce — but neither can the feature that PR added. A branch off main alone would have nothing to test.

    The branch therefore has two commits, kept separate so the second reviews on its own:

    1. Re-apply PR Keep a file attachment intact when its comment is edited #99385 — a plain revert of the revert, nothing else.
    2. Harden the rename path — the four changes from my proposal.
    What the second commit changes
    • editReportComment decided whether an edit renamed the attachment by comparing the draft's markdown label against the data-name attribute, but applyLabelToUploadingAttachmentHtml only rewrote the anchor's inner text. Once those disagreed, every later edit re-renamed the queued file. The comparison now reads the tag's own current label through a new getUploadingAttachmentLabel helper, and applyLabelToUploadingAttachmentHtml keeps data-name in sync.
    • renameQueuedAttachment returns the file untouched when the label is empty. A multipart part sent with no filename is stored under the form field name, which is how an attachment ends up called file.
    • renameQueuedAttachment rebuilds a File to change its name, which dropped the non-standard uri and source the app hangs off file objects and that prepareRequestPayload/index.native.ts reads to find the file on disk. Both are now carried across the rebuild.
    • prepareRequestPayload/index.native.ts falls back to the source basename so a part is never appended unnamed.

    Unit tests added for the label comparison being idempotent, for uri/source surviving the rebuild, and for an empty label leaving the queued filename alone.

    Ran locally: RequestConflictUtilsTest (83 passed), ReportUtilsTest (1396 passed), ReportTest + getAttachmentDetailsTest + FileUtilsTest (363 passed), npm run typecheck, npm run lint-changed, npm run spell-changed — all pass. I did not run the full Jest suite or the Storybook smoke test.

    Please re-run the repro on a device before trusting this. My analysis pinned the mechanism at medium confidence: walking a first, text-only edit by hand, the draft label and the tag label come out equal, so the rename should not fire at all. Either the label diverges inside the native live-markdown edit composer, or the multipart filename arrives blank and the server falls back to the field name. The branch closes both routes, but which one it actually was is still unconfirmed.

    Two calls that are yours, not mine: whether re-landing #99385 is the right move at all versus fixing it forward separately, and whether ADD_ATTACHMENT should join addNewMessageWithText — I left that one out as a behavior change beyond this bug.


    view run

  13. 7 remaining items

  14. melvin-bot commented on Oct 12, 2026

    @melvin-bot

    @shubham1206agra Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

  15. shubham1206agra commented on Oct 14, 2026

    @shubham1206agra
    Contributor

    Still working on it

  16. melvin-bot commented on Oct 21, 2026

    @melvin-bot

    @shubham1206agra Whoops! This issue is 2 days overdue. Let's get this updated quick!

  17. shubham1206agra commented on Oct 22, 2026

    @shubham1206agra
    Contributor

    @mukhrr Status please

  18. mukhrr commented on Oct 22, 2026

    @mukhrr
    Contributor

    still working on it

  19. removed
    Reviewing
    on Oct 26, 2026
  20. changed the title [-]Hybrid - Chat - File name is changed into "file" after edit msg offline & back online[/-] [+][Due for payment 2026-11-02] Hybrid - Chat - File name is changed into "file" after edit msg offline & back online[/+] on Oct 26, 2026
  21. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    @shubham1206agra

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.5.20-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-11-02. 🎊

    The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]

  22. mukhrr commented on Oct 27, 2026

    @mukhrr
    Contributor

    I thinh we can skip payment here per #101744 (comment) oh wait this seems to be pre-existing and per #101744 (comment)

    @MelvinBot The PR was reverted and the issue is reproducible on production.

    and I was wrong here. This is not we should have fixed with original issue

    @shubham1206agra this is what we should have fixed in original PR and not paid.

    But still, I think, we can skip payment here and generalize amount on #98743 to be paid

  23. melvin-bot commented on Oct 27, 2026

    @melvin-bot

    @shubham1206agra Eep! 4 days overdue now. Issues have feelings too...

  24. shubham1206agra commented on Oct 28, 2026

    @shubham1206agra
    Contributor

    Since this is fixed and no one is going to be paid here. I am going to close this.

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

Metadata

Metadata

Labels

BugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions