fix(channel): a pairing can be reset from either side, and the link survives a closed tab, a relay restart and a fifth viewer #60

Merged
dawid merged 2 commits from pairing-reset into main 2026-11-19 10:10:12 +00:00
Owner

Fixes from the review of the control channel, with the pairing reset asked for.

Pairing could not be reset. When the watch had forgotten a viewer (forgotten in its menu while the tab was closed, a reinstall, a pairing never confirmed), the viewer waited forever with every button hidden. Now:

  • the viewer keeps a session only once the watch answered, and after 20 s without an answer offers Forget this pairing and Pair again;
  • ending a pairing (from either side) leaves a 7-day tombstone at the relay, so the other side hears 410 and forgets it too, also days later;
  • the watch's menu shows each viewer's last use, and the items no longer point at a stale index.

The link could wedge (found by the review, confirmed by tests):

Scenario Before Now
A paired tab closed, the watch cycling after 64 states, 429 forever; the watch never polled again the queue toward the viewer is a ring
Pairing a fifth viewer 5 channels in the poll, 400 forever, all sessions dead the poll takes 5
A relay restart (every deploy) the first N messages hidden by a stale after/Last-Event-ID a place past the end counts as 0
A viewer sending while the watch is away an answer too large for the watch, retried forever at most 8 messages per answer
Another base64 spelling of r the relay could replay an envelope within 2 minutes the run is known by its bytes
Four timers on a device that allows three "Too Many Timers" the link's retries ride on existing timers

Also: envelopes are checked and compacted at the relay, the body is read before the lock, 1,000 channels and 32 MB queued at most (and mem_limit: 128m), JSON bodies on every answer for the watch, any 4xx settles a watch request, the outbox is capped, the queue places survive an app restart, a malformed envelope can't crash the watch, and a tone where the device can't vibrate.

The privacy page says what the tombstone keeps (the random ID and two token hashes, 7 days, in memory).

Tests: relay go test -race (new tests for the ring, stale places, the poll's size and five channels, envelopes, tombstones); viewer 81 of 81, with tests for the stuck pairing and a pairing ended by the watch. The watch code is checked by CI's compile; its behavior needs the device tests: pair, forget from the menu with the tab closed, then open the tab (it should say the watch ended the pairing), and pair a fifth viewer.

Fixes from the review of the control channel, with the pairing reset asked for. **Pairing could not be reset.** When the watch had forgotten a viewer (forgotten in its menu while the tab was closed, a reinstall, a pairing never confirmed), the viewer waited forever with every button hidden. Now: - the viewer keeps a session only once the watch answered, and after 20 s without an answer offers **Forget this pairing** and **Pair again**; - ending a pairing (from either side) leaves a 7-day tombstone at the relay, so the other side hears 410 and forgets it too, also days later; - the watch's menu shows each viewer's last use, and the items no longer point at a stale index. **The link could wedge** (found by the review, confirmed by tests): | Scenario | Before | Now | |---|---|---| | A paired tab closed, the watch cycling | after 64 states, 429 forever; the watch never polled again | the queue toward the viewer is a ring | | Pairing a fifth viewer | 5 channels in the poll, 400 forever, all sessions dead | the poll takes 5 | | A relay restart (every deploy) | the first N messages hidden by a stale `after`/`Last-Event-ID` | a place past the end counts as 0 | | A viewer sending while the watch is away | an answer too large for the watch, retried forever | at most 8 messages per answer | | Another base64 spelling of `r` | the relay could replay an envelope within 2 minutes | the run is known by its bytes | | Four timers on a device that allows three | "Too Many Timers" | the link's retries ride on existing timers | Also: envelopes are checked and compacted at the relay, the body is read before the lock, 1,000 channels and 32 MB queued at most (and `mem_limit: 128m`), JSON bodies on every answer for the watch, any 4xx settles a watch request, the outbox is capped, the queue places survive an app restart, a malformed envelope can't crash the watch, and a tone where the device can't vibrate. The privacy page says what the tombstone keeps (the random ID and two token hashes, 7 days, in memory). **Tests:** relay `go test -race` (new tests for the ring, stale places, the poll's size and five channels, envelopes, tombstones); viewer 81 of 81, with tests for the stuck pairing and a pairing ended by the watch. The watch code is checked by CI's compile; its behavior needs the device tests: pair, forget from the menu with the tab closed, then open the tab (it should say the watch ended the pairing), and pair a fifth viewer.
fix(channel): a pairing can be reset from either side, and the link survives a closed tab, a relay restart and a fifth viewer
Some checks failed
CI / checks (pull_request) Successful in 20s
CI / relay (pull_request) Successful in 49s
CI / image (pull_request) Successful in 55s
CI / watch (pull_request) Failing after 19s
CI / e2e (pull_request) Successful in 4m5s
CI / android (pull_request) Has been cancelled
53b1ff7c5f
Pairing:
- The viewer keeps a session only once the watch has answered, ends the ones
  from before after pairing, and after 20 s without an answer offers to
  forget the pairing or pair again; it was stuck waiting with no way out.
- Ending a pairing (bye, then DELETE) leaves a tombstone at the relay for
  7 days: the other side hears 410 Gone, also days later, and forgets the
  session instead of creating the channel again. The watch's menu ends a
  session the same way and lists each viewer with the day of its last use.
- Both sides count a message either way as a use, so they expire alike.

Relay:
- The queue toward the viewer is a ring: a closed tab no longer fills it
  and blocks the watch's whole link with 429s.
- The poll takes five channels (four sessions and the one being paired),
  answers at most 8 messages, says unknown and gone channels at once, and
  lists a channel with another token as gone instead of failing the poll.
- A place past a queue's end counts as 0: after a restart the first
  messages were silently hidden.
- Only envelopes are queued, compacted to one line; the body is read
  before the lock; 1,000 channels and 32 MB queued at most; every answer
  has a JSON body; compose caps the relay at 128 MB.

Watch:
- Only the long-poll is cancelled for something to send; any 4xx settles
  a request; the outbox is capped and keeps one state per session.
- Retries ride on the marker's and the pairing screen's timers: four
  timers could exceed a device's limit.
- The places in the queues are kept when the app closes, so a batch read
  just before isn't run again; a malformed envelope can't crash the app.
- Menu items are named by the session, not an index that can go stale; a
  tone where the device can't vibrate.

Both: the replay check knows a run by its bytes, not its base64 spelling,
which let the relay replay an envelope within the 2-minute window.
fix(watch): the type checker's casts for equals
All checks were successful
CI / checks (pull_request) Successful in 36s
CI / e2e (pull_request) Successful in 1m52s
CI / relay (pull_request) Successful in 1m32s
CI / image (pull_request) Successful in 57s
CI / android (pull_request) Successful in 2m7s
CI / watch (pull_request) Successful in 2m58s
f27757d926
dawid merged commit 54e9c4982d into main 2026-11-19 10:10:12 +00:00
dawid deleted branch pairing-reset 2026-11-19 10:10:12 +00:00
Sign in to join this conversation.
No description provided.