You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-11-02] Chat- Attachment is empty when edit msg while file is loading #101692
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.
While the file is still loading, right click on it and select "Edit comment"
Edit the text in step 3
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
👋 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:
Identify the pull request that introduced this issue and revert it.
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.
The repro is the PR's own test. The reported steps 6-9 (send text + file, edit while the spinner is showing, save) are verbatim steps 8-10 of Keep a file attachment intact when its comment is edited #99385's test plan, and the offline variant reported in the Hybrid app is verbatim its "Offline tests" section. QA ran the PR's own QA steps and they fail.
Before this PR the "edit while uploading" scenario simply dropped the attachment via the pre-existing conflict resolver. The PR added a whole new path for it, and that new path is what is misbehaving.
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:
consthasQueuedAttachmentRequest=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:
constattachmentTags=currentCommentHtml.match(/<img\b[^>]*>|<video\b[^>]*>[\s\S]*?<\/video>|<a\b[^>]*data-expensify-source="[^"]*"[^>]*>[\s\S]*?<\/a>/gi)??[];constsyncedAttachmentTag=attachmentTags.find((tag)=>{…source.match(/chat-attachments\/(\d+)/)?.at(1)===reportActionID;});if(!syncedAttachmentTag){returndraftMarkdown;// ← 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-sourceand 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.replacereplacement 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:
In replaceLocalAttachmentReferences, when a local reference is present but no synced tag matches, signal failure instead of returning the draft unchanged.
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.
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.
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
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]
Activity
applause-bot commentedon Sep 21, 2026
While Applause doesn't embed attachments for this bug, here are the links for quick view:
https://platform.applause.com/services/links/v1/external/6028ed7367bb9c0d578ae2a53e83e90f54cb46df7604b5f55cc0770898af5c86
https://platform.applause.com/services/links/v1/external/770e26a45f8f691afb0f3705c7c22a0505f2d670811e7f901b22961940e7d746
melvin-bot commentedon Sep 21, 2026
@chuckdries recently merged #99385, but they are OOO right now, so I'll auto-assign someone else.
github-actions commentedon Sep 21, 2026
👋 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:
melvin-bot commentedon Sep 21, 2026
Triggered auto assignment to @luacmartins (
DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.melvin-bot commentedon Sep 21, 2026
@chuckdries @tgolen @brunovjk you have been assigned to this deploy blocker because you reviewed the offending PR: #99385
melvin-bot commentedon Sep 21, 2026
💬 A slack conversation has been started in #expensify-open-source
1 remaining item
MelvinBot commentedon Sep 21, 2026
🔍 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.
DeployBlockerCashis correct and stays (App-side fix, App deploy blocked).DeployBlockerwas never applied, so nothing to remove.📋 Detailed Analysis
Evidence
production...stagingwhose commits touch attachment upload or comment editing (git log production...stagingsurfaces only "Keep a file attachment intact when its comment is edited" in this area).Verification
Affected files, all touched by #99385:
src/libs/actions/Report/index.tssrc/libs/actions/Report/DeferredAttachmentEdits.tssrc/libs/ReportUtils.tsreplaceLocalAttachmentReferences, which must swap the local URI for the synced onesrc/libs/actions/RequestConflictUtils.tsgit logconfirmsDeferredAttachmentEdits.tsand theDEFERRED_ATTACHMENT_EDITSOnyx key did not exist before this PR, andgh pr view 99385 --json fileslists every file above.Root Cause
1. "While the file is still loading" always takes the brand-new deferred path.
Report/index.ts#L3885-L3891decides between the old conflict-resolution path and the new deferred path with:PersistedRequests.getAll()returns only the queued requests; the in-flight one lives inongoingRequest(PersistedRequests.ts#L520-L530). So an online "edit while the spinner is showing" is exactly the case where theAddAttachmentis in flight and therefore absent fromgetAll(), and the edit is always deferred: nothing is sent to the server, and the message is left withpendingAction: UPDATEand 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
editReportCommentwith the original draft markdown, which still contains the local reference ([name](blob:…)). Re-attaching depends entirely onreplaceLocalAttachmentReferences:The lookup is narrow: for a document the synced HTML must be an
<a>that still carriesdata-expensify-sourceand whose URL containschat-attachments/<reportActionID>. This PR itself documents that the server stripsdata-expensify-sourcefrom anchors on round-trip (that is why it addedrestoreAttachmentAnchorAttributesand theAnchorRendererfallback), so this precondition is not reliable, and the watcher fires on any report-action update that no longer hasdata-optimistic-src(DeferredAttachmentEdits.ts#L63-L68), including an intermediate merge that does not yet carry the final attachment markup.When the lookup misses, the
UpdateCommentthat finally reaches the server contains only[name](blob:…).ExpensiMark'sMARKDOWN_URL_REGEXrequires anhttp(s)/ftpprotocol, so ablob:/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.
cleanFileNamerewrites 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_.docxbecomes_n_d_m_t___ch___ng_.docx. Two consequences:[_n_d_m_t___ch___ng_.docx](blob:…)reference is no longer wrapped in an<a>tag (see point 2), ExpensiMark'sitalicrule 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.Report/index.ts#L3787-L3792infers "the user renamed the file" purely fromdraftLabel !== data-name, and any mismatch causesrenameQueuedAttachmentto rebuild the queuedFile. 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
.csvfiles.4. Neighbouring hazard worth fixing on the re-land.
applyLabelToUploadingAttachmentHtmlinterpolates a user-controlled filename into aString.replacereplacement string, so a filename containing$&,$`or$1would 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:
replaceLocalAttachmentReferences, when a local reference is present but no synced tag matches, signal failure instead of returning the draft unchanged.falsein that case so the watcher stays armed and retries on the next update, rather than sending aUpdateCommentthat drops the file.editReportComment: never send areportCommentthat 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.
melvin-bot commentedon Sep 21, 2026
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.
mukhrr commentedon Sep 21, 2026
yes, this is regression from #99385 and raising a fixing PR soon
IuliiaHerets commentedon Sep 21, 2026
Chrome / v9.4.90-2
Not repro
bandicam.2026-09-21.18-26-48-340.mp4
[-]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[/+]melvin-bot commentedon Oct 26, 2026
@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]