Skip to content

[Due for payment 2026-06-17] [$250] When a new agent added to workflow offline, it blinks to the admin and back online #92296

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: 9.3.90-2
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #91441
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: MacBook Air 26.5 Chrome, iPhone 15 iOS 26.5
App Component: Workspace Settings

Action Performed:

Preconditions: user does not have an agent

  1. Sign in to ND with an expensifail account
  2. Create a collect workspace
  3. Open workspace settings - Workflows
  4. Go offline
  5. Click "Add agent", complete the flow
  6. Verify that the greyed out agent is set as the approver
  7. Do not leave the workflows, go online
  8. Observe the Approver row

Expected Result:

Agent is set as the approver and does not change briefly after enabling internet connection

Actual Result:

Agent briefly changes to the workspace owner and back on the workflow card after enabling internet connection

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

To be added by Applause Leads

View all open jobs on GitHub

Applause Internal Information
Exported by: Vincenzo Godoy
Bug ID: 7168910

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

Activity

  1. applause-bot commented on Jun 1, 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/9837aad03b7f748519ba74a86669d6bf61362ade46a8be96853204fa2b1fe71b

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

    @melvin-bot

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

  4. melvin-bot commented on Jun 1, 2026

    @melvin-bot

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

  5. github-actions commented on Jun 1, 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 1, 2026

    @MelvinBot
    Contributor

    Proposal

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

    After adding an agent as approver while offline, restoring the connection makes the Approver row on the workflow card briefly flip to the workspace owner and then back to the agent. Introduced by #91441.

    What is the root cause of that problem?

    The agent is rendered as approver by only two sources:

    1. The deferred overlay in useDeferredAgentWorkflowReconciliation (while DEFERRED_AGENT_WORKFLOW_SAVES has an entry), and
    2. The optimistic employeeList write from updateApprovalWorkflow.

    On reconnect, the reconciliation effect resolves the agent, fires updateApprovalWorkflow, and immediately clears the overlay (reconciliation L167-L169). From that point the card relies solely on source (2).

    But reconnect also refetches the policy via fetchData → openPolicyWorkflowsPage (a READ). The server response carries the pre-approval-update employeeList (the agent's submitsTo is the workspace owner, so the owner is still approver — UPDATE_WORKSPACE_APPROVAL hasn't been persisted yet). If that read response lands after the overlay was cleared but before the approval update settles, it overwrites the optimistic agent-approver → the card shows the workspace owner → then flips back to the agent once UPDATE_WORKSPACE_APPROVAL is reflected. That window is the blink.

    The "workspace owner" value can only re-enter policy.employeeList/approver from a server payload (nothing client-side rewrites owner-as-approver after the optimistic agent write), and the blink occurs exactly when the connection is restored — which is precisely when the onReconnect refetch fires. CREATE_AGENT itself does not optimistically touch employeeList (Agent.ts successData); the agent only enters employeeList via the backend response with submitsTo = previous default approver.

    Evidence chain
    • Offline: agent lives only in the deferred entry; rawApprovalWorkflows (from employeeList) still shows the owner; overlay (keyed by the owner's firstApproverEmail) renders the agent faded.
    • Reconnect: backend CREATE_AGENT response adds the agent to employeeList with submitsTo = owner (owner still approver) — overlay still active, still shows agent.
    • Reconciliation effect resolves the agent → updateApprovalWorkflow(...) (optimistic: agent becomes approver) then clearDeferredAgentWorkflowSave(...) (overlay off) at L168-L169.
    • openPolicyWorkflowsPage READ response (Policy.ts L3646-L3685) lands with owner-as-approver, clobbering the optimistic write while the overlay is already gone → blink → resolves when UPDATE_WORKSPACE_APPROVAL settles.

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

    Keep the deferred overlay alive until the agent is durably the approver, so it bridges the reconnect-refetch window:

    • In useDeferredAgentWorkflowReconciliation, decouple "fire the save" from "clear the overlay." Continue firing updateApprovalWorkflow exactly once (the reconciledDeferredKeysRef guard at L72 already prevents re-firing), but only clearDeferredAgentWorkflowSave once the raw workflow's first approver email equals the resolved agent email (i.e. policy.employeeList actually reflects the agent as approver). Until then, keep overlaying so the card never falls back to the stale server approver.
    • Overlay the upgraded approver (real email, pendingAction: undefined) during that retention window so it renders solid rather than faded.
    Alternative

    Guard the onReconnect refetch: skip / defer openPolicyWorkflowsPage while a DEFERRED_AGENT_WORKFLOW_SAVES entry for that policy is still pending. Simpler, but narrower — it only addresses the refetch clobber, whereas the overlay-retention fix is robust to any server payload that lands during the window.

    Related issues


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

  7. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Jun 1, 2026
  8. NicolasBonet commented on Jun 1, 2026

    @NicolasBonet
    Contributor

    It is behind a beta, so demoting

  9. 46 remaining items

  10. NicolasBonet commented on Jun 11, 2026

    @NicolasBonet
    Contributor

    Changing priority as this has been merged

  11. thesahindia commented on Jun 11, 2026

    @thesahindia
    Member

    Please unassign me.

  12. NicolasBonet commented on Jun 12, 2026

    @NicolasBonet
    Contributor

    Please unassign me.

    Done

  13. melvin-bot commented on Jun 12, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  14. mkhutornyi commented on Jun 15, 2026

    @mkhutornyi
    Contributor

    BugZero Checklist:

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

      Link to comment: feat: [91244] add agent to workflow approval #91441 (comment)

    • [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.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue: https://github.com/Expensify/Expensify/issues/650324

    Regression Test Proposal

    Preconditions:

    user does not have an agent

    Test:

    1. Create a collect workspace
    2. Open workspace settings - Workflows
    3. Go offline
    4. Click "Add agent", complete the flow
    5. Verify that the greyed out agent is set as the approver
    6. Do not leave the workflows, go online
    7. Observe the Approver row
    8. Verify that agent is set as the approver and does not change briefly after enabling internet connection

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-70a8-a43b-07bd-f3d890402fe4
  15. melvin-bot commented on Jun 16, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2061597829446593746/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  16. mallenexpensify commented on Jun 18, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @mkhutornyi due $250 via NewDot

    ^ Test case created. Thx

  17. m-natarajan commented on Jun 22, 2026

    @m-natarajan

    @mkhutornyi This is regarding the Regression test proposal
    Is this feature reverted? Add agent button not displayed for new expensifail account

    Recording.3060.mp4
  18. mkhutornyi commented on Jun 22, 2026

    @mkhutornyi
    Contributor

    Looks like it from #93315

  19. trjExpensify commented on Jun 23, 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.EngineeringExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions