Skip to content

[Due for payment 2026-09-14] Distance - Page count remains after reducing waypoints to two when receipt has only one page #100336

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.70-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #97813
Email or phone of affected tester (no customers): oisdnjonjiodjodjsioj@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.5 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create a map distance expense with many waypoints so that the receipt has more than 1 page.
  4. Open the expense.
  5. Click Distance.
  6. Remove waypoints until there are only two left.
  7. Save the distance.

Expected Result:

Page count will disappear after reducing waypoints to two because receipt has only one page.

Actual Result:

Page count remains after reducing waypoints to two when receipt has only one page.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7250438_1788461531773.2.mp4

View all open jobs on GitHub

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

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. applause-bot commented on Sep 3, 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/b24608d59d994d716915a6d732ee99c2c8562ff84f6b60a8ba330e949cd8c58b

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 3, 2026
  3. melvin-bot commented on Sep 3, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #97813

  4. melvin-bot commented on Sep 3, 2026

    @melvin-bot

    @MonilBhavsar @abzokhattab you have been assigned to this deploy blocker because you reviewed the offending PR: #97813

  5. github-actions commented on Sep 3, 2026

    @github-actions
    Contributor

    👋 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.
  6. melvin-bot commented on Sep 3, 2026

    @melvin-bot

    @ishpaul777 you have been assigned to this deploy blocker because you authored the offending PR: #97813

  7. melvin-bot commented on Sep 3, 2026

    @melvin-bot

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

  8. MelvinBot commented on Sep 3, 2026

    @MelvinBot
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #97813 - "Show a page count badge on multi-page PDF receipts" by @ishpaul777 (High confidence)
    Related Issues: #100332 (StagingDeployCash checklist containing the PR)

    Recommendation: ROLL FORWARD

    The badge feature is new, self-contained and otherwise working; the only defect is that receipt.pageCount is never invalidated on the distance/waypoint edit path, which is a small additive fix that mirrors the invalidation this same PR already added for the two other receipt-replacement paths. A revert would pull a fully reviewed and unit-tested feature for a stale cosmetic badge.

    Assigned: @ishpaul777 (PR author), @abzokhattab and @MonilBhavsar (approving reviewers) — already auto-assigned by melvin-bot, no change needed.
    Labels: No changes. DeployBlockerCash stays (App PR caused it, fix is in Expensify/App). DeployBlocker was not present, so nothing to remove.

    📋 Detailed Analysis

    Evidence

    • PR [Payment due @abzokhattab] Show a page count badge on multi-page PDF receipts #97813 merged 2026-09-03T18:04:45Z; this issue was filed 2026-09-03T19:08:57Z, ~1 hour later. It is in the open StagingDeployCash checklist Deploy Checklist: New Expensify 2026-09-03 #100332.
    • The page count badge did not exist before this PR, which is consistent with "Reproducible in production?: N/A - new feature". The entire symptom (a page count indicator) is introduced by this PR.
    • The PR is the only thing in the release that reads receipt.pageCount; a repo-wide search finds pageCount on the transaction receipt only in files this PR touched.
    • The PR itself demonstrates that the author knew a stale pageCount had to be explicitly cleared, and did so on two of the three paths that invalidate a receipt:
      • replace receipt: src/libs/actions/IOU/Receipt.ts#L213 — pageCount: null with the comment "Clear the old count while the replacement is pending."
      • merge transactions: src/libs/actions/MergeTransaction.ts#L371 — "Clear the old count so it does not describe the newly chosen receipt."
      • missing: the distance edit path, where the server regenerates the map receipt after a waypoint / distance / rate change.

    Verification

    Affected files (all line links pinned to the PR merge commit 649427c):

    The unit tests added in the PR (tests/ui/components/MoneyRequestReceiptViewTest.tsx) only assert static Onyx states (pageCount: 3 shows, pageCount: 1 hides, non-PDF hides). There is no test for a transition where the receipt is replaced/regenerated, which is exactly the gap this bug falls into.

    Root Cause

    receiptPageCount is read straight off Onyx with no tie to the identity of the receipt it describes:

    const receiptPageCount = displayedTransaction?.receipt?.pageCount ?? 0;
    ...
    const shouldShowReceiptPageCount = receiptPageCount > 1 && Str.isPDF(receiptURIs?.filename ?? '') && !isLoading;

    Sequence for the repro:

    1. Many-waypoint map distance expense → server generates a multi-page PDF map receipt and sets receipt.pageCount = N (>1). Badge correctly shows "Page 1 of N".
    2. User reduces to two waypoints and saves. updateMoneyRequestDistance flags waypoints/merchant as pending and optimistically merges {...updatedTransaction} into the transaction key. getUpdatedTransaction never touches receipt, so receipt.pageCount is untouched. The badge is temporarily hidden only because isLoading is set to true in the waypoints branch.
    3. The server regenerates a single-page receipt and pushes the new receipt down. Because this is an Onyx MERGE (deep merge), any key the push does not include survives. pageCount is not reset to 1/null, so the old N persists.
    4. isLoading clears, the filename is still a PDF, receiptPageCount is still N > 1 → the badge reappears reading "Page 1 of N" over a one-page receipt.

    This is the same stale-value-under-Onyx-MERGE hazard the PR already guarded against in replaceReceipt and getOnyxTargetTransactionData; the distance-regeneration path was simply not covered.

    Suggested targeted fix (in src/libs/actions/IOU/UpdateMoneyRequest.ts, at the optimistic transaction merge around L1944-L1953): when shouldFlagMerchantPending is true (i.e. waypoints / distance / customUnitRateID / selectedRouteKey changed, the exact set that makes the BE regenerate the receipt), also clear the count:

    value: {
        ...updatedTransaction,
        // The BE regenerates the map receipt on this edit, so the old page count no longer describes it.
        ...(shouldFlagMerchantPending && updatedTransaction?.receipt ? {receipt: {...updatedTransaction.receipt, pageCount: null}} : {}),
        pendingFields,
        errorFields: null,
        reportID: newTransactionReportID ?? updatedTransaction?.reportID,
    },

    An equivalent alternative is to gate the badge on !hasPendingDistanceReceiptRegeneration(displayedTransaction) and clear the count, but gating alone is not sufficient: the stale value survives past the pending window, which is precisely what the tester saw.

    One follow-up worth confirming with the fix: whether the regeneration push includes pageCount when the new receipt is still multi-page (e.g. 20 waypoints → 8). If it does not, the badge would be correctly cleared but never restored for that case, and the backend should start emitting pageCount on regenerated distance receipts.

    💡 Suggested AI code review rule

    This bug looks like 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:

    • Rule: CONSISTENCY-19 Clear new Onyx sub-object fields on every path that replaces the object
    • Condition: When a PR adds a new optional field to a nested object in src/types/onyx/* (e.g. Transaction['receipt']), every Onyx.METHOD.MERGE / Onyx.merge writer that replaces that parent object must explicitly set the new field, using null when the value is unknown. Onyx merges deeply, so an omitted key keeps its previous value and silently goes stale.
    • Why: [Payment due @abzokhattab] Show a page count badge on multi-page PDF receipts #97813 added receipt.pageCount and cleared it in the replace-receipt and merge-transaction paths, but not in the distance-edit path, so a reduced-waypoint expense kept showing "Page 1 of 3" over a one-page receipt (this deploy blocker).
    • Search pattern: for each field added under src/types/onyx/, list every writer of the parent key — grep -rn "<parentField>:\s*{" src/libs/actions src/libs/*Utils* and grep -rn "\.\.\.<updatedObject>" src/libs/actions — and verify each either assigns the new field or nulls it.
    • Offending code (❌):
      // Optimistically modify the transaction and the transaction thread
      optimisticData.push({
      onyxMethod: Onyx.METHOD.MERGE,
      key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
      value: {
      ...updatedTransaction,
      pendingFields,
      errorFields: null,
      reportID: newTransactionReportID ?? updatedTransaction?.reportID,
      },
    • Fix (✅): the two paths the same PR got right —
      pageCount: null,
      and
      receipt: mergeTransaction.receipt ? {pageCount: null, ...mergeTransaction.receipt} : null,

    The full rule file, with the ❌/✅ code inline in Expensify/App's coding-standards format, would go in Expensify/App itself. If it's worth adding, a maintainer can open it there as a draft PR.


    view run

  9. 14 remaining items

  10. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Sep 13, 2026
  11. melvin-bot commented on Sep 13, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  12. melvin-bot commented on Sep 13, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  13. mallenexpensify commented on Sep 16, 2026

    @mallenexpensify
    Contributor

    Claude posting on behalf of Matt:

    Nothing is due on this issue. Not $250. abzokhattab approved the offending PR twice, so this regression came from a PR he reviewed.

    This is the twin of #100342. Same offending PR, same fix PR, same assignees, same payment date, same Melvin proposal. Paying both is $500. The full reasoning sits on that issue.

    Offending PR #97813 by ishpaul777, merged 2026-09-03. 18 files, +130 / -1
    Fix PR #100357 by ishpaul777, merged 2026-09-04. 4 files, +111 / -1. It fixed this issue and #100342 together
    Contributor Nothing due. ishpaul777 authored the offending PR, and he is a Backend Contributor
    Contributor+ Nothing due. abzokhattab approved the offending PR on 2026-08-14 and approved it again on 2026-09-01
    Job price $250, standard, no price in the title
    Melvin proposed $250 to abzokhattab
    Rule 0%: the regression came from the payee's own PR
    Precedent #98833, the same shape. Melvin proposed $250 each and Matt paid $0
    Contributor+ checklist None posted. Melvin asked on 2026-09-07 and nagged on 2026-09-10
    Needs a ruling Only if abzokhattab appeals
    Why nothing is due

    Melvin named the reviewers itself: "@MonilBhavsar @abzokhattab you have been assigned to this deploy blocker because you reviewed the offending PR".

    abzokhattab approved PR #97813 on 2026-08-14 and again on 2026-09-01, after the backend shipped. He then approved the fix PR on 2026-09-04. That fix work is cleanup of a fault his own approval let through, so it sits inside the original job price and earns nothing here.

    Melvin correctly zeroed ishpaul777 as a contractor, then paid the reviewer in full. That is right on an ordinary issue and wrong on a regression issue, because the reviewer is on the offending PR.

    This one was more findable than its twin

    Worth recording, because it matters if abzokhattab appeals.

    Melvin's investigation shows PR #97813 cleared the stale pageCount on two of the three paths that replace a receipt, and missed the third:

    • Replace receipt, cleared. Receipt.ts#L213, "Clear the old count while the replacement is pending."
    • Merge transactions, cleared. MergeTransaction.ts#L371, "Clear the old count so it does not describe the newly chosen receipt."
    • Distance edit, not cleared. This bug.

    The correct pattern was in the same diff, twice, with comments explaining it. A reviewer had the answer in front of them.

    Two things to handle outside this issue

    The penalty belongs on the original job. PR #97813 is titled "[Payment due @abzokhattab]" and closed Expensify/Expensify#667914. That is where abzokhattab gets paid for this work, and that is where the regression cut applies. #97813 caused two confirmed regressions, this one and #100342, and the rule for two or more is 25% of the job price. Worth checking on 667914 before it is paid, if it has not been paid already.

    The Contributor+ checklist is still outstanding. It gates the regression test case, not the money, so it does not change anything above. The standing ask: plz complete the Contributor+ checklist and tag me in a post once you have. Thx

    On a live run this would tag abzokhattab and MonilBhavsar. It tags nobody here, because the comment carries a test marker.


    Claude posting on behalf of Matt. PAYRUBRICTEST v2

  14. mallenexpensify commented on Sep 16, 2026

    @mallenexpensify
    Contributor

    Going to close as not due payment, will leave open for a pass in case anyone wants to comment

  15. abzokhattab commented on Sep 23, 2026

    @abzokhattab
    Contributor

    Can be closed as its handled in #100336

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions