Skip to content

Network state awareness: don't bounce to login when offline and distingush between Network Offline and Server Unavailable#89

Merged
subpop merged 1 commit into
subpop:mainfrom
rexbron:network-state-awareness
May 10, 2026
Merged

Network state awareness: don't bounce to login when offline and distingush between Network Offline and Server Unavailable#89
subpop merged 1 commit into
subpop:mainfrom
rexbron:network-state-awareness

Conversation

@rexbron
Copy link
Copy Markdown
Contributor

@rexbron rexbron commented May 8, 2026

Summary

Addresses #87
Cold-launching with no connectivity used to bounce to the login screen because AuthenticationService.restoreSession() returned nil for both "no saved session" and "buildClient failed." This branch distinguishes the two and surfaces an offline state in the sidebar instead.

  • New RestoreOutcome enum on AuthenticationService: .noSavedSession / .restored / .offlineWithSavedSession / .failed.
  • When a saved session exists but the homeserver is unreachable, we keep the user logged in, flip syncState to .offline, and ask SyncManager to retry the full restore on the next reconnect.
  • Network-shaped SDK errors are classified by typed pattern-match in NetworkErrorClassifierClientBuildError.{ServerUnreachable, WellKnownLookupFailed} and ClientError.MatrixApi(.connectionFailed / .connectionTimeout). No string sniffing.
  • Runtime sync failures of those shapes drop to .offline instead of the terminal .error state and retry with truncated binary exponential backoff (Ethernet-style, base 1 s, cap 2⁶ slots, randomized to avoid thundering-herd reconnects).
  • Bottom-of-sidebar pill disambiguates the two cases:
    • Network Offline with wifi.slash glyph when NWPathMonitor reports no path.
    • Server Unreachable with an xserve glyph + caution-triangle badge when the radio is up but the homeserver isn't responding.

Out of scope

This commit fixes the login-bounce regression but doesn't yet populate the timeline with cached messages during an offline cold-start — that requires the SDK client itself to build successfully without contacting the homeserver, which is its own investigation. For now the offline-restored state shows MainView with empty rooms until connectivity returns.

Test plan

  • Sign in normally with the network up, then airplane-mode and relaunch — app stays logged in, sidebar shows "Network Offline" pill (wifi-slash glyph).
  • Sign in normally, then disable just the homeserver (e.g. block its hostname, point it at a dead IP) and relaunch — sidebar shows "Server Unreachable" pill (server + caution glyph).
  • Restore connectivity in either case — sync resumes within the backoff window, pill disappears.
  • First-time launch with no saved session and no network still shows the login screen.
  • No saved session + network present: login flow unchanged.
  • Mid-session network drop: existing offline behavior unchanged (sync stops, queue disabled, banner appears).
    🤖 Generated with Claude Code

…pill

Cold-launching with no connectivity used to bounce to the login
screen because `AuthenticationService.restoreSession()` returned nil
for both "no saved session" and "buildClient failed." Now those are
distinguished via a new `RestoreOutcome` enum. When a saved session
exists but the homeserver is unreachable, we keep the user logged in,
flip `syncState` to `.offline` to surface the banner, and ask
`SyncManager` to retry the full restore on the next reconnect.

Network-shaped SDK errors are classified by typed pattern-match
(`ClientBuildError.ServerUnreachable` / `WellKnownLookupFailed`,
`ClientError.MatrixApi(.connectionFailed / .connectionTimeout)`) — no
string sniffing. Runtime sync failures of those shapes drop to
`.offline` instead of the terminal `.error` state and retry with
truncated binary exponential backoff (Ethernet-style, randomized to
avoid thundering-herd reconnects).

The bottom-of-sidebar banner now disambiguates the two cases:
"Network Offline" with the wifi-slash glyph when `NWPathMonitor`
reports no path, and "Server Unreachable" with an `xserve` glyph plus
a caution-triangle badge when the radio is up but the homeserver
isn't responding.

Note: this commit fixes the login-bounce regression but doesn't yet
populate the timeline with cached messages during an offline cold-
start — that requires the SDK client itself to build successfully
offline, which is a separate change.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@rexbron rexbron marked this pull request as ready for review May 9, 2026 12:19
@subpop subpop merged commit a3ead5d into subpop:main May 10, 2026
1 check passed
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