Skip to content

Agents - Agent is not created when confirm page shows RuleBot has been added to your workspace #93624

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.4.8-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: #93466
Email or phone of affected tester (no customers): oidjnoisdjoisjiosjdio@gmail.com
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 Rules in workspace settings.
  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Rules.
  3. Click Add Agent rule.
  4. Enter anything > Save.
  5. Dismiss the confirm modal.
  6. Go to Account > Agents.
  7. Wait for the agent to show up.
  8. Delete the agent.
  9. Go to workspace settings > Rules.
  10. Delete the agent rule from Step 4.
  11. Click Add Agent rule.
  12. Enter anything > Save.
  13. Dismiss the confirm modal.
  14. Go to Account > Agents.

Expected Result:

New agent will be created because confirm modal shows "RuleBot has been added to your workspace!".

Actual Result:

New agent is not created when confirm modal shows "RuleBot has been added to your workspace!".

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7181525_1781548553902.3.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Nathan Lemma
Bug ID: 7181525

Issue OwnerCurrent Issue Owner: @puneetlath

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 15, 2026
  2. applause-bot commented on Jun 15, 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/60655daddfd30a3352ff08c7ce4ebd624b63317f15f57dcef1aa1a0587cdb845

  3. melvin-bot commented on Jun 15, 2026

    @melvin-bot

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

  4. melvin-bot commented on Jun 15, 2026

    @melvin-bot

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

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

    @MelvinBot
    Contributor

    Issue Analysis

    Root Cause: Two separate things are conflated here, and the real fix is outside the App repo.

    1. The "RuleBot has been added to your workspace!" modal is purely cosmetic and unconditional. In AddAgentRulePage.tsx:71 the modal is shown whenever isEmptyObject(policy?.rules?.agentRules) is true. It does not verify that a RuleBot agent was actually created — it just assumes "zero agent rules ⇒ this is the first rule ⇒ backend will create RuleBot."

    2. The actual RuleBot agent creation is a backend side-effect of the ADD_POLICY_AGENT_RULE command. The App-side action addPolicyAgentRule in Rules.ts:329 only writes the rule to Onyx — it never touches the agent.

    In the repro, the user deletes the RuleBot agent (step 8) and all agent rules (step 10). When they re-add a rule (step 12), agentRules is empty again, so the App re-shows the "RuleBot has been added" modal — but the backend does not re-create the manually-deleted agent. The modal's claim is therefore false.

    Why this surfaced now: PR #93466 only added the (correct, by-design) modal. It did not introduce the "agent not re-created" behavior — that is a pre-existing gap in the backend ADD_POLICY_AGENT_RULE command. The PR simply made the gap visible by asserting success in the UI.

    Recommended fix (backend — escalate to an internal engineer): The substantive fix lives in the backend command that handles agent-rule creation, not in App. The backend should ensure a RuleBot agent exists whenever a workspace has ≥1 agent rule (i.e. re-create it on rule add if it was deleted). An internal engineer with access to the backend repo needs to own this.

    A secondary App-side hardening is possible — only show the modal when the agent was actually created — but the App currently has no signal for RuleBot's existence (the agents list at settings/agents is backed by separate data, and RuleBot does not appear anywhere in the policy object). So this would also require the backend to return whether the agent was created. The clean fix is backend-first.

    Investigation details
    • Modal logic: AddAgentRulePage.tsx:68-108. isFirstRule is derived solely from isEmptyObject(policy?.rules?.agentRules).
    • Add action: Rules.ts:329-397 — optimistic/success/failure data only mutate rules.agentRules; no agent record.
    • Delete action: Rules.ts:468-531 — removes the rule from agentRules, leaving it empty after the last rule is deleted, which re-arms the isFirstRule heuristic.
    • RuleBot appears in App only as copy strings in AddAgentRulePage.tsx and the src/languages/*.ts files — the frontend holds no agent-existence state.

    Alternative explanation considered: a stale agents list (agent created but UI not refreshed). Less likely given the reporter explicitly "waits for the agent to show up" successfully on the first pass but not the second, and the title frames it as "not created." Backend logs keyed on the workspace's policyID would confirm definitively whether the second ADD_POLICY_AGENT_RULE created an agent — the issue only provides a tester email, so identifiers for a log query weren't available here.

    Confidence: Medium — the misleading-modal mechanism is confirmed in App code; the "agent not re-created" root cause is inferred from the symptom and lives in a backend repo not visible from App.


    Next Steps:

    • This needs a backend change (outside Expensify/App) — please escalate to an internal engineer with access to the ADD_POLICY_AGENT_RULE command repo.
    • Reply with @MelvinBot <your feedback> to refine this analysis.
  7. NicolasBonet commented on Jun 15, 2026

    @NicolasBonet
    Contributor

    Handling in Auth, this is a backend issue

  8. puneetlath commented on Jun 18, 2026

    @puneetlath
    Contributor

    The PR was reverted.

  9. self-assigned this
    on Jun 18, 2026
  10. NicolasBonet commented on Jun 30, 2026

    @NicolasBonet
    Contributor
  11. melvin-bot commented on Jun 30, 2026

    @melvin-bot

    @puneetlath Whoops! This issue is 2 days overdue. Let's get this updated quick!

  12. puneetlath commented on Jul 1, 2026

    @puneetlath
    Contributor

    Yep, this is done!

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.DailyKSv2EngineeringReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions