Skip to content

Keep a hidden tab's socket open, and hold presence sent during subscribe - #1815

Closed
michielbdejong wants to merge 1 commit into
developfrom
claude/hidden-tab-connection
Closed

michielbdejong wants to merge 1 commit into
developfrom
claude/hidden-tab-connection

Conversation

@michielbdejong

Copy link
Copy Markdown
Contributor

Closes #1800

Two separate causes, both seen in the 25 Sep user-testing session.

The connection dropped while the tab was hidden

The client's liveness check (browser/lib/src/liveness.ts) runs every 5 s: after 20 s of silence it sends a KEEPALIVE probe, and after 45 s of silence it closed the socket, probe or not. In a hidden tab Chrome batches timers to once a minute. The first check after the socket went quiet then saw about 60 s of silence, past the deadline, and closed a healthy connection without ever probing the server. The log line said "probe unanswered", but no probe had been sent.

The evidence fits: every close in ux.jsonl falls at :24.6 past the minute (09:03:24, 09:28:24, 09:37:24, 09:39:24 and so on), which is the throttled cadence. The server logged no drop of its own, and the browser answers the server's protocol pings outside the throttled timers.

Fix: silence alone never closes the socket. The client closes only when a probe it sent has gone unanswered for LIVENESS_PROBE_TIMEOUT_MS (25 s), counted from when it was sent. Socket events are not throttled, so the echo still resets the state between two throttled ticks. A dead socket still closes, one tick after its probe times out.

"presence update from non-subscriber" after reconnect

On every (re)connect the client sends PRESENCE_SUBSCRIBE and immediately rebroadcasts its presence. The server's SubscribePresence handler is a ResponseActFuture: it awaits a store read for the drive check, and the CommitMonitor keeps handling messages meanwhile. So the rebroadcast arrived before the connection was in the subscriber map. It was logged as "non-subscriber" and dropped, and peers did not see the tab until its next heartbeat.

Fix: CommitMonitor records the subscribe as pending before the check yields. It holds the latest update from a pending connection, and delivers it (cache, peers and fan-out) when the check passes, or drops it when the check fails, the socket closes or the connection unsubscribes. An update from a connection that never subscribed still warns and is still refused.

Tests

  • browser/lib/src/liveness.test.ts: replays the timer loop at a once-a-minute cadence against a server that answers every probe. With the old rule the first tick returned close. Also covers the normal cadence, and a dead socket still closing (['probe', 'close']).
  • server/tests/it/drive_presence.rs presence_sent_right_after_subscribe_is_delivered: an update sent right behind PRESENCE_SUBSCRIBE reaches the other subscriber on the first try, over 5 reconnects, and an update held for a refused subscribe is not relayed. It fails on develop (round 0: None) and passes with the fix.
  • cargo test -p atomic-server --test it drive_presence (3 tests) and ws_auth_gate (12 tests) pass. The browser/lib liveness and WS tests pass.

Docs (docs/src/websockets.md Liveness) and TESTING_COVERAGE.md are updated. No UI change, so there are no screenshots.

🤖 Generated with Claude Code

A hidden tab's timers fire about once a minute, so the 5 s liveness check
first saw a quiet socket after 60 s of silence, past the 45 s deadline, and
closed it without ever sending the KEEPALIVE probe. The client now closes
only when a probe it sent has gone unanswered for 25 s, measured from when
it was sent.

After a reconnect the client subscribes to drive presence and announces
itself straight away. The server's subscribe runs an async read check and
keeps handling messages meanwhile, so the announcement arrived before the
connection counted as a subscriber: it was dropped with "presence update
from non-subscriber". The server now holds the latest update from a
connection whose subscribe is still being checked, delivers it once the
check passes, and drops it if the check fails.

Closes #1800

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joepio added a commit that referenced this pull request Sep 25, 2026
…) (#1828)

Combined batch, green on Mancave in run 4639 on 3be85ae.

Includes #1809, #1810, #1811, #1812, #1813, #1814, #1815, #1816, #1817,
#1818, #1819, #1820, #1821, #1823, #1824, #1827 and #1765, plus the e2e
label updates for #1816 and settled translation catalogs.

joepio commented Sep 25, 2026

Copy link
Copy Markdown
Member

Landed on develop in 46562ff via the combined batch #1828 (green on Mancave, run 4639). Closing.


Generated by Claude Code

@joepio joepio closed this Sep 25, 2026
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.

Connection drops when the tab is hidden; presence warnings after reconnect

2 participants