Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(connection): refresh network status after app activation #5597

ClosedDominicVonk(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/5597/headopened View on GitHub

Mobile network listeners can miss connectivity changes while the app is suspended. After returning to the foreground, an environment could remain offline or continue an old retry ladder even though the live network was available again.

This change adds one shared connectivity follower that:

  • applies the current network state when a connection runtime starts;
  • refreshes the authoritative platform status on application activation;
  • serializes live reports and refresh snapshots so later reports always win;
  • ignores duplicate reports without invalidating a newer refresh;
  • delivers wakeup signals and refreshed network state in one deterministic order;
  • refreshes managed relay discovery through the same lifecycle path.

The behavior is shared by web, desktop, and mobile through client-runtime. No wire contract or provider adapter changes are required.

These PRs all target main and can be merged in any order:

  • #5597 — network status recovery
  • #5598 — environment availability and management
  • #5596 — mobile pairing-link paste

Verification

  • vp test run packages/client-runtime/src/connection/connectivity.test.ts packages/client-runtime/src/connection/supervisor.test.ts packages/client-runtime/src/relay/discovery.test.ts
    • 3 files passed
    • 48 tests passed
  • vp run --filter @t3tools/client-runtime typecheck
    • passed; one pre-existing Effect suggestion remains in relay discovery
  • targeted vp lint for the six changed runtime/test files
    • passed
  • fallow audit --base upstream/main
    • passed the new-change gate; inherited repository findings were excluded

No screenshot is included because this PR changes lifecycle ordering rather than rendered UI.

Built and reviewed with GPT-5 Codex via Codex CLI.

Fork validation PR


Note

Medium Risk Touches core connection lifecycle (supervisor, registry, relay discovery) and ordering between wakeups and network state; behavior is heavily tested but regressions could affect reconnect timing or discovery offline flags.

Overview Fixes environments staying offline or on stale retry state when mobile suspends network listeners while the app is backgrounded.

Introduces Connectivity.followNetworkStatus in client-runtime: applies the current status at startup, streams connectivity.changes, and on application-active wakeups re-reads connectivity.status with revision sequencing and a lock so live change events beat stale async snapshots and duplicate applies are skipped.

EnvironmentSupervisor, EnvironmentRegistry, and RelayEnvironmentDiscovery now use this helper instead of separate subscriptions to network changes and wakeups; relay discovery adds networkStateLock so offline/refresh transitions stay consistent with in-flight status reads.

On mobile (platform.ts), connectivity changes no longer polls Network.getNetworkStateAsync on AppState active—that refresh is centralized in followNetworkStatus via wakeups.

New unit tests cover the follower, supervisor recovery when online was missed without a listener event, and relay offline/online edge cases.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1cdcc1565f0e2305ed51ea4c283fd261902fd0e4. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Refresh network status on app activation using Connectivity.followNetworkStatus

  • Introduces Connectivity.followNetworkStatus in connectivity.ts, a new effect that consumes connectivity status, change events, and wakeup signals to apply network status updates via a callback, with deduplication and revision-based sequencing to prevent stale async reads from overwriting newer change events.
  • Wires followNetworkStatus into EnvironmentSupervisor, EnvironmentRegistry, and RelayEnvironmentDiscovery, replacing direct subscriptions to connectivity.changes and ConnectionWakeups.changes.
  • On app activation (wakeup), the current network status is re-read and applied only if no newer change event has arrived, fixing missed transitions while the app was suspended.
  • RelayEnvironmentDiscovery adds a networkStateLock semaphore to serialize offline/refresh transitions against concurrent connectivity changes.
  • Behavioral Change: the mobile platform layer in platform.ts no longer emits a connectivity event on AppState active transitions; wakeup-driven refresh is now handled entirely within followNetworkStatus.
Macroscope summarized 1cdcc15.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: deaa0201-97bc-486d-a84f-5edd5b49dafb

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR introduces a new followNetworkStatus utility with revision-based concurrency handling that changes how network status is tracked and refreshed across multiple connection-related components. The synchronization changes and cross-cutting behavioral modifications to core connection infrastructure warrant human review.

      No code changes detected at 8e38c0b. Prior analysis still applies.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      There are 2 total unresolved issues (including 1 from previous review).

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 79205911d1dca74c0c0cecc4981667896cb5a449. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Closing as part of the open-PR backlog sweep (wave 1).

      Reason: Foreground/network refresh already lives in connection supervisor Related: #4878

      Reopen if this is still wanted and you’re willing to rebase onto current main.

    6. juliusmarminge closed this

Sign in to join this conversation.