Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions docs-developers/frontend/apple-watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ or scrub given only book seconds, it prefers the playing file among tied files.
- **A file that fails** stops the book, its span ending where the audio last moved
(`lastAdvance`), not at the moment of the failure.

**Resume** (`Resume.plan`, `Core/PlayerRules.swift`) follows the phone's
([Resume protection](playback.md#resume-protection)) on the watch's clock. It moves
these server times back by `clockSkewMs`: the time of the watch's own row, another
device's `updated_at` and a finish's `finished_at`. The skew is 0 until the answer
to a foreground batch measures it (a single-event retry's or a background upload's
never does). Unlike the phone, which weighs the times alone, another device's row
replaces the place here only when it is newer and its version is above the watch's
acknowledged one, and an unfinished row with no device id never does.

**Spans** follow the phone's rules
([Listening spans](playback.md#listening-spans-sync-v2)), except that the watch cuts every 15 s
while its last sync answered. A bare move and a move to nowhere are the phone's
Expand All @@ -136,12 +145,26 @@ when it is that book's and a resume from this watch's own place, not when `Resum
server's row (`loadsFromRow`). The move is kept on disk too (`open-span-move.json`,
`OpenSpanStore.saveMove`) until a span opens, so a launch that ends before the book plays (a
background wake) leaves it to the next. It leaves the store only once that span is stored, and
leaving the account forgets it.
leaving the account forgets it. A move, a Stay or a cut while playing closes the
span into the outbox, and the stored span is replaced by the next one in a single
write (`SpanRecorder.close`'s `clearStore`).

**Stay** is the phone's too ([Stay wins](playback.md#stay-wins)):
`SpanRecorder.standBy(..., stay:)`, gated by the cached `/server`'s `listening_stay` (`AppModel.takesStay`), `Spans.carried`,
`Outbox.takesStay` (read as each body is built, the background upload's too), and
`AckRules.staysHeld` with `OfferThrottle.shouldShow(..., stayHeld:)`.
`SpanRecorder.standBy(..., stay:)`, gated by the cached `/server`'s `listening_stay`
(`AppModel.takesStay`), and `Spans.carried`. `Outbox` reads the flag as it builds each
request, a single-event retry's and the background upload's too, and sends a queued
`stay` as a `jump` while it is off. Unlike the phone, a `stay` refused alone with a `400` is not tried again as a
`jump`. It moves to the couldn't-sync list as `invalid`, as a v2.6.0 server's
`rejected` `invalid` does.

**Offers** (`Core/AckAndOffer.swift`) follow the phone's
[throttles](playback.md#offering-another-devices-place-sync-v2), with two
differences. There is no held-listen repeat: only a held Stay, sent as a `stay`, offers
the kept place again at once (`AckRules.staysHeld`, `OfferThrottle.shouldShow(...,
stayHeld:)`), so a Stay that went as a `jump` earns nothing. And the offer is a sheet
with no timeout. One swiped away unanswered (`AppModel.ignore`) has its key noted in the
same `answered` list as Jump and Stay (`ignoreOffer`, nothing acknowledged), so it is
not offered again.

**Addresses.** The home rule is the [phone's](connect-and-addresses.md#the-pick-rule-srclibserver-addressts):
no token before the `server_id` probe. The pick is dropped on backgrounding and probed again while active.
Expand All @@ -151,7 +174,9 @@ The background upload goes to the away or paired address, never home
**Background sync.** Going to the background cuts the span. The watch hands the outbox's first
chunk to a background upload carrying `clock_offset`, not `sent_at`, and adds a best-effort app
refresh flush. Replays are safe (event ids are the idempotency keys). An answer that arrives on a
wake is applied like a foreground one, for the account it was sent for. In the foreground the
wake is applied like a foreground one, for the account it was sent for. The upload's tag
(`SyncUploadTag`) records that account, the event ids and whether the body sent a `stay`
(`sentStay`), so the wake judges a held Stay by what was sent. In the foreground the
watch sends the outbox at launch, on the foreground, after each closed span, and every 60 s while
events wait. It never gates on `NWPathMonitor`, which was seen reporting `unsatisfied` while
`URLSession` worked. It tries, and a failure with no answer means offline.
Expand Down
4 changes: 3 additions & 1 deletion docs-developers/frontend/book-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ footer. The place is measured from where the primary would play from
(`resumePosition`). The line says "On another device" when the server has no name.
**Play from there** answers the offer (`answerOffer`) and plays the book there
(`{ at: { position } }`). Answering acknowledges the row's version and notes the
place, so it isn't offered again. Nothing shows on a server without the flag.
place, so it isn't offered again. Nor is a place whose toast timed out
(`settledOffers`), and the line never repeats a held offer
([the throttles](playback.md#offering-another-devices-place-sync-v2)). Nothing shows on a server without the flag.

`HeroActions` lays the row out after the primary:

Expand Down
30 changes: 20 additions & 10 deletions docs-developers/frontend/offline.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,10 @@ end ([What a kill leaves behind](playback.md#what-a-kill-leaves-behind)). On the
- when it last synced (`lastSyncAt`);
- the "couldn't sync" list: rejected events with their reason, kept 30 days, at most
100;
- the server's clock skew from the answers' `server_time` (`clockSkewMs`), which
`progress-sync` reads through `stored-skews.ts`.
- the server's clock skew (`clockSkewMs`), which `progress-sync` reads through
`stored-skews.ts`. A sync answer whose request times are known measures it
(`clockSkewOf`): its `server_time` minus the midpoint of sending and answering.
Until a connection has one, the skew is 0. A progress `GET` never measures it.

**Locking.** The read-modify-writes of the three documents run in a serial queue and
under `tabLock` (`src/lib/tab-lock.ts`), so two tabs can't lose each other's events.
Expand Down Expand Up @@ -793,7 +795,11 @@ A queued span whose `start` is `stay` goes as a `jump` while the connection's
`/server` doesn't say `listening_stay` (`eventsForServer`, on every send path: the
batch, one by one, and the web page's keepalive), and the stored event keeps its `stay`
and its id
([Stay wins](playback.md#stay-wins)).
([Stay wins](playback.md#stay-wins)). The flag is read as each request is built. A
stale cached `true` can still let a `stay` through: a v2.6.0 server answers it inside
a `200` as `rejected` `invalid`, so it moves to the couldn't-sync list like any
rejected event, and a server that refuses the whole request with a `400` gets it
again as a `jump` (below).

Each answer is handled like this:

Expand All @@ -803,8 +809,10 @@ Each answer is handled like this:
kept for has its version acknowledged (`ackVersion`, never lowered). That is
`keptMine`: applied, or diverged with `kept: "event"`, and the row's `device_id` is
this device's. The place reconcile is told of the rows (`onSyncAnswer`) so it can
offer another device's place. A `stay` that came back `diverged` `kept: "stored"`
(`staysHeld`) has the kept place offered at once.
offer another device's place. `heldListens` identifies the books for which the
server kept its row over a listen, using each event's start as sent. The
[player's offer rules](playback.md#offering-another-devices-place-sync-v2)
determine when that place appears again.
- An answer that arrives while the cached `listening_sync` flag is `false` makes the
query cache ask `/server` again. The server took the events, so the cached answer
is older than the server.
Expand Down Expand Up @@ -889,11 +897,13 @@ place was saved on a download's older file order. The server does the same with
span's file places. The local resume works on any server; the server's remap needs
`listening_sync`.

A file place is used only when it is not older than the record it is for
(`holdsFilePlace`). The check allows 5 s of slack, widened by how far the
connection's server clock is known to be ahead (the stored `clockSkewMs`). So a device
whose clock runs slow keeps its file place, and a mirror that lost writes never
resumes at a stale file.
A file place is used only when it belongs to the record the resume picked
(`holdsFilePlace`). That is the same place (within 1 s), or a record of the same
device in the same finished state that is at most 5 s newer than the file place.
Both are compared on this device's clock, with a server timestamp moved back by the
stored `clockSkewMs`, 0 until a sync answer has measured it. So once the skew is
known, a server clock that runs ahead keeps a timely file place, and a mirror that lost
writes never resumes at a stale file.

### Taking a finish back

Expand Down
Loading