Skip to content

Expense - Expense is created in another report with error when Submissions are disabled - #94386

Merged
puneetlath merged 15 commits into
Expensify:mainfrom
thelullabyy:fix/94282
Jul 13, 2026
Merged

puneetlath merged 15 commits into
Expensify:mainfrom
thelullabyy:fix/94282

Conversation

@thelullabyy

@thelullabyy thelullabyy commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #94282
PROPOSAL: N/A

Tests

Precondition:

  • Disable Submissions in Workflows.
  • Enable newManualExpenseFlow beta
  1. Go to staging.new.expensify.com
  2. Open self DM.
  3. Send a message.
  4. Open FAB > Create expense > Manual.
  5. Enter amount.
  6. Click Create expense.
  7. Verify that we can create expense successfully
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Precondition:

  • Disable Submissions in Workflows.
  • Enable newManualExpenseFlow beta
  1. Go to staging.new.expensify.com
  2. Open self DM.
  3. Send a message.
  4. Open FAB > Create expense > Manual.
  5. Enter amount.
  6. Click Create expense.
  7. Verify that we can create expense successfully
  • 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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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
Screen.Recording.2026-06-24.at.01.29.33.mov
Android: mWeb Chrome
Screen.Recording.2026-06-24.at.01.30.45.mov
iOS: Native
Screen.Recording.2026-06-24.at.01.34.15.mov
iOS: mWeb Safari
Screen.Recording.2026-06-24.at.01.35.11.mov
MacOS: Chrome / Safari
Screen.Recording.2026-06-23.at.23.03.13.mov

…ctly routed. Update tests to verify that expenses with the current user as the sole recipient are processed as self-DM track expenses, preventing erroneous money request submissions
@thelullabyy

Copy link
Copy Markdown
Contributor Author

@codex review

const selectedParticipantsForRequest = iouType === CONST.IOU.TYPE.SPLIT ? splitParticipants : selectedParticipants;

const soleSelectedParticipant = selectedParticipants.length === 1 ? selectedParticipants.at(0) : undefined;
const isSelfDMDestination =

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Old flow: the amount step (AmountSubmission) resolves the destination before navigating, and when the target is the self-DM it navigates to the confirmation with iouType: TRACK baked into the route. So the confirmation reads TRACK reliably → trackExpense.

New flow: the confirmation is embedded, and the conversion to TRACK happens after mount via an async navigation.setParams({iouType: TRACK}). createTransaction decides trackExpense vs requestMoney purely from that route iouType. When the conversion hasn't landed at submit time, it falls through to requestMoney with the current user as recipient → backend rejects with "you cannot request money from yourself."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should derive the track decision from the resolved participant (the same signal the old flow uses: destination is the self-DM), not the async route iouType

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 3a047ce32f

ℹ️ 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".

@MelvinBot

Copy link
Copy Markdown
Contributor

Checked the draft — the approach looks correct, and you're right that my earlier proposal was aimed at the wrong layer. 👍

Why my proposal missed it: I theorized the expense was being routed to a policy expense chat because of a stale autoReporting flag, and proposed gating shouldAutoReport in useDefaultParticipants.ts. But the real failure is simpler and one layer down: the sole recipient resolves to the current user, yet the route iouType was never converted to TRACK, so submission fell through to requestMoney — which the backend rejects ("you cannot request money from yourself"). My fix wouldn't have helped, because the confirmation step's iouType → TRACK conversion at IOURequestStepConfirmation.tsx:329-347 keys off isSelfDM only, and the failing participant carries the current user's accountID without that flag set.

Your fix addresses exactly that gap. Deciding isSelfDMDestination at the submission point (useExpenseSubmission.ts:241-248) catches both representations (isSelfDM === true or accountID === currentUserAccountID), and the guards (!isPolicyExpenseChat, !isSender, sole participant, excluding SPLIT/INVOICE/PAY) keep it from misfiring on real requests/splits/workspace submissions. Forcing trackReport = undefined so getTrackExpenseInformation defaults to the self-DM, and threading the self-DM into post-batch cleanup, are both consistent with the existing track path (optimisticChatReportID already pointed at optimisticSelfDMReportID). Nice to see the regression unit test covering it too.

CI is green (the two checklist failures are just the unchecked PR checklists), and Codex found no major issues.

A couple of optional, non-blocking thoughts:

  1. Single source of truth. You now have two places that decide "this is really a self-DM track": the confirmation step's isSelfDM-based iouType conversion, and this new isSelfDMDestination. Longer term it might be worth having the confirmation step also recognize the accountID === currentUser case so iouType becomes TRACK and the rest of the code (which already branches on isTrackExpense) just works — rather than threading a parallel flag through the request/distance/track branches. Your localized approach is a perfectly reasonable deploy-blocker fix though; just flagging it for the reviewer's consideration.

  2. accountID heuristic. Worth a sentence in the PR/code comment on why accountID === currentUserAccountID is a safe self-DM signal here (it's guarded against policy-expense-chat and sender participants), so a future reader doesn't worry it could capture a legitimate "expense involving me" case.

Thanks for digging into this and correcting the direction.

@MelvinBot

Copy link
Copy Markdown
Contributor

I reviewed this — the approach is sound and at the right layer, and you correctly identified that my earlier proposal was aimed at the wrong place. Quick reconciliation for the record:

  • My proposal changed shouldAutoReport in useDefaultParticipants, on the assumption that the expense was being routed to a policy expense chat. That's not what happens in the repro.
  • The real mechanism (which your regression test pins down): the sole selected participant resolves to the current user themselves (accountID === currentUserAccountID) without the isSelfDM flag set. The confirmation step only converts iouType → TRACK when participant.isSelfDM === true, so iouType stays non‑TRACK, and the submit decision — which keys solely on isTrackExpense (iouType === TRACK) — falls through to requestMoney with yourself as the recipient. Fixing participant resolution upstream can't catch this because the participant is already "self."

Your fix encodes the correct invariant directly at the submission boundary: an expense whose only recipient is the current user can never be a money request, so it must be a track expense. Catching it in useExpenseSubmission.ts (isSelfDMDestination) is robust regardless of how the participant got there, and the !isPolicyExpenseChat / !isSender / non‑SPLIT/INVOICE/PAY guards correctly avoid hijacking legitimate submit‑to‑workspace and invoice flows. 👍

A few things worth tightening before it goes up for review:

  1. Add negative-path test coverage for the guards. The one new test covers the happy path. Please also assert that a policy‑expense‑chat sole participant (owned by the current user) still routes through requestMoney, so a future refactor can't silently widen isSelfDMDestination and break submit‑to‑own‑workspace.

  2. Verify the distance self‑DM path. You now skip createDistanceRequest for isSelfDMDestination (:794) and route it through trackExpenseIOUActions instead. That's the right outcome (a self distance expense should be tracked), but it's a newly exercised branch — please manually confirm a manual distance expense created from the FAB to the self DM works end‑to‑end, and ideally add a unit case for it.

  3. Confirm equivalence for the existing (beta‑off) self‑DM track flow. Forcing trackReport = undefined also applies when isTrackExpense was already true and report was already the self‑DM. It should be a no‑op since getTrackExpenseInformation defaults to the self‑DM via optimisticChatReportID, but worth a quick check that the optimistic chat report ID resolves identically in that case.

Net: I agree with this direction over my earlier useDefaultParticipants proposal. Once the above are covered (and the new unit test passes in CI), this looks good to me.

@thelullabyy
thelullabyy marked this pull request as ready for review June 24, 2026 03:16
@thelullabyy
thelullabyy requested review from a team as code owners June 24, 2026 03:16
@melvin-bot
melvin-bot Bot requested review from flaviadefaria and situchan June 24, 2026 03:16
@melvin-bot

melvin-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

@situchan 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]

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03a31d01ac

ℹ️ 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".

Comment thread src/pages/iou/request/step/confirmation/useExpenseSubmission.ts Outdated
@situchan

situchan commented Jun 25, 2026

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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • 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 and each prop has a /** comment above it */
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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.mov
Android: mWeb Chrome
iOS: HybridApp
ios.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

Comment on lines +242 to +248
iouType !== CONST.IOU.TYPE.SPLIT &&
iouType !== CONST.IOU.TYPE.INVOICE &&
iouType !== CONST.IOU.TYPE.PAY &&
!!soleSelectedParticipant &&
!soleSelectedParticipant.isSender &&
!soleSelectedParticipant.isPolicyExpenseChat &&
(soleSelectedParticipant.isSelfDM === true || (!!currentUserPersonalDetails.accountID && soleSelectedParticipant.accountID === currentUserPersonalDetails.accountID));

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.

Do we need all of these conditions?

Some existing self-DM detection logic:

const firstParticipant = val.at(0);
if (firstParticipant?.isSelfDM && !isSplitRequest) {
trackExpense();
return;
}

const firstParticipant = val.at(0);
if (firstParticipant?.isSelfDM && !isSplitRequest) {
trackExpense();
return;
}

Both rely on the single participant.isSelfDM flag.
And I assume parallel accountID === currentUserPersonalDetails.accountID fallback is needed in case where the new manual flow leaves isSelfDM unset and doesn't run the iouTypeTRACK conversion — so the expense reaches useExpenseSubmission still as CREATE.

Anyway, your conditions are safe. Can we move to IOUUtils?

Something like this:

/**
 * A participant points at the current user's self-DM when it carries the self-DM flag,
 * or — for flows that seed the raw account before the flag is set — when it's the sole
 * recipient and resolves to the current user. Excludes workspace/invoice participants.
 */
function isSelfDMParticipant(participant: Participant | undefined, currentUserAccountID: number | undefined): boolean {
    if (!participant || participant.isSender || participant.isPolicyExpenseChat) {
        return false;
    }
    return participant.isSelfDM === true || (!!currentUserAccountID && participant.accountID === currentUserAccountID);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@situchan Yes, I updated

@melvin-bot
melvin-bot Bot requested a review from puneetlath June 29, 2026 20:45
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d65eb3d2b8

ℹ️ 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".

puneetlath
puneetlath previously approved these changes Jul 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6e21f5b67

ℹ️ 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".

Comment thread src/pages/iou/request/step/confirmation/useExpenseSubmission.ts Outdated
@thelullabyy

Copy link
Copy Markdown
Contributor Author

@situchan Please help review again

@MelvinBot

Copy link
Copy Markdown
Contributor

Regression review

I traced the three highest‑risk areas of this diff (the self‑DM heuristic, the distance‑request early‑return, and the destinationReportID refactor). No regression to existing non‑self‑DM flows — but two things are worth a look before merge.

1. ⚠️ backToReport is now ignored for self‑DM destinations (behavior change)

In IOURequestStepConfirmation.tsx:519:

const destinationReportID = (isSelfDMDestination ? selfDMReportID : (backToReport ?? routeDestinationReportID)) ?? selfDMReportID;

When isSelfDMDestination is true, selfDMReportID is selected first and backToReport is never consulted. Previously backToReport was the highest‑priority operand (backToReport ?? … ?? selfDMReportID), so it won. Because isSelfDMSoleDestination also returns true for a normal TRACK with a sole self‑DM participant, this changes any TRACK/self‑DM flow that was launched with a backToReport — it now navigates to the self‑DM report instead of back to the originating report.

Please verify there's no entry point (e.g. tracking an expense from within a report and expecting to return to it) that passes backToReport for a self‑DM/TRACK submit. If one exists, this is a navigation regression.

2. accountID === currentUserAccountID fallback is safe today but fragile

isSelfDMParticipant in IOUUtils.ts treats a sole selected participant whose accountID matches the current user as a self‑DM destination even when the isSelfDM flag is absent. I could not construct a real SUBMIT/REQUEST/CREATE flow that misfires — P2P participant builders explicitly filter out the current user, and self‑DM participants are seeded as {accountID: 0, isSelfDM: true}. So it's safe as written.

The safety is an emergent property of how transaction.participants happens to be built, not an intrinsic guarantee. Consider tightening the fallback to also require a self‑DM signal (a reportID resolving to the self‑DM, or requiring the isSelfDM flag) so a future participant‑construction path can't accidentally route a real request through trackExpense. Hardening suggestion, not a bug.

✅ Cleared

  • Distance requests to self‑DM correctly fall through to trackExpense() (useExpenseSubmission.ts:973), which fully forwards distance, validWaypoints, customUnitRateID, distanceRequestType, odometer and GPS data. This is identical to how iouType === TRACK distance already behaved (the !isTrackExpense guard already skipped createDistanceRequest), so it's just unifying CREATE‑self‑DM with TRACK‑self‑DM.
  • destinationReportID refactor is algebraically equivalent for all isSelfDMDestination === false flows. (backToReport ?? routeDestinationReportID) ?? selfDMReportID equals the old backToReport ?? (perDiem ternary) ?? selfDMReportID via ?? left‑associativity, and selfDMReportID reduces to the old iouType === TRACK condition.
  • canPreInsertSearch / canUseReportPreInsert changes are inert when isSelfDMDestination is false (added as && !isSelfDMDestination and || isSelfDMDestination), so PAY/SPLIT/INVOICE/per‑diem/normal‑request navigation is unchanged.
Verification notes
  • P2P participants exclude the current user: getMoneyRequestParticipantsFromReport filters accountID !== currentUserAccountID (src/libs/actions/IOU/MoneyRequest.ts). Self‑DM participants use {accountID: 0, isSelfDM: true}. The attendee selector's includeCurrentUser: true writes comment.attendees, not transaction.participants, so it never reaches this gate.
  • isSelfDMSoleDestination early‑returns only for SPLIT/INVOICE/PAY; REQUEST/SUBMIT/TRACK/CREATE all reach the participant check, which is intentional.
  • trackExpenseIOUActions (src/libs/actions/IOU/TrackExpense.ts) builds the distance‑rate custom unit and map receipt from waypoints, confirming a real distance track expense (not a degraded one).

Next Steps: Reply with @MelvinBot <feedback> to dig deeper into any of these.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 148ac6fdcc

ℹ️ 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".

// Telemetry spans (SPAN_SUBMIT_EXPENSE, SPAN_SUBMIT_TO_DESTINATION_VISIBLE)
// are started by SubmitExpenseOrchestrator before calling createTransaction.
if (!isTrackExpense && isDistanceRequest && !isMovingTransactionFromTrackExpense && !isUnreported) {
if (!isTrackExpense && !isSelfDMDestination && isDistanceRequest && !isMovingTransactionFromTrackExpense && !isUnreported) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reset the draft report before tracking self-DM distance

When a self-DM distance expense reaches this path, it now skips createDistanceRequest and falls through to trackExpense, but the draft transaction can still carry the generated P2P/source reportID from participant selection. trackExpense preserves distance draft fields by merging the existing transaction over the optimistic one, so that stale reportID overrides the self-DM/UNREPORTED report and the optimistic expense is still attached to the wrong report. This affects distance expenses whose sole recipient is the current user in the new manual flow; clear or override the draft reportID before calling trackExpense.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the same path the pre-existing iouType === TRACK distance flow already uses, so no fix is needed.

}

if (!isPerDiemRequest && (isTrackExpense || isCategorizingTrackExpense || isSharingTrackExpense)) {
if (!isPerDiemRequest && (isTrackExpense || isCategorizingTrackExpense || isSharingTrackExpense || isSelfDMDestination)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve taxes for self-DM expenses routed as tracks

This branch routes self-DM CREATE/SUBMIT expenses through trackExpense, but the earlier tax calculation still treats only iouType === TRACK as a tracked expense. In the raw-current-user case this change is meant to handle, transaction.reportID may not be UNREPORTED and isPolicyExpenseChat is false, so isTaxTrackingEnabled(...) returns false and the taxCode/taxValue passed to trackExpense are blank even when the user selected tax on a tax-enabled workspace. Include isSelfDMDestination in the track-like tax calculation before submitting.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@situchan

situchan commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Please check ^

@thelullabyy

Copy link
Copy Markdown
Contributor Author

@situchan All good now

@melvin-bot
melvin-bot Bot requested a review from puneetlath July 10, 2026 12:26
@trjExpensify

Copy link
Copy Markdown
Contributor

@thelullabyy you have a conflict. :)

puneetlath
puneetlath previously approved these changes Jul 13, 2026
@puneetlath

Copy link
Copy Markdown
Contributor

@thelullabyy feel free to ping me on slack once you've fixed conflicts so that I can merge.

@puneetlath
puneetlath merged commit af11be2 into Expensify:main Jul 13, 2026
35 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 puneetlath has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/puneetlath in version: 9.4.34-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed the changes in this PR against Expensify's help site files under docs/articles. No help site updates are required.

Why: This PR is an internal bug fix, not a behavior or feature change. It corrects routing in the new manual expense flow so that an expense whose sole recipient is the current user is created in the self-DM as a tracked expense (via trackExpense) instead of being sent to the wrong report with an error. In other words, it restores the already-expected behavior described in the linked issue ("Expense will be created in self DM without issue").

The changes are confined to internal logic — IOUUtils.ts, IOURequestStepConfirmation.tsx, SubmitExpenseOrchestrator.tsx, and useExpenseSubmission.ts — with no changes to feature names, tab names, settings labels, buttons, or any user-facing workflow. The help articles that cover this area (e.g. Track-Expenses.md, Create-an-Expense.md, and Track-Personal-Expenses.md) already describe the correct, post-fix behavior and need no edits.

Since no changes are needed, I did not create a draft PR.

@thelullabyy, if you believe this change does introduce user-facing behavior that the help site should document, let me know and I'll draft the corresponding docs PR.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.4.34-14 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 failure ❌

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.4.34-14 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

7 participants