Skip to content

Let an open tab notice what another device did - #137

Merged
suskozaver merged 1 commit into
ArunNGun:betafrom
suskozaver:an-open-tab-asks-the-server
Sep 18, 2026
Merged

suskozaver merged 1 commit into
ArunNGun:betafrom
suskozaver:an-open-tab-asks-the-server

Conversation

@suskozaver

Copy link
Copy Markdown
Collaborator

A dose logged on a phone at 20:22 still showed as due on a desktop at 20:47. Both devices online, both signed in, and sync working: the protocol edited on the desktop at 19:01 was already on the phone. Four exports, taken from both devices across the evening, confirmed it was one record's worth of difference and nothing else.

What was missing

SyncRunner starts a run on four things, and every one of them is about this device:

  • its own data changing
  • its own tab becoming visible
  • its own network coming back
  • startup

A tab that is open, in the foreground and untouched matches none of them, and visibilitychange does not fire for a tab you never looked away from. The one state in which somebody is staring at the screen was the one state that never asked the server anything.

The fix

One minute, while visible. The request is a fetch of one small record, and decideSync answers "in-step" when nothing moved, so the common case costs one small GET a minute and transfers no data either way.

Skipped while hidden: a hidden tab has nothing to show, becoming visible is already a trigger, and browsers throttle timers there anyway.

The engine already did its half correctly. There is now a test named for the incident holding it: asked, a device with nothing of its own to send takes what the other device left, as a clean pull rather than as a question.

Written down

06-traps.md: a list of triggers assembled from local events has no entry for "somebody else did something", and the gap is invisible in testing because a developer reloads constantly and a reload is a trigger. Worth checking against any future trigger list: at least one entry has to come from outside this device.

Checks

npx tsc --noEmit clean, npx next lint clean, 1714 tests pass (1 new).

A dose logged on a phone at 20:22 still showed as due on a desktop at
20:47. Both online, both signed in, and sync working: the protocol
edited on the desktop at 19:01 was already on the phone.

SyncRunner starts a run on four things, and every one is about this
device: its own data changing, its own tab becoming visible, its own
network coming back, startup. A tab that is open, in the foreground and
untouched matches none of them, and visibilitychange does not fire for
a tab you never looked away from. The one state where somebody is
staring at the screen was the one state that never asked.

So it asks, once a minute, while visible. The request is a fetch of one
small record and decideSync answers "in-step" when nothing moved, so
the cost of the common case is one small GET a minute. Skipped while
hidden, since a hidden tab has nothing to show, becoming visible is
already a trigger, and browsers throttle timers there anyway.

The engine already did its half correctly, and there is now a test
named for the incident holding it: asked, a device with nothing to send
takes what another device left, as a clean pull rather than a question.

Written into 06-traps.md: a list of triggers assembled from local
events has no entry for "somebody else did something", and the gap is
invisible in testing because a developer reloads constantly and a
reload is a trigger.
@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Arun's projects Team on Vercel.

A member of the Team first needs to authorize it.

@suskozaver
suskozaver merged commit d847fc5 into ArunNGun:beta Sep 18, 2026
1 of 2 checks passed
@suskozaver
suskozaver deleted the an-open-tab-asks-the-server branch September 18, 2026 19:05
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