From 4deddd96673c508d7ea41070a1a85b2d422d18dc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 17:01:15 +0000 Subject: [PATCH 1/3] Initial plan From 69109e7bdbbac68d9cf41b09b1b1c83c14c313a1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 17:06:58 +0000 Subject: [PATCH 2/3] Fix stale SyncSetDeltaPacket by tracking actual change IDs in batch sync Co-authored-by: TheBjoRedCraft <143264463+TheBjoRedCraft@users.noreply.github.com> --- .../cloud/core/client/sync/SyncRegistryImpl.kt | 6 +++--- .../synchronizing/ClientboundBatchSyncSetPacket.kt | 14 ++++++++++---- .../surf/cloud/core/common/sync/SyncSetImpl.kt | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/sync/SyncRegistryImpl.kt b/surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/sync/SyncRegistryImpl.kt index f68b5b1e..0cd43a83 100644 --- a/surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/sync/SyncRegistryImpl.kt +++ b/surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/sync/SyncRegistryImpl.kt @@ -62,12 +62,12 @@ class SyncRegistryImpl : CommonSyncRegistryImpl() { lastChangeIds[packet.setId] = packet.changeId } - fun applyBatchSyncSets(bulk: List>>) { - bulk.forEach { (id, snapshot) -> + fun applyBatchSyncSets(bulk: List, Long>>) { + bulk.forEach { (id, snapshot, changeId) -> val set = getSet(id) if (set != null) { set.addAllInternal(snapshot) - lastChangeIds[id] = Long.MAX_VALUE // Reset change ID to max after bulk update + lastChangeIds[id] = changeId } } } diff --git a/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt b/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt index 9f02703a..8779902d 100644 --- a/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt +++ b/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt @@ -27,10 +27,10 @@ class ClientboundBatchSyncSetPacket : NettyPacket, InternalNettyPacket>> + val syncSets: List, Long>> constructor(syncValues: Map>) { - this.syncSets = syncValues.map { (key, value) -> key to value.toSet() } + this.syncSets = syncValues.map { (key, value) -> Triple(key, value.toSet(), value.currentChangeId) } } private constructor(buf: SurfByteBuf) { @@ -43,10 +43,13 @@ class ClientboundBatchSyncSetPacket : NettyPacket, InternalNettyPacket(syncId) if (syncSet == null) { buf.skipBytes(syncSize) + buf.readLong() // Skip the change ID as well unknownSyncValues.add(syncId) null } else { - syncId to syncSet.codec.decode(buf) + val set = syncSet.codec.decode(buf) + val changeId = buf.readLong() + Triple(syncId, set, changeId) } }.filterNotNull() @@ -57,7 +60,7 @@ class ClientboundBatchSyncSetPacket : NettyPacket, InternalNettyPacket + buf.writeCollection(syncSets) { buf, (syncId, set, changeId) -> buf.writeUtf(syncId) // Reserve 4 bytes for length @@ -72,6 +75,9 @@ class ClientboundBatchSyncSetPacket : NettyPacket, InternalNettyPacket(override val id: String, val valueCodec: StreamCodec>() private val changeCounter = AtomicLong() + val currentChangeId: Long + get() = changeCounter.get() init { CommonSyncRegistryImpl.instance.register(this) From fbd082061dcf8e05dfe79855d843d0ad4a99e5d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 17:09:21 +0000 Subject: [PATCH 3/3] Fix formatting: remove extra blank line Co-authored-by: TheBjoRedCraft <143264463+TheBjoRedCraft@users.noreply.github.com> --- .../protocol/synchronizing/ClientboundBatchSyncSetPacket.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt b/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt index 8779902d..2d0d34c4 100644 --- a/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt +++ b/surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientboundBatchSyncSetPacket.kt @@ -75,7 +75,7 @@ class ClientboundBatchSyncSetPacket : NettyPacket, InternalNettyPacket