[$175] WS Settings - Error message when creating an agent with a People Admin
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:
- Launch new expensify logged in as a People Admin of a WS (or invite your user as one from another account)
- Go to WS > Open the WS where you are People Admin
- Open Agents > New Agent
- Select any of the available options > Confirm
- 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
Applause Internal Information Exported by: Alberto Gutierrez Bug ID: 7320329
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022124254006507039510
- Upwork Job ID: 2124254006507039510
- Last Price Increase: 2026-11-21
Issue Owner
Current Issue Owner: @Gonals
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
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
- permissions.ts:124–131 explicitly grants People Admins Agents write access.
- WorkspaceAgentsPage.tsx:89–110 gates both creation entry points on that permission.
- Agent.ts:210–216 sends
CreateCompanyAgentwith optimistic updates. - DynamicAddAgentPage.tsx:206–235 navigates after a local write rather than server confirmation.
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.
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?
- 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.
- 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.
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]insrc/libs/PolicyUtils/permissions.tsgives People AdminsAGENTS: WRITE. WorkspaceAgentsPageuses that permission to show the New agent button, andDynamicAddAgentPageuses it to allow the form. So a People Admin can fill the form and fireCreateCompanyAgent.- 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. createCompanyAgentwrites the agent optimistically and navigates away before the server answers. WhenCreateCompanyAgentis rejected for the People Admin, thefailureDataputs the genericagentsPage.error.genericAdderror 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.
- In
permissions.ts, changePEOPLE_ADMIN'sAGENTSaccess fromWRITEtoREAD. People Admins keep seeing the Agents page (getWorkspaceMenuItemsonly needs read access), but:- the New agent button and the empty-state button disappear (
canWriteAgentsis false), and DynamicAddAgentPageblocks a direct link to the add flow, because it already checkscanWriteAgents.
- the New agent button and the empty-state button disappear (
- Update the one line in
Create-and-Use-Agents.mdso 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)isfalseandcanMemberRead(...)istrueon a Control workspace.WorkspaceAgentsPageshows 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! 📣 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:
- Make sure you've read and understood the contributing guidelines.
- 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.
- 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.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01e1a10b20c43f3060
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
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
CreateCompanyAgentfor People admins regardless of role. - The App still grants People admins
AGENTS: WRITE(ROLE_PERMISSION_BUNDLES[PEOPLE_ADMIN]insrc/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! 📣 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:
- Make sure you've read and understood the contributing guidelines.
- 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.
- 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.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
@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
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?