Skip to content

Send full state instead of deltas - #175

Merged
maximmaxim345 merged 7 commits into
mainfrom
149-drop-state-diffs
Aug 28, 2026
Merged

maximmaxim345 merged 7 commits into
mainfrom
149-drop-state-diffs

Conversation

@kahrendt

@kahrendt kahrendt commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

client/state, server/state and group/update each defined their own merge rules, and the three disagreed on whether merging was required, whether null cleared a field, how deep the merge went, and which message had to be complete (#149). Rather than reconcile them into one rule, drop merging.

Changes:

  • All three messages carry full state on every message.
  • For client/state and server/state the role object is the unit: an included object carries that role's full state, and an omitted one leaves that role's state unchanged. Differential updates survive at role granularity, which is what the optional role objects were always for.
  • Drop the | null variant from leaf fields in the metadata and color objects. A role object may still be null in server/state, which is how the server ends a role's state when it drops the role from active_roles, and it was never a delta mechanism.
  • group/update's playback_state, group_id and group_name are no longer optional.

What this costs is bandwidth on metadata text, which is sent on state change rather than continuously; anything large already travels as a binary message. What it saves is the reconciliation layer on the receiving side, which has been a steady source of bugs and runs to a few hundred lines in a client that gets it right.

Fields whose absence carried a second meaning

Dropping the merge silently repurposes every optional field that used to mean "unchanged". Each one is now stated where the reader meets the field, rather than in a rule they have to remember:

  • metadata.progress: omitting it clears the client's position, so the server includes it in every metadata state that has a position to report. Track position is calculated from the current metadata state rather than from the last message that happened to include progress, which only made sense while absent meant unchanged. A resent progress is measured at the new timestamp rather than copied forward under it, which the merge rules used to make moot by never resending it at all.
  • The player state object's supported_commands: absence now says the player accepts no commands, which is what [] already says. The ? goes rather than the redundant encoding staying around to silently revoke set_output_delay. Both other supported_commands in the spec are already non-optional.
  • Role objects themselves, covered by the omitted-object rule above.

Follow-on cleanups

  • The player role's "Delta updates" paragraph is gone.
  • REQUIRED for players on the three non-optional fields in the player state object goes with it. It was an anchor for that paragraph, ? already marks optionality (see the note under Communication), and the object is player-only.
  • The available: false handling no longer describes sending a group/update carrying only playback_state.

This conflicts with #135 on messaging.md, roles/metadata/v1.md and roles/color/v1.md, in that PR's favour: with no merging, its rule that the first message after a scheduled one must repeat the scheduled message's fields has nothing left to do.

Out of scope: the management/set-pairing-config patch semantics in management.md, which is a configuration API rather than state streaming.

Closes #149
Refs #101

Breaking changes

Both directions break, not just the server.

Servers must send full server/state and group/update messages instead of deltas. A client that still merges keeps stale leaves, because clearing a leaf is now omission rather than an explicit null.

Clients must send full client/state messages, and a player must now always carry supported_commands. A client that still sends deltas has them read as full state, so every field it omits is dropped rather than retained. Neither side errors.

client/state, server/state and group/update each defined their own merge rules,
and the three disagreed on whether merging was required, whether null cleared a
field, how deep the merge went, and which message had to be complete. Rather
than reconcile them, drop merging.

Every message on all three now carries full state, and the receiver replaces
what it holds rather than merging into it. What this costs is bandwidth on
metadata text, sent on state change rather than continuously; anything large
already travels as a binary message. What it saves is the state-reconciliation
layer on the receiving side, which has been a steady source of bugs and runs to
a few hundred lines in a client that gets it right.

Dropping merging makes null on a leaf field meaningless: with no "unchanged"
case to distinguish it from, an absent field simply has no value. Leaf fields
in the metadata and color objects lose their null variant. A role object may
still be null, which is how the server ends a role's state when it drops the
role from active_roles - that was never a delta mechanism.

Follow-on cleanups:

- group/update fields are no longer optional, since every message carries all
  of them
- The player role's "Delta updates" paragraph is gone; its presence rules now
  apply to every message rather than only the first
- Track position is calculated from the current metadata state rather than from
  the last message that happened to include progress, which only made sense
  while absent meant unchanged
@kahrendt
kahrendt force-pushed the 149-drop-state-diffs branch from 8121f38 to 406f0bf Compare August 26, 2026 15:46

@maximmaxim345 maximmaxim345 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also expand the breaking changes section of the description to clients that used differential updates? client/state also changes after all.

Comment thread roles/metadata/v1.md Resolved
Comment thread messaging.md Resolved
@maximmaxim345
maximmaxim345 merged commit e210859 into main Aug 28, 2026
1 check passed
@maximmaxim345
maximmaxim345 deleted the 149-drop-state-diffs branch August 28, 2026 09:19
maximmaxim345 added a commit that referenced this pull request Aug 28, 2026
Define what a future timestamp on `metadata`, `color`, and artwork
messages means: the update is scheduled and takes effect at that time,
with one shared current-plus-pending model where the newest message
always wins the pending slot.

## Changes

The `metadata` and `color` state timestamps left the future-timestamp
case undefined, and the artwork binary rule ("latest wins") could be
read as either arrival order or timestamp order, so client behavior
diverged and a server could not safely send an update ahead of time
(e.g. the next track's metadata timed to the audible track change, which
lags the server's own transition by the buffered audio).

All three roles now define the same model. Clients keep their current
state plus at most one pending update: a future-timestamped message
becomes the pending update, replacing any held one, and applies when its
time is reached; any other message applies immediately and discards the
held one. Clients never compare timestamps. Around it, `server/state`
defers to the role sections instead of implying apply-on-receipt, a
`null` role object discards any pending update, omitting a role object
leaves a pending update in place, the first state message for a role
must carry a past-or-present timestamp, progress extrapolation reads
only from the current state and never from a pending update, an empty
artwork message is a scheduled clear, and `stream/end` discards pending
images. There is no wire change and no role version bump; this pins down
what v1 left undefined.

This solves the problem without needing `stream/clear`. `stream/clear`
would not properly solve this problem, since:
- It is only defined on a stream basis. `metadata` and `color` don't use
binary streams.
- `stream/clear` would clear all pending artwork channels, this would
not look great in practice, causing disappearing images.

## What #175 removed

Rebased onto main now that #175 has landed. Dropping delta merging
retired the rule this PR previously needed: that the first message sent
after a scheduled update repeat every field the scheduled message
carried. With full state on every message, a client that applied the
pending update and one that discarded it both land in the next message's
state, so there is nothing left to reconcile. The cancel recipe survives
in simplified form and now reads the same way in all three roles.

#175 also anchors `track_progress` to the metadata `timestamp`, which is
what makes a scheduled `progress` well defined: it describes the
position at the moment the update takes effect.

## Changed after review

The lead-time bound now measures from the timestamp rather than from the
moment of scheduling: "SHOULD NOT send a scheduled update more than 20
seconds before its `timestamp`". That is a different rule from the
original "SHOULD NOT schedule an update more than 20 seconds ahead", and
the better one, since it bounds how long a client holds a pending update
and therefore how much a pause discards.

## Breaking changes: server

In practice none: AFAIK no server sends timestamps in advance, and
timestamping every update with the current time remains fully conformant
with no obligations. A server that schedules ahead cancels by resending
the current state with a past or present timestamp; artwork needs
nothing special since every message is a complete image.

## Breaking changes: client

Clients that apply `metadata`/`color` on receipt render scheduled
updates too early once servers start scheduling; they need the single
pending slot: hold a future-timestamped message until its time, let any
newer message replace it, no timestamp comparison anywhere. Artwork
clients that queue multiple timestamped images or block on them must
reduce to the same single pending image per channel and discard pending
images on `stream/end`.
maximmaxim345 added a commit that referenced this pull request Sep 2, 2026
`supported_commands` was split across two messages, `'volume'` and
`'mute'` in the `client/hello` support object and `'set_output_delay'`
in `client/state`, so a player could not change which commands it
accepts without reconnecting and `server/command` had to name both
locations as sources of truth. The whole list moves into the
`client/state` player object.

The split also failed silently: an SDK reading only `client/hello`
ignores `set_output_delay`, one reading only `client/state` ignores
`volume` and `mute`, and neither errors. Consolidating matches the
CONTRIBUTING rule that a field expected to change during a connection
belongs in `client/state`.

This breaks `player@v1` on the wire, and a server can no longer see
command capabilities at `server/activate` time, which is exotic but
worth stating.

#175 already made `supported_commands` non-optional and defined an empty
list as accepting no commands, so the field line itself only gains
`'volume'` and `'mute'`, and the `client/hello` copy is deleted.

# Rules the move requires

A server MUST NOT send a player command before the client has sent a
`client/state` containing the `player` object, mirroring the existing
rule for binary data. The move opens that window because
`server/activate` precedes the first state message, and the player
object is the unit that carries `supported_commands`.

`supported_commands` advertises settability, not reportability. A player
MAY report `volume` or `muted` without accepting the matching command,
an amplifier with a physical volume knob being the real case, and
capability cannot be inferred from field presence because
`output_delay_ms` is never optional either way. A server MUST NOT treat
a reported `volume` or `muted` as settable while the matching command is
absent, though it MAY still surface the value read-only.

Group volume averages over volume-capable players, so when the last
capable player withdraws the reported value jumps to 100 and the control
disappears with nobody having touched a volume. Both reading rules now
say so and require a recompute when a player's support changes.

# Group volume writes

The group volume algorithm already disagreed with itself before this
change: it computed its delta against the average of all player volumes
and sent a command to every player, while the reading rules excluded
players without volume support. The move makes the mismatch reachable
mid-session, so both paths now filter on capability, and setting group
mute gets the same fix. This part is separable if you would rather it
went on its own.

# Editorial

The "Server behavior" bullets sat under the `client/hello`
support-object heading while describing `required_lead_time_ms` and
`min_buffer_ms`, which live in `client/state`, and two cross-references
pointed at that mismatched anchor. The text merges into "Server Audio
Send Constraints", which already carries the overlapping lead and
send-ahead rules.

Closes #142
maximmaxim345 added a commit to Sendspin/aiosendspin that referenced this pull request Oct 1, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

Since #408, `server/state` sends full metadata and color objects with
unset fields left out. Clients from before spec #175, like the
aiosendspin client up to 9.1.1, still merge each object into the
previous one, so a field that becomes unset (album, artwork, a color,
`progress`) never clears, and a cleared `progress` keeps extrapolating.

Legacy connections now get every unset metadata and color field as an
explicit `null`, which these clients read as a clear. Current clients
still get the fields omitted.

**Related issue or spec PR (if applicable):**

- Sendspin/spec#175

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [x] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [ ] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
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.

Define one shared delta-merge rule for client/state, server/state, and group/update

2 participants