Skip to content

The bridges connect again when their connection to the mind ends - #3

Merged
jonastemplestein merged 1 commit into
mainfrom
bridges-reconnect
Nov 22, 2026
Merged

jonastemplestein merged 1 commit into
mainfrom
bridges-reconnect

Conversation

@jonastemplestein

Copy link
Copy Markdown
Contributor

The bridges connect again when their connection to the mind ends

What. bridge/mind-connection.mjs is a connection that lasts: it waits on the connection's own closed (and on calls that fail with a closed connection), connects again after 1 s, twice as long each failure, at most 60 s, and runs a callback on each new connection. device-live.mjs subscribes again and fetches the ICE servers again on each connection, and checks once a minute that its subscription still hears (an ephemeral device/live-ping only it consumes). device-events.mjs keeps events while the connection is down (at most 2,000; moves and keys go first), retries a batch that failed, and sends in order after the reconnect; the app then publishes its presence again. live.state().signalling now says whether the signalling is connected. 12 node --test tests with a fake mind, now in CI.

Why. A session's sign-in lasts 4 hours; then the mind closes the socket with 1008. The live and events bridges connected once, so after that every call failed: "Watch live" stayed at "asking the device…", and presence changes were lost. A live subscription also ended once on the mind's side with no word to the bridge.

Proof. Against a live mind, on a test device: the live bridge heard a watcher's signal again after a 1008 close, after a terminated socket, and after its subscription row was removed on the mind (found by the ping); the events bridge sent 6 of 6 events in order across a 1008 close, 2 of them queued while it was down. Tests: node --test 'bridge/*.test.mjs' (12), swift build, swift test.

Risk map.

  • Reconnect loop: at least 1 s between attempts, at most 60 s; one attempt is given up after 60 s. It never spins and never gives up.
  • Ping: one ephemeral append a minute per lent Mac; no log write; no other subscriber hears it. A false miss costs one reconnect; watches that run are peer to peer and go on.
  • Events: a batch the mind refuses (not a connection failure) is retried twice, then dropped, as before. Ephemeral moves queued during an outage arrive late.
  • The bridges' scripts now export their loops and run their CLI only as the main script (realpath(argv[1]) against the module's path).

🤖 Generated with Claude Code

Session: claude b0eec5e0-9c0a-43e6-bf1b-01b7e83c523c on jonas-macbook-pro

🤖 Generated with Claude Code

A session's sign-in lasts 4 hours. The live bridge and the device-events bridge connected once,
so after 4 hours the Mac heard no watcher and its presence events were lost. Both now hold their
connection through `bridge/mind-connection.mjs`: it notices a closed or failed connection,
connects again with the stored sign-in after 1 s, doubling to 60 s, and runs each bridge's setup
again (the live bridge subscribes again and asks for the ICE servers again; it checks once a
minute that its subscription still hears). Events wait during a gap and go up in order; after a
reconnect the app publishes the present presence again. `live.state().signalling` says whether
the signalling is connected. CI runs the bridges' new tests.

Session: claude b0eec5e0-9c0a-43e6-bf1b-01b7e83c523c on jonas-macbook-pro
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonastemplestein
jonastemplestein merged commit 3e5a2eb into main Nov 22, 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.

1 participant