Skip to content

fix: do not save queueFlushedData on failed responses#96041

Merged
mountiny merged 7 commits into
Expensify:mainfrom
callstack-internal:fix/gate-queue-flushed-data-on-jsoncode
Jul 16, 2026
Merged

fix: do not save queueFlushedData on failed responses#96041
mountiny merged 7 commits into
Expensify:mainfrom
callstack-internal:fix/gate-queue-flushed-data-on-jsoncode

Conversation

@BartekObudzinski

@BartekObudzinski BartekObudzinski commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

SequentialQueue's process() function commits queueFlushedData (this is how HAS_LOADED_APP gets written to Onyx) whenever a queued request resolves, regardless of the response's jsonCode. HttpUtils.xhr resolves application-level failures instead of rejecting them, so a failed-but-resolved OpenApp or ReconnectApp request still committed HAS_LOADED_APP: true. Once that happens, the next app boot runs ReconnectApp only, and the app can no longer retry a full OpenApp to recover from a stuck loading state.

This change only commits queueFlushedData when the response's jsonCode is CONST.JSON_CODE.SUCCESS, so a failed request no longer marks the app as loaded.

Fixed Issues

$ #96059
PROPOSAL:

Tests

  1. Sign in normally. Verify the app loads to the Inbox as usual (successful OpenApp still marks the app loaded, no stuck loading state).
  2. Using browser dev tools or a proxy, intercept the OpenApp response and force it to resolve with jsonCode: 400 while still returning HTTP 200. Inspect Onyx state and verify hasLoadedApp is NOT set to true, so the next boot retries a full OpenApp instead of being stuck in ReconnectApp-only mode.
  3. Repeat with jsonCode: 200 and verify hasLoadedApp correctly becomes true.
  • Verify that no errors appear in the JS console

Offline tests

N/A — the gate only runs when a response arrives; offline requests stay queued and produce no response.

QA Steps

Same as tests (step 2 requires dev tools or a proxy to intercept the OpenApp response)

  • 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 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 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)
  • 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)
  • 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.
  • 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

Comment thread src/libs/Network/SequentialQueue.ts
@BartekObudzinski
BartekObudzinski marked this pull request as ready for review July 14, 2026 13:15
@BartekObudzinski
BartekObudzinski requested review from a team as code owners July 14, 2026 13:15
@melvin-bot
melvin-bot Bot requested review from cretadn22 and heyjennahay and removed request for a team July 14, 2026 13:15
@melvin-bot

melvin-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

@cretadn22 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 removed the request for review from a team July 14, 2026 13:15
@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 9ae24d6a30

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

@cretadn22

cretadn22 commented Jul 14, 2026

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 proper code patterns were followed (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 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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 and each prop has a /** comment above it */
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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 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 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.
  • 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

OpenApp return 200

Screen.Recording.2026-07-15.at.00.51.38.mov

OpenApp return 400

Screen.Recording.2026-07-15.at.00.50.21.mov

@cretadn22

Copy link
Copy Markdown
Contributor

@BartekObudzinski mind updating this branch with the latest from main?

// Only commit queueFlushedData (e.g. HAS_LOADED_APP: true) on success — HttpUtils resolves (not rejects) app-level
// failures, so committing on a failed-but-resolved OpenApp/ReconnectApp would wrongly mark the app as loaded and
// break self-healing on the next boot.
if (requestToProcess.queueFlushedData && response?.jsonCode === CONST.JSON_CODE.SUCCESS) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

response?.jsonCode has type number | string. While the backend usually returns a number, using strict equality (===) could fail if "200" is ever returned as a string. Should we normalize it with Number(response?.jsonCode) === CONST.JSON_CODE.SUCCESS, or confirm whether the backend API contract strictly guarantees a number here?

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.

Intentional, it matches the successData gate in OnyxUpdates.ts so both commit under the same condition. Normalizing one side only could make them diverge

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

@cretadn22 main sync ready to review

@melvin-bot
melvin-bot Bot requested a review from mountiny July 15, 2026 14:47
@mountiny
mountiny merged commit 1e15d08 into Expensify:main Jul 16, 2026
34 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.36-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 I reviewed the changes in this PR against Expensify's help site content under docs/articles.

No help site changes are required.

This is a purely internal networking fix: it gates the commit of queueFlushedData (the mechanism that writes HAS_LOADED_APP to Onyx) on the response's jsonCode being SUCCESS, so a failed-but-resolved OpenApp/ReconnectApp request no longer marks the app as loaded. The change is invisible to users — there's no new or changed feature, setting, label, workflow, or UI that a customer-facing help article would document.

Files reviewed
  • src/libs/Network/SequentialQueue.ts — code change (jsonCode gate)
  • tests/unit/SequentialQueueTest.ts — unit test
  • contributingGuides/SEQUENTIAL_QUEUE.md — internal developer guide, not part of the public help site (docs/articles)

None of these correspond to any customer-facing help article. No draft PR was created since no documentation update is needed.

@BartekObudzinski, since no help site changes are required, no draft PR was created. If you believe a customer-facing behavior did change and warrants a docs update, let me know and I'll create the PR.

@kavimuru

Copy link
Copy Markdown

@BartekObudzinski @mountiny
Please help with steps 2 and 3 what exactly to be checked

Using browser dev tools or a proxy, intercept the OpenApp response and force it to resolve with jsonCode: 400 while still returning HTTP 200. Inspect Onyx state and verify hasLoadedApp is NOT set to true, so the next boot retries a full OpenApp instead of being stuck in ReconnectApp-only mode.
Repeat with jsonCode: 200 and verify hasLoadedApp correctly becomes true.

@cretadn22

Copy link
Copy Markdown
Contributor

Since this requires dev tools/proxy interception to verify, I think we should mark this PR as 'No QA'

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.

7 participants