Skip to content

fix(app): re-fetch visible session messages on foreground resume#1390

Open
jlixfeld wants to merge 1 commit into
slopus:mainfrom
jlixfeld:fix/foreground-resync-visible-session
Open

fix(app): re-fetch visible session messages on foreground resume#1390
jlixfeld wants to merge 1 commit into
slopus:mainfrom
jlixfeld:fix/foreground-resync-visible-session

Conversation

@jlixfeld

Copy link
Copy Markdown

Problem

Addresses the app-side half of #1308. When the mobile app is backgrounded/locked, iOS suspends the websocket. The server intentionally does not push a notification for every new-message, so a suspended socket silently misses realtime message deliveries.

On foreground resume, the AppState active handler refreshed global state and session metadata (sessionsSync) but never invalidated the currently-open conversation's messages. Result: the open chat stays stale until the user backs out to the session list and re-enters it (which fires onSessionVisible). Conversation titles update; the reply body doesn't appear.

Fix

Extract the resume-resync sequence into a small dependency-injected helper (resyncOnForeground) and add a per-session invalidation for the visible session via onSessionVisible(currentViewingSessionId). Global-sync behavior is unchanged (same syncs, same order); the only new behavior is re-fetching the open session's messages on resume.

Test

foregroundResync.test.ts covers the helper in isolation (the regression: resume re-fetches the visible session's messages; no-op when no chat is open). Unit-tested standalone because Sync is an import-time singleton with heavy socket/storage deps.

Scope

Only the app-side foreground recovery. The server-side push-suppression problem in #1308 (session-scoped CLI sockets counting as active user surfaces) is not touched here.

🤖 Generated with Claude Code

A backgrounded mobile websocket can silently miss realtime new-message
deliveries (the server does not push per-message). On foreground resume
the app refreshed global/session-metadata state but never invalidated the
currently-open conversation's messages, so the chat stayed stale until the
user backed out to the session list and re-entered it.

Extract the resume-resync sequence into a dependency-injected helper
(resyncOnForeground) and add a per-session invalidation for the visible
session via onSessionVisible. Unit-tested in isolation since Sync is an
import-time singleton with heavy socket/storage deps.

Refs slopus#1308

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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