Skip to content

fix(mobile): preserve channel list across background/resume reconnection#588

Merged
wesbillman merged 1 commit into
mainfrom
fix-mobile-refresh
May 14, 2026
Merged

fix(mobile): preserve channel list across background/resume reconnection#588
wesbillman merged 1 commit into
mainfrom
fix-mobile-refresh

Conversation

@wesbillman
Copy link
Copy Markdown
Collaborator

Summary

  • Reduced background grace timer from 30s to 5s — the socket now disconnects sooner for a clean reconnect on resume instead of disconnecting right when the user returns
  • onAppResumed() now force-reconnects immediately in any non-connected state, cancelling any exponential backoff timer
  • refresh() bails when the session isn't connected — prevents fetchHistory() from sending REQs over an unauthenticated socket that either time out (returning empty []) or get cancelled, replacing cached channels with nothing
  • build() preserves the last successfully loaded channel list during reconnection instead of re-entering a loading state

Root cause

When the app was backgrounded 30s+ and reopened, the appLifecycleProvider listener called refresh() during reconnection. refresh() called fetchHistory() over a socket still authenticating, the REQ timed out or was cancelled, and AsyncValue.guard set state to AsyncData([]) or AsyncError — nuking the cached channel list and showing the "Connecting…" blank screen.

Test plan

  • flutter analyze — no issues
  • flutter test — all 9 existing tests pass (relay_session_test + channels_provider_test)
  • Manual testing: background app for 30s+, reopen — channels stay visible with brief "Reconnecting…" banner

🤖 Generated with Claude Code

When the app was backgrounded for 30s+ and reopened, the channel list
disappeared behind a "Connecting…" spinner for up to 30s. Three
compounding issues:

1. The background grace timer was 30s — the socket disconnected right
   when the user returned. Reduced to 5s.

2. onAppResumed() only reconnected when status was `disconnected`. If
   the session was in `reconnecting` with a long backoff timer, it just
   waited. Now force-reconnects immediately in any non-connected state.

3. The appLifecycleProvider listener fired refresh() on resume, which
   called fetchHistory() over an unauthenticated socket. The REQ either
   timed out (returning empty []) or was cancelled on disconnect,
   replacing cached channels with nothing. refresh() now bails when
   the session isn't connected, and build() preserves cached channels
   during reconnection instead of re-entering a loading state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wesbillman wesbillman enabled auto-merge (squash) May 14, 2026 21:19
@wesbillman wesbillman merged commit 586b367 into main May 14, 2026
15 checks passed
@wesbillman wesbillman deleted the fix-mobile-refresh branch May 14, 2026 21:24
tlongwell-block added a commit that referenced this pull request May 15, 2026
* origin/main: (33 commits)
  dev-mcp: add view_image tool (#602)
  fix(relay,desktop): only advertise NIP-43 when enforced; probe pairing by supported_nips (#601)
  fix(desktop): derive unread state from NIP-RS + relay catch-up only (#599)
  docs(testing): rewrite TESTING.md for current API and CLI-first workflow (#597)
  fix(agent): fix OpenAI-compat request body serialization and max_tokens (#595)
  feat(desktop): per-persona and per-agent env var overrides (#594)
  fix(desktop): stop pinning agents to deprecated SPROUT_ACP_TURN_TIMEOUT (#592)
  fix(desktop): populate member_count in get_channels so channel browser shows real counts (#548)
  fix(desktop): autofocus message composer on channel/thread open (#572)
  refactor(cli): restructure flat commands into 12 subcommand groups (#585)
  feat(sdk): add builder functions for workflows, DMs, and presence (#589)
  feat(desktop): add message more-actions dropdown menu (#590)
  fix(mobile): preserve channel list across background/resume reconnection (#588)
  Redesign Home as an inbox (#582)
  fix(desktop): drive unread badges from live subscription, not refetched lastMessageAt (#581)
  fix(desktop): refine header scaling and shadow (#573)
  fix(desktop): keep day dividers below header (#574)
  Move agent activity below composer (#579)
  docs(nips): NIP-AE — Agent Engrams (#575)
  refactor: extract shared @mention resolver into sprout-sdk (#580)
  ...

Signed-off-by: Tyler Longwell <tlongwell@squareup.com>
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.

1 participant