Skip to content

Group personal and company agents in Account Settings - #103788

Merged
yuwenmemon merged 28 commits into
Expensify:mainfrom
s77rt:company-agent-split-agents-sections
Oct 18, 2026
Merged

yuwenmemon merged 28 commits into
Expensify:mainfrom
s77rt:company-agent-split-agents-sections

Conversation

@s77rt

@s77rt s77rt commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

This is based on #103486 so let's get that one merged first

Explanation of Change

Added Owner column to Agents table

Fixed Issues

$ #101123
PROPOSAL:

Tests

Test 1: Agent "Owner" column

  • Have an account with agents
  1. Go to Agents
  2. Verify there is a "Owner" column
Screenshot 2026-10-12 at 4 37 03 PM

Test 2: Copilot removal

  • Have two accounts (Account A and Account B)
  1. Account A: Add Account B as copilot
  2. Account B: Switch to copilot mode to Account A
  3. Account A: Remove Account B from being a copilot
  4. Account B: Verify you are logged out back to your account
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

Same as Tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@s77rt
s77rt marked this pull request as ready for review October 12, 2026 15:40
@s77rt
s77rt requested review from a team as code owners October 12, 2026 15:40
@melvin-bot
melvin-bot Bot requested a review from linhvovan29546 October 12, 2026 15:40
@melvin-bot

melvin-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

@linhvovan29546 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested review from dylanexpensify and removed request for a team October 12, 2026 15:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-12T15:56:44.558060Z a51cbf0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/hooks/useWorkspaceAgents.ts 0.00% <ø> (ø)
...s/Navigation/AppNavigator/DelegatorConnectGate.tsx 88.23% <ø> (ø)
src/libs/actions/Delegate.ts 66.97% <100.00%> (+0.15%) ⬆️
src/pages/settings/Agents/AgentsPage.tsx 94.28% <100.00%> (ø)
src/pages/workspace/WorkspaceAgentsPage.tsx 0.00% <0.00%> (ø)
src/DelegateAccessHandler.tsx 88.57% <70.00%> (-4.77%) ⬇️
src/selectors/Policy.ts 87.50% <40.00%> (-1.22%) ⬇️
src/components/Tables/AgentsTable/index.tsx 0.00% <0.00%> (ø)
...c/components/Tables/AgentsTable/AgentsTableRow.tsx 85.00% <68.42%> (-15.00%) ⬇️
src/hooks/useAgents.ts 62.65% <36.36%> (-4.02%) ⬇️
... and 11 files with indirect coverage changes

Comment thread src/hooks/useWorkspaceAgents.ts Resolved
@s77rt
s77rt requested a review from linhvovan29546 October 16, 2026 17:44
@linhvovan29546

Copy link
Copy Markdown
Contributor

Bug: This is unrelated to the current PR but was introduced in a [previous PR](#103486). I noticed that the role column is not aligned with the table header.
Screenshot 2026-10-17 at 17 22 09

@linhvovan29546

Copy link
Copy Markdown
Contributor

@MelvinBot Review

@MelvinBot

Copy link
Copy Markdown
Contributor

Follow-up review (4 new commits, up to 0d9f439b)

The new commits fix most of my earlier findings. One edge case from the blocker remains. I also found the cause of the Role column misalignment you reported.

✅ Fixed

  • Second disconnect: the restored !delegate early return stops the extra disconnect() call on a normal copilot exit or sign-out.
  • Dead type: WithOldDotFlag and the isFromOldDot uses are removed.
  • Policy lookup: the lookup now builds a map once instead of scanning all policies for each agent.

🟡 Still open: a missed disconnect is not retried after a reload

src/DelegateAccessHandler.tsx:34-49

Here is how it can happen:

  1. A copilot is removed while connected.
  2. The disconnect doesn't finish, because the app is killed or the request fails.
  3. On the next launch, usePrevious starts with the current value, so wasDelegateInDelegatesList is false.
  4. The effect returns early, and the removed copilot stays connected.

The code before this PR retried on every mount. The fix I suggested before still applies: exempt company-owned agents with an explicit check, not the transition. If the server already revokes the copilot token in this case, the risk is small, but please confirm that.

🐛 Role column misalignment (from the previous PR, easy to fix here)

The Role cell renders WorkspaceMemberRoleCell, and that cell wraps the label in EditableCell. EditableCell adds editableCellPadding plus a transparent border, so the value sits inset from its column. WorkspaceMembersTable handles this by giving the Role header styling: {containerStyles: [styles.editableCellHeader]} (WorkspaceMembersTable/index.tsx:135-138). The Agents Role column doesn't do this (AgentsTable/index.tsx:110-118), so its header label sits to the left of the values.

Fix: add styling: {containerStyles: [styles.editableCellHeader]} to the role column definition. I haven't checked this in the app.

🟡 Minor, unchanged

  • Copy: `${translate('common.owner')}: ${owner}` still builds the label by hand, so the colon can't be localized (AgentsTableRow.tsx:54).
  • Naming: groupByPolicyAccountIDPoliciesSelector returns one policy per key, not a group, and it isn't used as an Onyx selector. A name like getPoliciesByPolicyAccountID would describe it better (selectors/Policy.ts:579).
  • Tests: no test yet covers the DelegateAccessHandler behavior change.

view run

@linhvovan29546

linhvovan29546 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

@MelvinBot Please check this bug as well: #103788 (comment)

@MelvinBot

Copy link
Copy Markdown
Contributor

Confirmed: the Role header is missing the padding that the Role cell has. The fix is one line in the column definition.

Cause: the Role cell renders WorkspaceMemberRoleCell, which wraps the label in EditableCell. That cell adds 4px of padding and a 1px transparent border, so the role text starts about 5px to the right of the column edge. The Agents role column has no matching header style, so the "Role" label sits 5px to the left of the values (AgentsTable/index.tsx:112-117).

WorkspaceMembersTable uses the same cell and aligns correctly, because its header adds styles.editableCellHeader (WorkspaceMembersTable/index.tsx:135-138). That style has the same padding and border as the cell.

Fix: add the same styling to the Agents role column:

{
    key: 'role' as const,
    label: translate('common.role'),
    sortable: true,
    width: variables.workspaceMembersRoleColumnWidth,
    styling: {
        // editableCellHeader matches the padded role cell so the label and value share an edge.
        containerStyles: [styles.editableCellHeader],
    },
},

I'd also restore styles.editableCellColumn on the Role cell in AgentsTableRow.tsx:119, to match WorkspaceMembersTableRow. This PR removed it. It controls vertical stretch, not the horizontal offset, so it isn't the cause of this bug.

The new Owner column has no padded cell, so it doesn't need this style. main has the same bug, from [Payment due @linhvovan29546] [No QA] Add WorkspaceAgentsPage. I confirmed the cause in code but did not test the fix in the app.


view run

@linhvovan29546

Copy link
Copy Markdown
Contributor

I see some changes related to delegates. Are they related to this PR? I feel they may require more testing, so it might be better to move them to a separate PR.

@s77rt I’m still not clear on this. Could you please clarify?

@s77rt

s77rt commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

I see some changes related to delegates. Are they related to this PR? I feel they may require more testing, so it might be better to move them to a separate PR.

I’m still not clear on this. Could you please clarify?

The change is needed for the company-agent in general. The manager of company-agent can copilot into the agent without an explicit copilot share. The code on main does check for that explicit share and if it's not found the user is logged out.

@linhvovan29546

Copy link
Copy Markdown
Contributor

I see some changes related to delegates. Are they related to this PR? I feel they may require more testing, so it might be better to move them to a separate PR.

I’m still not clear on this. Could you please clarify?

The change is needed for the company-agent in general. The manager of company-agent can copilot into the agent without an explicit copilot share. The code on main does check for that explicit share and if it's not found the user is logged out.

How can I create a company agent? I assume it should be possible to create one here, rather than in the current PR. So, it looks like we don't have a way to create one right now.

@s77rt

s77rt commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

On the next launch, usePrevious starts with the current value, so wasDelegateInDelegatesList is false.
The effect returns early, and the removed copilot stays connected.

This is not really an issue. Once you reconnect (or take any action) the BE will return that the session is expired and you will be logged out back to your account

@s77rt

s77rt commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

How can I create a company agent? I assume it should be possible to create one #103817, rather than in the current PR. So, it looks like we don't have a way to create one right now.

Yes, you can create a company agent on that PR (the BE changes are already live so you can switch to that and create an agent for testing)

Let's keep that change here though because there is another backend PR held on this (and on the fix here). Also the other App PR will get merged next so it does not matter much

@linhvovan29546

linhvovan29546 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • [x ] Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
Screen.Recording.2026-10-17.at.21.58.39.mov
iOS: HybridApp
Screen.Recording.2026-10-17.at.22.04.27.mov
iOS: mWeb Safari
Screen.Recording.2026-10-17.at.21.55.07.mov
MacOS: Chrome / Safari
Screen.Recording.2026-10-17.at.21.44.22.mov
Screen.Recording.2026-10-17.at.21.44.38.mov

@linhvovan29546 linhvovan29546 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s77rt NAB: Could you please add a test step for switching Copilot to the PR description so QA doesn't miss it when this lands in staging?

@melvin-bot
melvin-bot Bot requested review from puneetlath and yuwenmemon October 17, 2026 15:09
@yuwenmemon
yuwenmemon merged commit adb2c02 into Expensify:main Oct 18, 2026
37 of 39 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 yuwenmemon has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/yuwenmemon in version: 9.5.14-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.5.14-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants