Skip to content

fix: clear NO_RADIO when a request succeeds - #108128

Open
adhorodyski wants to merge 12 commits into
Expensify:mainfrom
callstack-internal:fix/network-state-clear-no-radio-on-success
Open

adhorodyski wants to merge 12 commits into
Expensify:mainfrom
callstack-internal:fix/network-state-clear-no-radio-on-success

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

A successful request can now also clear the NO_RADIO hard stop after re-reading the current network state by NetInfo, so the app recovers even when it misses the reconnect.

Fixed Issues

$ #107620
PROPOSAL: N/A

Tests

Unit tests: tests/unit/NetworkStateReachabilityTest.ts, "success while NO_RADIO is set clears it once a NetInfo re-read finds a connection", which fails without the fix, and "success while NO_RADIO is set never brings the app online when the NetInfo re-read still reports no connection", which guards against the online/offline loop.

Manual test, web (Chrome). The NetInfo patch from #108127 fixes the Wi-Fi case, so simulate the missed reconnect:

  1. Open the App and, from the console, hold navigator.onLine at false, dispatch change on navigator.connection, then restore navigator.onLine without dispatching any event.
  2. Verify the offline banner appears and stays.
  3. Open Account, which sends the OpenInitialSettingsPage read.
  4. Verify the Network tab shows ReconnectApp being sent and the offline banner goes away without a reload.
  • Verify that no errors appear in the JS console

Offline tests

  1. Turn on airplane mode or turn off the Wi-Fi.
  2. Verify the offline banner appears and stays while offline. Navigating around must not clear it.
  3. Turn the network back on and verify the banner goes away.

QA Steps

Same as Offline tests, on staging.

// 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 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

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adhorodyski and others added 2 commits November 26, 2026 20:28
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adhorodyski and others added 3 commits November 26, 2026 22:27
Tests that go offline now leave requests unanswered instead of answering them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The in-flight APITest request now fails when the radio drops instead of getting an answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adhorodyski
adhorodyski marked this pull request as ready for review November 26, 2026 21:42
@adhorodyski
adhorodyski requested review from a team as code owners November 26, 2026 21:42
@expensify-chore-bot
expensify-chore-bot Bot requested review from Krishna2323 and removed request for a team November 26, 2026 21:42
@expensify-chore-bot

Copy link
Copy Markdown

@Krishna2323 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]

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 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-26T21:56:11.827288Z 60d4fd8 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.

@expensify-chore-bot
expensify-chore-bot Bot requested review from garrettmknight and removed request for a team November 26, 2026 21:42

@Krishna2323 Krishna2323 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.

Small things: the comments at NetworkState.ts:36 and FailureTracker.ts:20 still refer only to INTERNET_UNREACHABLE. ReimbursementAccountPageOfflineTest.tsx:156 still says the fetch settles, but it's paused now.

Comment thread src/libs/NetworkState.ts Outdated
if (!hasRadio) {
Log.info('[NetworkState] NO_RADIO cleared — a successful request proved connectivity');
hasRadio = true;
NetInfo.refresh();

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.

If NetInfo still reports isConnected=false when refresh() resolves, setHasRadio(false) sets NO_RADIO again. Each successful read then flips the app online and back offline, triggers a queue flush, and schedules a ReconnectApp, leaving the app offline.

A Jest test with an async refresh mock returning isConnected: false and 3 successful requests reproduces offline/online flips [false, true, false, true, false, true] and 3 reconnects.

Your issue comment says a success should count "no matter what the library says."

Is this PR intended to cover only the case where NetInfo corrects itself on refresh? The new test mocks refresh as a no-op, so it doesn't cover what happens after the re-read.

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.

That is on purpose. NetInfo gets the final say, so if it still says offline, we go back offline. It's correct though to re-ask for this state when any READ succeeds, and the library should be made solid with upstream fixes when proved unreliable (I did a patch in another PR with just that for Chrome). Added a test for it too.

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 can reproduce this on the iOS simulator. NetInfo is stuck on isConnected=false, type=none while every request returns 200, and the app gets into a loop.

A read succeeds and clears NO_RADIO. The app goes online and flushes the queue, causing pages to re-fire OpenHomePage, OpenSearchPage, and SearchForTodos. refresh() then sets NO_RADIO again, and the re-fired reads clear it again.

This repeats every ~560 ms, causing the banner to flicker nonstop. Every cycle also sends 3+ reads and a ReconnectApp.

Because going online is what triggers the next reads, giving NetInfo the final say doesn't leave the app offline,it keeps it looping.

Monosnap.screencast.2026-12-01.22-12-47.mp4

Comment thread src/libs/NetworkState.ts Resolved
adhorodyski and others added 2 commits November 30, 2026 19:41
Adds a test for a re-read that still reports no connection and updates comments that only mentioned INTERNET_UNREACHABLE.

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

Copy link
Copy Markdown
Contributor Author

@Krishna2323 I have reworded some explanations too so it's clear what I'm after with this PR.

@Krishna2323

Krishna2323 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

@adhorodyski I left a comment on this thread: #108128 (comment)

Please check when you get a chance. Thanks!

adhorodyski and others added 2 commits December 2, 2026 22:05
Clearing NO_RADIO straight from a successful request looped when NetInfo
stayed wrong: going online re-fired reads, the re-read set NO_RADIO again,
and those reads cleared it again. The success now only triggers the re-read.

With that, the test workarounds that kept requests from succeeding while
offline are no longer needed, so SessionTest, APITest and
ReimbursementAccountPageOfflineTest go back to main.

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

Copy link
Copy Markdown
Contributor Author

@Krishna2323 really good catch, thank you. I worked on this for a while and settled on the fact that we shouldn't in fact force a true/false NO_RADIO by hand like initially proposed. I believe the current state of this PR is correct, we just use successful READs as clues to re-read the current network state and that allows for getting back online, which is not yet possible on current main.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/libs/FailureTracker.ts 100.00% <ø> (ø)
src/libs/NetworkState.ts 95.30% <100.00%> (+0.18%) ⬆️
... and 7552 files with indirect coverage changes

@adhorodyski

Copy link
Copy Markdown
Contributor Author

@Krishna2323 are you able to continue the review here?

Comment thread src/libs/NetworkState.ts
// false does not re-set the hard stop. When the Ping finally passes, the NetInfo listener
// sees the app is already online and does nothing.
onRequestSuccess(() => {
if (!hasRadio) {

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.

❌ CONSISTENCY-18 (docs)

On a successful request the INTERNET_UNREACHABLE path (below) clears the hard stop directly, but the new NO_RADIO path instead calls NetInfo.refresh() and then does nothing when hasRadio is still false. Why these two branches differ — that NetInfo can miss the radio reconnect so a re-read is needed, and that clearing hasRadio directly on success would flip the app briefly online, re-fire the reads that bypass the paused queue, and loop with each re-read — is non-obvious and only documented in the test, not at the code. The module comment above onRequestSuccess explains the overall wiring but not this asymmetry or the inner if (!hasRadio) return guard.

Add a short comment at the branch, e.g.:

if (!hasRadio) {
    // NetInfo can miss a radio reconnect, so re-read it instead of clearing NO_RADIO here directly:
    // clearing it on success would flip the app briefly online, re-fire the reads that bypass the
    // paused queue, and loop. Only clear once the re-read actually finds a connection.
    NetInfo.refresh().then(() => {
        if (!hasRadio) {
            return;
        }
        ...
    });
    return;
}

Reviewed at: f426eec | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

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