Skip to content

[No QA] Add RBR to workspace agents + Prepare for 1:1:1 - #104800

Open
s77rt wants to merge 27 commits into
Expensify:mainfrom
s77rt:company-agents-beta-label
Open

s77rt wants to merge 27 commits into
Expensify:mainfrom
s77rt:company-agents-beta-label

Conversation

@s77rt

@s77rt s77rt commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Explanation of Change

  • Added RBR to workspace agents option
  • Split useAgents and useWorkspaceAgents to useAgents/useAgentsTable and useWorkspaceAgents/useWorkspaceAgentsTable

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/694594
https://github.com/Expensify/Expensify/issues/694677
PROPOSAL:

Tests

(Not for QA)

  1. Merge agent errors to Onyx e.g. Onyx.merge('agent_7363', {promptErrors: {"1": "test"}})
  2. Go to Workspace
  3. Verify there is a RBR in the Agents option
Screenshot 2026-10-22 at 9 40 01 PM
  • Verify that no errors appear in the JS console

Offline tests

n/a

QA Steps

n/a

  • 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 22, 2026 20:42
@s77rt
s77rt requested review from a team as code owners October 22, 2026 20:42
@melvin-bot
melvin-bot Bot requested a review from hoangzinh October 22, 2026 20:42
@melvin-bot

melvin-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

@hoangzinh 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 removed the request for review from a team October 22, 2026 20:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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 ✅ Completed 2026-10-22T20:58:33.375776Z 1e8b902 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.

@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and removed request for a team October 22, 2026 20:43
@s77rt
s77rt requested review from linhvovan29546 and removed request for hoangzinh October 22, 2026 20:43
Comment thread src/pages/settings/useInitialSettingsPageMenuData.ts Outdated
const canReadVendors = canMemberRead(policy, currentUserLogin ?? '', CONST.POLICY.POLICY_FEATURE.VENDORS);
usePolicyConnectionsPrefetch(policy, canReadVendors);

const {agents: policyAgents} = useWorkspaceAgents(policy, false);

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.

❌ PERF-11 (docs)

useWorkspaceAgents(policy, false) subscribes (via useAgents) to the whole AGENT and POLICY collections without selectors and builds the full workspaceAgents row array (joined with workspace members, with per-agent closures) on every render. WorkspaceInitialPage only forwards policyAgents to getWorkspaceMenuItems, which reduces it to a single boolean hasAgentsError = policyAgents?.some((agent) => agent.errors). Materializing the entire agents array just to compute one brick-road boolean forces an expensive recompute on every write to those collections.

Derive the boolean with a scalar selector over the AGENT collection (scoped to the policy's agents) and pass that boolean into getWorkspaceMenuItems instead of the full array, so Onyx only compares a primitive:

const [hasAgentsError] = useOnyx(ONYXKEYS.COLLECTION.AGENT, {
    selector: (agents) => Object.values(agents ?? {}).some((agent) => /* agent belongs to this policy && has errors */),
});

Reviewed at: 2fe4a2f | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The agent collection is not an issue. The policy collection is an issue indeed. I will handle that here https://github.com/Expensify/Expensify/issues/694677

Comment thread src/pages/workspace/getWorkspaceMenuItems.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e8b9024b5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/pages/workspace/WorkspaceInitialPage.tsx Outdated
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/hooks/useWorkspaceMembers.ts 94.73% <100.00%> (+5.08%) ⬆️
src/pages/settings/Agents/AgentsPage.tsx 94.44% <100.00%> (+0.15%) ⬆️
...c/pages/settings/useInitialSettingsPageMenuData.ts 87.00% <100.00%> (ø)
src/pages/workspace/WorkspaceInitialPage.tsx 86.72% <100.00%> (+0.23%) ⬆️
src/pages/workspace/getWorkspaceMenuItems.ts 98.51% <100.00%> (+0.01%) ⬆️
src/libs/AgentUtils.ts 91.66% <91.66%> (ø)
src/pages/workspace/WorkspaceMembersPage.tsx 79.16% <90.90%> (+0.26%) ⬆️
src/hooks/useAgents.ts 85.71% <84.61%> (+23.06%) ⬆️
src/pages/workspace/DynamicWorkspaceInvitePage.tsx 0.00% <0.00%> (ø)
src/pages/workspace/WorkspaceAgentsPage.tsx 0.00% <0.00%> (ø)
... and 3 more
... and 7 files with indirect coverage changes

@JmillsExpensify JmillsExpensify 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.

LGTM

const canReadVendors = canMemberRead(policy, currentUserLogin ?? '', CONST.POLICY.POLICY_FEATURE.VENDORS);
usePolicyConnectionsPrefetch(policy, canReadVendors);

const {agents: policyAgents} = useWorkspaceAgents(policy, false, false);

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.

The false, false flags only skip the API calls, so the whole derivation still runs here on every render:

  • useWorkspaceMembers subscribes to useAllPersonalDetails() + usePersonalDetailsByLogins(employeeList) and loops over the entire employeeList
  • useAgents subscribes to COLLECTION.AGENT, COLLECTION.POLICY, personal details, and mounts useChatWithAgent, useSwitchToDelegator, useConfirmModal, useRuleBotGuardModal plus a highlight effect on a tableRef that is never attached
  • useWorkspaceAgents does workspaceMembers.find(...) once per agent, so O(agents × members)

This also runs for users who never see the Agents row, since it's gated by isGroupPolicy && canReadPolicyFeature(AGENTS) && isCompanyAgentsBetaEnabled && !isAgentAccount in getWorkspaceMenuItems.

On a workspace with thousands of members, any personal details or policy collection update now re-renders this page and redoes the member join. Before, this page didn't subscribe to any of that.

The RBR only needs a boolean, and the read-only rows that useWorkspaceAgents pushes never carry errors. Could we extract the error merge from useAgents into a pure helper (e.g. getAgentErrors(agent) in a lib) and use a boolean selector instead?

const [hasAgentsError] = useOnyx(ONYXKEYS.COLLECTION.AGENT, {
    selector: (agents) =>
        Object.entries(agents ?? {}).some(([key, agent]) => {
            const accountID = Number(key.slice(ONYXKEYS.COLLECTION.AGENT.length));
            const isInWorkspace = agent?.ownerAccountID === workspaceAccountID || memberAccountIDs.has(accountID);
            return isInWorkspace && !!getAgentErrors(agent);
        }),
});

useAgents would call getAgentErrors too, so there's still a single source of truth.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have updated the hooks, now useWorkspaceAgents use less data. Only biggest part now is useWorkspaceMembers subscribing to the personalDetailsList. Not sure if it's an issue given that the workspace members page already do the same or if we should split the manageable/non-manageable agents hooks

I still want to keep useAgents instead of using useOnyx to avoid duplicating the "deleted agents" filter

const [hasAgentErrors] = useOnyx(ONYXKEYS.COLLECTION.AGENT, {
selector: (agents) => Object.values(agents ?? {}).some((agent) => !isEmptyObject(agent?.nameErrors) || !isEmptyObject(agent?.promptErrors) || !isEmptyObject(agent?.avatarErrors)),
});
const {agents} = useAgents(false);

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.

The old selector returned a boolean, so this hook only re-rendered when the boolean flipped. With useAgents(false), it now re-renders on every COLLECTION.AGENT / COLLECTION.POLICY / personal details change and rebuilds all agent rows (with closures). This hook backs the Account tab, which is always mounted on wide layouts.

There are also two behavior changes the description doesn't mention:

  1. useAgents drops agents without personal details (if (!details) return [];), so an agent with nameErrors/promptErrors whose personal details aren't loaded no longer shows an RBR here.
  2. Generic agent.errors now counts (create failure agentsPage.error.genericAdd, delete failure common.genericErrorMessage in Agent.ts). The old selector ignored these. This is probably desirable, but can you confirm it's intended?

With a shared getAgentErrors(agent) helper (see my comment on WorkspaceInitialPage), this can stay a cheap selector:

const [hasAgentErrors] = useOnyx(ONYXKEYS.COLLECTION.AGENT, {
    selector: (agents) => Object.values(agents ?? {}).some((agent) => !!getAgentErrors(agent)),
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated the hook, now useAgents only subscribes to the agent collection. I think this is still fine as agents are not supposed to be that many or change often

Comment thread src/pages/workspace/getWorkspaceMenuItems.ts Outdated
Comment thread src/hooks/useAgents.ts Outdated
Comment thread tests/ui/WorkspaceInitialPageTest.tsx Outdated
screenName: SCREENS.WORKSPACE.AGENTS,
sentryLabel: CONST.SENTRY_LABEL.WORKSPACE.INITIAL.AGENTS,
badgeTranslationKey: 'common.beta',
brickRoadIndicator: hasAgentsError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,

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.

Question: getPolicyBrickRoadIndicatorStatus (PolicyUtils/errors.ts) doesn't include agent errors, so this RBR shows on the Agents row but not on the workspace row in the Workspaces list or the Workspaces tab. Categories behave the same way today, so this isn't blocking. Is that the expected scope for this issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wanted to fix this but it requires subscribing to policy members too. Probably NAB. I have added RBR to the Account tab (since agents can be found in Account > Agents too) so the agents errors are not hidden (even if the policy does not include them).

@s77rt s77rt changed the title [No QA] Add RBR to workspace agents [No QA] Add RBR to workspace agents + Prepare for 1:1:1 Oct 25, 2026
@melvin-bot

melvin-bot Bot commented Oct 25, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx bun ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx bun ./scripts/generateTranslations.ts --compare-ref main

@s77rt

s77rt commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

I have done some refactor. I think I will also remove useAgents hook (since it's almost same as useOnyx). Will do that tomorrow

This branch has not been deployed

No deployments
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.

3 participants