From 83358d1cbd99833640d749b2bf7a5d4f2b9137a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 25 Mar 2026 17:26:55 -0600 Subject: [PATCH] Fix followup ordering: use CONCIERGE_RESPONSE_DELAY_MS as createdOffset The optimistic Concierge response was using createdOffset: 1 (1ms), which was not sufficient to guarantee correct sort order when both the user's comment and Concierge response are queued to Onyx near-simultaneously. Using CONCIERGE_RESPONSE_DELAY_MS (4s) ensures the Concierge response timestamp is well after the user's comment. Also adds tests verifying: - HTML formatting (bullets, breaks, strong tags) is preserved in followup-response parsing - Concierge response timestamp is strictly after user comment Co-Authored-By: Claude Opus 4.6 (1M context) --- src/libs/actions/Report/SuggestedFollowup.ts | 5 ++- tests/actions/ReportTest.ts | 47 ++++++++++++++++++++ tests/unit/ReportActionsFollowupUtilsTest.ts | 16 +++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report/SuggestedFollowup.ts b/src/libs/actions/Report/SuggestedFollowup.ts index 3e489ed75b4b..f1f00d4598c7 100644 --- a/src/libs/actions/Report/SuggestedFollowup.ts +++ b/src/libs/actions/Report/SuggestedFollowup.ts @@ -78,10 +78,13 @@ function resolveSuggestedFollowup( }, }); + // Use the full delay as createdOffset so the Concierge response timestamp is + // strictly after the user's comment — a 1ms offset was not enough to guarantee + // correct sort order when both actions are queued to Onyx near-simultaneously. const optimisticConciergeAction = buildOptimisticAddCommentReportAction({ text: selectedFollowup.response, actorAccountID: CONST.ACCOUNT_ID.CONCIERGE, - createdOffset: 1, + createdOffset: CONCIERGE_RESPONSE_DELAY_MS, reportActionID: optimisticConciergeReportActionID, reportID, isHTML: true, diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 842d91cf2a99..676a634ea7b2 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -4953,6 +4953,53 @@ describe('actions/Report', () => { const typingStatus = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING}${REPORT_ID}` as const); expect(typingStatus?.[CONST.ACCOUNT_ID.CONCIERGE]).toBe(true); }); + + it('should create Concierge response with timestamp strictly after the user comment', async () => { + const reportAction = { + reportActionID: REPORT_ACTION_ID, + actorAccountID: CONST.ACCOUNT_ID.CONCIERGE, + message: [ + { + html: '

Here is help

How do I set up QuickBooks?To set up QuickBooks, go to Settings...', + text: 'Here is help', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + }, + ], + } as OnyxTypes.ReportAction; + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + }); + await waitForBatchedUpdates(); + + resolveSuggestedFollowup( + report, + undefined, + reportAction, + {text: 'How do I set up QuickBooks?', response: 'To set up QuickBooks, go to Settings...'}, + CONST.DEFAULT_TIME_ZONE, + TEST_USER_ACCOUNT_ID, + TEST_USER_EMAIL, + ); + await waitForBatchedUpdates(); + + // Get the pending Concierge response and verify its created timestamp + const pendingResponse = await getOnyxValue(`${ONYXKEYS.COLLECTION.PENDING_CONCIERGE_RESPONSE}${REPORT_ID}` as const); + expect(pendingResponse).not.toBeNull(); + + // Find the user's comment action (any new action that isn't the original Concierge message) + const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}` as const); + const userCommentAction = Object.values(reportActions ?? {}).find( + (action) => action?.reportActionID !== REPORT_ACTION_ID && action?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE, + ); + + // The Concierge response timestamp should be strictly after the user comment + expect(userCommentAction).toBeDefined(); + expect(userCommentAction?.created).toBeDefined(); + expect(pendingResponse?.reportAction.created).toBeDefined(); + expect(new Date(pendingResponse?.reportAction.created ?? 0).getTime()).toBeGreaterThan(new Date(userCommentAction?.created ?? 0).getTime()); + }); }); // Shared test constants for leave functions diff --git a/tests/unit/ReportActionsFollowupUtilsTest.ts b/tests/unit/ReportActionsFollowupUtilsTest.ts index 02af520d248b..c06894bcf512 100644 --- a/tests/unit/ReportActionsFollowupUtilsTest.ts +++ b/tests/unit/ReportActionsFollowupUtilsTest.ts @@ -88,6 +88,22 @@ describe('ReportActionsFollowupUtils', () => { ]); }); + it('should preserve HTML formatting in followup-response (bullets, breaks, strong tags)', () => { + const html = ` + + How do I set up QuickBooks? + To set up QuickBooks:
  • Step 1: Go to Settings
  • Step 2: Click Integrations
+
+
`; + const result = parseFollowupsFromHtml(html); + expect(result).toEqual([ + { + text: 'How do I set up QuickBooks?', + response: 'To set up QuickBooks:
', + }, + ]); + }); + it('should handle empty followup-response element', () => { const html = `