Skip to content

Filter DELETE-pending transactions out of LHN RBR aggregation - #97706

Open
dilshodmackbook-sketch wants to merge 2 commits into
Expensify:mainfrom
dilshodmackbook-sketch:fix/96967-rbr-reverted-split
Open

Filter DELETE-pending transactions out of LHN RBR aggregation#97706
dilshodmackbook-sketch wants to merge 2 commits into
Expensify:mainfrom
dilshodmackbook-sketch:fix/96967-rbr-reverted-split

Conversation

@dilshodmackbook-sketch

@dilshodmackbook-sketch dilshodmackbook-sketch commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Reverting a split on a report removes the split child transaction(s) optimistically — they are marked with pendingAction: DELETE and stay in Onyx (with their reportID and their transactionViolations entry) until the server confirms and nulls them.

The LHN red-dot (RBR) is computed by getViolatingReportIDForRBRInLHN in src/libs/ReportUtils.ts. It built the report's transaction set with a plain getReportTransactions(...) and did not exclude transactions that are pending deletion. That set is passed down into hasVisibleViolationsForUser / hasViolations / hasWarningTypeViolations / hasNoticeTypeViolationsForRBRInLHN, each of which reads transactionViolations_<transactionID> for every transaction — so a DELETE-pending transaction whose violation entry still existed kept the red dot lit.

Meanwhile the report contents (and the sibling "is this report empty" check a few lines above in the same file) already filter out DELETE-pending transactions, which is why the opened report looked clean. The LHN aggregation and the report view disagreed about whether the reverted transaction still existed.

This PR makes the RBR aggregation ignore transactions that are already pending deletion, mirroring the empty-report check in the same function:

const transactions = getReportTransactions(potentialReport.reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

Because this filtered array is the one handed to every downstream violation check, the single change fixes the whole RBR path in one place and keeps the LHN consistent with what the opened report actually renders — for reverted splits and any other flow that leaves a transaction queued for deletion.

A unit test was added to tests/unit/ReportUtilsTest.ts covering the case where the only violating transaction is DELETE-pending, asserting getViolatingReportIDForRBRInLHN returns null.

Fixed Issues

$ #96967
PROPOSAL: #96967 (comment)

Tests

  1. Open a report and move some expenses onto it.
  2. Split an expense on the report.
  3. Revert the split.
  4. Open the report and observe there are no per-transaction violations to fix.
  5. Verify the report's RBR (red-dot) indicator in the LHN is not shown while the reverted split's child transaction is still queued for deletion.
  6. Verify reports that genuinely have violations still show the RBR indicator.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline.
  2. Split an expense on a report, then revert the split.
  3. Verify the LHN does not show a policy-violation red-dot for that report while the reverted child transaction sits pending deletion.
  4. Go back online and verify the state stays consistent after the server confirms the removal.

QA Steps

  1. Open a report and move some expenses onto it.
  2. Split an expense on the report.
  3. Revert the split.
  4. Open the report and confirm there are no per-transaction violations to fix.
  5. Verify the report no longer shows a policy-violation red-dot (RBR) indicator in the LHN.
  6. Verify reports that do have real violations still display the RBR indicator.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
96967-android.mp4
Android: mWeb Chrome
video_2026-08-04_00-12-57.mp4
iOS: Native
96967-ios.mp4
iOS: mWeb Safari
video_2026-08-04_00-12-59.mp4
MacOS: Chrome / Safari
96967-macos-chrome.online-video-cutter.com.mp4

Reverting a split leaves the split child transaction in Onyx marked
pendingAction DELETE until the server confirms. getViolatingReportIDForRBRInLHN
counted that lingering transaction's violation and kept the report's red-dot
lit, while the opened report (which filters DELETE-pending transactions) looked
clean. Filter DELETE-pending transactions from the RBR aggregation, mirroring
the empty-report check in the same file.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 3efef0859f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@dilshodmackbook-sketch
dilshodmackbook-sketch marked this pull request as ready for review August 3, 2026 20:18
@dilshodmackbook-sketch
dilshodmackbook-sketch requested review from a team as code owners August 3, 2026 20:18
@melvin-bot
melvin-bot Bot requested a review from marufsharifi August 3, 2026 20:18
@melvin-bot

melvin-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

@marufsharifi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested review from garrettmknight and removed request for a team August 3, 2026 20:19
Comment thread src/libs/ReportUtils.ts Outdated
const transactions = getReportTransactions(potentialReport.reportID);
// Ignore transactions that are already pending deletion (e.g. a reverted split child) so the LHN RBR stays
// consistent with what the opened report renders, which also filters out DELETE-pending transactions.
const transactions = getReportTransactions(potentialReport.reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse the existing isTransactionPendingDelete predicate instead of the raw comparison.

TransactionUtils already exports a named predicate for exactly this check:

https://github.com/Expensify/App/blob/main/src/libs/TransactionUtils/index.ts#L3001-L3003

For a transaction with a set pendingAction it's behaviorally identical to this line (the pendingFields branch in getTransactionPendingAction only ever yields UPDATE, never DELETE), so this is a safe swap:

const transactions = getReportTransactions(potentialReport.reportID).filter((transaction) => !isTransactionPendingDelete(transaction));

isTransactionPendingDelete isn't imported into ReportUtils.ts yet, but this file already imports heavily from TransactionUtils, so just add it to that import. This keeps the intent ("skip transactions pending deletion") readable rather than hardcoding the CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE comparison.

Comment thread src/libs/ReportUtils.ts Outdated
const transactions = getReportTransactions(potentialReport.reportID);
// Ignore transactions that are already pending deletion (e.g. a reverted split child) so the LHN RBR stays
// consistent with what the opened report renders, which also filters out DELETE-pending transactions.
const transactions = getReportTransactions(potentialReport.reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "drop DELETE-pending transactions" filter is now the third copy of the same inline pattern in this file.

The same raw pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE filter over a transaction list already lives at:

The comment on this new line even notes the opened-report path does the same filtering — that's the smell. Switching all three to !isTransactionPendingDelete(...) (see the other comment) collapses them onto one shared predicate.

Extracting a small getActiveReportTransactions / filterOutDeletedTransactions helper in TransactionUtils would make the reuse fully explicit, but that's a larger refactor and out of scope here — the predicate swap is the minimal DRY fix for this PR.

Comment thread src/libs/ReportUtils.ts Outdated
const transactions = getReportTransactions(potentialReport.reportID);
// Ignore transactions that are already pending deletion (e.g. a reverted split child) so the LHN RBR stays
// consistent with what the opened report renders, which also filters out DELETE-pending transactions.
const transactions = getReportTransactions(potentialReport.reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filter runs before the cheap isOpenOrProcessingReport early-return

getReportTransactions(...).filter(...) executes before the isOpenOrProcessingReport(potentialReport) guard just below (line 9459). For any report that isn't open/processing, both the transaction lookup and the new allocation-and-iterate are wasted. This is a pre-existing ordering issue — this PR only widens the wasted work by adding the .filter() to it. Per-report transaction lists are small and bounded, so the absolute cost is negligible even across many LHN rows; flagging only for a cheap cleanup.

Move the transactions computation below the early-return so it runs only for reports that survive the guard:

// Allow both open and processing reports to show RBR for violations
if (!isOpenOrProcessingReport(potentialReport)) {
    return false;
}

const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${potentialReport.policyID}`];
const transactions = getReportTransactions(potentialReport.reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

Comment thread src/libs/ReportUtils.ts Outdated
const transactions = getReportTransactions(potentialReport.reportID);
// Ignore transactions that are already pending deletion (e.g. a reverted split child) so the LHN RBR stays
// consistent with what the opened report renders, which also filters out DELETE-pending transactions.
const transactions = getReportTransactions(potentialReport.reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: This line chains getReportTransactions(...).filter(...) with a long inline predicate, pushing it well past the width of the surrounding lines. The meaningful pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE check ends up buried at the tail of the line.

Consider extracting a named predicate so the intent reads at a glance:


const isNotPendingDeletion = (transaction: Transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
const transactions = getReportTransactions(potentialReport.reportID).filter(isNotPendingDeletion);

expect(result).toBeNull();

await Onyx.clear();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test: mixed DELETE-pending + live transaction on the same report.

Both this new test and the existing positive test use a single transaction, so nothing proves the filter is per-transaction (drops only the reverted child) rather than "if any transaction is DELETE-pending, drop the whole report's RBR." That's the exact split-report shape this fix targets.

Please add, right after this test:

it('should still surface RBR when a report has a live violating transaction alongside a DELETE-pending one', async () => {
    // ...same policy / chatReport / expenseReport setup as the pending-delete test...

    // Two violating transactions on the SAME expense report:
    // one reverted split child (DELETE-pending) and one still live.
    const deletedChild: Transaction = {
        ...createRandomTransaction(809),
        transactionID: 'transaction-rbr-mixed-deleted',
        reportID: expenseReportID,
        amount: 5000,
        currency: CONST.CURRENCY.USD,
        status: CONST.TRANSACTION.STATUS.POSTED,
        reimbursable: true,
        pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
    };
    const liveChild: Transaction = {
        ...createRandomTransaction(810),
        transactionID: 'transaction-rbr-mixed-live',
        reportID: expenseReportID,
        amount: 5000,
        currency: CONST.CURRENCY.USD,
        status: CONST.TRANSACTION.STATUS.POSTED,
        reimbursable: true,
        // no pendingAction
    };

    // Give BOTH transactions a MISSING_CATEGORY violation, then merge policy/reports/
    // transactions/violations into Onyx as in the tests above.

    const result = getViolatingReportIDForRBRInLHN(chatReport, transactionViolationsCollection);
    expect(result).toBe(expenseReportID); // RBR still shown because the live child violates

    await Onyx.clear();
});

Verdict: Covered 2/3 changed behaviors — the mixed-transaction case is the one gap, and it's the realistic split-report scenario the fix is about.

await waitForBatchedUpdates();

const result = getViolatingReportIDForRBRInLHN(chatReport, transactionViolationsCollection);
expect(result).toBeNull();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a positive control so this test can't pass vacuously.

Right now the test only asserts the DELETE-pending case returns null. That doesn't prove the filter is what produces the null — if any unrelated gate in getViolatingReportIDForRBRInLHN (isCurrentUserSubmitter, isOpenOrProcessingReport, or shouldShowViolation rejecting MISSING_CATEGORY) were the real reason, the test would still pass while testing nothing, and it would keep passing even if the fix were reverted in a way that broke a different gate.

Please assert that the same setup lights the RBR when the transaction is not pending deletion. Cheapest version — flip pendingAction and re-assert right after line 15471:

// Positive control: the same violating transaction lights the RBR when it isn't pending deletion.
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {pendingAction: null});
await waitForBatchedUpdates();
expect(getViolatingReportIDForRBRInLHN(chatReport, transactionViolationsCollection)).toBe(expenseReportID);

This guarantees the test actually exercises the new filter (and would fail on main), instead of relying on QA step 6 to cover the positive case.

@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot Review

@marufsharifi

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@MelvinBot

Copy link
Copy Markdown
Contributor

Review — LGTM ✅

The fix is correct, minimal, and well-placed. Filtering DELETE-pending transactions at ReportUtils.ts:9456 is the right choke point — that single transactions array is threaded into every downstream violation check, so one filter fixes the whole RBR path and keeps the LHN consistent with what the opened report renders.

Verification

The filter propagates to all four downstream checks. Each honors the passed array rather than re-fetching:

  • hasVisibleViolationsForUser iterates the passed transactions directly (ViolationsUtils.ts:1176).
  • hasViolations / hasWarningTypeViolations use reportTransactions ?? getReportTransactions(...) (ReportUtils.ts:9547, :9603), and the PR passes the filtered array, so the nullish-coalescing keeps the filter.
  • hasNoticeTypeViolationsForRBRInLHN iterates reportTransactions (:9522).

Pattern matches existing code. transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE is the standard "is this queued for deletion" check used throughout the file (e.g. :4684). Array elements are non-null (downstream reads transaction.transactionID without optional chaining), so transaction.pendingAction is safe.

The test is meaningful. The new case is a byte-for-byte clone of the existing positive test should return the violating report ID for an open expense report with violations (ReportUtilsTest.ts:15298, same MISSING_CATEGORY violation → asserts toBe(expenseReportID)), differing only by adding pendingAction: DELETE and asserting toBeNull(). The identical setup lights the RBR without the flag, so the test genuinely fails without this fix.

(I couldn't execute Jest in this sandboxed run, so the test-behavior claim above is from code analysis, not a local run — CI's test.yml will confirm.)

Non-blocking observation

Other violation aggregators — hasAnyViolations (:9641) and the strict-submit gate shouldBlockSubmitDueToStrictPolicyRules (:9659) — don't filter DELETE-pending transactions, so the same stale-violation class could theoretically surface through them. That's outside this issue's LHN-RBR scope and fine to leave, but worth a mental note in case a similar report lands.


This is an automated review from MelvinBot — not a substitute for the human reviewer checklist. Reply with @MelvinBot <feedback> to refine.

@marufsharifi

Copy link
Copy Markdown
Contributor

@dilshodmackbook-sketch, could you please check the above comments.

…, cover mixed case

- Swap the raw pendingAction !== DELETE comparisons for the existing
  isTransactionPendingDelete predicate across all three call sites in ReportUtils.
- Move the transaction filter below the isOpenOrProcessingReport early-return so
  it only runs for reports that survive the guard.
- Add a positive control to the pending-delete RBR test and a mixed
  live + DELETE-pending test proving the filter is per-transaction.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@marufsharifi Done.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants