Skip to content

[Due for payment 2026-11-02] Chat- Attachment is empty when edit msg while file is loading #101692

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?: No
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): duytestnguyen+373@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Windows 10/Chrome
App Component: Chat Report View

Action Performed:

Preconditions:

  • Prepare csv or doc file: use a non-English name file.
  1. Open https://staging.new.expensify.com/
  2. Go to any chat
  3. Type any text
  4. Click "+"
  5. Select "Add attachment"
  6. Upload file in precondition and Send
  7. While the file is still loading, right click on it and select "Edit comment"
  8. Edit the text in step 3
  9. Save

Expected Result:

Verify the edited text appears straight away and the file is still there.

Actual Result:

The attachment is empty, file disappears.
In Hybrid app, this happens with Offline steps: Send and edit in offline, when go online again the file disappears

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7263777_1789800814652.file_disappears_when_edit_msg_while_its_loading.mp4

Ăn dặm tự chủ động_.docx

View all open jobs on GitHub

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

Issue OwnerCurrent Issue Owner: @brunovjk

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 21, 2026
  2. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    @chuckdries recently merged #99385, but they are OOO right now, so I'll auto-assign someone else.

  3. github-actions commented on Sep 21, 2026

    @github-actions

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  4. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    Triggered auto assignment to @luacmartins (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

  5. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    @chuckdries @tgolen @brunovjk you have been assigned to this deploy blocker because you reviewed the offending PR: #99385

  6. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  7. 1 remaining item

  8. MelvinBot commented on Sep 21, 2026

    @MelvinBot

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: Keep a file attachment intact when its comment is edited (Expensify/App#99385) - by @mukhrr (High confidence)
    Related Issues: Attachment-Both CSV files become misaligned after editing the second CSV (second deploy blocker from the same PR), [Exploratory] Chat - Doc file border and download icon missing after edit comment. (the issue #99385 was fixing)

    Recommendation: REVERT

    PR #99385 is confirmed as the cause: it is the only PR in the 9.4.90 staging release that touches the attachment-upload / comment-edit path, this exact scenario is its own test step 8-10, and it has produced a second deploy blocker (#101689) in the same release. The new "deferred attachment edit" machinery is a large, stateful addition (a new persisted Onyx key plus a background replay engine) with several unguarded failure paths, so a targeted patch under deploy-blocker time pressure is riskier than reverting and re-landing with the gaps closed.

    Assigned: @mukhrr (PR author), @chuckdries, @tgolen, @brunovjk (approving reviewers, already auto-assigned) from the causing PR
    Labels: No changes. DeployBlockerCash is correct and stays (App-side fix, App deploy blocked). DeployBlocker was never applied, so nothing to remove.

    📋 Detailed Analysis

    Evidence

    Verification

    Affected files, all touched by #99385:

    File Role in this bug
    src/libs/actions/Report/index.ts New "defer the edit instead of calling the API" branch
    src/libs/actions/Report/DeferredAttachmentEdits.ts New file: the replay watcher
    src/libs/ReportUtils.ts replaceLocalAttachmentReferences, which must swap the local URI for the synced one
    src/libs/actions/RequestConflictUtils.ts Drops or renames the file on the queued request

    git log confirms DeferredAttachmentEdits.ts and the DEFERRED_ATTACHMENT_EDITS Onyx key did not exist before this PR, and gh pr view 99385 --json files lists every file above.

    Root Cause

    1. "While the file is still loading" always takes the brand-new deferred path.

    Report/index.ts#L3885-L3891 decides between the old conflict-resolution path and the new deferred path with:

    const hasQueuedAttachmentRequest = getAll().some((request) => addNewMessageWithText.has(request.command) && request.data?.reportActionID === reportActionID);
    if (uploadingAttachmentHtml && !hasQueuedAttachmentRequest) {
        Onyx.update(optimisticData);
        deferAttachmentEdit(reportActionID, deferredEdit);
        return;   // no API.write, no failureData, no persisted request
    }

    PersistedRequests.getAll() returns only the queued requests; the in-flight one lives in ongoingRequest (PersistedRequests.ts#L520-L530). So an online "edit while the spinner is showing" is exactly the case where the AddAttachment is in flight and therefore absent from getAll(), and the edit is always deferred: nothing is sent to the server, and the message is left with pendingAction: UPDATE and no failure path, relying entirely on the replay succeeding later.

    2. The replay silently ships a dead local reference when it cannot find the synced attachment.

    The replay re-runs editReportComment with the original draft markdown, which still contains the local reference ([name](blob:…)). Re-attaching depends entirely on replaceLocalAttachmentReferences:

    const attachmentTags = currentCommentHtml.match(/<img\b[^>]*>|<video\b[^>]*>[\s\S]*?<\/video>|<a\b[^>]*data-expensify-source="[^"]*"[^>]*>[\s\S]*?<\/a>/gi) ?? [];
    const syncedAttachmentTag = attachmentTags.find((tag) => { … source.match(/chat-attachments\/(\d+)/)?.at(1) === reportActionID; });
    if (!syncedAttachmentTag) {
        return draftMarkdown;   // ← ships the draft with the dead blob:/file: reference
    }

    The lookup is narrow: for a document the synced HTML must be an <a> that still carries data-expensify-source and whose URL contains chat-attachments/<reportActionID>. This PR itself documents that the server strips data-expensify-source from anchors on round-trip (that is why it added restoreAttachmentAnchorAttributes and the AnchorRenderer fallback), so this precondition is not reliable, and the watcher fires on any report-action update that no longer has data-optimistic-src (DeferredAttachmentEdits.ts#L63-L68), including an intermediate merge that does not yet carry the final attachment markup.

    When the lookup misses, the UpdateComment that finally reaches the server contains only [name](blob:…). ExpensiMark's MARKDOWN_URL_REGEX requires an http(s)/ftp protocol, so a blob:/file:/content: URL is not even linkified — the attachment is gone from the stored comment. That is precisely "the attachment is empty, file disappears", and in the offline variant it is the same failure deferred until reconnect.

    3. Why the non-English filename matters.

    cleanFileName rewrites every character outside [a-zA-Z0-9\-._] to _, and it runs on the chat attach path on both web (validateAttachmentFile → snapshotPickedFile) and native (FilePicker). Ăn dặm tự chủ động_.docx becomes _n_d_m_t___ch___ng_.docx. Two consequences:

    • Once the dead [_n_d_m_t___ch___ng_.docx](blob:…) reference is no longer wrapped in an <a> tag (see point 2), ExpensiMark's italic rule is free to consume those underscores, so the leftover text is mangled rather than merely wrong — which matches the "empty attachment" appearance rather than a plain visible link.
    • The new rename heuristic at Report/index.ts#L3787-L3792 infers "the user renamed the file" purely from draftLabel !== data-name, and any mismatch causes renameQueuedAttachment to rebuild the queued File. The more transformation a filename goes through, the more fragile that byte-for-byte comparison is.

    I could not execute the parser locally to prove the filename is strictly required to reproduce, so treat point 3 as the likely amplifier (medium confidence) rather than a precondition; points 1 and 2 are the structural defect and hold for any filename. Note that the sibling blocker #101689 uses plain ASCII .csv files.

    4. Neighbouring hazard worth fixing on the re-land. applyLabelToUploadingAttachmentHtml interpolates a user-controlled filename into a String.replace replacement string, so a filename containing $&, $` or $1 would corrupt the anchor. Use a function replacement.

    If a roll-forward is preferred over a revert

    The minimal safe change is to stop the replay from ever shipping a local reference:

    1. In replaceLocalAttachmentReferences, when a local reference is present but no synced tag matches, signal failure instead of returning the draft unchanged.
    2. In the replay callback, return false in that case so the watcher stays armed and retries on the next update, rather than sending a UpdateComment that drops the file.
    3. Add a hard guard in editReportComment: never send a reportComment that still matches /(blob:|file:|content:)/.

    That is still three coordinated changes in new, lightly-covered code plus a second blocker (#101689) from the same PR, which is why REVERT is the recommendation.

  9. melvin-bot commented on Sep 21, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  10. mukhrr commented on Sep 21, 2026

    @mukhrr

    yes, this is regression from #99385 and raising a fixing PR soon

  11. IuliiaHerets commented on Sep 21, 2026

    @IuliiaHerets

    Chrome / v9.4.90-2
    Not repro

    bandicam.2026-09-21.18-26-48-340.mp4
  12. self-assigned this
    on Sep 21, 2026
  13. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Sep 21, 2026
  14. changed the title [-]Chat- Attachment is empty when edit msg while file is loading[/-] [+][Due for payment 2026-11-02] Chat- Attachment is empty when edit msg while file is loading[/+] on Oct 26, 2026
  15. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    @brunovjk

    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]

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions