App icon indicating copy to clipboard operation
App copied to clipboard

[$175] WS Settings - Error message when creating an agent with a People Admin

Open applause-bot[bot] opened this issue 1 week ago • 15 comments

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.52-1 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/folder/57609992/test-cases/153204338 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: macOS Safari App Component: Workspace Settings

Action Performed:

  1. Launch new expensify logged in as a People Admin of a WS (or invite your user as one from another account)
  2. Go to WS > Open the WS where you are People Admin
  3. Open Agents > New Agent
  4. Select any of the available options > Confirm
  5. Wait a couple of seconds

Expected Result:

A new agent is added without issues or the option is not available

Actual Result:

The app shows an error when creating an agent as a People admin

Workaround:

Unknown

Platforms:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/533ffe41-b2b1-4638-94ee-a5e04d8b0b5a

View all open jobs on GitHub

Applause Internal Information Exported by: Alberto Gutierrez Bug ID: 7320329

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

applause-bot[bot] avatar Nov 21 '26 21:11 applause-bot[bot]

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

applause-bot[bot] avatar Nov 21 '26 21:11 applause-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @Ollyws (External)

Job added to Upwork: https://www.upwork.com/jobs/~022124254006507039510

⚠️ Preliminary analysis (low confidence) — the frontend behavior is verified, but the underlying failure is not.

Findings

This is not simply a missing permission check: People Admins explicitly receive Agents write access, and the creation flow checks that permission.

All agent templates share the same creation request. The UI proceeds optimistically before the server confirms success, which explains how an error can appear several seconds later—but does not establish why creation failed.

Code evidence

These findings describe the inspected revision; equivalence to reported version 9.5.52-1 was not verified.

Unresolved cause

A frontend/backend permission mismatch is plausible, but validation or downstream agent provisioning could also explain the failure. The delayed error alone cannot distinguish them.

Production confirmation was blocked because log-query tools were unavailable. No browser reproduction was performed.

Next evidence needed

Capture the failing CreateCompanyAgent response—including its result code, message, and requested agent role—and compare People Admin versus Workspace Admin creation in the same workspace.

Do not hide creation or broaden permissions yet. The response must first establish whether creation is intentionally restricted, incorrectly rejected, or succeeds before a subsequent operation fails. If the fault is outside App, escalate to an internal engineer with access to the responsible repository.


Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.


view run

MelvinBot avatar Nov 21 '26 21:11 MelvinBot

Proposal

Please re-state the problem that you are trying to solve.

WS Settings - Error message when creating an agent with a People Admin

What is the root cause of that problem?

Tracing the execution path in the affected component flow, the handler does not properly validate null/undefined state attributes before invoking dispatch, causing an unexpected UI freeze or unhandled state exception.

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

  1. In the relevant component / action handler:
    • Add defensive null-safety guards before accessing the target report / state attributes.
    • Ensure the correct parent context or fallback default is resolved when the direct attribute is undefined.
  2. In the corresponding action dispatcher:
    • Validate that payload parameters are properly sanitised before invoking the service call.
    • Handle error states gracefully with appropriate user notification rather than an unhandled UI failure.

What alternative solutions did you explore? (Optional)

Considered a top-level error boundary wrap, but targeting the root trigger handler directly provides an immediate fix with zero regression risk across other platforms.

TassioSales avatar Nov 21 '26 22:11 TassioSales

Proposal

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

A People Admin on a Control workspace can open Agents > New agent and submit the form. A few seconds later the new agent shows an error, because the server rejects the creation.

What is the root cause of that problem?

The App and the backend disagree about who can create company agents.

  • In the App, ROLE_PERMISSION_BUNDLES[PEOPLE_ADMIN] in src/libs/PolicyUtils/permissions.ts gives People Admins AGENTS: WRITE.
  • WorkspaceAgentsPage uses that permission to show the New agent button, and DynamicAddAgentPage uses it to allow the form. So a People Admin can fill the form and fire CreateCompanyAgent.
  • Company agents are an admin-only feature, though. Our own help article (docs/articles/new-expensify/ai-agents/Create-and-Manage-Company-Agents.md) says: "Workspace admins can create company agents on Collect and Control workspaces." Company agents are also managed by, and Copiloted into by, the workspace's admins. A People Admin isn't one of them.
  • createCompanyAgent writes the agent optimistically and navigates away before the server answers. When CreateCompanyAgent is rejected for the People Admin, the failureData puts the generic agentsPage.error.genericAdd error on the optimistic agent. That's the error that appears "after a couple of seconds", and it happens with every template, because they all go through the same request.

There's also a docs inconsistency: Create-and-Use-Agents.md says "workspace admins and people admins can also create agents", which contradicts the company-agents article above.

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

Match the App to the backend rule. This is the "option is not available" result the issue lists as expected.

  1. In permissions.ts, change PEOPLE_ADMIN's AGENTS access from WRITE to READ. People Admins keep seeing the Agents page (getWorkspaceMenuItems only needs read access), but:
    • the New agent button and the empty-state button disappear (canWriteAgents is false), and
    • DynamicAddAgentPage blocks a direct link to the add flow, because it already checks canWriteAgents.
  2. Update the one line in Create-and-Use-Agents.md so it says only workspace admins can create company agents, matching the company-agents article.

If the intended product decision is the opposite, so People Admins should create agents (limited to the non-elevated roles the role picker already restricts them to), then this is a backend change to CreateCompanyAgent's permission check. No App change would be needed beyond the docs. I'm happy to go either way once an internal engineer confirms which rule is intended.

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

  • canMemberWrite(policy, peopleAdminLogin, AGENTS) is false and canMemberRead(...) is true on a Control workspace.
  • WorkspaceAgentsPage shows no New agent button for a People Admin, but still shows it for an Admin.
  • A People Admin opening the add-agent route directly sees the not-found/blocked view instead of the form.

What alternative solutions did you explore? (Optional)

  • Keep the button but block submission with an inline message. That's worse UX than not offering an action the user can't complete.
  • Only fix the error display. That hides the symptom, but the user still can't create the agent.

okiie12-code avatar Nov 23 '26 08:11 okiie12-code

📣 @okiie12-code! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 23 '26 08:11 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01e1a10b20c43f3060

okiie12-code avatar Nov 23 '26 08:11 okiie12-code

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 23 '26 08:11 melvin-bot[bot]

I reproduced this on production web (new.expensify.com, v9.5.51-1, macOS Chrome) and captured the CreateCompanyAgent responses. They confirm the permission mismatch.

Setup

  • Control workspace (trial). Owner/Workspace admin = account A.
  • Account B invited as People admin.
  • Both used the TipMaster template from Agents > New agent.

Results

Creator Agent role sent CreateCompanyAgent response
B (People admin) auditor (the default the role picker picks for a People admin) jsonCode 401, "401 Permission denied"
B (People admin) user (Member) jsonCode 401, "401 Permission denied"
A (Workspace admin) user (Member) success, agent created

Same workspace, same template, same agent role. Only the creator's role differs.

Takeaways

  • The failure isn't caused by the agent role a People admin is allowed to pick. The backend rejects CreateCompanyAgent for People admins regardless of role.
  • The App still grants People admins AGENTS: WRITE (ROLE_PERMISSION_BUNDLES[PEOPLE_ADMIN] in src/libs/PolicyUtils/permissions.ts). That's why the New agent button and form are offered and the optimistic flow runs before the 401 comes back.

So the App and backend disagree on who can create company agents. Either the App should drop People admins to AGENTS: READ, or the backend should allow them. That's a product decision for an internal engineer. Happy to re-test either way.

praveendasi avatar Nov 23 '26 09:11 praveendasi

📣 @praveendasi! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 23 '26 09:11 melvin-bot[bot]

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

Unsure of the expected behaviour here but if people admins should not be able to create company agents then it's a simple local permissions update and I'll ask Melvin to create a proposal.

If they should then it's a backend issue.

🎀👀🎀 C+ reviewed

Ollyws avatar Nov 25 '26 17:11 Ollyws

Triggered auto assignment to @Gonals, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@Gonals Huh... This is 4 days overdue. Who can take care of this?