Open the agent DM via an optimistic reportID instead of guessing its identity#95631
Draft
mjasikowski wants to merge 5 commits into
Draft
Open the agent DM via an optimistic reportID instead of guessing its identity#95631mjasikowski wants to merge 5 commits into
mjasikowski wants to merge 5 commits into
Conversation
…identity Generate the owner<->agent DM's reportID client-side, the same way any other new chat's reportID is generated, and write the DM to Onyx optimistically alongside the agent itself. CreateAgent (see Expensify/Auth#22772 and Expensify/Web-Expensify#54367) creates the DM under that exact reportID, so the client can navigate to it immediately after submitting, online or offline, without waiting for the response or reconstructing the agent's identity from Onyx collection diffs. This replaces the previous approach of polling the agent-prompt collection to detect the newly created agent, which produced multiple race-condition bugs across review rounds.
dismissModal() and the delayed navigate() were scheduled independently via setTimeout + isNavigationReady(), which only checks the nav ref exists and doesn't wait for the dismiss transition to settle. Under load (e.g. creating several agents in quick succession) the dismissal's own delayed navigation could land after our navigate() and send the user back to the previous screen instead of the report they just opened. Sequence the navigate through dismissModal's afterTransition callback instead, matching the existing dismissModalWithReport pattern.
getDisplayNameForParticipant short-circuited to the formatted login for any optimistic personal detail, on the assumption that a login is the only thing known about it (true for invite-by-email flows). Agent creation is different: the display name the user chose is already known, but login is intentionally omitted (it's server-assigned), so the DM title resolved to an empty string. Since CREATE_AGENT's response usually lands within a second online, this was an imperceptible flicker there, but offline the write stays queued indefinitely and the blank title persists. Only take the login-based shortcut when no display name is already known, which existing optimistic-personal-detail callers already set to the same value as the login anyway, so their behavior is unchanged.
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Matches the Auth/Web-Expensify rename: CreateAgent's primary subject is the agent account, not a report, so the owner<->agent DM's client-supplied ID follows the optimisticReportID naming SharePolicy and MoveIOUReportToExistingPolicy already use for the same kind of auxiliary, side-effect report ID.
dismissModalWithReport is the established pattern for "dismiss the modal and open a report" (used by WorkspaceNewRoomPage, NewChatPage, Split, TeachersUnite, etc.) and already sequences the navigate through dismissModal's afterTransition correctly, so it isn't affected by the race that motivated exporting and patching navigateToReport. That patch is no longer needed, so revert navigateToReport back to its prior implementation and drop its export.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation of Change
Replaces the "poll and diff the agent-prompt collection" approach for opening the DM with a newly created agent with proper optimistic-report reconciliation, following up on review feedback on #95482.
createAgentnow generates the owner<->agent DM'sreportIDclient-side - the same way any other new chat's reportID is generated - and writes the DM report to Onyx optimistically (viabuildOptimisticChatReport), alongside the existing optimistic agent personal detail / prompt writes. ThatreportIDis sent toCREATE_AGENT, and the backend (Expensify/Auth#22772, Expensify/Web-Expensify#54367) creates the DM under that exact ID.AddAgentPagenavigates to the returnedoptimisticReportIDimmediately after submitting, online or offline, with no waiting, no submit spinner, and no polling hook. This removes the whole class of bugs surfaced during review of #95482 (cold-hydration baseline, concurrent-agent-creation mismatch, batched-response-before-baseline race) - none of them apply once identity is carried via a client-generated reportID instead of reconstructed via collection diffing.Depends on (must merge/deploy first, though this PR is safe to review in parallel):
Fixed Issues
$
PROPOSAL:
Tests
Offline tests
QA Steps
Same as Tests. Requires the two backend PRs above to be deployed to staging/production first.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionNote: this is a draft. Manual/device QA is pending until the dependent Auth and Web-Expensify PRs are deployed, since
CREATE_AGENTneeds to understand thereportIDparam for the DM to actually reconcile end-to-end.Screenshots/Videos
Pending backend PRs.