Skip to content

[Due for payment 2026-09-17] Expense - Second expense is highlighted when opening the duplicated report #100761

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.75-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #98744
Email or phone of affected tester (no customers): sjdojsndonsjoisnjio@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 two expenses.
  4. Click View to open the report.
  5. Click More > Duplicate report.
  6. Open the duplicated report.

Expected Result:

Second expense will not highlight when opening the duplicated report.

Actual Result:

Second expense is highlighted when opening the duplicated report.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7255412_1788983892880.3.mp4

View all open jobs on GitHub

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

Issue OwnerCurrent Issue Owner: @abzokhattab

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 9, 2026
  2. applause-bot commented on Sep 9, 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/368e4abd77f6ed24cfb3b5925d38dad4a7077ecbf320d0f5a4d9159f343f6040

  3. melvin-bot commented on Sep 9, 2026

    @melvin-bot

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

  4. github-actions commented on Sep 9, 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.
  5. melvin-bot commented on Sep 9, 2026

    @melvin-bot

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

  6. melvin-bot commented on Sep 9, 2026

    @melvin-bot

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

  7. melvin-bot commented on Sep 9, 2026

    @melvin-bot

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

  8. MelvinBot commented on Sep 9, 2026

    @MelvinBot
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #98744 - "refactor: the new-transaction highlight rail and the wide RHP width model" by @TaduJR (High confidence)
    Related Issues: #100757 (also a v9.4.75-0 staging-only highlight-rail regression, also attributed to #98744)

    Recommendation: ROLL FORWARD

    duplicateReport never opens the expense report it creates, so it should pass the existing shouldSkipReportHighlightRail: true escape hatch — a one-line change in Duplicate.ts, exactly the way SplitTransactionUpdate.ts already does it. Reverting #98744 means unwinding 49 files / +2414/-477 across two unrelated subsystems (the highlight rail and the wide-RHP width model), which is far riskier than this fix.

    Assigned: @TaduJR (PR author), @blimpich and @abzokhattab (approving reviewers) — already assigned
    Labels: No changes. DeployBlockerCash is kept (App-side regression, fix is in Expensify/App); DeployBlocker was not present.

    📋 Detailed Analysis

    Evidence

    Verification

    Affected files (permalinks at 2b613353, the 9.4.75-0 staging SHA):

    gh pr view 98744 --json files confirms #98744 modifies MoneyRequestBuilder.ts, useNewTransactions.ts, PendingNewTransactionFlags.ts, PendingNewTransactions.ts, selectors/ReportMetaData.ts and MoneyRequestReportActionsList.tsx. Merged 2026-09-09T00:07:42Z, which is in the 9.4.75-0 checklist (#100739) and ~20h before this bug was filed.

    Root Cause

    buildOnyxDataForMoneyRequest only flags a new expense on the highlight rail when the add makes the report multi-transaction. #98744 changed how that is computed.

    Production (works):

    const addMakesReportMultiTransaction =
        isMoneyRequestReport(iou.report) && existingReportTransactions.some((t) => t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

    Staging after #98744 (broken):

    const serverTransactionCountBeforeAdd = (iou.report?.transactionCount ?? 0) - 1;
    const transactionCountAfterAdd =
        existingReportTransactions.length >= serverTransactionCountBeforeAdd
            ? existingReportTransactions.filter((t) => t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length + 1
            : (iou.report?.transactionCount ?? 0);
    const addMakesReportMultiTransaction = isMoneyRequestReport(iou.report) && !isTransactionAlreadyOnReport && transactionCountAfterAdd >= 2;

    Walking the two-expense duplicate:

    1. duplicateReport loops synchronously over the source transactions, calling createExpenseByType → requestMoney for each, threading the optimistic new report through currentIOUReport. MoneyRequestBuilder pre-increments that object: iouReport.transactionCount = (iouReport.transactionCount ?? 0) + 1 (L1527).
    2. Iteration 1 (t1'): transactionCount becomes 1, so serverTransactionCountBeforeAdd = 0. Cache is empty, 0 >= 0 is true → transactionCountAfterAdd = 1 → no flag. Correct.
    3. Iteration 2 (t2'): transactionCount becomes 2, so serverTransactionCountBeforeAdd = 1. But getReportTransactions() reads a module-level cache populated by an async Onyx.merge, and iteration 1's optimistic write has not landed yet in the same tick — so the cache still reports 0 transactions for the brand-new report. 0 >= 1 is false, so the code falls back to the pre-incremented optimistic count: transactionCountAfterAdd = 2 → 2 >= 2 → a rail flag is written for t2' on reportMetadata_<duplicatedReportID>.
    4. Production's .some(...) form reads the same empty cache and correctly yields false, so no flag is ever written. That is the entire staging/production divergence.
    5. When the user opens the duplicated report, pendingNewTransactionIDsSelector still sees that flag as active (60s freshness window), useNewTransactions returns [t2'] from the rail, and MoneyRequestReportTransactionList highlights the second row — matching the report exactly.

    Two independent things went wrong, and either one alone would have prevented the bug:

    • The new existingReportTransactions.length >= serverTransactionCountBeforeAdd fallback trusts optimistic state whenever the synchronous cache looks "partial", which is indistinguishable from "the cache simply hasn't caught up with a write we just made".
    • duplicateReport never passes shouldSkipReportHighlightRail, even though the flag's own JSDoc says it exists "for flows that never open the expense report" — which is exactly what this flow is.

    Suggested fix (smallest safe change): set shouldSkipReportHighlightRail: true on the transactionParams that duplicateReport builds, as updateSplitTransactions already does. Optionally also harden the gate so the transactionCount fallback is not taken when existingReportTransactions is empty for a report that was created in this same tick.

    💡 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-18 Don't read Onyx-backed sync caches for writes made earlier in the same loop
    • Condition: Flag any loop body that calls an optimistic action creator (API.write, requestMoney, createExpenseByType, …) and reads a synchronous Onyx snapshot helper (getReportTransactions(, getReport(, or any deprecated* module cache) to decide something about state the loop itself just wrote. Onyx.merge resolves asynchronously, so iteration N sees the cache as it was before iteration 1. Thread the accumulated state explicitly through the loop (as currentIOUReport already is) or pass the collection in as a parameter instead.
    • Why: A stale cache read silently takes the "incomplete data" branch and falls back to optimistic counters, producing decisions that are correct on iteration 1 and wrong on every later iteration. Here it wrote a spurious new-transaction highlight flag for the second duplicated expense ([Due for payment 2026-09-17] Expense - Second expense is highlighted when opening the duplicated report #100761).
    • Search pattern: rg -U 'for\s*\(|\.forEach\(|while\s*\(' -A 40 src/libs/actions | rg 'getReportTransactions\(|deprecated[A-Z]' — then check whether the same loop body also calls an action creator or API.write.
    • Offending code (❌):
      // A 0→1 add fresh-mounts the table with the tx present, so nothing consumes its flag. No successData, which races the mount.
      const reportTransactionsFromCache = iou.report?.reportID ? getReportTransactions(iou.report.reportID) : [];
      const isTransactionAlreadyOnReport = reportTransactionsFromCache.some((reportTransaction) => reportTransaction.transactionID === transaction.transactionID);
      const existingReportTransactions = reportTransactionsFromCache.filter((reportTransaction) => reportTransaction.transactionID !== transaction.transactionID);
      // Only a cache holding every transaction the server counted can be trusted to subtract pending deletes. A partial one would count too few and drop the flag.
      const serverTransactionCountBeforeAdd = (iou.report?.transactionCount ?? 0) - 1;
      const transactionCountAfterAdd =
      existingReportTransactions.length >= serverTransactionCountBeforeAdd
      ? existingReportTransactions.filter((reportTransaction) => reportTransaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length + 1
      : (iou.report?.transactionCount ?? 0);
      const addMakesReportMultiTransaction = isMoneyRequestReport(iou.report) && !isTransactionAlreadyOnReport && transactionCountAfterAdd >= 2;
      driven by the loop at
      for (let i = 0; i < eligibleTransactions.length; i++) {
      const transaction = eligibleTransactions.at(i);
      if (!transaction) {
      continue;
      }
      const transactionDetails = getTransactionDetails(transaction);
      if (!transactionDetails) {
      continue;
      }
      const isLastExpense = i === eligibleTransactions.length - 1;
      const {transactionParams, waypoints} = buildDuplicateTransactionParams(transaction, transactionDetails);
      const params: RequestMoneyInformation = {
      report: parentChatReport,
      existingIOUReport: currentIOUReport,
      optimisticReportPreviewActionID: reportPreviewReportActionID,
      participantParams: {
      payeeAccountID: currentUserAccountID,
      payeeEmail: currentUserLogin,
      participant: participants.at(0) ?? {},
      },
      policyParams,
      gpsPoint: undefined,
      action: CONST.IOU.ACTION.CREATE,
      transactionParams,
      shouldPlaySound: false,
      shouldGenerateTransactionThreadReport: true,
      isASAPSubmitBetaEnabled,
      currentUserAccountIDParam: currentUserAccountID,
      currentUserEmailParam: currentUserLogin,
      transactionViolations: transactionViolations ?? {},
      quickAction,
      policyRecentlyUsedCurrencies,
      existingTransactionDraft: undefined,
      existingTransaction: {
      iouRequestType: getDuplicateRequestType(transaction),
      amount: 0,
      currency: '',
      created: '',
      merchant: '',
      reportID: '1',
      transactionID: '1',
      },
      isSelfTourViewed,
      conciergeChat,
      betas,
      personalDetails,
      shouldDeferAutoSubmit: !isLastExpense,
      isTrackIntentUser,
      delegateAccountID,
      formatPhoneNumber,
      getCurrencyDecimals,
      };
      const result = createExpenseByType({
      dateFnsLocale,
      transactionType: getTransactionType(transaction),
      params,
      transaction,
      transactionDetails,
      waypoints,
      participants,
      policyRecentlyUsedCurrencies,
      quickAction,
      customUnitPolicyID: targetPolicy?.id,
      personalDetails,
      recentWaypoints,
      isTrackIntentUser,
      formatPhoneNumber,
      participantsPolicyTags,
      policyTags: targetPolicyTags ?? {},
      });
      if (result?.iouReport) {
      currentIOUReport = result.iouReport;
      }
      }
    • Fix (✅): the production form that does not consult a count fallback, https://github.com/Expensify/App/blob/production/src/libs/actions/IOU/MoneyRequestBuilder.ts#L695-L701, plus explicitly opting the flow out via shouldSkipReportHighlightRail as at
      updateSplitTransactions({...params, isFromSplitExpensesFlow: true, shouldSkipReportHighlightRail: true});

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

  9. blimpich commented on Sep 9, 2026

    @blimpich
    Contributor

    consolidating conversation around this deploy blocker and it's related deploy blockers here: https://expensify.slack.com/archives/C01GTK53T8Q/p1788996794073959

  10. melvin-bot commented on Sep 10, 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.

  11. IuliiaHerets commented on Sep 10, 2026

    @IuliiaHerets

    This issue is not repro on Windows 10/Chrome Build v9.4.75-1

    Recording.1579.mp4
  12. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Sep 10, 2026
  13. changed the title [-]Expense - Second expense is highlighted when opening the duplicated report[/-] [+][Due for payment 2026-09-17] Expense - Second expense is highlighted when opening the duplicated report[/+] on Sep 10, 2026
  14. melvin-bot commented on Sep 10, 2026

    @melvin-bot

    @abzokhattab / @TaduJR

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.4.75-3 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-09-17. 🎊

    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