Skip to content

Agents - Company agent is not removed from table after deleting workspace until reset app #104647

Closed

Description

@applause-bot

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


Version Number: 9.5.16-0
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: #103817
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.5 / Chrome
App Component: Workspace Settings

Action Performed:

Precondition:

  • Enable companyAgents beta.
  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Agents.
  3. Create a company agent.
  4. Delete the workspace.
  5. Go to Account > Agents.
    → Company agent is shown in the table.
  6. Go to Account > Troubleshoot > Clear cache and restart > Reset and refresh.
  7. Go to Account > Agents.
    → Company agent is removed from the table.

Expected Result:

In Step 6, after deleting workspace, company agent should be removed from the table.

Actual Result:

In Step 6, after deleting workspace, company agent remains in the table.
In Step 7, after resetting app, company agent is removed from the table.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7292511_1792612438830.3.mp4

View all open jobs on GitHub

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

Activity

  1. applause-bot commented on Oct 21, 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/3473f748b3d5f2f81b770705bf92ba234a441faf2b0bcde09891d80d5bc77d98

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 21, 2026
  3. melvin-bot commented on Oct 21, 2026

    @melvin-bot

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

  4. melvin-bot commented on Oct 21, 2026

    @melvin-bot

    @yuwenmemon @puneetlath @linhvovan29546 you have been assigned to this deploy blocker because you reviewed the offending PR: #103817

  5. melvin-bot commented on Oct 21, 2026

    @melvin-bot

    @s77rt you have been assigned to this deploy blocker because you authored the offending PR: #103817

  6. melvin-bot commented on Oct 21, 2026

    @melvin-bot

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

  7. github-actions commented on Oct 21, 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.
  8. MelvinBot commented on Oct 21, 2026

    @MelvinBot
    Contributor

    Deploy Blocker Analysis

    Causing PR: [Payment due @linhvovan29546] Create company agents (medium confidence). It adds the "New agent" button, which makes this bug reachable. The bug itself is a gap in the new Account > Agents table: it never hides agents whose owner workspace was deleted.

    Recommendation: Fix forward. Don't revert. The feature is beta-only and not in production. The fix is App-only.

    Fix: In src/hooks/useAgents.ts:83-86, skip workspace-owned agents when the owner policy is missing or pending delete:

    const policy = agent.ownerAccountID ? policiesByAccountID.get(agent.ownerAccountID) : undefined;
    if (!policy || (!isOffline && policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)) {
        return [];
    }
    Investigation details

    Why the agent stays in the table

    • useAgents lists every agent_* Onyx key. It only drops rows with no personal details or with the agent's own pending delete (L62-L76). A missing or deleted owner policy only leaves ownerDisplayName undefined. The row is still shown.
    • deleteWorkspace (src/libs/actions/Policy/Policy.ts:435) never touches agent keys in its optimistic, success, or failure data.
    • openAgentsPage runs each time the page mounts, but the stale row survives it. The response seems to merge agents without removing ones the server no longer returns. Only "Reset and refresh" clears Onyx, which matches the repro.

    Why this PR

    • Before this PR, Workspace > Agents had no create button, and the old create path always sent isPersonalAgent: true. Users couldn't create a workspace-owned agent.
    • The table code was added earlier in Group personal and company agents in Account Settings, which is not on this checklist. This PR is the first one that exposes the path.

    Optional follow-ups

    • In deleteWorkspace, mark the workspace's agents pendingAction: DELETE optimistically, set them to null on success, and roll back on failure. This keeps offline behavior consistent.
    • On the backend, DeleteWorkspace could clear agent_<id> keys, and OpenAgentsPage could replace the collection instead of merging. That would also fix other devices. I couldn't verify the backend response from App code, and it isn't required to unblock the deploy.

    Next Steps: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.


    view run

  9. linhvovan29546 commented on Oct 22, 2026

    @linhvovan29546
  10. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Oct 22, 2026
  11. s77rt commented on Oct 22, 2026

    @s77rt
    Member

    I think this is a low value issue for two reasons:

    1. The agent page gets updated right away. In the OP it didn't due to another bug which the fix for was deployed just an hour ago https://github.com/Expensify/Auth/pull/25626
    Screen.Recording.2026-10-22.at.7.51.42.PM.mov
    1. Looks we are switching to "Archive workspace" flow instead of deleting it and with that flow the agent is not transferred or deleted.

    As for Melvin suggested solution that won't work because we can't know if the agent is going to be deleted (it may be transferred).

    Closing

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

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions