Skip to content

[No QA] Repair the HybridWeb experience cookie after New Expensify starts - #107009

Draft
jakubstec wants to merge 1 commit into
Expensify:mainfrom
software-mansion-labs:jakubstec/hybridweb-experience-cookie-repair
Draft

jakubstec wants to merge 1 commit into
Expensify:mainfrom
software-mansion-labs:jakubstec/hybridweb-experience-cookie-repair

Conversation

@jakubstec

@jakubstec jakubstec commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Explanation of Change

Context. expensify.com is going to serve both products from one address. A router in front of it picks New Expensify or Expensify Classic based on the experience cookie. The Classic backend rewrites the cookie from the account's saved preference whenever it serves a page. With experience=new the router sends the user to New Expensify, so the backend never gets that chance. If the preference changes to Classic while the cookie says new, the user stays in New Expensify for as long as the cookie lives, up to a year. This happens when the user switches to Classic in another browser, closes the tab while the switch is saving, or is removed from the hybridWeb beta.

What changes

  • After the app starts on expensify.com, New Expensify checks the cookie once, as soon as the first OpenApp or ReconnectApp response has been applied:
    • The cookie is new and the account in the beta prefers Classic: it opens Classic the same way switching does, which sets experience=classic first.
    • The cookie is new and the account is no longer in the beta: it deletes the cookie and opens Classic, which then sends the user wherever it did before HybridWeb.
    • Anything else: nothing changes. Without a new cookie the user reached New Expensify through a New Expensify-only link on purpose, and Classic fixes the cookie on the next visit to a shared path.
  • The check only runs on the response from the server. A new RAM-only flag, hasFreshAppData, is set in the success data of OpenApp and ReconnectApp. It's only applied after a successful response and lands in the same Onyx update as the response data, so the check never decides on data cached by an earlier session. Requests that run outside the queue (GetMissingOnyxMessages, the side-effect ReconnectApp) don't set it.
  • Supportal and Copilot sessions are skipped, like the backend does, because the cookie belongs to the agent.
  • The check does nothing while the betas or the beta configuration haven't loaded, so the user isn't treated as removed from the beta too early.
  • To prevent a loop, each tab repairs the cookie at most once, recorded in sessionStorage. A start that keeps the user in New Expensify clears the record, so the next mismatch in that tab is repaired again. If sessionStorage is unavailable, the check doesn't navigate.
  • useOpenClassic ignores a second call on expensify.com, because the first one already replaces the page. This covers the check and "Switch to Expensify Classic" finishing in the same queue flush.
  • readExperienceCookie and isSharedProductHost are exported from ExperienceCookie, with no-op native versions.

On new.expensify.com, its dev host and native, the check does nothing.

Known limits

  • The check uses shouldUseOldApp, the same rule native HybridApp uses, and it differs from the backend in two cases that fail safe. An account with isLockedToNewApp stays in New Expensify. So does a classicRedirect without a boolean dismissed, which the backend treats as Classic. In both cases the cookie isn't repaired and nothing loops.
  • An incremental ReconnectApp doesn't return betas, so removal from the beta is caught at the next OpenApp: signing in, clearing the cache and then reloading, or a full reconnect.
  • The check decides once each time the signed-in app starts. A preference changed elsewhere during the session is picked up on the next reload.
  • If the first successful response arrives late, for example after starting offline, Classic opens at that point.
  • hasFreshAppData isn't shared between tabs. A tab that isn't processing the request queue doesn't get it and doesn't repair the cookie.
  • On non-production builds beta overrides can make the app and the backend disagree about the beta, which costs at most one trip to Classic per tab.
  • "Go back just once" in the exit survey still opens Classic without useOpenClassic on purpose, because a one-time visit must not change the cookie.

This removes the blocker named in Write and clear the HybridWeb experience cookie when switching to Classic and signing out: "The router must stay off for the beta until this check ships."

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/700250

Tests

Prerequisites

  • A local Expensidev VM running Web-Expensify main.
  • A test account in the hybridWeb beta, and a second local account to act as its Copilot. Locally every account has the all beta, which doesn't include the explicit-only hybridWeb, so in the VM set private static array $toggledBetas = [self::BETA_HYBRID_WEB]; in Web-Expensify/lib/BetaManager.php and sign in again. Revert it in step 9.
  • No hybridWeb beta override in the app's Troubleshoot settings.
  • The account's tryNewDot NVP must have nudgeMigration, or Settings doesn't show "Switch to Expensify Classic", and classicRedirect.dismissed: false. To reset it, run from Expensidev/ with your account ID and check the reply is 200 OK:
    printf '%s\n' 'Query' "query: UPDATE nameValuePairs SET value='{\"classicRedirect\":{\"dismissed\":false},\"nudgeMigration\":{\"timestamp\":\"2026-10-01T00:00:00.000Z\"}}' WHERE accountID=<accountID> AND name='tryNewDot';" 'format: json' '' | vagrant ssh -- -T '(cat; sleep 3) | nc -q 1 127.0.0.1 4444'
    A signed-in app keeps its cached NVP until the next sign-in, so the steps sign in again after each reset.
  • The app served from the shared host:
    1. In /etc/hosts, change the existing expensify.com.dev entry, which points to the VM, to 127.0.0.1. Restore it after testing.
    2. From App/, run mkcert -cert-file config/rsbuild/certificate.pem -key-file config/rsbuild/key.pem dev.new.expensify.com expensify.com.dev localhost 127.0.0.1.
    3. In .env, set NEW_EXPENSIFY_URL=https://expensify.com.dev:8082/, EXPENSIFY_URL=https://www.expensify.com.dev/ and USE_WEB_PROXY=false.
    4. Run npm run web-server -- --host expensify.com.dev.

There's no router locally, so the cookie is set by hand. On any page on expensify.com.dev, including Classic, run this in the console:
document.cookie = 'experience=new; Domain=.expensify.com.dev; Path=/; Max-Age=31536000; Secure; SameSite=Lax'
Change new to classic where a step says so. Turn on "Preserve log" in DevTools > Network and the "Verbose" level in the console. The once-per-tab record is EXPERIENCE_COOKIE_REPAIR under DevTools > Application > Session storage > https://expensify.com.dev:8082.

  1. Reset the tryNewDot NVP and sign in with the beta account on https://expensify.com.dev:8082. Set the cookie to new and reload the page.
  2. Verify the tab stays in New Expensify, no OpenOldDotLink request is sent, and Session storage has no EXPERIENCE_COOKIE_REPAIR.
  3. Open a private window, sign in with the same account on https://expensify.com.dev:8082, press "Switch to Expensify Classic" in Settings and complete the survey. Close the private window once Classic opens.
  4. In the first window, reload the page. Verify that after the ReconnectApp response arrives, an OpenOldDotLink request is sent and the tab opens https://www.expensify.com.dev/inbox, and in Network the inbox document request has experience=classic in its Cookie header.
  5. While Classic is still open in that tab, set the cookie to new, then open https://expensify.com.dev:8082 in the same tab. Verify the tab stays in New Expensify, the console shows [ExperienceCookie] Not repairing the cookie again in this tab, and Session storage still has EXPERIENCE_COOKIE_REPAIR.
  6. Set the cookie to classic and reload the page. Verify the tab stays in New Expensify and EXPERIENCE_COOKIE_REPAIR is removed from Session storage.
  7. Set the cookie to new and reload the page. Verify the tab opens Classic again.
  8. Open https://expensify.com.dev:8082 in the same tab and wait until the ReconnectApp request has finished. Set the cookie to new, block the ReconnectApp request URL in DevTools > Network request blocking and reload the page. Verify the tab stays in New Expensify while ReconnectApp fails. Remove the block and wait up to 10 seconds for the retry to succeed. Verify the tab opens Classic.
  9. Open https://expensify.com.dev:8082 and sign out. Reset the tryNewDot NVP and revert the BetaManager.php change. On the sign-in page, set the cookie to new and sign in again. Verify that after OpenApp, the experience cookie is deleted before OpenOldDotLink is sent, and the inbox document request carries no experience cookie. Classic then redirects to New Expensify on its own host, which is expected.
  10. Restore the BetaManager.php change. In Settings > Security of the beta account, add the second account as a Copilot. Sign in with the second account on https://expensify.com.dev:8082 and switch to the beta account as its Copilot. Switch the beta account to Classic from a private window as in step 3, then set the cookie to new in the first window and reload the page. Verify the tab stays in New Expensify and the cookie is still new.
  11. Sign out, reset the tryNewDot NVP and sign in with the beta account again. Set the cookie to new, set throttling to "Slow 3G" in DevTools > Network and reload the page. Before ReconnectApp finishes, press "Switch to Expensify Classic" in Settings and complete the survey. Verify only one OpenOldDotLink request is sent and Classic opens once.
  12. Restore .env and /etc/hosts, restart the app with npm run web and sign in with the beta account on https://dev.new.expensify.com:8082. Switch the account to Classic from a private window as in step 3 and reload the page. Verify no OpenOldDotLink request is sent and the tab stays in New Expensify.
  • Verify that no errors appear in the JS console

Offline tests

  1. Reset the tryNewDot NVP, sign in with the beta account on https://expensify.com.dev:8082 and switch to Classic from a private window as in step 3 of the Tests.
  2. In the first window, turn on "Force offline" in Account > Troubleshoot.
  3. Set the cookie to new and reload the page.
  4. Verify the tab stays in New Expensify and no ReconnectApp or OpenOldDotLink request is sent.
  5. Turn off "Force offline". Verify that once ReconnectApp succeeds, the tab opens Classic.

QA Steps

Staging runs on staging.new.expensify.com and adhoc builds on their own test hosts, not on staging.expensify.com, so the check is off there and only the switching flow can be checked.

  1. Sign in on staging.new.expensify.com with an account that shows "Switch to Expensify Classic" in Settings.
  2. Press "Switch to Expensify Classic" and complete the survey if it shows.
  3. Verify Classic opens once.
  • 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 @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).
  • 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

@jakubstec

Copy link
Copy Markdown
Member Author

@MelvinBot review
@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T15:58:28.143675Z 9ea3ccf 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.

@codecov

codecov Bot commented Nov 16, 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 96.15% <ø> (ø)
src/ONYXKEYS.ts 100.00% <ø> (ø)
src/hooks/useOpenClassic.ts 100.00% <100.00%> (ø)
src/hooks/usePermissions.ts 100.00% <ø> (ø)
src/libs/ExperienceCookie/index.native.ts 100.00% <100.00%> (ø)
src/libs/ExperienceCookie/index.ts 97.87% <100.00%> (+0.43%) ⬆️
src/libs/ExportOnyxState/masking.ts 93.45% <ø> (ø)
...Navigation/AppNavigator/AuthScreensInitHandler.tsx 88.11% <100.00%> (+0.11%) ⬆️
src/libs/actions/App.ts 85.89% <100.00%> (+5.21%) ⬆️
src/setup/index.ts 100.00% <ø> (ø)
... and 1 more
... and 32 files with indirect coverage changes

@MelvinBot

Copy link
Copy Markdown
Contributor

Review finding

[P2] Reset the repair decision when switching accounts — useRepairExperienceCookie.ts:67–76

Starting as a Copilot sets hasDecided before skipping repair. Disconnecting then restores the original account and clears Onyx without remounting this hook. Consequently, the original account’s fresh OpenApp response cannot trigger repair—even if its preference changed to Classic elsewhere and its cookie remains new.

Scope the decision to account initialization, or reset it when app freshness resets. Add coverage for Copilot → original-account restoration.

Static review only; browser behavior was not verified.


view run

@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: 9ea3ccf886

ℹ️ 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 +174 to +175
// Then only a known experience value is returned
expect(readExperienceCookie()).toBe(expected);

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 required When sections to the new cookie tests

The three new test blocks include // Given and // Then, but none has a // When section. AGENTS.md explicitly requires all three, with comments explaining why each phase exists. Add the missing action section to these cases rather than combining invocation and assertion under Then.

AGENTS.md reference: AGENTS.md:L93-L93

Useful? React with 👍 / 👎.


/** A start that keeps the user in New Expensify ends any back and forth, so the next mismatch in this tab can be repaired again */
function releaseRepairInThisTab() {
if (typeof sessionStorage === 'undefined') {

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 Catch failures while resolving sessionStorage

When a browser denies Web Storage access, resolving the sessionStorage property can itself throw a SecurityError; typeof sessionStorage still invokes that getter. This probe is outside the try, as is the equivalent probe in claimRepairInThisTab, so the error escapes the new startup effect instead of safely skipping repair. This cleanup helper runs even when there is no new cookie, exposing ordinary shared-host initialization to the failure. Move both availability probes inside their protected access blocks.

Useful? React with 👍 / 👎.

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