Skip to content

Don't lose mutations delayed by priority on insertion or removal - #792

Closed
oloflarsson wants to merge 1 commit into
simgine:masterfrom
oloflarsson:fix-delayed-mutation-with-insertion
Closed

oloflarsson wants to merge 1 commit into
simgine:masterfrom
oloflarsson:fix-delayed-mutation-with-insertion

Conversation

@oloflarsson

Copy link
Copy Markdown

Fixes #791.

Timeline of the lost mutation on master and with the fix

When priority delays an entity's mutation for a client, and the entity has an insertion or a removal for that client on the same tick, update_ticks moved EntityTicks::system_tick past the delayed change, so it was never sent.

Now Mutations records whether a mutation was delayed for the current entity (reset in start_entity, like entity_location). When it was, collect_changes keeps the previous system_tick while still updating server_tick, the components and the diff cursors. Priority depends only on the entity and the client, so when a mutation is delayed none of the entity's mutations were written for that client. Keeping the older tick only makes us resend more, so the delayed change stays pending (this would still hold with per-component priority, #698).

Trade-offs:

  • Components inserted on that tick are newer than the kept system_tick, so they are sent once more as mutations together with the delayed one. The client gets the same value again, which triggers change detection (and, for immutable components, insertion hooks and observers) a second time, as a resent mutation already does after a lost ack.
  • server_tick is still bumped by the update message, so priority accumulation for the entity restarts from that tick (as it already does today). The delayed mutation therefore goes out up to 1 / priority ticks later, and is held back for as long as the entity keeps getting insertions or removals more often than that.

An alternative would be to ignore priority for an entity that has an insertion or removal for the client and write its mutations into the update message. That needs to know about insertions before the first mutation is written (removals are known up front, insertions only once their component is reached), so I went with the smaller change. Happy to switch if you prefer that.

Added priority::with_insertion and priority::with_removal. Both fail on master and pass with the fix. Also added a changelog entry.

Tested locally on the PR head: cargo test --workspace --all-features --all-targets, cargo test --workspace --all-features --doc, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo rustdoc --all-features -- -D warnings (and for the example backend), cargo fmt --all --check, taplo fmt --check, typos and cargo hack check --feature-powerset. server_message::server_buffering failed once in my runs on a loaded machine; it fails at a similar rate on master (3/30 vs 5/30 interleaved), since the default ServerPlugin ticks in FixedPostUpdate on real time, so it looks unrelated.

If priority delayed an entity's mutation for a client and the entity had
an insertion or removal for that client on the same tick, `update_ticks`
moved `system_tick` past the delayed change and it was never sent.
Keep the previous `system_tick` in that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Shatur

Shatur commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Fixed it a bit differently in #794, thanks!

@Shatur Shatur closed this Nov 14, 2026
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.

Mutation delayed by priority is lost when the entity gets an insertion or removal on the same tick

2 participants