Skip to content

[Due for payment 2026-06-01] [$250] Expense - Marked as paid message is shown twice on receipt cropped expense. #89131

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: V9.3.62-6
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/folder/13176924/test-cases/41237576
Email or phone of affected tester (no customers): dreamnitethedragon+vegst@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redmi note 10s android 13
App Component: Money Requests

Action Performed:

  1. Launch app
  2. Login with new gmail account and complete onboarding via Get paid back by employer
  3. Tap fab - create expense - try it out
  4. Tap receipt and crop the receipt
  5. Tap create expense
  6. Open the expense

Expected Result:

Marked as paid message must not be shown twice on receipt cropped expense.

Actual Result:

Marked as paid message is shown twice on receipt cropped expense.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7139475_1777312216591.Screenrecorder-2026-04-27-23-14-39-185.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @samarroy84
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022049214584338062184
  • Upwork Job ID: 2049214584338062184
  • Last Price Increase: 2026-04-28

Activity

  1. added
    Daily
    Bug
    on Apr 28, 2026
  2. MelvinBot commented on Apr 28, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    buildOnyxDataForTestDriveIOU (index.ts:1092-1152) creates an optimistic PAY action that overwrites the original CREATE action at the same reportActionID (line 1108). However, successData and failureData are left empty (lines 1096-1097), so this optimistic overwrite is never cleaned up.

    When the server processes REQUEST_MONEY with isTestDrive=true (TrackExpense.ts:1807), it auto-settles the expense and creates its own PAY action with a new server-generated reportActionID. Meanwhile, the parent buildOnyxDataForMoneyRequest success callback only clears pendingAction/errors on the original reportActionID (lines 1625-1629) — it does not revert the action type from PAY back to CREATE.

    Result: two PAY actions coexist in Onyx (the stuck optimistic one + the server-generated one), and both render as "marked as paid" via PaymentContent.tsx:30-31.

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

    Add successData to buildOnyxDataForTestDriveIOU that removes the optimistic PAY action at iou.action.reportActionID once the server responds (since the server creates the real PAY action with its own ID). This can be done by pushing an entry to successData that sets the action to null at that key, effectively cleaning up the optimistic overwrite:

    successData.push({
        onyxMethod: Onyx.METHOD.MERGE,
        key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouOptimisticParams.report.reportID}`,
        value: {
            [iouOptimisticParams.action.reportActionID]: null,
        },
    });
    

    Alternatively, the successData could revert the action's originalMessage.type back to CREATE instead of removing it, so the original CREATE action is restored and only the server's PAY action shows "marked as paid".

    What alternative solutions did you explore? (Optional)

    Another approach would be to deduplicate PAY-type actions in shouldReportActionBeVisible in ReportActionsUtils.ts, but this treats the symptom rather than the root cause. The optimistic action should be properly cleaned up in successData to keep the data layer accurate.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    External
    on Apr 28, 2026
  4. added
    Help Wanted
    on Apr 28, 2026
  5. melvin-bot commented on Apr 28, 2026

    @melvin-bot

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

  6. changed the title [-]Expense - Marked as paid message is shown twice on receipt cropped expense.[/-] [+][$250] Expense - Marked as paid message is shown twice on receipt cropped expense.[/+] on Apr 28, 2026
  7. melvin-bot commented on Apr 28, 2026

    @melvin-bot
  8. KJ21-ENG commented on Apr 28, 2026

    @KJ21-ENG
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    In the test-drive flow ("Try it out"), when you scan a receipt and tap Create expense, the resulting expense thread renders the "Marked as paid" / "Paid elsewhere" message twice on the iouReport, instead of once. The duplication is reproducible on Android, iOS, and Windows Chrome (matching the issue's checked platforms) and is reproducible in staging and production.

    What is the root cause of that problem?

    buildOnyxDataForTestDriveIOU (src/libs/actions/IOU/index.ts L1092-L1152) optimistically writes a PAY-type IOU report action under the same reportActionID that is already being used by the optimistic CREATE action of the parent flow:

    • The optimistic PAY is built with type: PAY, paymentType: ELSEWHERE, and reportActionID: testDriveIOUParams.iouOptimisticParams.action.reportActionID (lines 1099-1109).
    • It is then pushed into optimisticData at ${REPORT_ACTIONS}${iouReportID} keyed by that same iou.action.reportActionID, overwriting the optimistic CREATE action at that key (lines 1138-1144).
    • The function declares successData and failureData empty (lines 1096-1097) and returns them empty (lines 1147-1151), so this overwrite is never reverted or cleaned up.

    When REQUEST_MONEY runs with isTestDrive=true (src/libs/actions/IOU/TrackExpense.ts L1807), the server auto-settles the expense and returns its own PAY action with a new server-generated reportActionID (separate from iou.action.reportActionID). The parent buildOnyxDataForMoneyRequest success callback at src/libs/actions/IOU/index.ts L1625-L1629 only clears pendingAction / errors / isOptimisticAction on iou.action.reportActionID — it does not revert the action's type back to CREATE, and it does not delete the stuck optimistic PAY.

    Trigger → mechanism → impact: end of the optimistic build leaves a PAY action at iou.action.reportActionID; the server response adds a second PAY action at a new ID; both pass shouldReportActionBeVisible, both reach PaymentContent (src/pages/inbox/report/actionContents/PaymentContent.tsx L30-L31) with paymentType === ELSEWHERE, so both render iou.paidElsewhere ("Marked as paid"). Hence the duplicate message.

    function buildOnyxDataForTestDriveIOU(
    testDriveIOUParams: BuildOnyxDataForTestDriveIOUParams,
    ): OnyxData<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT> {
    const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [];
    const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [];
    const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT>> = [];
    const optimisticIOUReportAction = buildOptimisticIOUReportAction({
    type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
    amount: testDriveIOUParams.transaction.amount,
    currency: testDriveIOUParams.transaction.currency,
    comment: testDriveIOUParams.transaction.comment?.comment ?? '',
    participants: testDriveIOUParams.transaction.participants ?? [],
    paymentType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
    iouReportID: testDriveIOUParams.iouOptimisticParams.report.reportID,
    transactionID: testDriveIOUParams.transaction.transactionID,
    reportActionID: testDriveIOUParams.iouOptimisticParams.action.reportActionID,
    });
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    const text = Localize.translateLocal('testDrive.employeeInviteMessage', personalDetailsList?.[deprecatedUserAccountID]?.firstName ?? '');
    // delegateAccountIDParam: will be threaded in PR 15; buildOptimisticAddCommentReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
    const textComment = buildOptimisticAddCommentReportAction({
    text,
    actorAccountID: deprecatedUserAccountID,
    reportActionID: testDriveIOUParams.testDriveCommentReportActionID,
    delegateAccountIDParam: undefined,
    });
    textComment.reportAction.created = DateUtils.subtractMillisecondsFromDateTime(testDriveIOUParams.iouOptimisticParams.createdAction.created, 1);
    optimisticData.push(
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${testDriveIOUParams.chatOptimisticParams.report?.reportID}`,
    value: {
    [textComment.reportAction.reportActionID]: textComment.reportAction,
    },
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT}${testDriveIOUParams.iouOptimisticParams.report.reportID}`,
    value: {
    ...{lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED},
    hasOutstandingChildRequest: false,
    lastActorAccountID: deprecatedCurrentUserPersonalDetails?.accountID,
    },
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${testDriveIOUParams.iouOptimisticParams.report.reportID}`,
    value: {
    [testDriveIOUParams.iouOptimisticParams.action.reportActionID]: optimisticIOUReportAction,
    },
    },
    );
    return {
    optimisticData,
    successData,
    failureData,
    };
    }

    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iou.report.reportID}`,
    value: {
    ...(shouldCreateNewMoneyRequestReport
    ? {
    [iou.createdAction.reportActionID]: {
    pendingAction: null,
    errors: null,
    isOptimisticAction: null,
    },
    }
    : {}),
    [iou.action.reportActionID]: {
    pendingAction: null,
    errors: null,
    isOptimisticAction: null,
    },
    },
    },

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

    The optimistic PAY produced by buildOnyxDataForTestDriveIOU is the duplicate that must be cleaned up once the server returns its own PAY action. Two viable shapes:

    1. Minimal patch. Inside buildOnyxDataForTestDriveIOU, push a successData entry that nulls the optimistic PAY action at ${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouOptimisticParams.report.reportID} keyed by iouOptimisticParams.action.reportActionID. Mirror the same null in failureData so an offline-then-failed retry also leaves the report in a sane state (otherwise a failed test-drive submission would leave the same stuck PAY action behind). The server-supplied CREATE and PAY (each at their own new reportActionID) survive — matching the non-test-drive happy path.

    2. Cleaner data shape. Stop overwriting iou.action.reportActionID. Generate a unique reportActionID via NumberUtils.rand64() for the optimistic PAY in buildOnyxDataForTestDriveIOU, push it into optimisticData under that new key, and null it in both successData and failureData. The optimistic CREATE then survives unchanged at its original key, and CREATE/PAY never share a reportActionID. This is invariant-preserving and is the path I'd recommend if a slightly broader change is acceptable.

    Either shape addresses the same root cause (the missing cleanup); option 2 also removes the brittle "PAY masquerades as CREATE under the CREATE's reportActionID" intermediate state.

    Scope boundaries. Edits are confined to one function (buildOnyxDataForTestDriveIOU) in src/libs/actions/IOU/index.ts. The fix lives in shared JS so it covers Android, iOS, and web (the three platforms checked on the issue). Explicitly not touched: the non-test-drive REQUEST_MONEY path, the manager-McTest branch at src/libs/actions/IOU/index.ts L1418+ (which has its own PAY-overwrite logic and is not affected by this bug), src/libs/actions/IOU/TrackExpense.ts, PaymentContent.tsx, and ReportActionsUtils.shouldReportActionBeVisible. No backend / API contract change.

    What alternative solutions did you explore? (Optional)

    • MelvinBot's primary suggestion (post successData that nulls the optimistic action at iou.action.reportActionID) identifies the same root cause and lands at the same fix as option 1 above. That part of the bot proposal is correct.
    • MelvinBot's alternative (deduplicate PAY actions inside shouldReportActionBeVisible in src/libs/ReportActionsUtils.ts) should be rejected: it suppresses the second message in the UI without correcting the stale optimistic state in Onyx, which still leaks into other consumers (search snapshots, lastActionType, report previews, RBR / counters, exports). It treats the symptom and creates a maintenance trap.
    • Server-side cleanup (have the REQUEST_MONEY onyxData for isTestDrive=true explicitly null iou.action.reportActionID on success) would also work, but is a backend change. The client-only fix above is preferred for being merge-ready in this repo.
    • Bypassing the overwrite by always rendering only the most recent PAY (e.g., suppressing earlier PAY actions in PaymentContent) was considered and rejected for the same "treat the symptom" reason as the dedup alternative above.
  9. ProjectNOVACo commented on Apr 28, 2026

    @ProjectNOVACo

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  10. ProjectNOVACo commented on Apr 28, 2026

    @ProjectNOVACo

    📋 Contributor details

  11. github-actions commented on Apr 28, 2026

    @github-actions
    Contributor

    ⚠️ @ProjectNOVACo Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  12. nabi-ebrahimi commented on Apr 28, 2026

    @nabi-ebrahimi
    Contributor

    Proposal

    What is the root cause of that problem?

    The test-drive receipt flow temporarily overwrites the original money-request IOU action with a PAY action, using the same reportActionID.

    In buildOnyxDataForTestDriveIOU, the optimistic action is built with type: CONST.IOU.REPORT_ACTION_TYPE.PAY and paymentType: ELSEWHERE, but it reuses iouOptimisticParams.action.reportActionID:

    function buildOnyxDataForTestDriveIOU(
    testDriveIOUParams: BuildOnyxDataForTestDriveIOUParams,
    ): OnyxData<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT> {
    const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [];
    const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [];
    const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT>> = [];
    const optimisticIOUReportAction = buildOptimisticIOUReportAction({
    type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
    amount: testDriveIOUParams.transaction.amount,
    currency: testDriveIOUParams.transaction.currency,
    comment: testDriveIOUParams.transaction.comment?.comment ?? '',
    participants: testDriveIOUParams.transaction.participants ?? [],
    paymentType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
    iouReportID: testDriveIOUParams.iouOptimisticParams.report.reportID,
    transactionID: testDriveIOUParams.transaction.transactionID,
    reportActionID: testDriveIOUParams.iouOptimisticParams.action.reportActionID,

    That PAY action is merged into the IOU report actions collection at the same key as the original CREATE action:

    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${testDriveIOUParams.iouOptimisticParams.report.reportID}`,
    value: {
    [testDriveIOUParams.iouOptimisticParams.action.reportActionID]: optimisticIOUReportAction,
    },
    },

    However, the helper returns empty successData and failureData, so the overwritten CREATE action is never restored:

    return {
    optimisticData,
    successData,
    failureData,
    };

    The test-drive REQUEST_MONEY call also sends isTestDrive, which lets the backend auto-settle the request and return the real PAY action separately:

    const parameters: RequestMoneyParams = {
    debtorEmail: payerEmail,
    debtorAccountID: payerAccountID,
    amount,
    currency,
    comment,
    created,
    merchant,
    iouReportID: iouReport.reportID,
    chatReportID: chatReport.reportID,
    transactionID: transaction.transactionID,
    reportActionID: iouAction.reportActionID,
    createdChatReportActionID,
    createdIOUReportActionID,
    reportPreviewReportActionID: reportPreviewAction.reportActionID,
    receipt: isFileUploadable(receipt) ? receipt : undefined,
    receiptState: receipt?.state,
    category,
    tag,
    taxCode,
    taxAmount,
    billable,
    // This needs to be a string of JSON because of limitations with the fetch() API and nested objects
    receiptGpsPoints: gpsPoint ? JSON.stringify(gpsPoint) : undefined,
    transactionThreadReportID,
    createdReportActionIDForThread,
    reimbursable,
    description: parsedComment,
    attendees: attendees ? JSON.stringify(attendees) : undefined,
    isTestDrive,
    guidedSetupData: guidedSetupData ? JSON.stringify(guidedSetupData) : undefined,
    testDriveCommentReportActionID,

    The generic money-request success data only clears pending/error fields on the original action ID; it does not restore the original CREATE action content:

    isOptimisticAction: null,
    },
    },
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iou.report.reportID}`,
    value: {
    ...(shouldCreateNewMoneyRequestReport
    ? {
    [iou.createdAction.reportActionID]: {
    pendingAction: null,
    errors: null,
    isOptimisticAction: null,
    },
    }

    As a result, the report contains two PAY actions: the stuck optimistic PAY action and the real server-created PAY action. PaymentContent renders each ELSEWHERE PAY action as “marked as paid”, so the message appears twice:

    const paymentType = originalMessage.paymentType;
    const wasAutoPaid = originalMessage.automaticAction ?? false;
    if (paymentType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
    return <ReportActionItemBasicMessage message={translate('iou.paidElsewhere')} />;

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

    Restore the original optimistic IOU CREATE action in buildOnyxDataForTestDriveIOU after the API response instead of leaving the temporary PAY action in Onyx.

    Required changes:

    • Add a shared iouReportActionsKey for the IOU report actions collection.
    • Add successData that merges iouOptimisticParams.action back at iouOptimisticParams.action.reportActionID.
    • Add matching failureData so a failed test-drive request also returns the report action to the normal CREATE state before the existing failure-data error merge runs.
    • Keep the real server-generated PAY action untouched; it remains the only action rendered as “marked as paid”.

    Tests to add:

    • Add a unit test around buildOnyxDataForMoneyRequest or getMoneyRequestInformation for a transaction with receipt.isTestDriveReceipt = true.
    • Assert that optimistic data still temporarily writes a PAY action for the test-drive flow.
    • Assert that success data restores the original CREATE IOU action at the same reportActionID.
    • Assert that failure data also restores the original CREATE IOU action.

    MelvinBot identified the correct data-layer area, but the concrete cleanup should restore the original CREATE action rather than remove the action. Removing the action can hide the original money-request action from the report, while restoring it preserves the expense entry and leaves only the backend-created PAY action to render “marked as paid”.

    I also considered deduplicating PAY actions in ReportActionsUtils or PaymentContent, but that would hide a corrupted Onyx state instead of fixing the optimistic update that creates it.

    What alternative solutions did you explore? (Optional)

  13. github-actions commented on Apr 28, 2026

    @github-actions
    Contributor

    ⚠️ @nabi-ebrahimi Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  14. wildan-m commented on Apr 28, 2026

    @wildan-m
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a new user goes through the "Try it out" scan-test flow from the FAB, taps the receipt thumbnail in the confirmation step, crops the receipt, and then submits the expense, the resulting expense thread shows the "marked as paid" system message twice. Without cropping the test receipt first, the message correctly appears only once.

    What is the root cause of that problem?

    The "Try it out" tooltip starts the scan-test flow by calling setMoneyRequestReceipt with isTestReceipt = true, which stamps that flag onto the draft transaction's receipt. The downstream optimistic logic in buildOnyxDataForMoneyRequest reads this flag to decide whether to mark the optimistic IOU report action as PAY with payment type ELSEWHERE (which is what PaymentContent renders as "marked as paid") and to set the optimistic lastActionType: MARKED_REIMBURSED on the iouReport:

    if (isMoneyRequestToManagerMcTest) {
    const date = new Date();
    const isTestReceipt = transaction.receipt?.isTestReceipt ?? false;
    const managerMcTestParticipant = getManagerMcTestParticipant(currentUserAccountIDParam, personalDetails) ?? {};
    const optimisticIOUReportAction = buildOptimisticIOUReportAction({
    type: isScanRequest && !isTestReceipt ? CONST.IOU.REPORT_ACTION_TYPE.CREATE : CONST.IOU.REPORT_ACTION_TYPE.PAY,
    amount: iou.report?.total ?? 0,
    currency: iou.report?.currency ?? '',
    comment: '',
    participants: [managerMcTestParticipant],
    paymentType: isScanRequest && !isTestReceipt ? undefined : CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
    iouReportID: iou.report.reportID,
    transactionID: transaction.transactionID,
    reportActionID: iou.action.reportActionID,
    });
    iouAction = optimisticIOUReportAction;
    iouReport = {
    ...iouReport,
    ...(!isScanRequest || isTestReceipt
    ? {lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED}
    : undefined),
    hasOutstandingChildRequest: false,
    lastActorAccountID: deprecatedCurrentUserPersonalDetails?.accountID,
    };
    onyxData.optimisticData?.push(
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING}`,
    value: {[CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.SCAN_TEST_TOOLTIP]: {timestamp: DateUtils.getDBTime(date.valueOf()), dismissedMethod: 'click'}},
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
    value: {
    ...iou.report,
    ...(!isScanRequest || isTestReceipt
    ? {lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED}
    : undefined),
    hasOutstandingChildRequest: false,
    lastActorAccountID: deprecatedCurrentUserPersonalDetails?.accountID,
    },
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iou.report.reportID}`,
    value: {
    [iou.action.reportActionID]: {
    ...(optimisticIOUReportAction as OnyxTypes.ReportAction),
    },
    },
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
    value: {
    ...transaction,
    },
    },
    );
    }

    When the user taps the receipt thumbnail and crops it on the confirmation step, the crop's "save" handler calls applyDurableReceipt, which for a draft transaction invokes setMoneyRequestReceipt without forwarding the receipt's existing test flags:

    const applyDurableReceipt = useCallback(
    (imageUri: string, filename: string, file: File, isSameReceipt?: boolean) => {
    if (!transaction?.transactionID) {
    return Promise.resolve();
    }
    return moveReceiptToDurableStorage(imageUri, filename).then((durableUri) => {
    const durableFile = Object.assign(new File([file], file.name || filename, {type: file.type}), {uri: durableUri, source: durableUri});
    if (isOdometerImage) {
    setMoneyRequestOdometerImage(transaction, imageType, durableFile, isDraftTransaction, !isEditingConfirmation);
    } else if (isDraftTransaction) {
    setMoneyRequestReceipt(transaction.transactionID, durableUri, filename, isDraftTransaction, fileType);
    } else {
    replaceReceipt({
    transactionID: transaction.transactionID,
    file: durableFile,
    source: durableUri,
    transactionPolicyCategories: policyCategories,
    transactionPolicy: policy,
    ...(isSameReceipt ? {state: transaction?.receipt?.state, isSameReceipt: true} : {}),
    });
    }
    });
    },
    [transaction, isDraftTransaction, isOdometerImage, isEditingConfirmation, imageType, fileType, policyCategories, policy],
    );

    setMoneyRequestReceipt has its isTestReceipt and isTestDriveReceipt parameters defaulted to false, and explicitly merges them as null onto the receipt object — which clears the flags whenever a value isn't supplied:

    function setMoneyRequestReceipt(
    transactionID: string,
    source: string,
    filename: string,
    isDraft: boolean,
    type?: string,
    isTestReceipt = false,
    isTestDriveReceipt = false,
    thumbnail?: string,
    ) {
    Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
    // isTestReceipt = false and isTestDriveReceipt = false are being converted to null because we don't really need to store it in Onyx in those cases
    receipt: {source, filename, type: type ?? '', isTestReceipt: isTestReceipt ? true : null, isTestDriveReceipt: isTestDriveReceipt ? true : null, thumbnail},
    });
    }

    So after the crop, transaction.receipt.isTestReceipt is null. When the user taps "Create expense", the Manager McTest branch in buildOnyxDataForMoneyRequest evaluates isScanRequest && !isTestReceipt as true and picks the CREATE / no-paymentType variant, also skipping the optimistic lastActionType: MARKED_REIMBURSED update on the iouReport. The transaction is still treated as a demo on the server because the participant is Manager McTest (isDemoTransactionParam is derived from the participant login, not the receipt flag), so the backend auto-pays it and returns a server-generated IOU PAY / ELSEWHERE action plus a MARKED_REIMBURSED action. With no optimistic PAY action holding the same reportActionID to merge into, both server actions land independently in the chat — one rendering "marked as paid" through PaymentContent and the other through SimpleMessageContent, producing the observed duplicate.

    The same gap affects the rotate button on the same modal because it shares applyDurableReceipt, but the user-visible repro is the crop button.

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

    In applyDurableReceipt inside TransactionReceiptModalContent.tsx, when the draft-transaction branch calls setMoneyRequestReceipt, forward the receipt's existing isTestReceipt and isTestDriveReceipt values from transaction.receipt instead of letting them default to false. With the flag preserved across the crop and rotate operations, the downstream optimistic branch in buildOnyxDataForMoneyRequest once again selects the PAY / ELSEWHERE path and emits the matching optimistic IOU action plus the optimistic lastActionType: MARKED_REIMBURSED. The server's PAY response merges into the same reportActionID rather than landing as an independent action, and only one "marked as paid" message renders — matching the no-crop behavior.

    The fix is a single-call-site change at the boundary between the receipt-modify UI and the receipt store; it doesn't require any behavioral changes in the IOU optimistic-data builder. It's also robust against future scan-test or test-drive flows that depend on flags surviving in-place receipt edits — even though the rotate-and-crop button is currently hidden for test-drive receipts via shouldShowRotateAndCropReceiptButton, mirroring the same forward for isTestDriveReceipt keeps the two flags symmetric at this boundary.

    What alternative solutions did you explore? (Optional)

    A broader alternative is to change the optimistic-data heuristic in buildOnyxDataForMoneyRequest so the PAY / ELSEWHERE branch is taken whenever the participant is Manager McTest, regardless of whether the receipt flag is still present — effectively aligning the optimistic side with the isDemoTransactionParam rule already used for the API call. This is a wider blast radius (every Manager McTest expense path is affected, including non-scan ones) and feels closer to a behavioral redesign than a bug fix, so the surgical preserve-on-edit approach above is preferable for this issue.

  15. 46 remaining items

  16. trjExpensify commented on Jun 2, 2026

    @trjExpensify
    Contributor

    But we knowingly introduced a regression as a result of the change, so shouldn't the FE PR have been placed on hold for a BE PR to come first to avoid that? CC: @roryabraham as you were the internal reviewer on the PR.

  17. melvin-bot commented on Jun 5, 2026

    @melvin-bot

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

  18. mallenexpensify commented on Jun 9, 2026

    @mallenexpensify
    Contributor

    @roryabraham 👀 above please. I think it would have been better to place this on hold but.. it's water under the bridge now and the regression wasn't unexpected so I think it's likely best to pay both @mkhutornyi and @samarroy84 $250 and move on (assuming it's ready to be closed, I'm not well-versed in everything here)

  19. roryabraham commented on Jun 9, 2026

    @roryabraham
    Contributor

    @mallenexpensify I agree. The regression was flagged before merge so I think it's best to pay both @mkhutornyi and @samarroy84 $250

  20. mallenexpensify commented on Jun 9, 2026

    @mallenexpensify
    Contributor

    Payment summary updated above.

    @samarroy84 can you please accept the job below? Please reply here and tag me once you have.
    https://www.upwork.com/jobs/~022061598602863514656

  21. melvin-bot commented on Jun 12, 2026

    @melvin-bot

    @samarroy84 Whoops! This issue is 2 days overdue. Let's get this updated quick!

  22. melvin-bot commented on Jun 16, 2026

    @melvin-bot

    @samarroy84 Still overdue 6 days?! Let's take care of this!

  23. mallenexpensify commented on Jun 17, 2026

    @mallenexpensify
    Contributor

    @samarroy84 paid, summary updated above. Thx.

    @samarroy84 please post on issues and tag me when you accept the job in Upwork, otherwise I won't know. Thx

  24. trjExpensify commented on Jun 23, 2026

    @trjExpensify
    Contributor

    approved $250 for @mkhutornyi

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions