Skip to content

[Payment due @parasharrajat] Gate AgentZero indicators on personalDetails.isCustomAgent - #92807

Merged
yuwenmemon merged 1 commit into
mainfrom
yuwen-app-is-custom-agent-from-server
Jun 11, 2026
Merged

yuwenmemon merged 1 commit into
mainfrom
yuwen-app-is-custom-agent-from-server

Conversation

@yuwenmemon

@yuwenmemon yuwenmemon commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

@inimaga please review
cc @iwiznia

Explanation of Change

Follow-up to #90751. Replaces the App-side custom-agent detection (which subscribed to the full SHARED_NVP_AGENT_PROMPT Onyx collection and required a wasted OpenAgentsPage call on every auth init) with a per-account flag the server now stamps on personalDetails.

Backend half: Auth#22080 — Account::formatNewDotPersonalDetails adds isCustomAgent: true to known-user payloads whenever Agent::getOwnerAccountID > 0. The flag rides every personalDetails response (OpenReport, OpenApp, ReconnectApp, GetPersonalDetailsForEmails, etc.), so the App's gate can read it off the participant's existing personalDetails entry — no extra fetch, no extra subscription.

Marked draft until Auth#22080 merges + deploys. Without the server side, the gate never sees isCustomAgent: true and custom-agent chats stop firing the indicator.

Addresses Puneet's review comment on the previous PR.

Changes

  • src/types/onyx/PersonalDetails.ts — adds isCustomAgent?: boolean alongside the existing per-account flags.
  • src/selectors/AgentZeroChat.ts — drops getAgentAccountIDFlags. Adds getCustomAgentParticipantAccountID(participantAccountIDs) — a parameterized selector that iterates only the report's participants against personalDetailsList and returns the first agent's accountID (or undefined). Output is a primitive, so deepEqual short-circuits cheaply and re-renders fire only when an agent participant's flag actually flips.
  • src/pages/inbox/AgentZeroStatusContext.tsx + src/pages/inbox/ConciergeDraftContext.tsx — swap the gate from a SHARED_NVP_AGENT_PROMPT collection subscription to the new selector. Same gate semantics, narrower subscription.
  • src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx — removes the openAgentsPage() auth-init call (and its import). Every user paid one wasted API call per session even if they never interacted with an agent. Settings → Agents still calls openAgentsPage() on its own mount.
  • tests/ui/AuthScreensInitHandlerTest.tsx — removes the matching @userActions/Agent mock that was only there to stub the auth-init call.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/636271

Tests

Requires Auth#22080 deployed.

  1. Sign out, then sign in fresh (so SHARED_NVP_AGENT_PROMPT is empty and OpenAgentsPage is not auto-called).
  2. Open a custom-agent DM from inbox / deep link / search bar.
  3. Send a message. Verify within ~1s:
    • Thinking indicator appears under the agent's avatar.
    • Draft body streams character-by-character during LLM generation.
    • Indicator clears when the response lands.
  4. Sanity: open a Concierge DM. Verify thinking + draft streaming still works under Concierge's avatar (regression check).
  5. Settings → Agents still loads the agent list (it owns its own openAgentsPage call on mount).
  6. DevTools → Network during fresh sign-in: no OpenAgentsPage request.
  7. Verify no errors appear in the JS console.

Offline tests

Custom-agent DM opened while offline shows nothing extra (PersonalDetails arrives once the connection comes back; gate evaluates on the next render).

QA Steps

Same as Tests. Custom-agent feature is gated behind BETAS.CUSTOM_AGENT — QA testers need that beta on their account.

  • Verify 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 tested this PR with a High Traffic account

@yuwenmemon
yuwenmemon force-pushed the yuwen-app-is-custom-agent-from-server branch from 324672f to c28e593 Compare June 9, 2026 21:57
@yuwenmemon
yuwenmemon requested a review from inimaga June 9, 2026 23:23
@yuwenmemon
yuwenmemon marked this pull request as ready for review June 9, 2026 23:23
@yuwenmemon
yuwenmemon requested review from a team as code owners June 9, 2026 23:23
@melvin-bot
melvin-bot Bot requested review from parasharrajat and removed request for a team June 9, 2026 23:23
@melvin-bot

melvin-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

@parasharrajat 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 flaviadefaria and removed request for a team June 9, 2026 23:23
@yuwenmemon

Copy link
Copy Markdown
Contributor Author

@inimaga @parasharrajat bump please!

// Hydrate the user's custom-agent prompts so AgentZeroStatusProvider can recognize
// custom-agent chats opened directly from a deep link or right after sign-in, without
// requiring a prior visit to Settings > Agents.
openAgentsPage();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why are we removing this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see that we don't need it now.

@parasharrajat

parasharrajat commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

Send a message. Verify within ~1s:

For me, it takes some time. I am on a bit slow internet.

12.06.2026_00.37.59_REC.mp4

@parasharrajat parasharrajat left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
    • 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 proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • 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 a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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

🔲 iOS / native

12.06.2026_00.55.08_REC.mp4

🔲 iOS / Safari

12.06.2026_00.57.23_REC.mp4

🔲 MacOS / Chrome

12.06.2026_00.37.59_REC.mp4

🔲 Android / native

12.06.2026_00.51.36_REC.mp4

🎀 👀 🎀 C+ reviewed

@parasharrajat

Copy link
Copy Markdown
Member

Looks good. I think LLM response time has nothing to do with this PR so approved.

@melvin-bot melvin-bot Bot changed the title Gate AgentZero indicators on personalDetails.isCustomAgent [Payment due @parasharrajat] Gate AgentZero indicators on personalDetails.isCustomAgent Jun 11, 2026
@melvin-bot

melvin-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🎯 @parasharrajat, thanks for reviewing and testing this PR! 🎉

A payment issue will be created for your review once this PR is deployed to production.
E/E issue linked to the PR - https://www.github.com/Expensify/Expensify/issues/636271.

If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created.

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

Changes look good.

@inimaga

inimaga commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@yuwenmemon looking at the flow, I think there might still be one issue to fix, perhaps in a follow-up PR.

At present, Workflows still uses SHARED_NVP_AGENT_PROMPT to find the agents owned by the current user. So after this change, a user can sign in fresh, go straight to Workspace > Workflows, press Add agent, and that data may not be loaded yet. In which case we would treat “not loaded yet” the same as “no agents exist”, and send them to create a new agent even if they already have one.

I think a good fix would be to load owned agents only on screens that need them, with a shared hook like useOwnedAgents(). That hook can then call openAgentsPage() on mount, build the owned agents list from SHARED_NVP_AGENT_PROMPT + personalDetails, and expose a loading state. So Workflows can wait for that load before deciding whether to use an existing agent or open the create-agent page.

@yuwenmemon
yuwenmemon merged commit 3021695 into main Jun 11, 2026
41 of 42 checks passed
@yuwenmemon
yuwenmemon deleted the yuwen-app-is-custom-agent-from-server branch June 11, 2026 23:03
@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 OSBotify mentioned this pull request Jun 11, 2026
60 tasks done
@OSBotify

Copy link
Copy Markdown
Contributor

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

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Help site review: no changes required.

I reviewed the changes in this PR against the help articles under App/docs/articles. No documentation updates are needed, so I have not created a draft PR.

Why this is doc-neutral

This PR is an internal architecture/performance refactor with no user-facing behavior change:

  • Swaps the App-side custom-agent gate from a SHARED_NVP_AGENT_PROMPT Onyx collection subscription to the server-stamped personalDetails.isCustomAgent flag (src/selectors/AgentZeroChat.ts, src/pages/inbox/AgentZeroStatusContext.tsx, src/pages/inbox/ConciergeDraftContext.tsx).
  • Removes a wasted openAgentsPage() call at auth init (src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx).
  • Adds the isCustomAgent?: boolean type (src/types/onyx/PersonalDetails.ts) and drops the now-unused test mock.

The thinking indicator and draft-streaming behavior, the Settings → Agents page, and every feature/label a member sees are all unchanged — only the under-the-hood detection mechanism moved. None of this touches anything described in the AgentZero or MCP help articles.

Articles checked
  • App/docs/articles/Unlisted/AgentZero-Upcoming-Features.md — internal roadmap reference; this PR ships no new user-facing feature to add here.
  • App/docs/articles/Unlisted/MCP-Server-Capability-Guide.md — covers MCP server capabilities, unrelated to this gating refactor.

Neither article documents the internal custom-agent detection mechanism that this PR changes.

@yuwenmemon, since no user-facing behavior changed, no help site PR was created. If you believe a member-facing doc should be updated for the custom-agent feature, let me know and I'll draft one.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.6-4 🚀

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

@melvin-bot

melvin-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #93477

@quinthar quinthar added the #ai label Aug 11, 2026
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.

6 participants