Skip to content

Agents-Additional greyed‑out workflow appears after changing deleted agent in offline #93260

Closed

Description

@applause-bot

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


Version Number: v9.4.5-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #92286
Email or phone of affected tester (no customers): applausetester+ag090626@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Windows 11/ Chrome, Samsung S23FE/ Android 16, iPhone 13 Mini/ iOS 26.3
App Component: Workspace Settings

Action Performed:

  1. Launch the Expensify app
  2. Go to "Account" > "Agents"
  3. Create a new agent.
  4. Go to "Workspaces" > "Members"
  5. Add the Agent to the workpace
  6. Go to "Workspaces" > "Workflows"
  7. Tap on "Add Agent" > "Save"
  8. Go offline
  9. Return to "Account" > Agents" and delete the agent
  10. Return to "Workspaces" > "Workflows"
  11. Tap on approver to open "Edit Approval" RHP
  12. Click on "Approver" field > "Approver" field
  13. Select a member
  14. Tap Save > Save

Expected Result:

No extra workflow appears.

Actual Result:

A greyed‑out workflow appears with the deleted agent.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7177572_1781152375783.Additional_greyed_out_workflow.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Mita Rachim
Bug ID: 7177572

Issue OwnerCurrent Issue Owner: @mkhutornyi

Activity

  1. applause-bot commented on Jun 11, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/7f84c17cea534f38c4647249a7b58f3c294888fd9ca78a22ddc47b54f17814c0

  2. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 11, 2026
  3. melvin-bot commented on Jun 11, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #92286

  4. melvin-bot commented on Jun 11, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  5. github-actions commented on Jun 11, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  6. MelvinBot commented on Jun 11, 2026

    @MelvinBot
    Contributor

    Proposal

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

    After deleting an agent offline and then editing an approval workflow where that agent was the approver, a phantom greyed‑out workflow showing the deleted agent appears. This is a regression from #92286 (in this StagingDeployCash).

    What is the root cause of that problem?

    PR #92286 made deleteAgent optimistically mark the agent's row in every policy employeeList with pendingAction: DELETE, so the workflow UI strikes it through while the delete is in flight (Agent.ts:354-377). The whole strikethrough/hide behavior depends on that DELETE marker surviving — convertPolicyEmployeesToApprovalWorkflows only excludes a member and suppresses its pending styling when pendingAction === DELETE (WorkflowUtils.ts:184-185, 233, 243-250).

    Saving an edited approval clobbers that DELETE marker to UPDATE, so the deleted agent is no longer hidden and instead renders as a greyed‑out (pending) workflow. Two spots in the save path do this:

    Where the DELETE pendingAction is lost
    1. updateApprovalWorkflow — Workflow.ts:107 builds previousEmployeeList by forcing pendingAction: null on every employee. So the DELETE‑preserving ternary inside the convert helper (WorkflowUtils.ts:386) never sees DELETE.

    2. The membersToRemove (WorkflowUtils.ts:416-424) and approversToRemove (WorkflowUtils.ts:428-436) branches set pendingAction unconditionally to UPDATE — unlike the main approver loop, they have no DELETE‑preserving check at all.

    When the user swaps the approver away from the deleted agent, the agent goes into approversToRemove, so updatedEmployees[agent] = {forwardsTo: '', pendingAction: UPDATE}. That row is MERGEd into the policy's employeeList, overwriting the existing DELETE. On recompute the agent now carries UPDATE, which is not filtered/suppressed → greyed‑out phantom workflow.

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

    Preserve the agent's DELETE pendingAction through the workflow‑edit save so the existing hide/strikethrough logic keeps working:

    • In Workflow.ts:107, don't blanket‑null pendingAction; keep it when it's DELETE (e.g. pendingAction: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ? value.pendingAction : null).
    • In the membersToRemove and approversToRemove branches of convertApprovalWorkflowToPolicyEmployees, mirror the main loop's guard so a previous DELETE is retained instead of overwritten with UPDATE.

    A pending‑delete agent should never be re‑written with an ADD/UPDATE pendingAction. Add a unit test in WorkflowUtilsTest/AgentActionTest covering "edit approver while an approver row is pending‑delete".

    What alternative solutions did you explore? (Optional)

    Because this is a time‑sensitive deploy blocker, reverting #92286 is the fastest way to unblock the deploy if a forward fix can't land quickly — the offline strikethrough is a nice‑to‑have, and reverting removes the DELETE marker that the save path mishandles.

    Confidence & verification

    High confidence from static tracing of the data flow (Onyx optimistic MERGE → workflow recompute). Not reproduced in a running app. The mechanism explains all symptoms: offline‑only (optimistic data persists, never reconciled by server), greyed‑out (pendingAction styling), and "deleted agent reappears" (DELETE → UPDATE flip un‑hides the row).


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

  7. neil-marcellini commented on Jun 11, 2026

    @neil-marcellini
    Contributor

    @MelvinBot why are there also two approval workflows after updating the approver in one workflow from the deleted agent to another user while offline?

  8. mkhutornyi commented on Jun 11, 2026

    @mkhutornyi
    Contributor

    I reproduced the same bug (workspace member instead of agent) in production. Not blocker.

    Repro step:

    1. Login A and create workspace
    2. Go to "Workspaces" > "Members"
    3. Invite B
    4. Go to "Workspaces" > "Workflows"
    5. Set B as approver
    6. Go offline
    7. Go to "Workspaces" > "Members" and delete B
    8. Return to "Workspaces" > "Workflows"
    9. Tap on approver to open "Edit Approval" RHP
    10. Click on "Approver" field > "Approver" field
    11. Select other member
    12. Tap Save > Save
    bug.mov
  9. MelvinBot commented on Jun 11, 2026

    @MelvinBot
    Contributor

    Same root cause as above — the second workflow is the deleted agent resurfacing, not a real new workflow.

    Offline, deleting the agent never actually removes its employeeList row; it only marks it. PR #92286 sets that row to pendingAction: DELETE, and the workflows page relies on DELETE to hide the row (it's filtered out of availableMembers/members and not allowed to spawn or grey a workflow — WorkflowUtils.ts:184, 233, 243, 249).

    When you change the approver and save, the agent goes into approversToRemove and its row is re-written with pendingAction: UPDATE (WorkflowUtils.ts:428-436; the DELETE is also already discarded one step earlier at Workflow.ts:107, which nulls every row's pendingAction). That UPDATE row is MERGEd into the policy, overwriting the DELETE marker that was keeping the agent hidden.

    So now there are two cards:

    1. The workflow you actually edited — the member now submits to the new approver.
    2. The deleted agent's own still-present row. It's no longer DELETE-suppressed, and it still carries the submitsTo the backend's shareWithEmployees gave it when the agent was promoted to approver (the previous default approver — see the comment at Workflow.ts:117-123). Since each workflow card is keyed on an employee's submitsTo (WorkflowUtils.ts:195), that residual submitsTo makes the resurrected agent render as its own greyed grouping instead of staying hidden.

    Both cards are greyed because both rows carry a pending action while you're offline.

    The fix in my analysis above resolves this too: preserve the agent's DELETE pendingAction through the workflow-edit save so its row stays suppressed.

    Confidence

    High confidence on the mechanism (the DELETE → UPDATE clobber un-hides the agent). The exact shape of the second card — whether it's a standalone group or the default workflow re-greyed with the agent re-added — depends on the agent's residual submitsTo value, which I traced statically rather than reproduced. Happy to confirm the precise rendering in-app if useful.

  10. neil-marcellini commented on Jun 11, 2026

    @neil-marcellini
    Contributor

    @MelvinBot pls implement your solution from here. Include automated tests, and also run a manual test in the web platform. Ensure you properly go through set up for manual testing like going through onboarding, creating a workspace, etc.

  11. 6 remaining items

  12. mkhutornyi commented on Jun 11, 2026

    @mkhutornyi
    Contributor

    Assign me here too

  13. MelvinBot commented on Jun 11, 2026

    @MelvinBot
    Contributor

    ⏱️ Ran out of time before I could finish. This usually means the task was too complex or I got stuck exploring. Please try again with a more specific request or post in #melvinbot-ai.

    Run details

  14. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 11, 2026
  15. aswin-s commented on Jun 11, 2026

    @aswin-s
    Contributor

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

    On all platforms (Android, iOS, Web, Desktop), when a user deletes an agent while offline and then edits an existing approval workflow that referenced that agent (swapping the approver for another member and tapping Save), a greyed‑out phantom workflow row for the deleted agent appears in the Workflows list. The expected behavior is that the deleted agent's row stays hidden/marked DELETE and no extra workflow card is rendered.

    What is the root cause of that problem?

    The bug requires two functions working in tandem to reproduce: updateApprovalWorkflow in src/libs/actions/Workflow.ts and convertApprovalWorkflowToPolicyEmployees in src/libs/WorkflowUtils.ts.

    Step 1 — updateApprovalWorkflow strips all DELETE markers before the converter ever runs.

    When the user taps Save on the edited workflow, updateApprovalWorkflow (src/libs/actions/Workflow.ts:100-204) builds its previousEmployeeList snapshot on line 107:

    const previousEmployeeList = Object.fromEntries(
        Object.entries(policy.employeeList ?? {}).map(([key, value]) => [key, {...value, pendingAction: null}])
    );

    This unconditionally sets pendingAction: null on every entry — including the deleted agent whose entry was carrying pendingAction: 'DELETE' (set optimistically by deleteAgent in src/libs/actions/Agent.ts). The sanitised previousEmployeeList (with DELETE erased) is then handed to convertApprovalWorkflowToPolicyEmployees.

    Step 2 — the converter writes UPDATE onto the deleted agent's entry.

    Inside convertApprovalWorkflowToPolicyEmployees (src/libs/WorkflowUtils.ts:345-437), the approversToRemove loop (lines 428–436) writes the deleted agent's email into updatedEmployees with pendingAction: pendingAction (which resolves to UPDATE for an edit). The approver loop at line 386 already has a DELETE-preserving guard:

    pendingAction: previousPendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
        ? previousPendingAction
        : pendingAction,

    but because previousEmployeeList arrived with pendingAction: null on every entry, previousPendingAction is always null here, so the guard never fires and the deleted agent gets pendingAction: UPDATE.

    Step 3 — calculateApprovers emits the stale entry.

    With the DELETE marker replaced by UPDATE (per the changes from PR #92286 that made calculateApprovers read pendingAction from policy.employeeList), the agent's entry is no longer filtered out and renders as a greyed‑out phantom workflow card.

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

    The fix has two parts: (1) stop updateApprovalWorkflow from nulling DELETE markers, and (2) add the matching guard inside the converter for the loops that currently lack it.

    1. src/libs/actions/Workflow.ts:107 — Preserve DELETE pendingAction when building previousEmployeeList.

    Change the previousEmployeeList construction so that entries with pendingAction: 'delete' keep their value; only non-DELETE entries are nulled out (which is the caller's intent — clearing stale UPDATE/ADD markers before a re-compute):

    // Before
    const previousEmployeeList = Object.fromEntries(
        Object.entries(policy.employeeList ?? {}).map(([key, value]) => [key, {...value, pendingAction: null}])
    );
    
    // After
    const previousEmployeeList = Object.fromEntries(
        Object.entries(policy.employeeList ?? {}).map(([key, value]) => [
            key,
            {
                ...value,
                pendingAction:
                    value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
                        ? value.pendingAction
                        : null,
            },
        ])
    );

    This is the primary fix. It ensures the DELETE marker set by deleteAgent survives into convertApprovalWorkflowToPolicyEmployees so the existing guard in the approvers loop (and the new guards below) can act on it.

    2. src/libs/WorkflowUtils.ts:428-436 — Mirror the DELETE-preserving guard in the approversToRemove loop.

    // Before
    if (approversToRemove) {
        for (const {email} of approversToRemove) {
            updatedEmployeeList[email] = {
                ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
                forwardsTo: '',
                pendingAction,
            };
        }
    }
    
    // After
    if (approversToRemove) {
        for (const {email} of approversToRemove) {
            const previousPendingAction = previousEmployeeList[email]?.pendingAction;
            updatedEmployeeList[email] = {
                ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
                forwardsTo: '',
                pendingAction:
                    previousPendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
                        ? previousPendingAction
                        : pendingAction,
            };
        }
    }

    3. src/libs/WorkflowUtils.ts:416-424 — Apply the same guard to the membersToRemove loop.

    // Before
    if (membersToRemove) {
        for (const {email} of membersToRemove) {
            updatedEmployeeList[email] = {
                ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
                submitsTo: defaultApprover,
                pendingAction,
            };
        }
    }
    
    // After
    if (membersToRemove) {
        for (const {email} of membersToRemove) {
            const previousPendingAction = previousEmployeeList[email]?.pendingAction;
            updatedEmployeeList[email] = {
                ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
                submitsTo: defaultApprover,
                pendingAction:
                    previousPendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
                        ? previousPendingAction
                        : pendingAction,
            };
        }
    }

    4. src/libs/WorkflowUtils.ts:395-412 — Apply the same guard in the members loop for parity.

    The approvalWorkflow.members loop at lines 395–412 writes pendingAction unconditionally on every member entry whose submitsTo changed. Add the DELETE-preserving guard here too so the same offline-delete scenario on the member side does not resurrect a DELETE-pending row:

    // Before
    updatedEmployeeList[email] = {
        ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
        submitsTo,
        pendingAction,
        pendingFields: {
            submitsTo: pendingAction,
        },
    };
    
    // After
    const previousMemberPendingAction = previousEmployeeList[email]?.pendingAction;
    updatedEmployeeList[email] = {
        ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
        submitsTo,
        pendingAction:
            previousMemberPendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
                ? previousMemberPendingAction
                : pendingAction,
        pendingFields: {
            submitsTo: pendingAction,
        },
    };

    5. Add a WorkflowUtilsTest case covering the full offline-delete-then-edit path.

    The test should assert: given previousEmployeeList[agentEmail].pendingAction === 'delete' and agentEmail ∈ approversToRemove, calling convertApprovalWorkflowToPolicyEmployees with type UPDATE must produce updatedEmployees[agentEmail].pendingAction === 'delete' (not 'update'). A companion integration test should verify that after updateApprovalWorkflow runs under the same conditions, the Onyx-merged policy.employeeList[agentEmail].pendingAction remains 'delete' and the agent does not appear in the output of calculateApprovers.

    What alternative solutions did you explore? (Optional)

    Filter out DELETE-pending entries inside calculateApprovers instead — rejected because the persisted policy.employeeList would still carry the wrong pendingAction: UPDATE after the offline edit and would diverge from the optimistic DELETE intent set by deleteAgent; fixing it at the write site keeps the Onyx state correct for every consumer.

  16. wildan-m commented on Jun 11, 2026

    @wildan-m
    Contributor

    Proposal

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

    After deleting an agent while offline and then editing the approval workflow that used that agent as approver (changing the approver to another member and saving), an extra greyed‑out workflow appears that still contains the deleted agent. Expected: no extra workflow appears.

    What is the root cause of that problem?

    When an agent is deleted while offline, deleteAgent optimistically marks the agent's row in every policy's employeeList with pendingAction: DELETE. The display path (convertPolicyEmployeesToApprovalWorkflows) correctly treats that row as pending‑delete — it excludes it from the members list and does not let the DELETE turn a workflow grey.

    The problem is the save path that runs when the approval is edited. updateApprovalWorkflow builds the "previous" employee list it diffs against, and it force‑nulls the pendingAction of every employee:

    const previousEmployeeList = Object.fromEntries(Object.entries(policy.employeeList ?? {}).map(([key, value]) => [key, {...value, pendingAction: null}]));

    This wipes the in‑flight DELETE off the deleted agent before the conversion even runs, which defeats the DELETE‑preservation guards that already exist downstream (they all check previousPendingAction === DELETE, but previousPendingAction is now always null).

    On top of that, when the deleted agent is removed as the approver during the edit, it flows through the "approvers to remove" loop in convertApprovalWorkflowToPolicyEmployees, which assigns the ADD/UPDATE pending action unconditionally — it has no DELETE guard at all:

    // For each approver to remove, we update the employee list with forwardsTo set to ''
    // which will reset the forwardsTo on the backend.
    if (approversToRemove) {
    for (const {email} of approversToRemove) {
    updatedEmployeeList[email] = {
    ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
    forwardsTo: '',
    pendingAction,
    };
    }

    The combined effect: the agent's pendingAction is downgraded from DELETE to UPDATE. On the next render the agent is no longer treated as pending‑delete, so it is added back as a member of the workflow keyed by its submitsTo, and that workflow renders greyed‑out (pending update) — the extra greyed‑out workflow with the deleted agent.

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

    Preserve an in‑flight DELETE pending action through the entire approval‑workflow edit so a deleted agent stays flagged for deletion instead of being downgraded to UPDATE.

    1. In updateApprovalWorkflow (and the sibling create/remove flows that build the same "previous" employee list), when clearing pending actions on the previous employee list, clear only ADD/UPDATE — keep a DELETE pending action intact. This makes the existing previousPendingAction === DELETE guards effective again.

    const previousEmployeeList = Object.fromEntries(Object.entries(policy.employeeList ?? {}).map(([key, value]) => [key, {...value, pendingAction: null}]));

    1. In convertApprovalWorkflowToPolicyEmployees, add the same DELETE guard to the "members to remove" and "approvers to remove" loops that the main approvers loop already uses: when the previous pending action for that email is DELETE, keep DELETE rather than overwriting it with the ADD/UPDATE pending action.

    // For each member to remove, we update the employee list with submitsTo set to ''
    // which will set the submitsTo field to the default approver email on backend.
    if (membersToRemove) {
    for (const {email} of membersToRemove) {
    updatedEmployeeList[email] = {
    ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
    submitsTo: defaultApprover,
    pendingAction,
    };
    }
    }
    // For each approver to remove, we update the employee list with forwardsTo set to ''
    // which will reset the forwardsTo on the backend.
    if (approversToRemove) {
    for (const {email} of approversToRemove) {
    updatedEmployeeList[email] = {
    ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
    forwardsTo: '',
    pendingAction,
    };
    }
    }

    With both in place, the deleted agent keeps its DELETE pending action across the edit, so convertPolicyEmployeesToApprovalWorkflows continues to exclude it and no greyed‑out workflow with the deleted agent is produced.

    This was verified with a Jest test that drives updateApprovalWorkflow for the exact repro (an offline‑deleted agent removed as approver while editing the workflow) and asserts the agent's optimistic pendingAction stays DELETE. The test fails on main (the agent's pending action is update) and passes with the fix.

    Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/93260-preserve-delete-pending-on-workflow-edit?expand=1

    What alternative solutions did you explore? (Optional)

    An alternative is to skip emitting any update entry for an employee whose previous pending action is DELETE (rather than preserving DELETE on the emitted entry), since a to‑be‑deleted agent does not need a forwardsTo/submitsTo reset sent to the server. Preserving the DELETE pending action was chosen instead because it mirrors the guard the main approvers loop already uses, keeps the optimistic employee state self‑consistent, and is the smaller, more localized change.

  17. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 11, 2026
  18. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 11, 2026
  19. yusufdeveloper2903 commented on Jun 11, 2026

    @yusufdeveloper2903
    Contributor

    Proposal

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

    When an agent (or member) is deleted while offline and you then edit the approval workflow that used them as approver — swapping the approver for someone else and tapping Save — a phantom greyed‑out workflow still showing the deleted agent appears. Expected: the deleted agent stays hidden and no extra workflow card is rendered.

    What is the root cause of that problem?

    deleteAgent is offline‑safe: it can't actually remove the agent's employeeList row, so it optimistically marks that row pendingAction: DELETE on every policy (Agent.ts:362-373). The whole "hide the deleted approver" behaviour hangs on that DELETE marker surviving — convertPolicyEmployeesToApprovalWorkflows only excludes the row and suppresses its grey styling when pendingAction === DELETE (WorkflowUtils.ts:184, 233, 243-251).

    The single root cause is Workflow.ts:107. When you save the edit, updateApprovalWorkflow builds the previousEmployeeList snapshot it diffs against and force‑nulls pendingAction on every employee:

    const previousEmployeeList = Object.fromEntries(Object.entries(policy.employeeList ?? {}).map(([key, value]) => [key, {...value, pendingAction: null}]));

    The deleted agent's DELETE is wiped right here, before any conversion runs. I want to highlight evidence the other proposals missed: the codebase already tries to preserve DELETE in three places that all read previousEmployeeList[...].pendingAction === DELETE — the main approver loop (WorkflowUtils.ts:386) and the recently‑added default‑approver backstop (Workflow.ts:127-132). Both of those guards are dead code — line 107 guarantees previousPendingAction is always null by the time they run, so they never fire. The bug isn't "a missing guard"; it's that one upstream line silently defeats the guards the maintainers already wrote.

    The second gap is in the conversion itself. In the repro the agent is removed as approver, so it flows through the approversToRemove loop — which, unlike the main loop, has no DELETE guard at all and overwrites the row with pendingAction: UPDATE (WorkflowUtils.ts:428-435); the membersToRemove loop has the same gap (416-423). That {forwardsTo: '', pendingAction: UPDATE} row is MERGEd into the policy, clobbering the DELETE. On the next render the agent is no longer DELETE‑suppressed and — still carrying the residual submitsTo the backend's shareWithEmployees gave it (see the comment at Workflow.ts:117-123) — renders as its own greyed grouping. That residual submitsTo is also the answer to @neil-marcellini's question: the "second workflow" is the deleted agent's own row resurfacing, keyed on its submitsTo at WorkflowUtils.ts:195, not a genuinely new workflow.

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

    1. Stop Workflow.ts:107 from nulling a DELETE marker. This is the primary fix — it instantly revives the existing guards at WorkflowUtils.ts:386 and Workflow.ts:132, and (critically) it is also what makes the failureData rollback at Workflow.ts:175-186 restore DELETE correctly if the request fails.

    -    const previousEmployeeList = Object.fromEntries(Object.entries(policy.employeeList ?? {}).map(([key, value]) => [key, {...value, pendingAction: null}]));
    +    const previousEmployeeList = Object.fromEntries(
    +        Object.entries(policy.employeeList ?? {}).map(([key, value]) => [
    +            key,
    +            {...value, pendingAction: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ? value.pendingAction : null},
    +        ]),
    +    );

    2. In the approversToRemove / membersToRemove loops, skip a row that is already pending DELETE rather than rewriting it. I deliberately differ from the other proposals here, which mirror the main loop's "preserve DELETE on the emitted row". Mirroring works for display, but it keeps the agent in updatedEmployees, and updatedEmployees drives two things it shouldn't: the API payload employees: JSON.stringify(...) (Workflow.ts:200) — sending a pointless forwardsTo reset for a row that DELETE_AGENT is about to delete — and, more importantly, the successData null‑clear (Workflow.ts:193). Both DELETE_AGENT and UPDATE_WORKSPACE_APPROVAL queue offline and resolve in order; DELETE_AGENT's success sets the row to null (Agent.ts:365/374), then UPDATE's success MERGEs {[agent]: {pendingAction: null, pendingFields: null}} back onto that just‑cleared key. The agent's lifecycle is owned by DELETE_AGENT; the workflow‑edit command should not be writing to its row at all. Skipping keeps the two commands' Onyx footprints disjoint:

         if (approversToRemove) {
             for (const {email} of approversToRemove) {
    +            if (previousEmployeeList[email]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
    +                continue;
    +            }
                 updatedEmployeeList[email] = {
                     ...(updatedEmployeeList[email] ? updatedEmployeeList[email] : {email}),
                     forwardsTo: '',
                     pendingAction,
                 };
             }
         }

    The same one‑line continue guard goes in the membersToRemove loop (416-423) for the member‑deleted variant @mkhutornyi reproduced.

    With both in place: offline, the agent's DELETE row is left untouched by the edit, so convertPolicyEmployeesToApprovalWorkflows keeps excluding it → no phantom card and no double workflow. Online, UPDATE_WORKSPACE_APPROVAL no longer carries or re‑touches the deleted row, and DELETE_AGENT removes it cleanly. On failureData, fix #1 restores the DELETE so the row stays hidden after a rollback.

    Tests. Add a WorkflowUtilsTest case asserting that, given previousEmployeeList[agent].pendingAction === 'delete' and agent ∈ approversToRemove, convertApprovalWorkflowToPolicyEmployees({type: UPDATE, ...}) does not emit an agent entry (so the optimistic MERGE leaves the existing DELETE intact). Plus an AgentActionTest/integration case driving updateApprovalWorkflow end‑to‑end for the exact repro and asserting policy.employeeList[agent].pendingAction stays 'delete' and the agent is absent from convertPolicyEmployeesToApprovalWorkflows output.

    What alternative solutions did you explore? (Optional)

    • Preserve DELETE on the emitted row in the remove loops (the other proposals' approach). It fixes the visible bug, but as shown above it leaves the deleted agent inside updatedEmployees, so the workflow‑update command sends and later null‑clears a row that belongs to DELETE_AGENT's own success/failure lifecycle. Skipping is the smaller, more correct change — it never entangles the two commands.
    • Filter DELETE rows inside calculateApprovers/convertPolicyEmployeesToApprovalWorkflows only. Rejected: the persisted policy.employeeList would still carry the wrong UPDATE after the offline edit, diverging from the optimistic DELETE intent. Fixing it at the write site keeps Onyx correct for every consumer.
    • Revert #92286. This was the original deploy‑blocker escape hatch. No longer necessary now that agents are behind a beta and this is a forward‑fixable, well‑scoped change.
  20. Abdulloh0109 commented on Jun 11, 2026

    @Abdulloh0109
    Contributor

    What is the root cause of that problem?

    This is a regression from #92286 ("Handle agent deleted on approval workflow in offline mode", merged 06-10, one day before this was filed). That PR taught the display path to hide an employee whose employeeList row carries pendingAction: DELETE: convertPolicyEmployeesToApprovalWorkflows keeps a DELETE row out of availableMembers (WorkflowUtils.ts:184), never lets it grey a card (WorkflowUtils.ts:233, 249), and never adds it as a workflow member (WorkflowUtils.ts:243-245). deleteAgent stamps that marker on every policy's row optimistically (Agent.ts:354-373).

    What #92286 did not touch is the workflow-edit save path. So when you edit the approver while the agent's optimistic DELETE is still in flight (i.e. offline), the save path overwrites DELETE with UPDATE, and the now-UPDATE row sails straight through every DELETE filter above and renders as a greyed card containing the deleted agent.

    Two independent spots flip DELETE→UPDATE, and for the reported repro both have to be fixed:

    1. updateApprovalWorkflow builds previousEmployeeList by force-nulling pendingAction on every row (Workflow.ts:107). The agent's DELETE is erased here before the converter even runs.

    2. Swapping the approver away from the agent puts it into approversToRemove (WorkspaceWorkflowsApprovalsEditPage.tsx:107-110), and convertApprovalWorkflowToPolicyEmployees writes it back as {forwardsTo: '', pendingAction: UPDATE} (WorkflowUtils.ts:428-436). Unlike the main approver loop — which guards with prev === DELETE ? prev : UPDATE (WorkflowUtils.ts:380-386) — this loop sets pendingAction unconditionally and never reads the previous row at all.

    They compound: fix only #1 and the approversToRemove loop still ignores previousEmployeeList and writes UPDATE; fix only #2 and its guard reads previousEmployeeList[email].pendingAction, which #1 already nulled. The resulting {employeeList: updatedEmployees} is MERGEd into the policy (Workflow.ts:165-172), clobbering the standing DELETE.

    Same root cause explains the two greyed workflows mkhutornyi/neil saw: the resurrected agent row still carries the submitsTo the backend's shareWithEmployees gave it when it was promoted to approver (the old default approver). Since each card is keyed on submitsTo (WorkflowUtils.ts:195, 235), once it's no longer DELETE-suppressed it spawns its own greyed grouping next to the workflow you actually edited.

    This isn't agent-specific. Removing a regular member also stamps pendingAction: DELETE on the employeeList row (Policy/Member.ts:378-381) — which is why mkhutornyi reproduced the identical thing with a workspace member in production. The defect is in the generic save path, not in agent code.

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

    Fix layer: optimistic-data construction (the action + the util), not display. The display path already handles DELETE correctly; the job is to stop the save path from destroying the marker.

    1. Workflow.ts:107 — when building previousEmployeeList, keep pendingAction when it's DELETE and null it otherwise (pendingAction: value.pendingAction === DELETE ? value.pendingAction : null). This is the keystone: it re-arms the guard the approver loop already has and gives the remove-loop guard something truthful to read. It also flows into failureData (Workflow.ts:180), so an offline rollback correctly restores the in-flight DELETE.

    2. WorkflowUtils.ts:428-436 (approversToRemove) — mirror the approver loop's guard: read previousEmployeeList[email]?.pendingAction and keep DELETE instead of overwriting it. This is the loop the reported repro actually goes through, so it's required alongside Some initial fixes and code style updates #1.

    3. Parity (same class of bug): apply the identical guard to the membersToRemove loop (WorkflowUtils.ts:416-424) and the members loop (WorkflowUtils.ts:395-411). The reported repro only exercises approversToRemove, but a deleted member who is a plain submitter would hit membersToRemove with the same un-hiding result. Closing all three keeps one rule consistent: a pending-DELETE row is never downgraded to ADD/UPDATE.

    Edge cases this actually touches: offline (the only window where the optimistic DELETE lives long enough to be clobbered) and the optimistic failure rollback (now restores DELETE). Online is unaffected — DELETE_AGENT / member-remove reconciles the row away on the server.

    Test: a WorkflowUtilsTest case asserting that with previousEmployeeList[agent].pendingAction === 'delete' and agent ∈ approversToRemove, convertApprovalWorkflowToPolicyEmployees({type: UPDATE}) returns the agent with pendingAction === 'delete' (not 'update'); plus an integration-style check that after updateApprovalWorkflow the merged policy.employeeList[agent].pendingAction stays 'delete' and the agent produces no card from convertPolicyEmployeesToApprovalWorkflows. It should fail on the current SHA.

    What alternative solutions did you explore? (Optional)

    Filter DELETE rows harder in the display/consumer layer (e.g. drop them inside calculateApprovers / convertPolicyEmployeesToApprovalWorkflows). Rejected: the persisted optimistic employeeList[agent].pendingAction would still be wrong (update), diverging from what deleteAgent / member-remove intended, and the failureData rollback at Workflow.ts:180 plus every other reader of that row would inherit the wrong action. Fixing at the write site keeps Onyx self-consistent for all consumers.

    Skip emitting an entry at all for an employee whose previous action is DELETE (don't bother sending a forwardsTo/submitsTo reset for a row that's being deleted). Reasonable and marginally smaller, but I prefer preserving DELETE on the emitted row — it mirrors the guard the approver loop already uses and avoids a special-case "no-op" branch.

    Revert #92286 — the standard deploy-blocker escape hatch. Since this is already de-blockered (agents are beta-gated) and the production member variant is non-blocking, I'd rather land the forward fix than lose the offline strikethrough that PR added. Noting it only as the fallback if a fix can't land in time.

  21. github-actions commented on Jun 11, 2026

    @github-actions
    Contributor

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

  22. github-actions commented on Jun 12, 2026

    @github-actions
    Contributor

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

  23. NicolasBonet commented on Jun 12, 2026

    @NicolasBonet
    Contributor

    Closing per: #93315

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions