Skip to content

[Due for payment 2026-08-07] Agents - Wrong avatar is shown on the template agent after refreshing page #97388

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.46-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #95991
Email or phone of affected tester (no customers): iosjdnojsdoijdisojiso@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.5 / Chrome
App Component: User Settings

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to Account > Agents.
  3. Click New agent.
  4. Click Add on TipMaster.
  5. Refresh the page.
  6. Click RHP back button.
  7. Click Add on Translator Tess.
    → Blue avatar is shown instead of green avatar.
  8. Click RHP back button.
  9. Click Add on Translator Tess.
    → The correct green avatar is shown when reopening Translator Tess for the second time.

Expected Result:

In Step 7, after refreshing page and changing agent template, correct avatar will be shown for the selected template.

Actual Result:

In Step 7, after refreshing page and changing agent template, the previous avatar is shown for newly selected template.
In Step 9, the correct green avatar is shown when reopening Translator Tess for the second time.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7221274_1785359499375.3.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Svetlana Lazutkina
Bug ID: 7221274

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. applause-bot commented on Jul 29, 2026

    @applause-bot
    Author

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

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jul 29, 2026
  3. melvin-bot commented on Jul 29, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #95991

  4. melvin-bot commented on Jul 29, 2026

    @melvin-bot

    @yuwenmemon @gijoe0295 you have been assigned to this deploy blocker because you reviewed the offending PR: #95991

  5. melvin-bot commented on Jul 29, 2026

    @melvin-bot

    @shubham1206agra you have been assigned to this deploy blocker because you authored the offending PR: #95991

  6. melvin-bot commented on Jul 29, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  7. github-actions commented on Jul 29, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  8. MelvinBot commented on Jul 29, 2026

    @MelvinBot
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #95991 - "Add agent template picker structure" by shubham1206agra (High confidence)
    Related Issues: #94394 (feature issue this PR implemented)

    Recommendation: ROLL FORWARD

    This is a brand-new feature (not in production) and the root cause is a small, self-contained avatar-draft seeding bug. A targeted one-line fix (clear the stale avatar draft when a template is picked) is far safer than reverting the entire 14-commit feature PR. The bug is also cosmetic and self-heals on the second open, so a quick roll-forward fix is appropriate.

    Assigned: shubham1206agra (PR author), gijoe0295 and yuwenmemon (approving reviewers) — already assigned to this issue.
    Labels: No changes. Kept DeployBlockerCash (App/frontend deploy is blocked). DeployBlocker was not present, so nothing to remove.

    📋 Detailed Analysis

    Evidence

    • PR Add agent template picker structure #95991 introduced the entire Agents template-picker feature, including all three files in the failing flow: src/pages/settings/Agents/NewAgentPage.tsx, src/pages/settings/Agents/AddAgentPage.tsx, and src/libs/actions/Agent.ts.
    • It is line 60 of the current StagingDeployCash checklist (Deploy Checklist: New Expensify 2026-07-29 #97375), merged 2026-07-28, and the issue confirms the feature does not exist in production — matching "Reproducible in production?: N/A - new feature."
    • The reported symptom (avatar tied to the template preset color is stale on the first open after a refresh, correct on the second open) maps directly to the avatar-draft seeding logic this PR added.

    Verification

    Affected files, all authored by this PR:

    • src/pages/settings/Agents/AddAgentPage.tsx — derives the displayed avatar from the persisted draft and seeds it.
    • src/pages/settings/Agents/NewAgentPage.tsx — stashes the picked template and navigates into the builder.
    • src/libs/actions/Agent.ts — setNewAgentTemplate / setNewAgentAvatarPreset / clearNewAgentAvatarDraft Onyx writers.

    The avatar on the Add screen is driven only by the persisted Onyx draft AGENT_NEW_AVATAR_DRAFT, not by the selected template directly:

    Root Cause

    The seed effect writes the template's preset into the draft only when no draft already exists:

    • AddAgentPage.tsx#L73-L83 — the guard if (hasSeededRef.current || isDraftLoading || avatarDraft) { return; } bails whenever any draft is present. It never reconciles the draft against a newly-selected template.

    AGENT_NEW_AVATAR_DRAFT is a single global Onyx key that is intentionally designed to survive a page refresh (see the comment at lines 70–72 and setNewAgentAvatarPreset/clearNewAgentAvatarDraft in Agent.ts#L357-L370). It is cleared in only two places: on submit (AddAgentPage.tsx#L123) and in the useBeforeRemove cleanup when the user backs out without submitting (AddAgentPage.tsx#L92-L100).

    Step-by-step for the repro:

    1. Add TipMaster → NEW_AGENT_TEMPLATE = TipMaster, builder seeds AGENT_NEW_AVATAR_DRAFT = TipMaster's (blue) preset. Correct.
    2. Refresh on the Add RHP. The draft is meant to survive the refresh, so blue persists.
    3. Tap the RHP back button. The cleanup that would clear the draft runs through useBeforeRemove, which relies on React Navigation's beforeRemove event — a mechanism the hook itself flags as limited (useBeforeRemove.tsx). After a hard refresh into the deep-linked RHP, the back-navigation does not reliably fire beforeRemove for the refreshed screen, so clearNewAgentAvatarDraft() never runs and the blue draft leaks.
    4. Tap Add on Translator Tess → NEW_AGENT_TEMPLATE = Translator Tess (green). The builder re-opens, but the stale blue draft is still in Onyx, so the seed guard bails (avatarDraft is truthy) and selectedPresetID resolves to the leftover blue ID → wrong avatar.
    5. Backing out again now fires beforeRemove normally (no refresh in play), clearing the draft. Re-opening Translator Tess seeds green correctly — which is exactly why the second open is right.

    The underlying flaw: the avatar draft is a global key not scoped to the selected template, and the seed logic conflates "a draft exists" with "the user deliberately chose this avatar," so a leftover draft from a previous template silently overrides the newly-picked template's avatar.

    Suggested targeted fix (roll forward)

    Clear the leftover draft at the two points where the user deliberately starts a fresh builder session, in NewAgentPage.tsx#L94-L106 (handleBuildCustomAgent and handleAddTemplate): call clearNewAgentAvatarDraft() alongside setting/clearing the template before navigating. This resets the avatar per template selection while still letting the draft survive a mid-session refresh, since picking a template is a distinct user action from a refresh. Alternatively, make the seed effect reconcile the draft's preset against template.avatarID when the user has not explicitly overridden the avatar.


    Next Steps: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  9. 12 remaining items

  10. melvin-bot commented on Aug 3, 2026

    @melvin-bot

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

  11. shubham1206agra commented on Aug 4, 2026

    @shubham1206agra
    Contributor

    @yuwenmemon You can close this issue

  12. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Aug 4, 2026
  13. melvin-bot commented on Aug 6, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  14. melvin-bot commented on Aug 6, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
  15. shubham1206agra commented on Aug 7, 2026

    @shubham1206agra
    Contributor

    @mallenexpensify Nobody is required payment here

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions