Skip to content

[Due for payment 2026-10-22] [$175] Broken workflow disappears #99357

Closed

Description

@mallenexpensify

Coming from here

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number:
Reproducible in staging?:
Reproducible in production?:
If this was caught during regression testing, add the test name, ID and link from BrowserStack:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by:
Slack conversation (hyperlinked to channel name):

Action Performed:

Precondition: Employee 1 is approver

  1. Go offline
  2. Admin: remove Employee 1 from members list
  3. Approver is automatically switched to Admin (expected)
  4. Open Edit approval workflow > Approver
  5. Set approver to Employee 2 and Save
  6. While approver in default workflow is replaced with Employee 2, another broken workflow appears witth approver: admin, Expenses from: nothing (bug)
  7. Go online
  8. Broken workflow disappears
Image
repro.mov

Expected Result:

Describe what you think should've happened

Actual Result:

Describe what actually happened

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Select the officially supported platforms where the issue was reproduced:

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

Screenshots/Videos

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 24, 2026
  2. mallenexpensify commented on Aug 24, 2026

    @mallenexpensify
    ContributorAuthor

    @mkhutornyi if anything needs updating in the OP or title, please ping tag me here and ping me in Slack. Thx

  3. MelvinBot commented on Aug 24, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    A soft-deleted approver whose stale submitsTo still points at the Admin creates an empty "phantom" approval workflow that only exists offline.

    When Employee 1 (the approver) is removed offline, the app auto-reassigns the default workflow's approver to the Admin — which stamps Employee1.submitsTo = Admin — and then marks Employee 1 with pendingAction: DELETE (Policy/Member.ts MERGEs the DELETE flag while keeping the stale submitsTo). When you then edit the default workflow's approver to Employee 2, only live members get their submitsTo rewritten to Employee 2 — the deleted Employee 1 is left pointing at Admin.

    The Workflows list is built by convertPolicyEmployeesToApprovalWorkflows. It creates a workflow "bucket" for any employee whose submitsTo resolves to an approver — including the DELETE'd Employee 1 — at WorkflowUtils.ts:198. But members are only pushed into the bucket when pendingAction !== DELETE (WorkflowUtils.ts:246), so the bucket stays with members: []. Since the default approver is now Employee 2, this Admin bucket isn't flagged isDefault, and there's no filter dropping empty non-default workflows — so it renders as a second, broken row: Approver: Admin, Expenses from: (empty).

    Online it disappears because the backend removes the deleted employee's entry entirely, so nothing points at Admin and the bucket is never created.

    Why it vanishes online + data flow
    1. Offline remove Employee 1 → updateWorkflowDataOnApproverRemoval reassigns default approver to owner/Admin → Employee1.submitsTo = Admin, policy.approver = Admin.
    2. removeMembers MERGEs {pendingAction: DELETE} onto Employee 1, preserving submitsTo = Admin.
    3. Offline edit default approver Admin → Employee 2. Live members' submitsTo rewritten to Employee 2; policy.approver = Employee 2. Employee 1 (DELETE) still has submitsTo = Admin.
    4. Workflows recompute: Employee 1 creates approvalWorkflows[Admin] but its member is never pushed → members: [], isDefault: false → renders as an extra broken row.
    5. Online: backend success sets the deleted employee's state to null; no employee points at Admin → bucket never created → row disappears.

    This is a purely frontend (Expensify/App) optimistic-data bug — the backend returns correct data online.

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

    In convertPolicyEmployeesToApprovalWorkflows, skip pending-DELETE employees before they can create a workflow bucket. Right after the availableMembers handling (~line 189, the pendingAction is already destructured at line 175), continue when pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE.

    A deleted employee already contributes no member (guard at line 246) and no pendingAction (guard at line 252), so skipping it entirely only removes the phantom bucket and changes nothing else. A live member submitting to the same approver still creates the real bucket normally.

    What alternative solutions did you explore? (Optional)

    Filter out empty non-default workflows before returning at WorkflowUtils.ts:270-286: sortedApprovalWorkflows.filter((w) => w.isDefault || w.members.length > 0). This is a safety net but treats the symptom; the primary fix addresses the root cause and avoids risking the intentionally-empty default workflow.

    Confidence: High — root cause verified against current main code with a complete offline→online data flow; no production logs needed since the defect is deterministic in the offline conversion path.

    Possibly related issues


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/99357) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 24, 2026
  5. melvin-bot commented on Aug 24, 2026

    @melvin-bot

    Current assignee @mkhutornyi is eligible for the External assigner, not assigning anyone new.

  6. melvin-bot commented on Aug 24, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  7. Abdukhamid000 commented on Aug 25, 2026

    @Abdukhamid000
    Contributor

    Checked Melvin's analysis against main and it holds up. updateApprovalWorkflow does optimistically move policy.approver to Employee 2 (Workflow.ts:174), so the leftover Admin bucket really is a non-default workflow with members: [], and the deleted employee's submitsTo is never rewritten because the rewrite loop iterates approvalWorkflow.members (WorkflowUtils.ts:398), which excludes it. Two notes for whoever implements.

    Skipping the pending-DELETE employee is the better option, for a reason beyond "treats the symptom". The rejected alternative — filtering empty non-default workflows at the end — still lets the phantom bucket run WorkflowUtils.ts:227-231 and add Admin to usedApproverEmails, so Admin stays flagged as a used approver in the picker off a workflow that no longer renders. Skipping earlier fixes that too.

    One gap in the skip itself. If no live employee has a resolvable submitsTo, skipping every DELETE employee leaves approvalWorkflows empty — and the block that guarantees a default workflow only runs when the list is non-empty:

    // Add a default workflow if one doesn't exist (no employees submit to the default approver)
    const firstWorkflow = sortedApprovalWorkflows.at(0);
    if (firstWorkflow && !firstWorkflow.isDefault) {
    sortedApprovalWorkflows.unshift({
    members: [],
    approvers: calculateApprovers({employees, firstEmail: defaultApprover, personalDetailsByEmail}),
    isDefault: true,
    });
    }

    The page would then render no workflows at all rather than one phantom row. Test fixtures give every employee a submitsTo, so this is an edge case rather than the common path, but extending that guard to cover the empty list is a one-liner worth doing in the same change.

    For context, this is the same defect class as the backstop already sitting in Workflow.ts:121-143 — a stale submitsTo producing an orphan submission group — just for a pending-DELETE employee instead of a newly-promoted approver.

  8. melvin-bot commented on Aug 27, 2026

    @melvin-bot

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

  9. melvin-bot commented on Aug 31, 2026

    @melvin-bot

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

  10. mkhutornyi commented on Sep 1, 2026

    @mkhutornyi
    Contributor

    @MelvinBot draft PR for testing

  11. MelvinBot commented on Sep 1, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: #99988

    Please mark it as "Ready for review" when it is ready.

    What it changes: WorkflowUtils.ts now skips employees with pendingAction: DELETE at the top of the conversion loop, so a member removed offline — who keeps a stale submitsTo until the backend confirms — can no longer create a workflow they will never be a member of. It also stops that stale approver from landing in usedApproverEmails, which Abdukhamid000 flagged. The same fix is applied to convertApprovalWorkflowRulesToWorkflows, the MULTIPLE_APPROVERS beta counterpart, which had the identical defect. Two unit tests cover both paths.

    I did not take the second half of Abdukhamid000's suggestion — extending the "guarantee a default workflow" guard to cover an empty list. That guard's current behavior is pinned by two existing tests (Should return an empty list if there are no employees and Should not include users that submit to non-employee user), so making it unconditional would change behavior beyond this bug. After this fix, a workspace where no live employee has a resolvable submitsTo renders no workflows — the same as a workspace where nobody submits to anyone today.

    AI tests run locally on the branch: WorkflowUtilsTest (100 passed), WorkflowTest + ApprovalWorkflowSectionTest (21 passed), ESLint on the changed files, and npm run typecheck — all passed.

    Manual verification: blocked

    Step Status Observation
    Reach signed-in Home to start workspace setup ❌ Fail The web session signed in, but the app then rendered a blank page — 0 accessibility nodes, no text anywhere — and never progressed past load. The dev server returned HTTP 200 with a valid HTML shell and webpack reported a clean build, so this is an environment problem, not the change.
    Offline: remove the approver ⏭️ Not run Blocked by the above
    Offline: reassign the approver to a second member ⏭️ Not run Blocked by the above
    Offline: confirm no phantom workflow row ⏭️ Not run Blocked by the above
    Online: confirm the list is unchanged ⏭️ Not run Blocked by the above

    So the offline repro from the OP is not confirmed end to end — the unit tests are the only evidence so far. The PR body has the manual steps to run.

    Evidence (1)

    Blank white page after sign-in, 0 accessibility nodes

    Blank white page after sign-in, 0 accessibility nodes

    view run

  12. 26 remaining items

  13. mkhutornyi commented on Oct 16, 2026

    @mkhutornyi
    Contributor

    Contributor+ Checklist:

    • [Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to the comment on the PR:
      Link to the comment on the Issue:

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion:

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal

    Precondition:

    a workspace with an Admin, Employee 1 set as the default approver, and Employee 2

    Test:

    1. Go offline.
    2. As the Admin, remove Employee 1 from the members list.
    3. Verify the approver is automatically switched to the Admin.
    4. Open Workflows > Edit approval workflow > Approver.
    5. Set the approver to Employee 2 and save.
    6. Verify the default workflow now shows Employee 2 as the approver, and that no extra workflow row appears with "Approver: Admin" and an empty "Expenses from".

    Do we agree 👍 or 👎

  14. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Oct 16, 2026
  15. melvin-bot commented on Oct 21, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  16. melvin-bot commented on Oct 21, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  17. mallenexpensify commented on Oct 26, 2026

    @mallenexpensify
    ContributorAuthor

    Payment Summary

    Contributor+: @mkhutornyi due $250 via NewDot

  18. trjExpensify commented on Nov 6, 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 PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions