Skip to content

Consolidate AgentZero status into a Context#85535

Open
adhorodyski wants to merge 13 commits intoExpensify:mainfrom
callstack-internal:decompose/agent-zero-status-context
Open

Consolidate AgentZero status into a Context#85535
adhorodyski wants to merge 13 commits intoExpensify:mainfrom
callstack-internal:decompose/agent-zero-status-context

Conversation

@adhorodyski
Copy link
Contributor

@adhorodyski adhorodyski commented Mar 17, 2026

@rlinoz @mountiny @TMisiukiewicz

Explanation of Change

This PR replaces three scattered modules managing Concierge/AgentZero status with a single AgentZeroStatusContext using a two-level gate pattern:

  • Outer gate (AgentZeroStatusProvider): A cheap scalar check — if the current report is not a Concierge chat, children render with zero overhead (no hooks, no Pusher, no state).
  • Inner gate (AgentZeroStatusGate): Owns all logic for Concierge chats: Onyx subscription, Pusher subscription with per-callback cleanup, reasoning state with deduplication, and debounced label updates.

Consumers (ConciergeThinkingMessage, ReportActionCompose) now read from context instead of receiving props drilled through 4 levels (ReportScreen → ReportActionsView → ReportActionsList → ConciergeThinkingMessage).

Deleted modules:

  • src/hooks/useAgentZeroStatusIndicator.ts (162 lines)
  • src/libs/ConciergeReasoningStore.ts (122 lines)
  • Reasoning subscription functions from src/libs/actions/Report/index.ts (~50 lines)

New:

  • src/pages/inbox/AgentZeroStatusContext.tsx (224 lines)
  • src/selectors/ReportNameValuePairs.ts — new agentZeroProcessingIndicatorSelector

Tests: 21 new tests replace 3 deleted test files. 15 files changed, +462/-1386 lines.

Note: This PR depends on PR #85355 (useIsInSidePanel) and PR #85356 (Pusher per-callback handles). CI will fail until those merge.

Fixed Issues

$ #84895
PROPOSAL:

Tests

  1. Open Concierge chat → send a message → verify the "thinking" indicator appears with a status label (e.g., "Concierge is looking up...")
  2. Watch the reasoning history expand → tap the chevron to expand/collapse reasoning entries → verify animation works smoothly
  3. Send another message while Concierge is still processing → verify the indicator resets and starts fresh (new request ID clears old reasoning)
  4. Open a non-Concierge chat (any DM, group, or room) → verify no thinking indicator appears and no performance overhead
  5. Open Concierge chat in the side panel → verify the thinking indicator works the same as in the main view
  6. Open Concierge in both main view and side panel simultaneously → send a message → verify both show the indicator in sync
  7. Send a message to Concierge → immediately navigate away before response arrives → navigate back → verify no stale indicators or duplicate subscriptions
  8. Toggle airplane mode on/off during Concierge processing → verify the indicator clears when offline and resumes when back online
  9. Open Concierge → send a message → verify typing indicator still shows below the composer
  10. Log out and log back in → open Concierge → send a message → verify the indicator works fresh with no leaked state from the previous session

Offline tests

N/A

QA Steps

Same as tests, plus:

  1. Open the Concierge DM in the main pane and send a message that triggers AgentZero processing
  2. Wait for the thinking bubble to appear with reasoning entries streaming in — expand it to confirm entries are visible
  3. While AgentZero is still processing, open the side panel showing the same Concierge chat
  4. Send a message in the side panel to dismiss the welcome state
  5. Verify the side panel's thinking bubble appears. New reasoning entries arriving after both panes are open should appear in both.
  6. Once AgentZero finishes and sends its reply, verify both panes clear the thinking bubble and show the final response correctly

Known limitation: The side panel will only show reasoning entries that arrive after it mounts. Earlier entries visible in the main pane won't backfill into the side panel. This is cosmetic — both panes converge once new entries arrive or processing completes. A new user message triggers a new agentZeroRequestID which resets the reasoning chain in both panes anyway.

  • 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 followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • 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 @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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

Replace three scattered modules (useAgentZeroStatusIndicator hook,
ConciergeReasoningStore, and Pusher reasoning subscriptions in
Report/index.ts) with a single AgentZeroStatusContext that uses a
two-level gate pattern:

- Outer gate (AgentZeroStatusProvider): cheap scalar check — if not
  Concierge chat, renders children with no hooks/Pusher/state overhead
- Inner gate (AgentZeroStatusGate): owns all logic for Concierge chats:
  Onyx subscription, Pusher subscription with per-callback cleanup,
  reasoning state with deduplication, debounced label updates

Consumers (ConciergeThinkingMessage, ReportActionCompose) now read from
context instead of receiving props drilled through 4 levels. The prop
chain ReportScreen → ReportActionsView → ReportActionsList →
ConciergeThinkingMessage is eliminated.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@adhorodyski adhorodyski force-pushed the decompose/agent-zero-status-context branch from 964e83a to bbc1155 Compare March 17, 2026 13:31
@adhorodyski adhorodyski changed the title [No QA] Consolidate AgentZero status into a shared context provider Consolidate AgentZero status into a shared context provider Mar 17, 2026
@codecov
Copy link

codecov bot commented Mar 17, 2026

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/libs/actions/Report/index.ts 68.03% <ø> (-0.35%) ⬇️
src/pages/inbox/report/ReportActionsList.tsx 77.40% <ø> (+0.43%) ⬆️
src/pages/inbox/report/ReportActionsView.tsx 80.71% <ø> (-0.14%) ⬇️
src/pages/inbox/report/ReportFooter.tsx 53.70% <100.00%> (ø)
src/selectors/ReportNameValuePairs.ts 100.00% <100.00%> (+100.00%) ⬆️
src/hooks/useShouldSuppressConciergeIndicators.ts 80.00% <80.00%> (ø)
src/pages/home/report/ConciergeThinkingMessage.tsx 1.88% <50.00%> (+1.88%) ⬆️
...report/ReportActionCompose/ReportActionCompose.tsx 69.06% <75.00%> (+0.16%) ⬆️
src/pages/inbox/AgentZeroStatusContext.tsx 97.91% <97.91%> (ø)
src/pages/inbox/ReportScreen.tsx 70.84% <63.63%> (-0.28%) ⬇️
... and 7 files with indirect coverage changes

adhorodyski and others added 3 commits March 17, 2026 15:20
The new eslint-config-expensify@2.0.107 enforces context-provider-split-values:
contexts must not mix data and functions in a single provider.

Split AgentZeroStatusContext into:
- AgentZeroStatusStateContext: {isProcessing, reasoningHistory, statusLabel}
- AgentZeroStatusActionsContext: {kickoffWaitingIndicator}

Export useAgentZeroStatus() for state and useAgentZeroStatusActions()
for actions. Update ReportActionCompose to use the actions hook.
Update tests to use the appropriate hook per test case — state-only
tests use useAgentZeroStatus(), tests needing both spread inline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…atus-context

# Conflicts:
#	src/hooks/useAgentZeroStatusIndicator.ts
#	src/pages/inbox/ReportScreen.tsx
@adhorodyski adhorodyski marked this pull request as ready for review March 18, 2026 13:24
@adhorodyski adhorodyski requested review from a team as code owners March 18, 2026 13:24
@melvin-bot melvin-bot bot requested a review from DylanDylann March 18, 2026 13:24
@melvin-bot
Copy link

melvin-bot bot commented Mar 18, 2026

@DylanDylann 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 trjExpensify and removed request for a team March 18, 2026 13:24
Copy link

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

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: 7c1c53a639

ℹ️ 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".

@rlinoz rlinoz self-requested a review March 18, 2026 14:16
@adhorodyski adhorodyski changed the title Consolidate AgentZero status into a shared context provider [HOLD] Consolidate AgentZero status into a Context Mar 18, 2026
@adhorodyski
Copy link
Contributor Author

Marked as HOLD, SQ fixes that this PR needs will likely get reverted. I'll keep monitoring with @szymonzalarski98.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@trjExpensify
Copy link
Contributor

PR doesn’t need product input as a performance PR. Unassigning and unsubscribing myself.

@trjExpensify trjExpensify removed their request for review March 18, 2026 16:28
adhorodyski and others added 2 commits March 18, 2026 18:28
…me state

Self-derive shouldSuppressIndicators inside AgentZeroStatusGate using
side-panel context and report actions, then expose it via useAgentZeroStatus().
ConciergeThinkingMessage and a new AgentZeroAwareTypingIndicator wrapper
consume the flag to hide indicators until the user sends a message.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@adhorodyski adhorodyski changed the title [HOLD] Consolidate AgentZero status into a Context Consolidate AgentZero status into a Context Mar 19, 2026
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const isConciergeChat = reportID === conciergeReportID;
const isAdmin = chatType === CONST.REPORT.CHAT_TYPE.POLICY_ADMINS;
const isAgentZeroChat = isConciergeChat || isAdmin;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use isConciergeChatReport function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it requires me to provide the whole report to it which does not make sense here (and in general nowhere) now I'm able to calculate this without connecting to any onyx value and rely on route's reportID

@DylanDylann
Copy link
Contributor

  1. Open Concierge in both main view and side panel simultaneously → send a message → verify both show the indicator in sync

@adhorodyski I’m curious about how to simulate this test case. Could you help me?

@DylanDylann
Copy link
Contributor

  1. Open Concierge → send a message → verify typing indicator still shows below the composer

@adhorodyski Also confused about this test case? What typing indicator does you mean? I don't see any typing indicator in this case

@DylanDylann
Copy link
Contributor

@codex review

@DylanDylann
Copy link
Contributor

@adhorodyski I noticed a flicker when we open another chat and then go back to the Concierge chat. The old indicator briefly appears before disappearing, and then a new indicator shows up again after a few seconds.

Screen.Recording.2026-03-23.at.16.37.52.mov

Copy link

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

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: ff6322c2aa

ℹ️ 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".

adhorodyski and others added 4 commits March 23, 2026 11:52
Document the public interface (AgentZeroStatusState, AgentZeroStatusActions)
with JSDoc comments explaining each field's purpose, and add inline comments
to internal state variables, refs, effects, and derived values in the gate.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…hook

Extract useShouldSuppressConciergeIndicators hook that each consumer calls
directly, removing shouldSuppressIndicators from AgentZeroStatusState.
This keeps the context pure (isProcessing, reasoningHistory, statusLabel)
and scopes suppression to Concierge DMs only, fixing the #admins bug.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@adhorodyski
Copy link
Contributor Author

adhorodyski commented Mar 23, 2026

@adhorodyski I noticed a flicker when we open another chat and then go back to the Concierge chat. The old indicator briefly appears before disappearing, and then a new indicator shows up again after a few seconds.

This is because the NVP value only refreshes after a successful OpenReport most likely, working on this.

edit: ok looks like the old useAgentZeroStatusIndicator hook had the same isProcessing = !!serverLabel || !!optimisticStartTime derivation and the same flash. this should be also happening on main.

@adhorodyski
Copy link
Contributor Author

Open Concierge → send a message → verify typing indicator still shows below the composer
@adhorodyski Also confused about this test case? What typing indicator does you mean? I don't see any typing indicator in this case

I believe I broke this 2 commits before, can you retest please?

@adhorodyski
Copy link
Contributor Author

Open Concierge in both main view and side panel simultaneously → send a message → verify both show the indicator in sync
@adhorodyski I’m curious about how to simulate this test case. Could you help me?

I think the ~only case for this is the header's concierge everywhere features (Help button). @rlinoz can you confirm if there's any other way that we can have 2 concierge chats on the display (one in RHP)?

@rlinoz
Copy link
Contributor

rlinoz commented Mar 23, 2026

AFAIK that is the only way really

Avoids defaulting to empty string which violates the no-default-id-values
lint rule.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DylanDylann
Copy link
Contributor

Open Concierge → send a message → verify typing indicator still shows below the composer

@adhorodyski It still doesn’t work on my side.

@DylanDylann
Copy link
Contributor

DylanDylann commented Mar 24, 2026

@adhorodyski Could you please add video evidence?

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.

4 participants