Skip to content

mobile: instant reattach on foreground network change (Wi-Fi↔cellular) #71

Description

@pallaoro

Summary

Make mobile auto-reattach instant on a network change that happens while the app stays in the foreground (e.g. Wi-Fi ↔ cellular, without backgrounding).

Background

Auto-reattach shipped in #70 (apps/mobile/App.tsx, apps/mobile/src/connection.ts). It covers the two dominant triggers instantly:

  • App foregroundAppState active → probe (Connection.ping()) → reconnect if dead.
  • Socket drop — the transport's onClose → reconnect.

Both back off (1s → 15s) and rebind the board + open terminal to the fresh api.

The gap

A network change while the app stays foregrounded isn't caught instantly. We rely on the socket's onClose + the 15s keepalive (connection.ts) to notice. If the flip leaves a half-open socket that never fires a close event, reattach can lag up to ~15s (until the next keepalive ping fails).

This is a secondary case — the keepalive catches it eventually, and the far more common "app-switch" path is already instant via AppState. Filing so it's tracked, not lost.

Proposed fix

Add a network-state change listener that triggers the existing reconnect() immediately when connectivity returns.

  • expo-network exposes Network.addNetworkStateChangeListenerconfirmed not currently installed (apps/mobile/node_modules has neither expo-network nor @react-native-community/netinfo).
  • Cost: a native dependency → requires an expo prebuild + pod install cycle. That's the reason it was deliberately deferred rather than bundled into would it be possible to create #70 (which added zero native deps).

Acceptance

  • Toggling Wi-Fi/airplane mode off→on while a task terminal is open reattaches within ~1–2s (not up to 15s).
  • No new native module beyond the network listener; reuses the existing reconnect() path.

Priority

Low. Add only if the ~15s worst-case lag is felt in practice. See the Clawnify decision doc "Ateam Mobile Connectivity — Decision: SSH-to-any-host vs Tailscale."

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions