Skip to content

Keep the Concierge thinking indicator when a message is sent mid-turn - #105255

Open
mukhrr wants to merge 8 commits into
Expensify:mainfrom
mukhrr:fix/97049-concierge-indicator
Open

mukhrr wants to merge 8 commits into
Expensify:mainfrom
mukhrr:fix/97049-concierge-indicator

Conversation

@mukhrr

@mukhrr mukhrr commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Sending a message while a pregenerated followup reply was still loading hid the Concierge thinking indicator for the rest of the turn, because followup suppression covered the whole report and the status gate took the canned reply, which sorts after the new message, as the answer. This ties each pregenerated turn to its question so suppression lifts once a newer user message exists, and keeps the indicator while the newest action is a reply to an earlier turn.

Fixed Issues

$ #97049
PROPOSAL: #97049 (comment)

Tests

  1. Open Concierge and ask a question.
  2. Wait for Concierge to respond with suggested followup buttons.
  3. Click one of the suggested followup buttons.
  4. While the reply or the next set of followup buttons is still loading, send another message.
  5. Verify the Concierge thinking indicator stays visible until Concierge answers the second message.
  6. Verify the composer stays usable and Concierge answers without the chat looking stuck.
  • Verify that no errors appear in the JS console

Offline tests

  1. Do steps 1 to 3 above, then go offline and send another message.
  2. Verify the message shows as pending.
  3. Go back online and verify the indicator appears and Concierge answers.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

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 the Expensify/design team 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
682752085-2e93a3e8-b410-45ef-b524-9b3762a7dd2a.mp4

Anchor each pregenerated follow-up turn to its question reportActionID and
use it to detect a newer user message. The follow-up reconciliation no
longer wipes the server indicator for that message, the composer skips its
optimistic clear while a turn is still reconciling, and the pending
follow-up list stops suppressing indicators once the user has sent again.
@mukhrr
mukhrr requested review from a team as code owners October 28, 2026 13:13
@melvin-bot
melvin-bot Bot requested review from situchan and removed request for a team October 28, 2026 13:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T19:51:07.839619Z dc4c242 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@melvin-bot

melvin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

@situchan 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 heyjennahay and removed request for a team October 28, 2026 13:13
Comment thread src/hooks/usePendingConciergeResponse.ts Outdated
Comment thread src/hooks/useShouldSuppressConciergeIndicators.tsx Outdated
Comment thread src/libs/ReportActionFollowupUtils/index.ts Outdated
Comment thread src/pages/inbox/AgentZeroStatusContext.tsx Outdated
The code standards check asks for plain comment sentences, so the dashes and the semicolon-joined clause become separate sentences.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 97389e5147

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +200 to +201
const isPendingFollowupReply = !!pendingFollowupReplyID && pendingFollowupReplyID === newestReportAction.reportActionID;
if (!isLabelOn || (!isNewestFromBeforeLabel && !isPendingFollowupReply)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Track the pregenerated reply before the skeleton marker exists

When the canonical pregenerated action reaches REPORT_ACTIONS before the four-second local reveal finishes, usePendingConciergeResponse takes its persistedAction path and discards the pending response without ever creating CONCIERGE_PENDING_FOLLOWUP_LIST. If the user sent another message in that window, the old reply is future-stamped newest and the processing label was already on, so both exceptions here are false and line 201 removes Concierge; the indicator is again hidden until the newer answer arrives. Track the pending response's reply ID (or otherwise preserve turn identity), not only the post-apply skeleton marker.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I couldnt hit this live. in 8 runs (prod + staging) the reveal ended at 7-14s and the server copy landed 50-76s after the click, so it would need a ~5000 char reply. keeping it out of this PR

Comment thread src/pages/inbox/AgentZeroStatusContext.tsx Outdated
Comment thread tests/unit/hooks/useShouldSuppressConciergeIndicators.test.ts
A label that is already on when the gate mounts can belong to a reply that has landed and is waiting for the server clear, so recording it as the baseline kept the bubble on top of that reply. Also add the missing Given/When/Then comments to the new suppression tests.
@mukhrr

mukhrr commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@situchan this is ready to review. My only concern is this #97049 (comment) .

btw i found another related bug. canned reply still jumps below the typed message tho, so it reads like the answer to it which seems a BE bug to me.

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/hooks/usePendingConciergeResponse.ts 94.20% <100.00%> (-0.05%) ⬇️
src/hooks/useShouldSuppressConciergeIndicators.tsx 100.00% <100.00%> (ø)
src/libs/actions/Report/SuggestedFollowup.ts 86.11% <100.00%> (+0.39%) ⬆️
src/pages/inbox/AgentZeroStatusContext.tsx 94.25% <100.00%> (+0.83%) ⬆️
...ox/report/ReportActionCompose/useComposerSubmit.ts 90.36% <100.00%> (+0.36%) ⬆️
src/libs/ReportActionFollowupUtils/index.ts 93.33% <91.66%> (-1.12%) ⬇️
... and 25 files with indirect coverage changes

@situchan

Copy link
Copy Markdown
Contributor

Please fix conflict

@MelvinBot

Copy link
Copy Markdown
Contributor

Code review

The approach looks right to me: anchoring each pregenerated turn to its question with questionReportActionID is a clean fix. I found one gap that can bring the bug back, plus one minor edge case. The PR also has merge conflicts, as situchan noted.

1. The indicator can still disappear when the canned reply moves below the typed message (medium)

AgentZeroStatusContext.tsx:193-205 keeps Concierge's bubble only when one of these is true:

  • the newest action is the pending followup reply, or
  • the newest action was already newest when the label key changed.

Here is how it fails, using the "canned reply jumps below the typed message" behavior you reported:

  1. You click a followup. Then you type message B after the reply is revealed. At this point the newest action is B.
  2. The new turn's label turns on, or never turns off, while B is still newest. The baseline is B.
  3. The server copy of the canned reply lands with a later created, so it becomes newest. The same update carries <followup-list>, so usePendingConciergeResponse.ts:108-110 clears the pending marker.
  4. Neither condition is true now, so Concierge is removed. The bubble hides while the server is still answering B.

The fix only works if the gate sees the label go off and back on after the reply becomes newest. That does not happen if the clear and set arrive in one batch, or if B is processed while the old turn is still running.

Suggestion: keep the reply → question link after the pending marker clears. For example, store the last pregenerated reply ID with its questionReportActionID. Then keep the agent while hasUserMessageSinceQuestion is true for that question. Please also add a test where the label stays on the whole time and the reply becomes newest after the marker clears.

2. Any change to the agent list resets the baseline (minor)

serverAgentIDsKey joins every server agent ID. In a room that includes Concierge, such as #admins, a custom agent's label turning on resets the baseline. If Concierge's finished reply is newest at that moment and the server has not cleared Concierge's label yet, the bubble shows on top of the reply until the clear lands. That is the flash this block was meant to prevent. Tracking the baseline per agent would fix it.

Everything else looks fine:

  • The new tests include Given/When/Then comments.
  • The inline selector in useShouldSuppressConciergeIndicators updates when questionReportActionID changes, because Onyx's select depends on the selector.
  • Older pending markers without questionReportActionID fall back to the old behavior.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc4c242313

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const {unmount} = renderHook(() => usePendingConciergeResponse(REPORT_ID));
await waitForBatchedUpdates();

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[REPORT_ACTION_ID]: canonicalFollowupAction('2026-07-27 10:00:04.000')});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the missing When section

This newly added case has a // Given section and a // Then section, but the canonical-reply action here is not introduced by a // When comment; add that section before the merge so the test satisfies the repository's required Given/When/Then structure.

AGENTS.md reference: AGENTS.md:L90-L90

Useful? React with 👍 / 👎.

Comment on lines +102 to 105
const hasNewerRequest = hasUserMessageSinceQuestion(getAllReportActions(reportID), pendingFollowupList.questionReportActionID, CONST.ACCOUNT_ID.CONCIERGE);
if (!hasNewerRequest) {
clearAgentZeroProcessingIndicator(reportID, CONST.ACCOUNT_ID.CONCIERGE);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the prior reply identity after reconciliation

When a newer message is still in flight as the canonical reply for the earlier followup gains a real <followup-list>, this path deliberately leaves Concierge's NVP set but immediately clears CONCIERGE_PENDING_FOLLOWUP_LIST. AgentZeroStatusGate uses that marker as its only isPendingFollowupReply identity, so once it disappears, the future-stamped old reply is still newest and the continuously-set server-agent ID never captures it as a new baseline; the gate removes Concierge for the remainder of the newer turn. Fresh evidence beyond the earlier pre-reveal race is that this occurs on the normal post-reveal reconciliation (and TTL) path, so preserve the old-reply identity independently of the skeleton marker.

Useful? React with 👍 / 👎.

Comment on lines +68 to +70
action.actorAccountID !== agentAccountID &&
isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT) &&
action.created > question.created,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude other agents from user-turn detection

In a supported multi-agent report, a later ADDCOMMENT from any co-resident agent satisfies this predicate because only Concierge's account ID is excluded. When the old followup reconciles, hardClearIndicator therefore mistakes that agent reply for a new human request, skips clearing Concierge's processing slot, and can leave Concierge's thinking bubble visible until the safety timeout even though no user sent another message; distinguish human-authored comments or exclude every agent identity rather than only the passed agent.

Useful? React with 👍 / 👎.

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Web test steps verification results: ❌ fail

Typed messages and followup clicks worked without a stuck indicator. When a message was sent right after a followup click, Concierge never replied and no indicator appeared, even after about 3 minutes.
About 3 minutes later: no reply and no indicator

Step Status
Typed message: the indicator shows, then clears when the reply rendersSent two typed questions. Both replies rendered fully with no leftover indicator above or below them.
Concierge reply rendered cleanly with no stray indicator
✅
Followup click: no indicator under the reply while the next followups loadThe reply streamed in with no thinking bubble below it. The followup skeleton took 30+ seconds to clear, which is slow but is not the indicator.
Reply streaming in with no thinking indicator below itFollowup skeleton, no thinking bubble
✅
Followup click, then a typed message mid-turn: the indicator stays until Concierge answersThe typed message sent successfully (AddComment returned 200). No indicator appeared, and Concierge never replied after about 3 minutes.
Typed message sent right after a followup click, no indicatorAbout 3 minutes later: no reply and no indicator
❌
The composer stays usable, with no console errorsThe composer worked at every step. The tester could not read the web console. The network log showed only 200s during the failed step.
✅

Code check for regressions

I found no regressions in the existing flows. Steps 1 and 2 above confirm the normal typed and followup paths still behave.

The step 3 failure is probably not caused by this PR. The PR changes only local Onyx state, and clearAgentZeroProcessingIndicator is a local merge. No indicator appeared, so the server likely never set a label for that message. I did not run the same steps on main. Please retry them there to confirm whether the backend drops a message sent mid-turn.

Behavior changes I checked
  • Removed AgentZeroOptimisticStore check: not a regression. On this branch nothing calls kickoffWaitingIndicator or sets CONCIERGE_THINKING_KICKOFF. The old hasNewerRequest check was always false.
  • Skipped optimistic clear on send (useComposerSubmit.ts:82-85): after a followup click, sending no longer clears an old label. This lasts until the followup list arrives, or up to 120 seconds. A persisted label such as "...is working on your chat" would stay until the server updates it. Low risk.
  • Baseline reset on any agent-list change (AgentZeroStatusContext.tsx:193-205): in multi-agent rooms, a finished reply can briefly show a bubble until the server clears the label. I reported this in my earlier review.
  • Performance: the new selector in useShouldSuppressConciergeIndicators returns early when no followup is pending, so other reports pay almost nothing.

This branch has not been deployed

No deployments
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.

3 participants