Skip to content

Keep newly created agents editable across browser tabs - #101360

Merged
deetergp merged 8 commits into
Expensify:mainfrom
KJ21-ENG:KJ21-ENG/100865-agent-id-comparison
Nov 2, 2026
Merged

deetergp merged 8 commits into
Expensify:mainfrom
KJ21-ENG:KJ21-ENG/100865-agent-id-comparison

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Keep Edit Agent usable when another tab finishes creating the agent. Retain temporary-to-real ID mappings, resolve them in open agent screens and saved links, and keep Name, Instructions and Avatar Save/Back navigation on the same agent.

Fixed Issues

$ #100865
PROPOSAL: #100865 (comment)

Tests

  • Verify that no errors appear in the JS console
  1. Sign in and open Account > Agents in two browser tabs, opening the second tab last. In the first tab, create an agent, close its automatic chat, and immediately open the new agent from the list.
  2. Verify Edit Agent remains visible while creation finishes, then shows the saved name, instructions and avatar. Repeat with a second agent and in a single tab.
  3. During creation, open Name, Instructions or Avatar. Save an edit or use Back. Verify the values update and navigation returns to the same Edit Agent screen. Repeat for all three fields.
  4. Save the temporary Edit Agent URL while creation is pending. After creation finishes, reopen that URL and reload it. Verify it opens the saved agent.
  5. Delete the agent, then reopen its saved temporary URL. Verify the not-found page appears. Also verify a second client that was viewing the agent shows not-found after deletion.
  6. Where Workspace > Agents is available, open an agent through that page and repeat field Save/Back.

Offline tests

  1. In the first tab, disconnect the network, create an agent, and open its Edit page. Edit its name or instructions while creation is pending.
  2. Reconnect with the second tab open. Verify the agent and queued edits finish saving, its Edit page remains usable, and reopening it shows the saved values.
  3. With a previously created agent loaded, disconnect again. Verify Name, Instructions and Avatar still open and Back returns correctly. Reconnect and verify any saved edit is retained.

QA Steps

  • Verify that no errors appear in the JS console
  1. On staging, open Account > Agents in two browser tabs on the same account, opening the second tab last. Create an agent in the first tab, close its automatic chat, and immediately open the new agent.
  2. Verify Edit Agent remains visible as creation finishes. Repeat with a second agent and with one tab.
  3. Repeat while opening Name, Instructions or Avatar before creation finishes. Verify Save and Back return to the same agent and saved changes appear.
  4. Create an agent offline in the first tab, edit its name or instructions, and reconnect while the second tab is open. Verify the agent and edits save without a not-found page.
  5. Reopen and reload a temporary Edit Agent URL saved during creation. Verify it opens the completed agent. Delete that agent and verify both the old URL and a second client viewing that agent show not-found.
  6. On native platforms, repeat the single-session create/edit, offline/reconnect and Save/Back cases.
  7. Where Workspace > Agents is available, repeat field Save/Back through that entry point.

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

Recording from 42e5fcaf7f5: pending-agent editing reached Name Save, then the app became unresponsive.

android-qa-inconclusive-2x.mp4
Android: mWeb Chrome

Recording from 42e5fcaf7f5: online editing and second-tab reconnect. This recording contains excerpts.

android-mweb-qa-2x.mp4
iOS: Native

Recording from 42e5fcaf7f5: online field saves and offline queued-name reconnect/reopening.

ios-qa-trimmed-2x.mp4
iOS: mWeb Safari

Recording from 42e5fcaf7f5: online field saves and offline queued-name Save. Safari became unresponsive before reconnect verification.

ios-mweb-qa-2x.mp4
MacOS: Chrome / Safari

Recording from 42e5fcaf7f5.

after-fix-short-sanitized-1.5x.mp4

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/ONYXKEYS.ts 100.00% <ø> (ø)
src/hooks/useAgentAccountID.ts 100.00% <100.00%> (ø)
src/libs/AgentAccountIDMapping.ts 100.00% <100.00%> (ø)
...libs/Middleware/ReplaceOptimisticAgentAccountID.ts 97.01% <ø> (ø)
src/libs/PersonalDetailsStore.ts 100.00% <100.00%> (ø)
...s/actions/replaceOptimisticAgentWithActualAgent.ts 98.76% <100.00%> (+0.65%) ⬆️
src/pages/settings/Agents/DynamicEditAgentPage.tsx 95.04% <100.00%> (ø)
...tings/Agents/Fields/DynamicEditAgentAvatarPage.tsx 79.00% <100.00%> (+79.00%) ⬆️
...ges/settings/Agents/Fields/DynamicEditNamePage.tsx 100.00% <100.00%> (ø)
...s/settings/Agents/Fields/DynamicEditPromptPage.tsx 86.30% <100.00%> (ø)
... and 12 files with indirect coverage changes

@KJ21-ENG
KJ21-ENG marked this pull request as ready for review September 24, 2026 07:04
@KJ21-ENG
KJ21-ENG requested review from a team as code owners September 24, 2026 07:04
@melvin-bot
melvin-bot Bot requested a review from getusha September 24, 2026 07:04
@melvin-bot

melvin-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

@getusha 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 September 24, 2026 07:04
dylanexpensify
dylanexpensify previously approved these changes Sep 25, 2026

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

Good from product POV

@getusha

getusha commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@KJ21-ENG please resolve the conflict

@getusha

getusha commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Code review

The approach works. Keeping the mapping in Onyx fixes the cross-tab case: Onyx's web sync sends only keys, so the other tab re-reads storage and would see an empty mapping if it were deleted. The new hook also covers screens opened after the redirect. CI passes.

Two items need attention before approval:

  1. The PR has merge conflicts. Please merge main.
  2. The mapping now grows forever, and every entry is reprocessed on every app start. No code removes an entry after it is used. On each app start or new tab, the listener in replaceOptimisticAgentWithActualAgent.ts:139-155 runs the full replacement for every agent the user has ever created. For each one, it walks the navigation state, scans all reports (L83-L96), and makes two Onyx.merge calls. On web, each merge also sends a sync event to the other tabs. The processedAccountIDs guard (L110-L113) is in memory only, so it resets on every reload. Please add a way to remove old entries. For example:
    • Remove the entry in deleteAgent when the agent's real ID matches.
    • Or store a timestamp with each entry and prune old ones on start.
    • At minimum, skip the cleanup and report scan when the optimistic personal detail and prompt are already gone.
Minor items

Testing gaps. The PR description reports open QA failures:

  • Android native froze on Name Save.
  • Safari froze before the reconnect check.
  • An old temporary URL opened in a new Android Chrome tab stayed on the loading screen.

I didn't find a cause for these in the diff. The hook can't loop, because once the route is updated, resolvedAccountID === accountID. Still, these failures should be fixed or shown to happen on main too before this PR is approved.


view run

@github-actions

Copy link
Copy Markdown
Contributor

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins, @chuckdries) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

@KJ21-ENG

KJ21-ENG commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@MelvinBot Following up on your review: I merged main, resolved the conflicts, and pushed the changes through dc9b9b4fb3f.

  • Startup replacements are now batched. Each batch walks the navigation tree and reports once, instead of once per retained mapping.
  • Cleanup waits for the data to load, then skips writes for temporary personal details and agent records that are already gone. Report repair still runs: an interrupted replacement can leave temporary IDs in report participants even after those other records have disappeared. Existing real participants are preserved.
  • I corrected the stale comments and naming, added Name/Prompt/Avatar tests for mappings arriving before and after mount, and added restart tests for completed cleanup and report-only recovery.

I kept valid mappings persisted because another tab or an old temporary-ID URL may still need them after cleanup. Clearing or expiring them can remove that recovery path. No pruning was added, so mapping storage still grows; this change addresses the repeated startup work. Both navigation mechanisms remain intentional: the hook repairs mounted and later-opened screens, while the sweep repairs routes buried in the stack.

@KJ21-ENG

KJ21-ENG commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@getusha Kind ping here, Thanks!

@tgolen
tgolen removed the request for review from chuckdries October 20, 2026 16:27
@github-actions

Copy link
Copy Markdown
Contributor

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins, @chuckdries) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

I kept the retained mappings, mounted-screen hook and navigation sweep. Other tabs and old temporary URLs still need the mappings. Skipping repair based only on missing temporary records would miss report-only recovery; a persisted completion marker would need a reliable rule for confirming all repair writes finished.

I corrected the mapping comment, shared account-ID validation, added Given/When/Then comments and added the suggested Reassure benchmark. The benchmark measures report processing over already-loaded data, rather than complete app startup.

I also fixed a Save/Back mismatch between numeric route writes and string route parameters. Both repair paths now preserve string route IDs while actions use numeric IDs, with regression tests covering the route contract.

Existing recordings retain their original-source labels.

The repository's Slack-approval rule specifically covers component performance exceptions; this subscription runs in an action outside React. Please confirm whether you also expect a separate Slack discussion for this action-level listener. The earlier approval predates this update, so I am requesting fresh review.

@chuckdries
chuckdries removed their request for review October 28, 2026 15:06
@luacmartins
luacmartins removed their request for review October 28, 2026 16:37
@getusha

getusha commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Code looks good, testing.

@mountiny
mountiny removed their request for review November 2, 2026 03:41

@deetergp deetergp 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

@deetergp
deetergp merged commit f2b1357 into Expensify:main Nov 2, 2026
39 of 53 checks passed
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #105813 was identified to be related to this PR.

@jponikarchuk

Copy link
Copy Markdown

This PR failing because of the issue #105813
This issue is reproducible in: Web

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/deetergp in version: 9.5.31-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR restores expected agent editing across browser tabs without adding a workflow or making existing article instructions incorrect.

@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/deetergp in version: 9.5.31-0 🚀

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

@OSBotify

OSBotify commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/blimpich in version: 9.5.31-4 🚀

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.

9 participants