Skip to content

[Payment due @TaduJR] Prevent over-limit approvers who already approve in the workflow - #105257

Merged
marcochavezf merged 5 commits into
mainfrom
alberto-overLimitApproverNotInWorkflow
Oct 30, 2026
Merged

marcochavezf merged 5 commits into
mainfrom
alberto-overLimitApproverNotInWorkflow

Conversation

@Gonals

@Gonals Gonals commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Usually, if an approver is in the approval workflow already, we don't show it as an option in other steps. This is not true for over-limit approvers. Let's make it true.

Fixed Issues

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

Tests

Setup: a Control workspace with Approvals turned on, members A, B, C, D and E, and the multipleApprovers beta enabled.

  1. Go to Workflows and tap Add approval workflow. In Expenses from, choose D. Choose A as the approver and tap Skip on the approval limit page.

  2. Add B as the second approver. On B's approval limit page, enter 50 in Report amount and tap Additional approver.

  3. Verify that A and B are not in the list and E is.

  4. Choose E and tap Next. Add C as the third approver, tap Skip on its approval limit page, then tap Add workflow.

  5. Verify that the workflow is saved and B shows "Reports above $50.00 forward to E".

  • Verify that no errors appear in the JS console

Offline tests

Same

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 verified any copy / text that was added to the app 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 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

@Gonals Gonals self-assigned this Oct 28, 2026
@OSBotify

This comment has been minimized.

@Gonals
Gonals marked this pull request as ready for review October 28, 2026 15:24
@Gonals
Gonals requested review from a team as code owners October 28, 2026 15:24
@melvin-bot
melvin-bot Bot requested review from TaduJR and removed request for a team October 28, 2026 15:24
@melvin-bot

melvin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

@TaduJR 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 commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T15:29:37.074473Z 6dfe12f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@melvin-bot
melvin-bot Bot requested review from joekaufmanexpensify and removed request for a team October 28, 2026 15:24
Comment thread src/libs/actions/Workflow.ts Resolved
@TaduJR

TaduJR commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Do you need review here @Gonals

@Gonals

Gonals commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Do you need review here @Gonals

Yes, please

@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

@TaduJR

TaduJR commented Oct 29, 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 any copy / text that was added to the app 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 other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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 Screenshot 2026-10-30 at 11 49 58 AM
Android: mWeb Chrome Screenshot 2026-10-30 at 11 47 00 AM
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari Screenshot 2026-10-30 at 11 33 30 AM

TaduJR

This comment was marked as resolved.

@Gonals

Gonals commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@TaduJR, while it is ok to get AI-help during reviews, we already have AI reviewers. The idea is to have a human reviewer beyond it. After all, the human is responsible for the review.

I can't imagine you can confirm whether those translations are more or less accurate than the previous ones :/

@TaduJR

TaduJR commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@TaduJR, while it is ok to get AI-help during reviews, we already have AI reviewers. The idea is to have a human reviewer beyond it. After all, the human is responsible for the review.
I can't imagine you can confirm whether those translations are more or less accurate than the previous ones :/

@Gonals

Yes We do have Melvin, and ofc the transition are checked via ChatGPT. You know we do use to verify using GPT and there were even a checkbox that you should verify translations that why I used AI for the translation

But beyond the translation the code comments are real bugs and nits I caught during review and even reproduced the parent body comments.

@Gonals

Gonals commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Gonals

The beta-gated filter and save block work, and nothing changes without the beta. Two gaps, one question, and some small fixes below.

1. The approver picker still offers another step's additional approver Add approver B, set a limit, pick E as additional approver, then add E as the next approver. E is offered, and Save fails on B's row. The other picker needs the matching filter. The step's own additional approver stays pickable, because replacing that approver clears its limit.

WorkspaceWorkflowsApprovalsApproverPage.tsx

-import {isApprovalWorkflowLockedByIntegration} from '@libs/WorkflowUtils';
+import {getOverLimitApproverEmails, isApprovalWorkflowLockedByIntegration} from '@libs/WorkflowUtils';
@@
         const membersEmail = approvalWorkflow?.members?.map((member) => member.email);
+        // This step's own over-limit approver is left out, since picking a new approver here clears this step's limit
+        const otherStepsOverLimitApproverEmails = getOverLimitApproverEmails(approversFromWorkflow ?? [], approverIndex);
@@
                 if (isEmailAlreadyInApprovers && visibleSelectedApproverEmail !== email) {
                     return null;
                 }
+                if (isMultipleApproversBetaEnabled && otherStepsOverLimitApproverEmails.has(email) && visibleSelectedApproverEmail !== email) {
+                    return null;
+                }

2. Workflows already saved this way can't be saved, and nothing says why until Save The old picker allowed this setup, and buildApprovalWorkflowRules has an isWorkflowApprover branch for it, so beta workspaces may already have saved workflows like this. Today the editor shows the error only after Save, and the Approval Limit page doesn't show it at all. I'd move the rule into WorkflowUtils next to getNonMemberApproverError, so the validator, editor, pickers and limit page share it and the editor flags it when it opens.

WorkflowUtils.ts

+function getOverLimitApproverNonMemberError(approver: Approver | undefined): TranslationPaths | undefined {
+    return approver?.isOverLimitForwardsToNotWorkspaceMember ? 'workflowsPage.overLimitApproverNotWorkspaceMember' : undefined;
+}
+
 function getNonMemberApproverError(approver: Approver | undefined, isDefaultWorkflow: boolean | undefined): TranslationPaths | undefined {
     if (approver?.isNotWorkspaceMember) {
         return isDefaultWorkflow ? 'workflowsPage.defaultWorkflowApproverNotWorkspaceMember' : 'workflowsPage.approverNotWorkspaceMember';
     }
-    if (approver?.isOverLimitForwardsToNotWorkspaceMember) {
-        return 'workflowsPage.overLimitApproverNotWorkspaceMember';
-    }
-    return undefined;
+    return getOverLimitApproverNonMemberError(approver);
 }
+
+function getWorkflowApproverEmails(approvers: Array<Approver | undefined>): Set<string> {
+    return new Set(approvers.map((approver) => approver?.email).filter((email): email is string => !!email));
+}
+
+/** The emails that reports over a limit go to, from every step except `exceptApproverIndex`. */
+function getOverLimitApproverEmails(approvers: Array<Approver | undefined>, exceptApproverIndex?: number): Set<string> {
+    return new Set(approvers.flatMap((approver, approverIndex) => (approverIndex !== exceptApproverIndex && approver?.overLimitForwardsTo ? [approver.overLimitForwardsTo] : [])));
+}
+
+/**
+ * Whether reports over the approver's limit go to someone who already approves in the workflow. The rules forward them
+ * straight there: the next approver means the limit adds no one, a later one skips the approvers in between, and an
+ * earlier one loops back.
+ */
+function isOverLimitApproverInWorkflow(approver: Approver | undefined, approvers: Array<Approver | undefined>): boolean {
+    return !!approver?.overLimitForwardsTo && getWorkflowApproverEmails(approvers).has(approver.overLimitForwardsTo);
+}
+
+function getOverLimitApproverError({approver, approvers, isMultipleApproversBetaEnabled}: GetOverLimitApproverErrorParams): TranslationPaths | undefined {
+    // A repeated approver's row only shows the circular workflow error, since replacing them to fix it clears their limit
+    if (approver?.isCircularReference) {
+        return undefined;
+    }
+    const nonMemberError = getOverLimitApproverNonMemberError(approver);
+    if (nonMemberError) {
+        return nonMemberError;
+    }
+    if (isMultipleApproversBetaEnabled && isOverLimitApproverInWorkflow(approver, approvers)) {
+        return 'workflowsPage.overLimitApproverInWorkflow';
+    }
+    return undefined;
+}
+
+function getApproverRouteError({isDefaultWorkflow, ...overLimitParams}: GetApproverRouteErrorParams): TranslationPaths | undefined {
+    const {approver} = overLimitParams;
+    if (approver?.isNotWorkspaceMember && !approver.isCircularReference) {
+        return getNonMemberApproverError(approver, isDefaultWorkflow);
+    }
+    return getOverLimitApproverError(overLimitParams);
+}

ApprovalWorkflowEditor.tsx: flag it on open

-        // Flag a route to a non-member as soon as the editor opens, rather than only after a Save attempt
-        const nonMemberApproverError = getNonMemberApproverError(approver, approvalWorkflow.isDefault);
-        if (!error && nonMemberApproverError) {
-            return translate(nonMemberApproverError);
+        // Flag a route validateApprovalWorkflow blocks as soon as the editor opens, rather than only after a Save attempt
+        const approverRouteError = getApproverRouteError({approver, approvers: approvalWorkflow.approvers, isDefaultWorkflow: approvalWorkflow.isDefault, isMultipleApproversBetaEnabled});
+        if (!error && approverRouteError) {
+            return translate(approverRouteError);
         }

WorkspaceWorkflowsApprovalsApprovalLimitPage.tsx: show it where it's fixed

+    const {isBetaEnabled} = usePermissions();
+    const isMultipleApproversBetaEnabled = isBetaEnabled(CONST.BETAS.MULTIPLE_APPROVERS);
@@
-    const approverErrorText = hasSubmitted && onlyApproverEmpty ? translate('workflowsApprovalLimitPage.enterApproverError') : undefined;
+    // Only with the beta does this page show the over-limit errors the editor flags and block Save on them
+    const overLimitApproverError = isMultipleApproversBetaEnabled
+        ? getOverLimitApproverError({approver: currentApprover, approvers: approvalWorkflow?.approvers ?? [], isMultipleApproversBetaEnabled: true})
+        : undefined;
+    let approverErrorText: string | undefined;
+    if (hasSubmitted && onlyApproverEmpty) {
+        approverErrorText = translate('workflowsApprovalLimitPage.enterApproverError');
+    } else if (overLimitApproverError) {
+        approverErrorText = translate(overLimitApproverError);
+    }
@@ handleSubmit
+        // The editor can't save the workflow with it, so the admin picks someone else or removes the limit here
+        if (overLimitApproverError) {
+            return;
+        }

Question: only the earlier-approver case is broken, because it loops. The next-approver case is harmless, and the later-approver case (A > B > C, with A's limit → C) might be an intentional escalation. Should those two stay allowed? If they stay blocked, the Workflows card and red dot should flag them too. Both only use getNonMemberApproverError today, so existing workflows look fine until Save fails.

I have all of the above implemented with tests. Here is the patch if that's easier than applying the suggestions one by one https://github.com/Expensify/App/compare/main...TaduJR:App:fix-overLimitApproverNotInWorkflow?expand=1

1 addressed.

2 is fine, not a problem (no workflows currently set with that case

The overall block is on purpose after discussing it with the team and figuring out what our customers have

@Gonals

Gonals commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Resolved most of the comments, since I'm only addressing point 1.

@Gonals
Gonals requested a review from TaduJR October 29, 2026 15:45
@TaduJR

TaduJR commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

I found no blocking issues. The save check and both picker filters agree. The beta gate leaves legacy workflows unchanged. CI is green except the independent-approval check.

I have two non-blocking notes:

  1. Auto-filled approver chains can still trip the new check. When the picked approver has a forwardsTo chain in employeeList, setApprovalWorkflowApprover fills the later steps from that chain (Workflow.ts:606-621). It also copies each employee's saved overLimitForwardsTo (WorkflowUtils.ts:131-139). Neither picker filter runs on those steps. For example, take a legacy setup of B → C → D, where B's reports over the limit skip to D. Picking B fills B → C → D, and Save then fails on B's row with overLimitApproverInWorkflow. The admin can fix it with Remove limit, so the only cost is a confusing error. I didn't reproduce this in the app.

  2. No test covers the beta gate. Every new validateApprovalWorkflow test passes true. A case with false would confirm that legacy workflows still save. This matches TaduJR's suggestion on tests/actions/WorkflowTest.ts.


view run

@TaduJR

TaduJR commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Thanks @Gonals, great work.

2 is fine, not a problem (no workflows currently set with that case

I reproduced point 2 with a real workflow: one saved with the current app, where B's additional approver C is also an approver, can't be saved with this PR, not even for a members-only edit. The error only shows after Save, and beta admins can still create these workflows until this ships.

Since this is intended, maybe you could add a QA step for this case? Sorry about the JaimeGPT translation suggestions, I'll leave those to the Polyglot Parrot in the future. The code side looks good to me.

@Gonals

Gonals commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

I reproduced point 2 with a real workflow: one saved with the current app, where B's additional approver C is also an approver, can't be saved with this PR, not even for a members-only edit. The error only shows after Save, and beta admins can still create these workflows until this ships.

What I mean is that there are no real users with this setup. It is not a common setup and we released the beta yesterday, so this is not a real problem

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

LGTM!

@melvin-bot
melvin-bot Bot requested a review from marcochavezf October 30, 2026 12:40
@melvin-bot

melvin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

@marcochavezf 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 changed the title Prevent over-limit approvers who already approve in the workflow [Payment due @TaduJR] Prevent over-limit approvers who already approve in the workflow Oct 30, 2026
@melvin-bot

melvin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

🎯 @TaduJR, 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/696896.

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.

@marcochavezf
marcochavezf merged commit a32d706 into main Oct 30, 2026
51 of 53 checks passed
@marcochavezf
marcochavezf deleted the alberto-overLimitApproverNotInWorkflow branch October 30, 2026 14:58
@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

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

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/marcochavezf in version: 9.5.27-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. Every behavior change here applies only when the MULTIPLE_APPROVERS beta is enabled: hiding existing approvers from the additional approver list, hiding another step's additional approver, and the new save error. Most users can't see these changes yet.


view run

@OSBotify

OSBotify commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/blimpich in version: 9.5.27-2 🚀

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

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #105663

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.

6 participants