Skip to content

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

Closed

Description

@balloob

Revised after the review by @maximmaxim345. The proposal is now smaller: it unifies the mechanical rules, and it keeps the difference in the minimum content.

Problem

Three messages carry a state update: client/state, server/state and group/update. Each message gives its own merge rules.

client/state server/state group/update
Merge the server MUST merge, and keeps absent fields the client "will merge" the client "should merge"
null clears not defined a null leaf clears the field, a null role object clears the role not defined
Merge depth not defined shallow, a nested object is replaced in full not defined
First full message the first message, and the full role state when a role becomes active the first message for each role, and the first message after the role becomes active again the first message on a connection
Minimum content MAY send only changed fields, MAY send the full state "Only include fields that have changed" "only the changed fields"

The first four rows are the same procedure with three descriptions. Only the last row is a true difference.

The spec says that the difference is intentional: "The asymmetry with client/state is deliberate". But it does not give the reason.

Change

Give the mechanical rules one time, in the Communication section of messaging.md. Keep the difference in the minimum content, and give the reason for it.

State-carrying messages (client/state, server/state, group/update) are delta updates. The first message for a scope MUST carry that scope's full state: the initial client/state on a connection and a role's full state when it becomes active in active_roles; the first server/state for a role on a connection and the first after the role is re-added to active_roles; the first group/update on a connection. Subsequent messages carry the fields that have changed; the receiver MUST merge each message into existing state, retaining the last value of any absent field. The merge is shallow: a nested object is replaced or cleared as a whole, never deep-merged, so nested objects are always sent complete. Where a field or role object is clearable (typed | null), setting it to null clears it; a role object set to null clears all of that role's state. A role's definition MAY defer when a merge is applied (see scheduled updates).

Servers SHOULD send only the fields that have changed. Clients MAY instead resend unchanged fields, up to their full state: the server is the more capable side, so a client may keep its implementation simple.

Then each message keeps one sentence and its field list. Remove the note about the intentional difference, because the new rule gives the reason.

The note in server/activate and the note in roles/player/v1.md already point to these rules. Change the anchors only.

Effect on behavior

None. The rule keeps the current minimum-content requirement for each direction.

Open point: the metadata timestamp

@maximmaxim345 found a problem in the first version of this proposal. It permitted the server to resend unchanged fields. That is not safe for the metadata role.

A metadata client calculates the position from the timestamp and the progress of the last message with a progress object. Thus an unchanged progress under a new timestamp moves the calculated position.

The revised rule prevents this, because the server keeps the minimum-content requirement. But PR #135 makes the server resend the fields of a scheduled message. Thus the two rules meet in that case.

Select one solution:

  1. A resent value keeps its original timestamp.
  2. The metadata role keeps its own rule, because its timestamp gives the fields a different function.

Solution 2 is possibly better, because the problem comes from the role, not from the merge procedure.

Correction to make at the same time

The controller object in server/state has mandatory leaves without the type | null. Thus the general null rule and the schema do not fully agree today. The new rule must say that the field type controls this behavior.

Sequence with PR #135

PR #135 changes the same server/state paragraphs. It adds scheduled updates: a future timestamp delays the merge, a null role object removes a pending update, and the first message for a role must have a past or present timestamp.

These rules apply to one role. They are not merge rules. Thus they stay with server/state and the role files, and they use the sentence "A role's definition MAY defer when a merge is applied".

Merge PR #135 first. Then apply this change on top of it.

Activity

  1. maximmaxim345 commented on Aug 18, 2026

    @maximmaxim345
    Member

    I think we just have to try this wording change. I'm not fully convinced yet, but if it stays understandable without a pile of per-message exceptions and overriding of the merge rules, it might be for the better.

    The rules do slightly differ in a couple of places:

    • metadata is not idempotent because of the progress calculation: position comes from the timestamp and progress of the last message that included progress, so resending progress unchanged under a fresh timestamp shifts the computed position. If resending unchanged fields becomes allowed, the rule has to say a resent value keeps its original timestamp.
    • The asymmetric requirement of minimal diffs is intentional, to allow simpler client implementations to exist. We assume the server is the more powerful side (so it can always compute the most minimal messages). If a client wants communication to be optimal/minimal, it can also only send what changed. If the client wants to have a simpler implementation, it can always send the full state.
    • With Define scheduled updates for metadata, color, and artwork #135 the merge is deferred, which makes the rules differ a bit more for the metadata/color roles.
  2. balloob commented on Aug 18, 2026

    @balloob
    ContributorAuthor

    Your first two points change the proposal. I made it smaller.

    The metadata timestamp. You found an error in the first version. That version let the server resend unchanged fields. A metadata client calculates the position from the timestamp and the progress of the last message with a progress object. Thus an unchanged progress under a new timestamp moves the position.

    The reason for the asymmetry. I did not know it. If the reason is a simple client implementation, the asymmetry is correct, and the spec must give the reason.

    Both points have the same solution: unify the mechanical rules only, and keep the minimum-content rule per direction.

    The mechanical rules are the merge itself, the null value, the shallow depth, and the first full message. These four are one procedure with three descriptions today.

    The minimum content stays different, with your reason in the text:

    Servers SHOULD send only the fields that have changed. Clients MAY instead resend unchanged fields, up to their full state: the server is the more capable side, so a client may keep its implementation simple.

    This also keeps the metadata role safe, because the server keeps the minimum-content rule.

    One case stays open. PR #135 makes the server resend the fields of a scheduled message, thus the two rules meet there. Select one solution:

    1. A resent value keeps its original timestamp.
    2. The metadata role keeps its own rule, because its timestamp gives the fields a different function.

    I prefer 2. The problem comes from the role, not from the merge procedure.

    Your third point is in the issue. The rule has the sentence "A role's definition MAY defer when a merge is applied", and PR #135 uses it. Merge #135 first.


    Generated by Claude Code

  3. maximmaxim345 commented on Aug 19, 2026

    @maximmaxim345
    Member

    We need to just simplify the protocol, we just drop diff messages.
    Then we don't need this overcomplicated diffing rule.
    This also simplifies #135

  4. moved this from Next to In Progress in Sendspin Project Boardon Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions