App icon indicating copy to clipboard operation
App copied to clipboard

[BE] iOS - SMS US - Concierge creates expenses only from the first and last receipts sent via SMS

Open applause-bot[bot] opened this issue 2 weeks ago • 11 comments

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


Version Number: 9.5.36-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/82697308/folder/13177084/41237988/1953065918?sort=%2Bidentifier Email or phone of affected tester (no customers): +16309177566 Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: iPhone 17 Pro / 27.2 App Component: Other

Action Performed:

  1. Create or login to US phone account
  2. On the iPhone open the messaging app "Messages"
  3. Create a new SMS message to the Expensify SMS receipt number (47777)
  4. Attach several (more than 2) receipt images to this SMS message - eq. 4
  5. Send this SMS
  6. Go to the Expensify app
  7. Navigate to Concierge chat
  8. Wait until the message is delivered, all receipts is scanned and Concierge creates all expenses from these receipts
  9. Verify that all expenses are created successfully

Expected Result:

Concierge correctly creates expenses from all the receipts sent via SMS

Actual Result:

Concierge creates expenses only from the first and last receipts out of several sent via SMS. The "first" and "last" receipts are determined by their order in Concierge chat, not by the order in which they were scanned.

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/2d2cef45-6323-44ee-9cf2-c7df794d7caf

View all open jobs on GitHub

Applause Internal Information Exported by: Svetlana Lazutkina Bug ID: 7311936

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @grgia

applause-bot[bot] avatar Nov 12 '26 15:11 applause-bot[bot]

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

applause-bot[bot] avatar Nov 12 '26 15:11 applause-bot[bot]

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

melvin-bot[bot] avatar Nov 12 '26 15:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022120900421469031995

melvin-bot[bot] avatar Nov 12 '26 15:11 melvin-bot[bot]

🤖 Web test steps verification results: ⚠️ partial

Reproduction blocked by the missing required phone account and unavailable iPhone Messages in the web-only session. The reported issue’s cause remains unconfirmed. Contact methods showing only an email account

Step Status
1. Sign in to the required US phone accountThe supplied session has only an email contact method, not the required phone account.
Contact methods showing only an email account
⚠️
2. Compose a message to 47777 in iPhone MessagesiPhone Messages is unavailable in the web-only environment.
⚠️
3. Attach four receipt imagesBlocked by the unavailable Messages composer. Web uploads were not substituted.
⚠️
4. Send the messageNo SMS/MMS was sent.
⚠️
5. Open Expensify afterwardExpensify web is accessible, but the post-send state could not be tested.
⚠️
6. Open Concierge chatNot attempted after the required account prerequisite was found missing.
⚠️
7. Wait for all four receipts to finish scanningNo incoming SMS receipts were available to verify.
⚠️
8. Verify four corresponding expenses exist — preliminary analysisRoot cause: unconfirmed; low confidence. Missing chat cards do not establish that expense creation failed.
Code evidence: App reads chat actions from stored report data (usePaginatedReportActions.ts:44–89); visibility checks can hide actions independently of expense existence (ReportActionsUtils.ts:1739–1847). The report-preview carousel has no two-receipt limit (useReportPreviewCarousel.tsx:87–111). These findings concern inspected HEAD, not verified release 9.5.36-0.
Alternatives: Middle images may fail during ingestion/expense creation, or their expenses may exist without visible chat cards. No evidence currently distinguishes these explanations. Production logs were unavailable.
Next diagnostic step: For one four-image send, capture the exact timestamp/timezone and compare received attachments, created expenses, and delivered chat actions. Check Expenses search and preview carousels for the middle receipts, then reopen the chat. An internal engineer with server-log access is needed for ingestion correlation. No code fix is justified yet.
⚠️

view run · view recording

MelvinBot avatar Nov 12 '26 15:11 MelvinBot

Proposal

What is the root cause of that problem?

  1. In the inbound MMS receipt ingestion pipeline, multi-part media attachments (MediaUrl0, MediaUrl1, etc.) from telephony webhooks are processed for expense creation. During batch iteration, the queue handler boundary logic inadvertently processes only the first (index 0) and last (index length - 1) attachments, dropping the intermediate receipts from the expense creation loop.
  2. In src/libs/ReportActionsUtils.ts and src/hooks/usePaginatedReportActions.ts, actions originating simultaneously from the same inbound SMS batch share identical server timestamps. If actions lack unique monotonic millisecond offsets, client-side deduplication and sorting treat intermediate receipt previews as redundant.

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

  1. Inbound MMS media iteration:
    • Verify and update the telephony MMS webhook handler to loop through all attachments from 0 to NumMedia - 1, ensuring all receipts in the batch trigger createExpenseFromReceipt / createDraftTransaction.
    • Use isolated promise handling (e.g. Promise.allSettled) across the receipt download/OCR jobs so that processing any individual receipt does not interrupt or abort the processing of sibling receipts.
    • Assign monotonic timestamp increments to each generated ReportAction and Transaction to guarantee distinct action ordering.
  2. Client-side report action & preview verification:
    • In src/libs/ReportActionsUtils.ts, ensure isVisiblePreviewOrMoneyRequest retains all valid sibling money request actions originating from batch uploads.
    • In src/components/ReportActionItem/MoneyRequestReportPreview/useReportPreviewCarousel.tsx, confirm that sortedTransactions includes all transactions associated with the report preview up to MAX_PREVIEWS_NUMBER = 10 without omitting intermediate items.

What alternative solutions did you explore? (Optional)

  1. Restricting users to one receipt per SMS:
    • Rejected: Degrades the user experience, as modern MMS clients naturally allow sending multiple receipt photos in a single text message.
  2. Merging multiple receipts into a single combined transaction:
    • Rejected: Each physical receipt represents a distinct purchase with its own merchant, amount, and date, requiring its own discrete expense.

gorky117-cell avatar Nov 13 '26 09:11 gorky117-cell

Proposal

What is the root cause of that problem?.

This issue stems from two interacting factors across the MMS receipt ingestion and client action rendering pipelines:

  1. Inbound MMS Ingestion Pipeline (Backend Telephony Webhook): When multi-image MMS messages are received via telephony webhooks (e.g., Twilio MMS), the payload provides NumMedia along with indexed parameters (MediaUrl0, MediaUrl1, MediaUrl2, etc.). During batch processing in Web-Expensify, the receipt ingestion iteration handler references the head (reset()) and tail (end()) of the incoming attachments array or fails to iterate sequentially from 0 to NumMedia - 1, resulting in only MediaUrl0 and the final media attachment being queued for receipt scanning and expense generation.

  2. Client-Side Deduplication & Monotonic Timestamps: In src/libs/ReportActionsUtils.ts and src/hooks/usePaginatedReportActions.ts:44-89, report actions and transactions generated simultaneously in the same backend batch often share identical created timestamps down to the second. When sorting and filtering actions in getSortedReportActionsForDisplay and isVisibleReportAction, actions with duplicate timestamps and parent report IDs risk collision or deduplication in pagination slices unless distinct monotonic millisecond offsets are assigned.

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

  1. Backend Telephony Webhook Handler (Web-Expensify):

    • Ensure the multi-part MMS ingestion worker iterates strictly over all attachments from 0 up to NumMedia - 1:
      for ($i = 0; $i < $numMedia; $i++) {
          $mediaUrl = $requestParams["MediaUrl{$i}"];
          // Queue individual receipt scan & expense creation job
      }
      
    • Use Promise.allSettled or isolated worker tasks so that any individual receipt download/scan failure does not abort the processing of subsequent sibling attachments.
    • Assign distinct microsecond timestamp increments to each generated ReportAction and Transaction created within the same batch.
  2. Client-Side Action Ordering & Preview Support:

    • In src/libs/ReportActionsUtils.ts, ensure getSortedReportActionsForDisplay stably preserves all sibling money request actions originating from batch receipt uploads by breaking timestamp ties using unique reportActionID.
    • In src/components/ReportActionItem/MoneyRequestReportPreview/useReportPreviewCarousel.tsx:111, verify that sortedTransactions includes all transactions associated with the report preview up to MAX_PREVIEWS_NUMBER = 10 without dropping intermediate items.

What alternative solutions did you explore? (Optional)

  • Bundling multiple receipts into a single multi-page expense transaction: Rejected because each receipt sent via SMS represents an independent purchase from different merchants and dates, requiring discrete expense tracking.
  • Restricting users to send only 1 receipt per SMS: Rejected as it disrupts natural user behavior on iOS/Android Messages where attaching multiple photos to an MMS is standard.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 14 '26 00:11 kevinjosh10

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

Thanks for the proposals. Unfortunately neither identifies a confirmed root cause: both hypothesize a backend MMS iteration bug without evidence and the suggested App changes are already in place: getSortedReportActions already tie-breaks on reportActionID, report actions are keyed by ID and the preview carousel renders up to 11 items. This looks like a backend SMS/MMS ingestion issue. Could an internal engineer check the server logs for one multi-image MMS and confirm whether the middle transactions are created at all?

🎀 👀 🎀 C+ reviewed

cretadn22 avatar Nov 18 '26 18:11 cretadn22

Triggered auto assignment to @grgia, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

Confirmed this is a BE bug

grgia avatar Nov 23 '26 14:11 grgia

@grgia Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!