Skip to content

Fix staging server toggle resetting on cold start in release builds - #98971

Draft
mikolajpochec wants to merge 11 commits into
Expensify:mainfrom
software-mansion-labs:fix-staging-toggle-native-fix
Draft

Fix staging server toggle resetting on cold start in release builds#98971
mikolajpochec wants to merge 11 commits into
Expensify:mainfrom
software-mansion-labs:fix-staging-toggle-native-fix

Conversation

@mikolajpochec

@mikolajpochec mikolajpochec commented Aug 19, 2026

Copy link
Copy Markdown
Member

Explanation of Change

Fixes the staging toggle resetting to production on Android GH-release builds, and being off by
default on a fresh install of a staging build.

Staging and production ship the same binary, so the environment is inferred at runtime. That
inference compared package.json's version against the latest GitHub release, which decays: once
production catches up, the build resolves to PRODUCTION and ApiUtils discards the stored
preference. It now uses the install source — anything the Play Store didn't install is a build a
tester was handed directly. Decided at install time, no network, cannot decay.

ApiUtils also derives the flag on demand instead of caching it, and getEnvironment can no
longer leave its promise unsettled.

OldDot half: https://github.com/Expensify/Mobile-Expensify/pull/14062 — both are needed for HybridApp.

Behavior changes vs main:

  • Installer ≠ com.android.vending (sideload, adb install, null → unknown) resolves STAGING
    regardless of version — including a sideloaded production APK. com.android.vending is characteristic to apps distributed via Play Store.
  • Play Store installs unchanged.
  • ONYXKEYS.IS_BETA preserved across sign-out (specific scenario, the old way fix).
  • A GitHub response with no usable tag returns production explicitly; it previously fell into
    semver.gt(version, undefined), threw, and landed in the catch. Same verdict, no throw.
  • null/undefined values in the OldDot transition payload are skipped rather than merged as
    {}, which left a truthy non-boolean in SHOULD_USE_STAGING_SERVER.
  • Play alpha/beta-track testers are not covered — install source can't see them.

Fixed Issues

$ #97891
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/CONST/index.ts 94.85% <ø> (ø)
src/libs/ApiUtils.ts 100.00% <100.00%> (ø)
src/libs/Environment/betaChecker/index.android.ts 100.00% <100.00%> (+100.00%) ⬆️
...rc/libs/Environment/getEnvironment/index.native.ts 85.71% <100.00%> (+26.89%) ⬆️
src/libs/actions/App.ts 60.62% <ø> (ø)
src/libs/actions/Delegate.ts 30.81% <ø> (ø)
src/libs/actions/SignInRedirect.ts 74.07% <100.00%> (+0.48%) ⬆️
src/libs/actions/Session/index.ts 59.05% <0.00%> (+2.14%) ⬆️
... and 194 files with indirect coverage changes

@Julesssss

Copy link
Copy Markdown
Contributor

Hi @mikolajpochec could you add the test steps and fix checks please, I'll generate builds in the meantime

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

@mikolajpochec

Copy link
Copy Markdown
Member Author

Hi @mikolajpochec could you add the test steps and fix checks please, I'll generate builds in the meantime

Hi @Julesssss, I'm still waiting for our SWM internal review. I'll add test steps soon, and I'll open this draft

@Julesssss
Julesssss requested a review from marufsharifi August 19, 2026 21:06

@war-in war-in left a comment

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.

Good job overall! I'd just review all comments and check if they can be shortened/removed

Comment on lines +796 to +798
// `?? {}` used to stand in for a missing value, but these keys are not all objects —
// merging `{}` into SHOULD_USE_STAGING_SERVER leaves a truthy non-boolean behind. There is
// nothing to apply when OldDot sends nothing, so skip the key instead.

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.

This sounds like a comment you could add here in GH to explain why the change was made, but it shouldn't land in the code. Once the PR is merged, everyone will wonder what ?? {} was and why this is mentioned here

// `?? {}` used to stand in for a missing value, but these keys are not all objects —
// merging `{}` into SHOULD_USE_STAGING_SERVER leaves a truthy non-boolean behind. There is
// nothing to apply when OldDot sends nothing, so skip the key instead.
if (value === undefined || value === null) {

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.

I wonder if we sometimes would want to send value: null to clear the onyx entry 🤔 if yes, the value won't be applied and we'll waste time debugging
Shouldn't we only check for undefined?

Comment on lines +28 to +33
/**
* Whether something other than the Play Store put this build on the device. Production builds only ever reach a
* device through the Play Store, so any other installer means the build was sideloaded, i.e. downloaded from a
* GitHub release. Unlike the version comparison below, the answer does not change once a production release catches
* up with the build's version — though Android does rewrite the installer if a different one later updates the app.
*/

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.

I wouldn't compare this function to the other in the description comment. Someone might change the other function and the comment would be outdated

* GitHub release. Unlike the version comparison below, the answer does not change once a production release catches
* up with the build's version — though Android does rewrite the installer if a different one later updates the app.
*/
function isSideloadedBuild(): boolean {

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.

How about naming it isProductionBuild?

*/
function isBetaBuild(): IsBetaBuild {
return new Promise((resolve) => {
// A sideloaded build is a beta build: testers install those from GitHub prereleases. Answering here also

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.

It could land in the function description

if (!productionVersion) {

// A rate limited or malformed response carries no usable tag. Production is the safe answer when
// we cannot tell — the missing `return` here used to fall through into semver.gt(version, undefined),

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.

Wasn't that intentional? To fall back to isLastSavedBeta? Also, this comment will get outdated when we merge the PR

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