Skip to content

Commit 83358d1

Browse files
marcochavezfclaude
andcommitted
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) <noreply@anthropic.com>
1 parent f0b9ae0 commit 83358d1

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

‎src/libs/actions/Report/SuggestedFollowup.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ function resolveSuggestedFollowup(
7878
},
7979
});
8080

81+
// Use the full delay as createdOffset so the Concierge response timestamp is
82+
// strictly after the user's comment — a 1ms offset was not enough to guarantee
83+
// correct sort order when both actions are queued to Onyx near-simultaneously.
8184
const optimisticConciergeAction = buildOptimisticAddCommentReportAction({
8285
text: selectedFollowup.response,
8386
actorAccountID: CONST.ACCOUNT_ID.CONCIERGE,
84-
createdOffset: 1,
87+
createdOffset: CONCIERGE_RESPONSE_DELAY_MS,
8588
reportActionID: optimisticConciergeReportActionID,
8689
reportID,
8790
isHTML: true,

‎tests/actions/ReportTest.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4953,6 +4953,53 @@ describe('actions/Report', () => {
49534953
const typingStatus = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING}${REPORT_ID}` as const);
49544954
expect(typingStatus?.[CONST.ACCOUNT_ID.CONCIERGE]).toBe(true);
49554955
});
4956+
4957+
it('should create Concierge response with timestamp strictly after the user comment', async () => {
4958+
const reportAction = {
4959+
reportActionID: REPORT_ACTION_ID,
4960+
actorAccountID: CONST.ACCOUNT_ID.CONCIERGE,
4961+
message: [
4962+
{
4963+
html: '<p>Here is help</p><followup-list><followup><followup-text>How do I set up QuickBooks?</followup-text><followup-response>To set up QuickBooks, go to Settings...</followup-response></followup></followup-list>',
4964+
text: 'Here is help',
4965+
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
4966+
},
4967+
],
4968+
} as OnyxTypes.ReportAction;
4969+
4970+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
4971+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {
4972+
[REPORT_ACTION_ID]: reportAction,
4973+
});
4974+
await waitForBatchedUpdates();
4975+
4976+
resolveSuggestedFollowup(
4977+
report,
4978+
undefined,
4979+
reportAction,
4980+
{text: 'How do I set up QuickBooks?', response: 'To set up QuickBooks, go to Settings...'},
4981+
CONST.DEFAULT_TIME_ZONE,
4982+
TEST_USER_ACCOUNT_ID,
4983+
TEST_USER_EMAIL,
4984+
);
4985+
await waitForBatchedUpdates();
4986+
4987+
// Get the pending Concierge response and verify its created timestamp
4988+
const pendingResponse = await getOnyxValue(`${ONYXKEYS.COLLECTION.PENDING_CONCIERGE_RESPONSE}${REPORT_ID}` as const);
4989+
expect(pendingResponse).not.toBeNull();
4990+
4991+
// Find the user's comment action (any new action that isn't the original Concierge message)
4992+
const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}` as const);
4993+
const userCommentAction = Object.values(reportActions ?? {}).find(
4994+
(action) => action?.reportActionID !== REPORT_ACTION_ID && action?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE,
4995+
);
4996+
4997+
// The Concierge response timestamp should be strictly after the user comment
4998+
expect(userCommentAction).toBeDefined();
4999+
expect(userCommentAction?.created).toBeDefined();
5000+
expect(pendingResponse?.reportAction.created).toBeDefined();
5001+
expect(new Date(pendingResponse?.reportAction.created ?? 0).getTime()).toBeGreaterThan(new Date(userCommentAction?.created ?? 0).getTime());
5002+
});
49565003
});
49575004

49585005
// Shared test constants for leave functions

‎tests/unit/ReportActionsFollowupUtilsTest.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ describe('ReportActionsFollowupUtils', () => {
8888
]);
8989
});
9090

91+
it('should preserve HTML formatting in followup-response (bullets, breaks, strong tags)', () => {
92+
const html = `<followup-list>
93+
<followup>
94+
<followup-text>How do I set up QuickBooks?</followup-text>
95+
<followup-response>To set up QuickBooks:<br><ul><li><strong>Step 1</strong>: Go to Settings</li><li><strong>Step 2</strong>: Click Integrations</li></ul></followup-response>
96+
</followup>
97+
</followup-list>`;
98+
const result = parseFollowupsFromHtml(html);
99+
expect(result).toEqual([
100+
{
101+
text: 'How do I set up QuickBooks?',
102+
response: 'To set up QuickBooks:<br><ul><li><strong>Step 1</strong>: Go to Settings</li><li><strong>Step 2</strong>: Click Integrations</li></ul>',
103+
},
104+
]);
105+
});
106+
91107
it('should handle empty followup-response element', () => {
92108
const html = `<followup-list>
93109
<followup>

0 commit comments

Comments
 (0)