Skip to content

[Payment due @situchan] Do not treat submitted expense reports on Dynamic External Workflow policies as awaiting first-level approval - #98704

Merged
mountiny merged 4 commits into
Expensify:mainfrom
c3024:chaitanya/671728-dew-submitted-report-reuse
Aug 20, 2026
Merged

mountiny merged 4 commits into
Expensify:mainfrom
c3024:chaitanya/671728-dew-submitted-report-reuse

Conversation

@c3024

@c3024 c3024 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

The backend never treats submitted expense reports on Dynamic External Workflow policies as awaiting first-level approval, so it rejects adding expenses to them with a 401. The App gate had no such check, so it reused the submitted report and the request failed. This adds the same exclusion to isAwaitingFirstLevelApproval so the App creates a new report instead. Via isForwardedReport, the exclusion also removes submitted DEW reports from report pickers and the share flow.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/671728
PROPOSAL:

Tests

Requires a workspace with delayed submissions enabled, the Dynamic External Workflow approval mode and routed to user in DEW to be same as the workspace approver.

  1. As an employee on the workspace, create an expense and submit the report.
  2. Click on Create Workspace from the composer in the same workspace chat.
  3. Enter an amount > Next.
  4. Verify that clicking on the report field shows only draft reports and does not include the submitted report from step 1.
  5. Submit the report.
  6. Verify that the report is submitted successfully.
Screen.Recording.2026-08-17.at.3.41.21.PM.mov

On main/staging/prod branch:

  1. Repeat steps 1 to 3 above.
  2. Verify that clicking on the report field shows not only draft reports but also the submitted report from step 1.
  3. Select the submitted report and create the expense.
  4. Backend throws an error and the creation of expense fails.
createmoneyrequestonmain.mov
  • Verify that no errors appear in the JS console

Offline tests

Requires a workspace with delayed submissions enabled, the Dynamic External Workflow approval mode and routed to user in DEW to be same as the workspace approver.

  1. As an employee on the workspace, create an expense and submit the report.
  2. Go offline.
  3. Click on Create Workspace from the composer in the same workspace chat.
  4. Enter an amount > Next.
  5. Verify that clicking on the report field shows only draft reports and does not include the submitted report from step 1.
  6. Submit the report.
  7. Go online.
  8. Verify that the report is submitted successfully.

QA Steps

Same as Tests.

  • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@c3024
c3024 marked this pull request as ready for review August 17, 2026 10:29
@c3024
c3024 requested review from a team as code owners August 17, 2026 10:29
@melvin-bot
melvin-bot Bot requested review from situchan and removed request for a team August 17, 2026 10:29
@melvin-bot

melvin-bot Bot commented Aug 17, 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]

@melvin-bot
melvin-bot Bot requested review from joekaufmanexpensify and removed request for a team August 17, 2026 10:29

@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: f7b5005ace

ℹ️ 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/libs/ReportUtils.ts Resolved
@situchan

situchan commented Aug 17, 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: mWeb Chrome
iOS: HybridApp
ios.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
before.mov
after.mov

@joekaufmanexpensify joekaufmanexpensify left a comment

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.

Good for product

@situchan situchan left a comment

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.

Looks good

@melvin-bot melvin-bot Bot changed the title Do not treat submitted expense reports on Dynamic External Workflow policies as awaiting first-level approval [Payment due @situchan] Do not treat submitted expense reports on Dynamic External Workflow policies as awaiting first-level approval Aug 19, 2026
@melvin-bot

melvin-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🎯 @situchan, thanks for reviewing and testing this PR! 🎉

A payment issue will be created for your review once this PR is deployed to production.
E/E issue linked to the PR - https://www.github.com/Expensify/Expensify/issues/671728.

If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created.

@situchan

Copy link
Copy Markdown
Contributor

Please confirm this is expected after submitting expense on DEW policy:

  1. Submitter loses delete / split / merge on their own submitted report
  2. Submitter can no longer rename their own submitted report
  3. Submitter can no longer hold their own expense

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: f7b5005ace

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

Review

The core change is small, correct, and well-scoped: for a DEW expense report the early return false in isAwaitingFirstLevelApproval only alters the submitted/processing case (open reports already returned false via isProcessingReport, and approved/closed/settled ones did too), so the fix lands exactly where the backend 401 was happening. The unit tests are solid.

But the main thing to flag is situchan's question — and the answer is yes, all three are real and directly caused by this diff. isAwaitingFirstLevelApproval is a shared gate, so flipping it to false for submitted DEW reports withdraws several submitter capabilities at once, not just report reuse:

Where each capability is gated by this predicate

For a non-admin/non-manager submitter on their own submitted DEW report, isAwaitingFirstLevelApproval → false now flips each of these:

So the three behaviors situchan listed (loses delete/split/merge, can't rename, can't hold) are not incidental — they're this predicate change propagating through every gate above. That's fine if submitted DEW reports are meant to be treated exactly like a forwarded report from the submitter's side (i.e. the backend also rejects those mutations, the same way it rejects adding an expense with a 401). It's a regression if any of them should still be allowed.

Recommendation: Get an explicit product/backend confirmation that a submitter should lose delete/split/merge/rename/hold on a submitted DEW report. If yes, this approach is correct — consider adding a short unit test asserting one of the non-add gates (e.g. canDeleteMoneyRequestReport or canModifyHoldStatus) is false for a submitted DEW report, so the intended broad effect is locked in and can't silently regress. If only the report-reuse/picker behavior should change, the fix should be scoped to canAddTransaction/isReportOutstanding rather than the shared isAwaitingFirstLevelApproval predicate.

Nits:

  • The added tests exercise the change indirectly through canAddTransaction; a direct test of isAwaitingFirstLevelApproval(DEW submitted report) === false would document intent more clearly.

I did not test the flow in-app — reproducing it needs a workspace configured with delayed submissions + Dynamic External Workflow + the routed user matching the approver, which the author's attached videos already demonstrate; the logic above is verified against the code.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor

Regression scan

Good news: the change is tightly scoped to exactly the buggy population, and touches nothing else. The early return false in isAwaitingFirstLevelApproval only actually changes a value for submitted (processing) DEW expense reports where the report's routed managerID equals the locally-configured submitsToAccountID — i.e. the "routed-to-self" case that is the bug. Verified safe elsewhere:

  • Non-DEW reports — no change (the early return is gated on isExpenseReport && hasDynamicExternalWorkflow).
  • Open / approved / closed / settled DEW reports — no change (isProcessingReport was already false, so the predicate was already false).
  • General DEW case (routed approver ≠ configured submitsTo) — no change: the predicate was already false because submitsToAccountID !== managerID, since getSubmitToAccountID returns the configured approver while the DEW managerID is set by the backend. So no new population is harmed — the reports that lose capabilities are the same reports that were broken.

The regressions to confirm — within that narrow population, the submitter loses these (all flow from the same shared predicate flipping to "forwarded"):

Capability Gate
Add / delete transaction canAddOrDeleteTransactions:2957
Delete report canDeleteMoneyRequestReport:3280
Merge isMoneyRequestReportEligibleForMerge:3036
Split isSplitAction:189
Rename (title + report fields) isReportFieldDisabled:4794
Hold / unhold canModifyHoldStatus:5483
Move expense to another report canEditFieldOfMoneyRequest:5370 (via isReportOutstanding)

The first six are the ones situchan already flagged. The 7th — "move expense to another report" — is an additional side effect that hasn't been called out yet; worth including in the confirmation.

Are these true regressions or correct alignment? That depends solely on whether the backend also blocks the submitter from delete/merge/split/rename/hold/move on a submitted DEW report (the same way it rejects add with a 401). I could not verify server behavior here. Two reasons to believe the direction is intended, though:

  • The App already blocks all of these for the submitter on ordinary forwarded reports (isForwardedReport = isProcessingReport && !isAwaitingFirstLevelApproval, :12166); this PR just makes submitted DEW reports satisfy that same condition.
  • canEditMoneyRequest already has an independent DEW lock — :5081 returns false for non-open DEW reports — so "a submitted DEW report is locked for the submitter" is already an established pattern in the codebase.

Recommendation: No unintended blast radius found — the change is correctly confined to the buggy reports. Before merging, get a one-line product/backend confirmation that the submitter should lose delete/merge/split/rename/hold/move on a submitted DEW report (i.e. the backend rejects those too). If yes, this is correct alignment; add a unit test on one non-add gate (e.g. canModifyHoldStatus or canDeleteMoneyRequestReport) returning false for a submitted DEW report to lock the intent in. If any of them should remain allowed, the fix needs to be scoped to canAddTransaction/isReportOutstanding rather than the shared predicate.

Verification notes

Analysis is against the checked-out branch (f7b5005). I did not run the flow in-app — it requires a workspace with delayed submissions + Dynamic External Workflow routed to the same user as the workspace approver, which the author's attached videos already demonstrate. The backend permission model for DEW submitted reports (delete/hold/rename/split/merge/move) could not be verified from the public repo and needs internal confirmation.


view run

@mountiny
mountiny self-requested a review August 19, 2026 19:43
@c3024

c3024 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Please confirm this is expected after submitting expense on DEW policy:
Submitter loses delete / split / merge on their own submitted report
Submitter can no longer rename their own submitted report
Submitter can no longer hold their own expense

Submitter loses split / merge on their own submitted report - backend rejects these.

Submitter can no longer rename their own submitted report
Submitter loses delete their own submitted report- while backend technically allows these with checking read access only and without verify write check, this is same as an ordinary forwarded report on advanced approval today. Once a report moves past first-level approval, the frontend already hides delete and rename for the submitter even though those two endpoints on the backend would accept the calls.

Submitter can no longer hold their own expense - backend rejects this.

So, I think these are all expected.

@mountiny mountiny left a comment

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.

Ok thanks that looks good to me

@mountiny
mountiny merged commit 8190b49 into Expensify:main Aug 20, 2026
44 of 50 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@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.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.58-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 No help site changes required.

This PR is an internal correctness fix, not a change to any documented user-facing behavior. It updates isAwaitingFirstLevelApproval so that submitted expense reports on Dynamic External Workflow policies are no longer treated as awaiting first-level approval — matching what the backend already enforces. The effect is that the App stops reusing a submitted report (which the backend rejected with a 401) and correctly creates a new one, and those reports are filtered out of report pickers and the share flow.

Why no docs update is needed
  • The change is a bug fix that aligns App behavior with existing backend behavior — no new feature, setting, tab, button, or workflow is introduced.
  • "Dynamic External Workflow" is an internal approval mode name, not a user-facing label documented on the help site.
  • The help site's approval-workflow articles (e.g. Workspace-Workflows.md, the Classic approval articles) describe how to set up approval workflows for users; none document the internal report-reuse gating logic this PR corrects, so there is nothing to update.
  • The corrected behavior (a new report is created instead of an error) is the already-expected outcome, so no existing article becomes inaccurate.

Because no changes are required, no draft help site PR was created, and there is nothing to review on the docs side.


view run

@IuliiaHerets

Copy link
Copy Markdown

Hi @c3024. How can we follow this precondition?

image

cc @mountiny @joekaufmanexpensify @situchan

@c3024

c3024 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@IuliiaHerets

Hey, does QA have access to any DEW (Dynamic External Workflow) approval mode workspaces?

@IuliiaHerets

Copy link
Copy Markdown

@c3024 I don't think so

@IuliiaHerets

Copy link
Copy Markdown

@c3024 Would you be able to check this PR internally on your side?

@c3024

c3024 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@situchan and I tested this and verified the result. Maybe we can check this off the deploy checklist if QA doesn’t have access to DEW workspaces.

cc: @mountiny

@mountiny

Copy link
Copy Markdown
Contributor

Checked it off, thanks

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 9.4.58-4 🚀

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

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #99231

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