Repository navigation
Send full state instead of deltas - #175
Merged
Merged
Conversation
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
force-pushed
the
149-drop-state-diffs
branch
from
August 26, 2026 15:46
8121f38 to
406f0bf
Compare
maximmaxim345
left a comment
Member
There was a problem hiding this comment.
Can you also expand the breaking changes section of the description to clients that used differential updates? client/state also changes after all.
This was referenced Aug 27, 2026
Main's changes since this branch's base (fragmentation IDs, Sentinel fallback, unpaired access, artwork letterboxing) do not touch state message semantics. README is regenerated from the merged sources.
maximmaxim345
approved these changes
Aug 28, 2026
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`.
This was referenced Aug 30, 2026
Closed
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
1 of 9 tasks
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`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
client/state,server/stateandgroup/updateeach defined their own merge rules, and the three disagreed on whether merging was required, whethernullcleared 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:
client/stateandserver/statethe 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.| nullvariant from leaf fields in themetadataandcolorobjects. A role object may still benullinserver/state, which is how the server ends a role's state when it drops the role fromactive_roles, and it was never a delta mechanism.group/update'splayback_state,group_idandgroup_nameare 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 everymetadatastate that has a position to report. Track position is calculated from the current metadata state rather than from the last message that happened to includeprogress, which only made sense while absent meant unchanged. A resentprogressis measured at the newtimestamprather than copied forward under it, which the merge rules used to make moot by never resending it at all.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 revokeset_output_delay. Both othersupported_commandsin the spec are already non-optional.Follow-on cleanups
REQUIRED for playerson 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.available: falsehandling no longer describes sending agroup/updatecarrying onlyplayback_state.This conflicts with #135 on
messaging.md,roles/metadata/v1.mdandroles/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-configpatch semantics inmanagement.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/stateandgroup/updatemessages instead of deltas. A client that still merges keeps stale leaves, because clearing a leaf is now omission rather than an explicitnull.Clients must send full
client/statemessages, and a player must now always carrysupported_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.