App icon indicating copy to clipboard operation
App copied to clipboard

Concierge stops responding when a new message is sent while a follow-up response is still generating

Open m-natarajan opened this issue 4 months ago • 94 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.44-6 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: Applause Internal Team Slack conversation (hyperlinked to channel name): More context here

Action Performed:

  1. Open Concierge and ask a question.
  2. Wait for Concierge to respond with suggested follow-up buttons.
  3. Click one of the suggested follow-up buttons.
  4. While Concierge is still generating the response (or while the next set of suggested follow-up buttons is still loading), send another user message.
  5. Wait for all pending requests to complete.
  6. Observe the conversation.

Expected Result:

Concierge should handle the new user message after the in-progress response, The conversation should remain responsive.

Actual Result:

Concierge does not reply to the message sent during the in-progress response. The conversation appears to become stuck after the second message is sent.

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Screenshots/Videos

https://github.com/user-attachments/assets/8d2d20b6-d865-4447-87cc-edc9286adb56

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @eh2077

m-natarajan avatar Jul 26 '26 15:07 m-natarajan

Issue Analysis

⚠️ Medium confidence — the App-side behavior is verified in code, but the definitive "message dropped" mechanism is backend and needs log confirmation (no reportID was available in the issue to run that).

Root Cause: This is not a case of the App blocking or dropping the second message. The composer has no in-progress guard — a freeform message typed while Concierge is still generating is always dispatched via AddComment. The failure to reply lives in the backend Concierge turn-handling, which the App repo can't fix. Two App-side timing behaviors make the chat look permanently stuck once the backend fails to answer:

  1. Sending a message into the Concierge chat clears the "Concierge is thinking" indicator and relies on the backend to re-establish it — useComposerSubmit.ts:84-85. If the backend never re-establishes it, there's no visual signal that anything is pending.
  2. Follow-up buttons that carry a pre-generated response open a 4-second optimistic-reply window (SuggestedFollowup.ts:19,108-126). A message sent inside that window can cause the pending optimistic Concierge reply to be discarded — usePendingConciergeResponse.ts:143,214.

The combination means: the second AddComment is sent, but if the backend treats that Concierge turn as already handled (the follow-up's pre-generated-response handshake) it never kicks off a new generation for the freeform message → Concierge never replies and the chat appears frozen.

Recommended Fix: The core defect ("Concierge doesn't reply to the second message") requires a change outside the App repo — this is a backend/Concierge issue in how a concurrent AddComment arriving mid-turn is handled. It should be escalated to an internal engineer with access to the Concierge/Auth backend to confirm whether the second message triggers a new agent generation or is dropped/deduped. An App-side hardening (e.g. not clearing the thinking indicator / not discarding the pending response when a message is sent mid-turn) could reduce the "stuck" appearance, but won't make Concierge answer on its own.

Investigation details

Follow-up buttons flow. Suggested follow-up buttons are parsed from a <followup-list> in the Concierge report action HTML and rendered by ChatActionableButtons.tsx. Clicking one calls resolveSuggestedFollowup() — not ResolveActionableReportMentionWhisper. The "resolution" it applies (<followup-list selected>) is purely cosmetic (hides the buttons) and does not gate the composer.

No composer gate. The only conditions that disable send are the abuse block (isBlockedFromConcierge), max-length, and empty draft — none related to an "in-progress" state. So the typed message is genuinely dispatched to the backend.

Why it looks web-only / stuck. The "thinking" indicator is a display-only signal; while a follow-up list is pending, indicators are additionally suppressed. Once the backend fails to answer the concurrent message, none of the client optimism recovers the state, so the chat sits with a sent message and no reply.

Recommended log confirmation (internal engineer): for an affected Concierge reportID during the repro, verify (a) the second AddComment reaches the backend within ~4s of the follow-up's AddComment, and (b) whether it triggers a new agent generation or is short-circuited/deduped by the pre-generated-response handshake (optimisticConciergeReportActionID / pregeneratedResponse).

Possibly related: #96237 is referenced for context (a payment-tracking issue, not a duplicate). No open duplicate of this specific race was found.


Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.

MelvinBot avatar Jul 26 '26 15:07 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External)

melvin-bot[bot] avatar Jul 26 '26 15:07 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022081408568435488941

melvin-bot[bot] avatar Jul 26 '26 15:07 melvin-bot[bot]

I can take over this.

marufsharifi avatar Jul 27 '26 05:07 marufsharifi

Triggered auto assignment to Contributor-plus team member for initial proposal review - @situchan (External)

melvin-bot[bot] avatar Jul 28 '26 01:07 melvin-bot[bot]

@situchan plz take over as C+

mallenexpensify avatar Jul 28 '26 01:07 mallenexpensify

@situchan Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Jul 31 '26 21:07 melvin-bot[bot]

@situchan 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Aug 04 '26 21:08 melvin-bot[bot]

@situchan Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

melvin-bot[bot] avatar Aug 06 '26 21:08 melvin-bot[bot]

@situchan this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

melvin-bot[bot] avatar Aug 09 '26 21:08 melvin-bot[bot]

@situchan 12 days overdue. Walking. Toward. The. Light...

melvin-bot[bot] avatar Aug 10 '26 21:08 melvin-bot[bot]

This issue has not been updated in over 14 days. @situchan eroding to Weekly issue.

melvin-bot[bot] avatar Aug 13 '26 21:08 melvin-bot[bot]

Agreed there is no in-progress composer guard, but the "stuck" half of this is reproducible client-side: once a pre-generated follow-up reply is applied, applyPendingConciergeAction sets CONCIERGE_PENDING_FOLLOWUP_LIST, and useShouldSuppressConciergeIndicators then returns true for the entire report, unconditionally, with no notion of a newer user turn:

https://github.com/Expensify/App/blob/e51e6af7728321eae7bf9653e3758814f08077fd/src/hooks/useShouldSuppressConciergeIndicators.tsx#L46-L48

That marker is cleared only when a <followup-list> lands on that one action or after a 120s TTL, never when the user sends a new message, so a message sent inside that window renders with no thinking bubble (ConciergeThinkingMessage.tsx#L55) and no typing indicator (ComposerTypingIndicator.tsx#L12) for up to two minutes.

yusufdeveloper2903 avatar Aug 19 '26 14:08 yusufdeveloper2903

This seems internal issue.

situchan avatar Aug 19 '26 14:08 situchan

Pulling up internal engineer to confirm

🎀 👀 🎀 C+ reviewed

situchan avatar Aug 23 '26 18:08 situchan

Triggered auto assignment to @AndrewGable, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Aug 23 '26 18:08 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

In the Concierge chat, the user taps a suggested follow-up whose answer is pre-generated, then sends their own message before that answer renders. Concierge never replies to the second message, and the chat sits with a sent message, no thinking indicator and no response.

What is the root cause of that problem?

Tapping a follow-up that carries a pre-generated response reserves a created four seconds in the future for Concierge's reply:

https://github.com/Expensify/App/blob/20a786bb2024bc50adc163c61dfbf347b78066c6/src/libs/actions/Report/SuggestedFollowup.ts#L95-L105

and that exact value is what the server is told to persist it at:

https://github.com/Expensify/App/blob/20a786bb2024bc50adc163c61dfbf347b78066c6/src/libs/actions/Report/SuggestedFollowup.ts#L117-L121

Nothing publishes that reservation to the send path. The reservation is written only to PENDING_CONCIERGE_RESPONSE, never to the report, so lastVisibleActionCreated still points at the user's question:

https://github.com/Expensify/App/blob/20a786bb2024bc50adc163c61dfbf347b78066c6/src/libs/actions/Report/SuggestedFollowup.ts#L135-L142

And that one value is the only floor addActions clamps a new comment against:

https://github.com/Expensify/App/blob/20a786bb2024bc50adc163c61dfbf347b78066c6/src/libs/actions/Report/index.ts#L899-L902

So a message sent inside the four-second window is stamped before a reply that has already been claimed — locally, and in the clientCreatedTime that ships with it:

https://github.com/Expensify/App/blob/20a786bb2024bc50adc163c61dfbf347b78066c6/src/libs/actions/Report/index.ts#L1030

Concierge's answer is still the newest action in the report after the user has sent, so that turn reads as already handled and no generation is kicked off for the new message.

What changes do you think we should make in order to solve the problem?

Raise the ordering floor to the reserved slot while it is pending. addActions already feeds a floor into getServerAnchoredDBTime, and that clamp needs no edit:

https://github.com/Expensify/App/blob/20a786bb2024bc50adc163c61dfbf347b78066c6/src/libs/NetworkState.ts#L274-L284

In src/libs/actions/Report/index.ts, read PENDING_CONCIERGE_RESPONSE into a module-level cache alongside the collections already cached there, and add a small helper that returns whichever is later: the created a pending pre-generated reply has reserved for this report, or lastVisibleActionCreated. Both are DB-format timestamps, so a plain string comparison is chronological. Then feed that helper's result into lastActionCreated at the single call site on L902, in place of reportForAction?.lastVisibleActionCreated. One behavioural change, one call site.

I built this on a test branch and measured it against the real Concierge, sampling the second message's created out of Onyx after send. In a run where the reply had reserved 2026-08-24 05:16:45.056, the message was stamped 05:16:45.057 at 200ms, 600ms and 1500ms — correctly one millisecond after the reserved slot, and that is the value clientCreatedTime carries. By 4000ms it was back to 05:16:43.690, the pre-clamp local time, and the final order was the broken one again. In the same run the pre-generated reply is persisted by the server at exactly the reserved timestamp under actorAccountID 8392101, so optimisticConciergeCreated is honoured while clientCreatedTime is not, and nothing on the client rewrites that field in between.

So the floor is necessary but not sufficient on its own: while clientCreatedTime is discarded for the user's comment, the message keeps sorting before a reply that was already claimed and the turn keeps reading as handled. I would like an internal confirmation on whether AddComment is meant to honour clientCreatedTime the way optimisticConciergeCreated is honoured for the pre-generated reply.

What alternative solutions did you explore? (Optional)

Clearing the reservation when a new message arrives, so the user's message is unambiguously newest. This drops an answer the server has already committed to persisting at that timestamp, and throws away the pre-generated content the user asked for.

Blocking the composer while a pre-generated reply is pending. This makes the chat feel unresponsive for four seconds after every follow-up tap, and the reported expectation is that the new message is answered, not that it is prevented.

Gating on the Agent Zero optimistic store instead of the reserved timestamp. That store tracks when a request started, not the slot a reply has claimed, so it cannot tell a message sent inside the window from one sent after the reply landed.

Abdulloh0109 avatar Aug 23 '26 18:08 Abdulloh0109

🚨 Edited by proposal-police: This proposal was edited at 2026-08-24 05:20:21 UTC.

Proposal

What is the root cause of that problem?

The App reserves Concierge's reply four seconds in the future and tells the server to persist it there, so a message sent inside that window lands before an answer that has already been claimed — on the client and in the record the backend keeps.

Tapping a follow-up that carries a pre-generated answer builds the reply before the question it answers, and buys the sort order with a four-second head start:

https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/Report/SuggestedFollowup.ts#L92-L105

That exact future value is then shipped to the server as optimisticConciergeCreated, so the canonical reply is persisted at it too:

https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/Report/SuggestedFollowup.ts#L117-L121

https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/Report/index.ts#L1056

The next message is stamped at real now, clamped only against lastVisibleActionCreated — which still points at the question, because nothing publishes the reservation:

https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/Report/index.ts#L899-L902

https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/Report/index.ts#L1030

Measured on d98460b9477 by resolving a pre-generated follow-up and then calling addComment:

question         2026-08-24 02:30:14.095
reserved reply   2026-08-24 02:30:18.093   <- +4000ms, and what the server is told
second message   2026-08-24 02:30:14.106   <- ships 3987ms BEFORE the reply

So Concierge's answer stays the newest action after the user has sent again, and the new user turn reads as already handled. The same inversion keeps Concierge as the newest actor indefinitely, which suppresses the thinking bubble for that message (ReportAction.ts#L63-L82).

Worth noting that #95002 merged on 2026-07-11, two weeks before this was filed — the hold was released, so the backend is honouring optimisticConciergeCreated exactly as asked. The defect is the value we send it.

Two further client behaviours turn "no reply" into "permanently frozen", and both are in scope because the issue's expected result is that the conversation stays responsive:

  1. useShouldSuppressConciergeIndicators returns true for the whole report while a follow-up list is pending, with no notion of a newer user turn — so a message sent in that window gets no thinking bubble and no typing indicator for up to 120s. This is the "or while the next set of suggested follow-up buttons is still loading" half of the repro, and it is unaffected by the ordering fix.

    https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/hooks/useShouldSuppressConciergeIndicators.tsx#L46-L48

  2. The composer clears the Concierge indicator on every send. Its own comment says "from a prior turn", but the repro drives it through a turn that is genuinely in flight — and the server has already emitted that indicator and won't emit it again. Clearing it also disarms the safety timer whose expiry fires the recovery getNewerActions for a late reply (useAgentZeroStatusIndicator.ts#L145).

    https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/pages/inbox/report/ReportActionCompose/useComposerSubmit.ts#L83-L89

What changes do you think we should make in order to solve the problem?

The four seconds are a reveal delay, not a chat position. They are already carried independently by displayAfter, and usePendingConciergeResponse schedules the reveal from that and never from created:

https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/libs/actions/Report/SuggestedFollowup.ts#L135-L143

https://github.com/Expensify/App/blob/d98460b94777eeee3f9acc1cdb50b325642c54fd/src/hooks/usePendingConciergeResponse.ts#L138

So the reply's position only ever needed to be one tick after the question it answers. The head start exists solely because the reply is built first. Reverse that.

1. addActions derives the reply's position after it stamps the question, and returns it. optimisticConciergeCreated stops being a caller-supplied input and becomes an output of the send path — the one place where the question's created is authoritative:

+    // A pre-generated Concierge reply answers the comment being sent right now, so its position in the chat is
+    // one tick after that comment — nothing more. The four seconds the client waits before revealing it is a
+    // display delay carried by `displayAfter` (see SuggestedFollowup), and must never leak into `created`.
+    const pregeneratedConciergeCreated = pregeneratedResponseParams ? getServerAnchoredDBTime(Date.now(), reportCommentAction?.created) : undefined;
-        parameters.optimisticConciergeCreated = pregeneratedResponseParams.optimisticConciergeCreated;
+        parameters.optimisticConciergeCreated = pregeneratedConciergeCreated;

getServerAnchoredDBTime's existing notBeforeDBTime clamp guarantees strictly-after regardless of elapsed time or skew direction. That is what createdOffset: 1 originally lacked: it used getDBTimeWithSkew (forward-only) while the question uses getServerAnchoredDBTime (bidirectional), so under negative skew the question could overtake the answer. Same clamp 4d0695754ac added to keep successive user sends monotonic — no new mechanism.

2. resolveSuggestedFollowup posts the question first, then queues the reply at the value it got back — so the local action and the server's copy stay byte-identical, preserving #95002's contract:

-    const optimisticConciergeAction = buildOptimisticAddCommentReportAction({... createdOffset: CONCIERGE_RESPONSE_DELAY_MS ...});
-    addComment({... pregeneratedResponseParams: {optimisticConciergeReportActionID, optimisticConciergeCreated: optimisticConciergeAction.reportAction.created, pregeneratedResponse}});
+    const conciergeReplyCreated = addComment({... pregeneratedResponseParams: {optimisticConciergeReportActionID, pregeneratedResponse}});
+    if (!conciergeReplyCreated) {
+        return;
+    }
+    const optimisticConciergeAction = buildOptimisticAddCommentReportAction({... created: conciergeReplyCreated ...});
     addOptimisticConciergeActionWithDelay(reportID, optimisticConciergeAction);

Supported by one optional created override on buildOptimisticAddCommentReportAction, defaulting to today's behaviour.

3. End the follow-up-list suppression once the user speaks again — the window describes waiting on buttons for a reply that already landed, and a newer user message is a turn of its own:

-    if (pendingFollowupList) {
+    if (pendingFollowupList && !hasUserActionSincePendingFollowup) {
         return true;
     }

4. Hold the composer's optimistic clear while a pre-generated turn is reconciling — keeping its original stale-indicator purpose intact:

+        const hasPendingConciergeTurn = !!pendingConciergeResponse || !!pendingConciergeFollowupList;
-        if (isConciergeChatReport(report, conciergeReportID)) {
+        if (isConciergeChatReport(report, conciergeReportID) && !hasPendingConciergeTurn) {
             clearAgentZeroProcessingIndicator(reportID, CONST.ACCOUNT_ID.CONCIERGE);
         }

Test branch: https://github.com/oqildev/App/tree/fix/97049-concierge-pregenerated-reply-ordering (based on d98460b9477)

Coverage — 10 new tests, red on main and green with the change, plus three guard tests that are green in both directions so the reveal delay and the stale-indicator clear are provably untouched:

  • tests/actions/ReportTest.ts — the second message ships after the reserved reply; it is the newest action once the reply is revealed; the reply sits one tick after its question, not four seconds; displayAfter still holds the reveal.
  • tests/unit/hooks/useShouldSuppressConciergeIndicators.test.ts — suppression ends on a newer user message, holds for the question itself, holds for a newer Concierge action.
  • tests/ui/ConciergeComposerIndicatorTest.tsx (new) — the indicator survives a send in both pending windows, and a stale one still clears.

Full sweep across the 10 affected suites: 400/400 green. typecheck, ESLint, React Compiler compliance and cspell all clean.

Attachments and the Side Panel composer funnel through addActions and useComposerSubmit, so all three send paths are covered by the same change, and offline sends clamp identically. With this, the user's message is the newest turn in both the client's copy and the record the server persists — the ordering that made it read as already answered is gone.

What alternative solutions did you explore? (Optional)

  • Raise the send-path ordering floor to the reserved slot instead (read PENDING_CONCIERGE_RESPONSE in addActions). It fixes the inversion with no plumbing, but leaves the reply timestamped four seconds after it was generated and pushes the user's own message up to four seconds into the future to clear it. Both are artefacts the fix above removes rather than compensates for, and it adds a module-level Onyx.connectWithoutView that this one doesn't need.
  • Publish the reservation as report.lastVisibleActionCreated. Same effect on ordering, but that field drives LHN ordering and unread state, so writing a four-second-future value into it for a message that hasn't rendered risks a spurious unread report.
  • Stop sending optimisticConciergeCreated altogether. Repairs the server's copy and leaves the client's broken: applyPendingConciergeAction still commits the local action four seconds ahead, so the composer's message keeps sorting behind it. It also reverts what 35977375ca8 was written to guarantee.
  • Shrink createdOffset back to 1 without anchoring. The comment at SuggestedFollowup.ts#L92-L94 records that this already failed once, and it would fail again for the skew reason above. Anchoring is what makes it hold.
  • Block the composer during an in-progress turn. Contradicts the feature's expected behaviour — the user is supposed to be able to send mid-turn and be answered afterward.

Before fix video:

https://github.com/user-attachments/assets/b58d9313-fa56-4091-ba34-7e44244e018a

After fix video:

https://github.com/user-attachments/assets/63320d5a-6b75-4f46-88c7-deb64a5425c5

oqildev avatar Aug 23 '26 18:08 oqildev

🚨 Edited by proposal-police: This proposal was edited at 2026-10-23 13:16:08 UTC.

Proposal

What is the root cause of that problem?

Retest on 9.5.18-1 shows BE now answers the second message, but chat still looks stuck for ~2 minutes. I reproduced it on current main: server sets "Concierge is working on your request..." / "searching documentation..." on the report the whole time, and the client renders nothing. Two client gates hide a turn that is genuinely in flight.

1. Follow-up suppression is report wide. While a follow-up list is pending, both indicator consumers are hidden for the whole report, with no notion of a newer user message:

https://github.com/Expensify/App/blob/bb3077d8990361bc592962ea0539d0622c12545a/src/hooks/useShouldSuppressConciergeIndicators.tsx#L46-L48

2. The status gate treats the canned reply as the answer. AgentZeroStatusGate drops Concierge's bubble whenever the newest action by created is a Concierge comment:

https://github.com/Expensify/App/blob/bb3077d8990361bc592962ea0539d0622c12545a/src/pages/inbox/AgentZeroStatusContext.tsx#L180-L186

The pregenerated reply is stamped 4s ahead, and the server copy is saved even later, so it sorts after the message the user typed. Live: typed message 12:41:08.159, canned reply 12:41:08.803. Gate sees Concierge as newest and hides the bubble for the new turn, first while the follow-up list loads and again for the whole second turn.

Also the follow-up cleanup still guards its NVP wipe with AgentZeroOptimisticStore, which is never populated since #95870 (CONCIERGE_THINKING_KICKOFF is only ever set to null), so hasNewerRequest is always false and the in-flight indicator gets cleared together with the recovery timer:

https://github.com/Expensify/App/blob/bb3077d8990361bc592962ea0539d0622c12545a/src/hooks/usePendingConciergeResponse.ts#L100-L106

What changes do you think we should make in order to solve the problem?

  1. Anchor each pregenerated turn to its question: thread questionReportActionID from resolveSuggestedFollowup into PENDING_CONCIERGE_RESPONSE and CONCIERGE_PENDING_FOLLOWUP_LIST.
  2. useShouldSuppressConciergeIndicators: lift the suppression once a user comment exists after that question.
  3. AgentZeroStatusGate: remember the newest action when the agent's label turns on, and keep the bubble if that same action is still newest or if the newest action is the pending pregenerated reply. A real reply that lands after the label turned on still hides the bubble right away, so the existing flash guard stays.
     if (newestReportAction?.actionName === ADD_COMMENT && newestReportAction.actorAccountID !== undefined) {
+        const isLabelOn = serverAgentIDs.includes(newestReportAction.actorAccountID);
+        const isOlderTurnReply = labelBaseline.newestActionID === newestReportAction.reportActionID || pendingFollowupReplyID === newestReportAction.reportActionID;
+        if (!isLabelOn || !isOlderTurnReply) {
             candidateIDs.delete(newestReportAction.actorAccountID);
+        }
     }
  1. Replace the dead optimistic store guard in the follow-up cleanup with an identity check (any user comment after the question), and skip the composer's optimistic clear while a pregenerated turn is reconciling.

Live result with prod account IDs: bubble stays up while the follow-up list loads and through the second turn until the answer lands. Remaining blanks are only where server label itself is empty between turns.

Test branch: https://github.com/Expensify/App/compare/main...mukhrr:App:fix/97049

Out of scope, BE: the canned reply still ends up below the typed message. I tried stamping it right after its question on the client, but server saves it at generation time (12:01:48.820 vs typed 12:00:21.078), so ordering needs a BE change.

What alternative solutions did you explore? (Optional)

Re-timing the canned reply on the client: refuted live, server re-stamps it. Restoring kickoffWaitingIndicator() on send would bring back the optimistic bubble #95870 removed on purpose. Blocking the composer during a turn contradicts the expected result.

After fix video:

https://github.com/user-attachments/assets/2e93a3e8-b410-45ef-b524-9b3762a7dd2a

mukhrr avatar Aug 23 '26 18:08 mukhrr

Proposal

What is the root cause of that problem?

Clicking a suggested follow-up button that carries a pre-generated answer runs resolveSuggestedFollowup. It builds the optimistic Concierge reply with createdOffset: CONCIERGE_RESPONSE_DELAY_MS (4000):

https://github.com/Expensify/App/blob/e51e6af7728321eae7bf9653e3758814f08077fd/src/libs/actions/Report/SuggestedFollowup.ts#L92-L126

Because that call does not pass anchorCreatedToServer, its created is getDBTimeWithSkew(Date.now() + 4000) — a timestamp four seconds in the future (ReportUtils.ts L6662). That exact future value is then used for two things at once: it is written to Onyx via addOptimisticConciergeActionWithDelay, and it is sent to the backend as optimisticConciergeCreated (SuggestedFollowup.ts L119 → Report/index.ts L1036) — the timestamp the server persists the pre-generated reply at.

Now the user sends another message inside that 4-second window. addActions stamps it with getServerAnchoredDBTime(Date.now(), lastVisibleActionCreated) ≈ real now (Concierge chat → anchorCreatedToServer: true):

https://github.com/Expensify/App/blob/e51e6af7728321eae7bf9653e3758814f08077fd/src/libs/actions/Report/index.ts#L899-L908

So the new message's created (≈ now + 2s) is earlier than the pre-generated reply's created (now + 4s). The consequence: the pre-generated Concierge reply is the newest action in the thread even though the user's message was sent after it, and the backend has been told to persist that reply at the future timestamp. The user's new message is therefore no longer the latest action, so the reply Concierge would produce for it is suppressed / sorted above the future-dated canned reply — the message visibly goes unanswered and the thread "appears stuck".

Sibling contrast (why it stays silent otherwise): the branch with no pre-generated answer calls plain addComment with no future offset (SuggestedFollowup.ts L76-L86), and any message sent after the 4-second window is stamped at real now and stays the newest action — in both cases Concierge replies normally. The window only exists for pre-generated replies, and only for ~4s. This is a regression from #86382, which raised the offset from createdOffset: 1 to createdOffset: CONCIERGE_RESPONSE_DELAY_MS to win a near-simultaneous sort race against the user's question; 1 ms opened no exploitable window, four seconds does.

What changes do you think we should make in order to solve the problem?

The four-second value is a reveal delay, not a chat position. It is already carried independently by displayAfter, and usePendingConciergeResponse schedules the reveal from displayAfter — never from created:

So the reply's created only needs to sort immediately after the user's follow-up comment, not four seconds ahead of everything. We should anchor it to the server clock just past that comment, reusing the same notBeforeDBTime clamp that already keeps consecutive user sends monotonic (NetworkState.ts L249-L254):

 const optimisticConciergeAction = buildOptimisticAddCommentReportAction({
     text: selectedFollowup.response,
     actorAccountID: CONST.ACCOUNT_ID.CONCIERGE,
-    createdOffset: CONCIERGE_RESPONSE_DELAY_MS,
+    createdOffset: 1,
+    anchorCreatedToServer: true,
+    lastActionCreated: userCommentCreated,
     reportActionID: optimisticConciergeReportActionID,
     reportID,
     isHTML: true,
     ...
 });

Supporting edit: compute the user's follow-up comment created once in resolveSuggestedFollowup with the same getServerAnchoredDBTime(Date.now(), report.lastVisibleActionCreated) the send path uses, pass it into addComment so the posted comment uses that exact created, and pass it as lastActionCreated above. That makes conciergeReply.created === userComment.created + 1ms regardless of skew.

This is safe because:

  • The 4-second reveal is untouched — it lives in displayAfter (L141) and the reveal reads that, not created (L138).
  • Ordering after the question is still guaranteed — now by the notBeforeDBTime clamp (L249-L254) instead of a multi-second head start. That clamp is skew-proof, which is exactly what the original createdOffset: 1 lacked (it used getDBTimeWithSkew, forward-only skew, while the question uses getServerAnchoredDBTime, bidirectional).
  • Optimistic and server-persisted created stay one identical value passed as optimisticConciergeCreated (L1036), so the reply keeps its chat position when the canonical action lands — the property #86382 was added for.

Note: with a non-future created, a canned answer revealed ~4s later inserts directly after its follow-up question — i.e. above a message the user typed in the meantime. That is its correct causal position (it answers the earlier follow-up), and it leaves the user's newer message as the latest action, which is precisely what lets Concierge reply to it. The old 4s offset placed the canned answer below the newer message, which is what made the thread look answered and swallowed the real reply.

What alternative solutions did you explore? (Optional)

  • Disable the composer / follow-up buttons while a response is pending. Rejected: it blocks a legitimate send in an offline-first app and doesn't fix ordering — a message sent right after the window still lands before the future-dated reply.
  • Clear PENDING_CONCIERGE_RESPONSE when a new message is sent. Rejected: the canned answer to the first follow-up is legitimate and should still appear, and the future-dated optimisticConciergeCreated was already sent to the backend in the first AddComment, so dropping the local copy leaves the root cause in place.

yusufdeveloper2903 avatar Aug 23 '26 18:08 yusufdeveloper2903