Skip to content

Keep the leader's unsent writes when another tab syncs the queue - #105420

Open
adhorodyski wants to merge 4 commits into
Expensify:mainfrom
callstack-internal:fm/exfy-3169-queue-fix
Open

adhorodyski wants to merge 4 commits into
Expensify:mainfrom
callstack-internal:fm/exfy-3169-queue-fix

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

A follower tab wrote its old copy of the queue back to shared storage, and the leader read that copy as proof its newer, unsent requests were done, so it dropped a queued ApproveMoneyRequest without ever sending it. Now a tab keeps other tabs' requests in its own memory only, and only followers drop requests that are gone from storage, so the leader removes a request only after it sends it and the server answers.

Fixed Issues

$ #105174
PROPOSAL: N/A

Tests

The new unit test places a follower's older copy of the queue, without the approval, in storage. It checks that the leader still sends ReadNewestAction, OpenReport and ApproveMoneyRequest.

  1. On web, open a report waiting for your approval and click Approve.
  2. Reload the page. Verify the report shows as approved.
  3. Open the app in a second tab. In one tab, open another report waiting for your approval and click Approve.
  4. Reload both tabs. Verify the report still shows as approved.

Before and after, from a two-tab run of the customer's case. The leader pauses its queue with ReadNewestAction and OpenReport and queues ApproveMoneyRequest. The second tab merges and writes its copy, then the queue resumes. The log lines come from the logging in #105372.

Before this change:

  • The second tab logs Merging requests from other tabs with ReadNewestAction and OpenReport.
  • The second tab writes [ReadNewestAction, OpenReport] to shared storage.
  • The leader logs Reconciled deletions from leader tab with removedCommands: ["ApproveMoneyRequest"].
  • The queue resumes with 2 requests.
  • Only ReadNewestAction and OpenReport are sent. The approval never is, and nothing rolls back.

After this change:

  • The second tab logs Merging requests from other tabs but writes nothing to shared storage.

  • There is no Reconciled deletions from leader tab line.

  • The queue resumes with 3 requests.

  • All three are sent, ApproveMoneyRequest last.

  • Verify that no errors appear in the JS console

Offline tests

  1. Open the app in two tabs. Go offline in the leader tab.
  2. Approve a report in the leader tab, then open a report in the other tab.
  3. Go back online. Verify the approval reaches the server and stays approved after both tabs reload.

QA Steps

Same as Tests and Offline 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)
      No new error UI. The failure case is the stale cross-tab write, which the new unit test covers.
    • 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)
      Not run by hand. The unit tests cover the two-tab case.
    • 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).
      Not run. The change only touches the multi-tab write queue.
  • I included screenshots or videos for tests on all platforms
    No UI change. The bug only happens with two web tabs.
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
      Single client, always the leader. Behavior unchanged.
    • Android: mWeb Chrome
      Covered by the unit tests. Manual check pending.
    • iOS: Native
      Single client, always the leader. Behavior unchanged.
    • iOS: mWeb Safari
      Covered by the unit tests. Manual check pending.
    • MacOS: Chrome / Safari
      Covered by the unit tests. Manual two-tab check pending.
  • 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)
    The unit tests log no errors. I will check the browser console during the manual run.
  • 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)
    No copy change.
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
    No new pattern. It reuses isClientTheLeader from ActiveClientManager.
  • 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)
    All 25 test suites that touch the persisted request queue pass.
  • 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)
      No assets.
    • The assets load correctly across all supported platforms.
      No assets.
  • 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.
    No change to message content. Only which tab drops queued requests.
  • 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)
    No component change.
  • 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.
    No component change.
  • 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.
    No page change.
  • 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.
      No UI change.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
      No UI change.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
      No UI change.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
      No UI change.
    • I verified all new/changed elements have meaningful accessible names and roles.
      No UI change.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
      No UI change.
  • 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.
    No review yet.

Screenshots/Videos

Android: Native

No UI change.

Android: mWeb Chrome

No UI change.

iOS: Native

No UI change.

iOS: mWeb Safari

No UI change.

MacOS: Chrome / Safari

No UI change.

A follower tab wrote its whole copy of the queue back to shared storage
whenever it merged a request from another tab. That copy could be older
than the leader's. The leader then treated the stale copy as proof the
missing requests were done and dropped them from memory, so a queued
ApproveMoneyRequest was never sent.

Now a tab only adds other tabs' requests to its own memory. Only
followers drop requests that are gone from storage. The leader removes a
request only after it sends it and the server answers.
Jest loads the mobile ActiveClientManager, where every tab is the
leader, so the tests had to mock isClientTheLeader. They now load the
web module and make leader and follower tabs through its init() and the
ACTIVE_CLIENTS key, the same way browser tabs register.
@adhorodyski
adhorodyski marked this pull request as ready for review October 30, 2026 17:25
@adhorodyski
adhorodyski requested review from a team as code owners October 30, 2026 17:25
@melvin-bot
melvin-bot Bot requested a review from FitseTLT October 30, 2026 17:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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 ⚠️ Failed 2026-10-30T17:53:21.871707Z
We couldn’t complete this review. Comment @codex review to try again.
c5a37f8 Draft marked ready
ℹ️ 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 removed the request for review from a team October 30, 2026 17:26
@melvin-bot

melvin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

@FitseTLT 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 garrettmknight and removed request for a team October 30, 2026 17:26
Comment thread src/libs/actions/PersistedRequests.ts Resolved
@FitseTLT

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • 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 verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 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).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

adhorodyski and others added 2 commits October 31, 2026 13:24
Moves the reconcile block into adoptLeaderDeletions, which returns early
on the leader, and names the pending-writes check isCrossTabWrite. The
leader has no leader to adopt deletions from, so any queue another tab
writes can only be a stale copy. Following it would drop unsent writes.

Moves the leader cross-tab test into SequentialQueueTest, which already
mocks isClientTheLeader, and deletes SequentialQueueCrossTabTest. The
guard only reads that boolean, so the real web election added no
coverage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adhorodyski

Copy link
Copy Markdown
Contributor Author

@FitseTLT are you able to continue the review here?

@FitseTLT

FitseTLT commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Reviewing

@garrettmknight
garrettmknight removed their request for review November 2, 2026 19:35
@FitseTLT

FitseTLT commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@adhorodyski Regarding the Rca in the pr description isn't the onyx.set writing newFromOtherTabs

persistedRequests = [...persistedRequests, ...newFromOtherTabs];
trackOnyxWrite(Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, persistedRequests));

or is it some sort of racing condition between the onyx writes that caused it?
How did you come up with the RCA? Do you have a concrete evidence may be from the logs? I am not reproducing it on main from the steps listed, do you?
I am not saying the change is wrong but I am feeling like we are removing a no-op operation but could we be making a real fix to the issue, that's my doubt.

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.

2 participants