Skip to content

Fix: return to Agents list when tapping back on a newly created agent DM - #97868

Merged
mjasikowski merged 2 commits into
mainfrom
claude-agentDmBackReturnsToAgents
Aug 27, 2026
Merged

mjasikowski merged 2 commits into
mainfrom
claude-agentDmBackReturnsToAgents

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

On narrow (native) layouts, creating an agent revealed the new DM as a fullscreen report and then dismissed the entire Settings → Agents → New agent modal stack (revealRouteBeforeDismissingModal). That left the Agents list off the back stack, so tapping back on the agent chat fell through to the LHN instead of returning to Agents.

This passes a backTo param pointing at the Agents list (ROUTES.SETTINGS_AGENTS) when revealing the DM, so the report header's back button (ReportHeader.onBackButtonPressNavigation.goBack(backTo)) returns to the Agents list as expected.

Wide layouts are unchanged: they already open the DM inside the RHP (AGENT_REPORT with forceReplace) and correctly return to Agents. Only the narrow-layout branch is affected. Follow-up to #95631.

Fixed Issues

$ #97832
PROPOSAL:

Tests

On a narrow layout or mobile native:

  1. Go to Account > Agents.
  2. Tap New agent and create a new agent.
  3. You land on the new agent DM chat. Tap the back button in the chat header.
  4. Verify you return to the Agents list (not the LHN / report list).
  5. On a wide layout, repeat and verify closing the agent DM still returns to the Agents list (no regression).
  • Verify that no errors appear in the JS console

Offline tests

Same as tests — the agent create + navigation flow is fully optimistic and works online or offline.

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 followed proper code patterns (see Reviewing the code)
    • 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 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • 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 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 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.
  • 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.

See checklist for screenshots

… DM (narrow)

Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@mjasikowski

Copy link
Copy Markdown
Contributor

@MelvinBot back to agent list works fine, but tapping the newly created agent row redirects to "hmm it's not here" page after a second or two

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Issue Analysis

Root cause: The newly-created agent row is keyed on a throwaway optimistic accountID. When CreateAgent responds (~1–2s later), the real agent arrives under a server-assigned accountID and the optimistic record is deleted — so EditAgentPage, which is pinned to the now-deleted optimistic accountID, falls into its not-found branch ("hmm… it's not here").

This is separate from and pre-existing relative to this PR — the diff here only touches AddAgentPage's backTo param, not the row → edit navigation. So the back-button fix is good; this is a different bug in the agent-creation flow (from #95631) that surfaces once you can reliably get back to the Agents list.

The chain:

  1. createAgent generates a client-side optimisticAccountID and writes the optimistic row + personal detail under it — Agent.ts:50.
  2. The Agents list renders that row and navigates on tap to SETTINGS_AGENTS_EDIT.getRoute(accountID) using the optimistic accountID — AgentsPage.tsx:119.
  3. On success, successData nulls PERSONAL_DETAILS_LIST[optimisticAccountID] and SHARED_NVP_AGENT_PROMPT{optimisticAccountID} — the real agent comes back under a different accountID — Agent.ts:111-121.
  4. EditAgentPage is still on the optimistic route param, so shouldShowNotFoundPage = isOnyxLoaded && !agent && !personalDetails flips to true → not-found — EditAgentPage.tsx:51.

The "after a second or two" timing is exactly the CreateAgent round-trip. Tap the same row after it resolves and it opens fine (real accountID); tap it while still pendingAction: ADD and it dies when the response lands. The DM reportID doesn't have this problem because it's reused verbatim by the backend — the agent's accountID is not.

Recommended fix (a design choice for you):

  • Simplest: gate the row's navigation while the agent is still optimistic — don't route to EditAgentPage while pendingAction === ADD (the row already carries pendingAction), so there's no stale route param to invalidate.
  • Fuller: reconcile the optimistic → real accountID on the client (map old→new) and redirect any open EditAgentPage/route from the optimistic accountID to the real one when successData lands, instead of dropping to not-found.

Since this is a distinct, pre-existing bug rather than a regression from this PR's change, I'd suggest fixing it separately (or explicitly folding it in) rather than silently expanding this PR's scope.


Next Steps: Reply with @MelvinBot implement the simplest fix here (or …in a new PR) and I'll open it, or @MelvinBot <feedback> to refine this.

@mjasikowski

Copy link
Copy Markdown
Contributor

@MelvinBot implement your latest suggestion (the full version) in a separate PR

@mjasikowski

Copy link
Copy Markdown
Contributor

@MelvinBot also remove this comment from the current PR:

            // backTo points the DM header's back button at the agents list; without it, dismissing the whole
            // settings modal stack leaves the list off the back stack, so back would fall through to the LHN.       

@MelvinBot

Copy link
Copy Markdown
Contributor Author

I dug in to build the full version and hit a wall — it can't be done in the App repo alone, so I haven't opened a PR. Correcting my earlier suggestion: the "reconcile optimistic → real accountID and redirect the open page" approach isn't actually possible client-side, because the client is never told the real accountID that replaces the optimistic one.

Why the full (redirect) fix needs the backend:

  • On success, createAgent nulls the optimistic agent entirely and the real agent arrives under a new, server-assigned accountID — Agent.ts:111-121. The CreateAgent response contains no optimistic→real accountID mapping, so there's no way to redirect EditAgentPage to the real record.
  • App's only optimistic-ID reconciliation mechanism (HandleUnusedOptimisticID.ts, preexistingReportID) is report-only — there's no accountID equivalent.

The correct root-cause fix is a backend change (Auth / Web-Expensify): have CreateAgent reuse the optimisticAccountID it's already passed as the agent's real accountID — exactly as it already reuses optimisticReportID for the DM ("creates the DM under this exact ID"). Then the App side just drops the two successData nulls, the optimistic route stays valid, and it works online and offline. That's outside this repo, so it needs an internal engineer with Auth access — I can't make it.

What I can ship in App (a mitigation, not the full fix): guard EditAgentPage so that when a still-optimistic agent gets cleaned up on success it falls back to the Agents list instead of flashing "not here" — EditAgentPage.tsx:51. It removes the broken not-found state (and preserves offline editing, where the optimistic record persists), but the user still has to tap the now-real row to actually edit — it doesn't auto-land them on the real edit page.

How do you want to proceed?

  • @MelvinBot open the App-only mitigation PR — I'll open the separate PR with the EditAgentPage guard.
  • Or escalate the backend CreateAgent accountID-reuse change to an internal engineer for the real fix, and I'll do the small App-side follow-up (dropping the successData nulls) once that lands.

Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Done — removed the two-line backTo explanatory comment in src/pages/settings/Agents/AddAgentPage.tsx. Pushed as 04a2d76f.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 No code-related checks are failing — nothing to push.

When this was reported, several checks (typecheck, the builds, and the perf tests) were still pending, not failed. They've all since completed and passed. I re-ran a full sweep and every functional check is green: Bun tests, ESLint, typecheck, test (jobs 1–8), all build jobs, and baseline/branch-perf-tests.

The only remaining red mark is Check independent approval, which is not a code failure — it's the review gate requiring an approval from an independent reviewer. That clears when a reviewer approves the PR; there's no code change that resolves it.

No fix was needed or pushed.

@mjasikowski
mjasikowski marked this pull request as ready for review August 17, 2026 10:43
@mjasikowski
mjasikowski requested a review from a team as a code owner August 17, 2026 10:43
@melvin-bot
melvin-bot Bot requested review from eVoloshchak and garrettmknight and removed request for a team August 17, 2026 10:43
@melvin-bot

melvin-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

@eVoloshchak 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 August 17, 2026 10:43

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

Looks good from a product perspective.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

⚠️ Something went wrong. This may be a transient issue — try again. If it persists, check status.anthropic.com.

Run details

@mjasikowski

Copy link
Copy Markdown
Contributor

@eVoloshchak can you review this please?

@eVoloshchak

eVoloshchak commented Aug 26, 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
    • 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 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 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)
  • 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)
  • 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 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.
  • 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
screen-20260826-143748-1787747834755.mp4
Android: mWeb Chrome
Screen.Recording.2026-08-26.at.09.00.45.mov
iOS: HybridApp
Screen.Recording.2026-08-26.at.08.49.46.mov
iOS: mWeb Safari
Screen.Recording.2026-08-26.at.08.50.28.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-25.at.20.12.27.mov

@eVoloshchak eVoloshchak 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!

@melvin-bot
melvin-bot Bot requested review from chuckdries and mjasikowski August 26, 2026 12:43
@mjasikowski
mjasikowski merged commit 1605be0 into main Aug 27, 2026
49 of 52 checks passed
@mjasikowski
mjasikowski deleted the claude-agentDmBackReturnsToAgents branch August 27, 2026 06:30
@github-actions

Copy link
Copy Markdown
Contributor

🚧 mjasikowski 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/mjasikowski in version: 9.4.63-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 No help site changes required.

This PR is an internal navigation bug fix, not a user-facing behavior or feature change, so no updates to App/docs/articles are needed and I did not open a docs PR.

Why no docs change is needed

The change adds a backTo param (ROUTES.SETTINGS_AGENTS) when revealing the newly created agent DM on narrow layouts, so the report header's back button returns to the Agents list instead of falling through to the LHN. It restores the expected navigation — it doesn't add, remove, or rename any feature, tab, setting, label, or button.

The relevant help article, Create and Use Agents, documents how to create, chat with, Copilot into, and manage agents. It does not document the low-level back-button navigation this PR corrects, and the documented create flow ("After saving, the new agent appears in your Agents list") remains accurate. Nothing in that article — or any other article under App/docs/articles — describes behavior that this change alters.

@mjasikowski, no linked help site PR was created since the change doesn't affect any documented behavior. Let me know if you'd like a docs PR opened anyway.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 9.4.63-1 🚀

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.

6 participants