Skip to content

fix: network stream desync from mismatched write/read byte-array framing - #19

Merged
KP2048 merged 1 commit into
1.21.xfrom
worktree-fix-network-write-read-mismatch
Aug 13, 2026
Merged

fix: network stream desync from mismatched write/read byte-array framing#19
KP2048 merged 1 commit into
1.21.xfrom
worktree-fix-network-write-read-mismatch

Conversation

@KP2048

@KP2048 KP2048 commented Aug 13, 2026

Copy link
Copy Markdown
Member

Summary

check CI (fabric:client, neoforge:client) was failing on 1.21.x with:

io.netty.handler.codec.DecoderException: ByteArray with size 12607 is bigger than allowed 703
	at net.minecraft.network.FriendlyByteBuf.readByteArray(FriendlyByteBuf.java:298)
	at net.kernelpanicsoft.archie.serialization.UtilsKt.read(Utils.kt:34)
	at net.kernelpanicsoft.archie.serialization.UtilsKt._get_streamCodec_$lambda$1(Utils.kt:100)

RegistryFriendlyByteBuf.write(serializer, data) wrote the encoded CBOR payload with writeBytes() - Netty's raw byte-array write, no length prefix. Its counterpart read(serializer) reads it back with readByteArray() - Minecraft's own length-prefixed format (a VarInt count, then that many bytes). The two were never actually compatible.

write() just had no real caller exercising the mismatch until streamCodec's implementation was refactored earlier this session to route through write()/read() instead of calling Nbt's/Cbor's encode/decode directly with matching writeByteArray/readByteArray calls (as it used to). Any StreamCodec built via KSerializer.streamCodec then hit this immediately - readByteArray() misread the front of the raw CBOR bytes as if they were a VarInt length prefix, producing a garbage size. A real stream desync, not a flake.

Fix

write() now uses writeByteArray() to match read()'s framing.

Verification

Reproduced locally via ComposeItemContainerMenuClientTests.testExcludedSlotBehaviorViaRealMenuOpen (does a real menu-open network round trip) - failed before this fix, passes after. Full :archie-gametest-neoforge:runGametestClient suite is clean (25/25 on a second run; the first run's lone failure was the already-documented pre-existing "stale render state" flake, unrelated).

🤖 Generated with Claude Code

…cts writeByteArray()'s framing

RegistryFriendlyByteBuf.write(serializer, data) wrote the encoded CBOR
payload with plain writeBytes() - Netty's raw byte-array write, no length
prefix. Its counterpart read(serializer) reads it back with
readByteArray() - Minecraft's own length-prefixed format (a VarInt count
followed by that many bytes). The two were never compatible; write() just
had no real caller previously exercising the mismatch.

That changed when streamCodec's implementation was refactored earlier
this session to route through write()/read() instead of calling
Nbt's/Cbor's encode/decode directly with matching writeByteArray/
readByteArray calls (as it used to). Any StreamCodec built via
KSerializer.streamCodec now hit this immediately in CI:

  io.netty.handler.codec.DecoderException: ByteArray with size 12607 is
  bigger than allowed 703

readByteArray() misread the front of the raw CBOR bytes as if they were
a VarInt length prefix, producing a garbage size - a real stream desync,
not a flake. Reproduced locally via ComposeItemContainerMenuClientTests.
testExcludedSlotBehaviorViaRealMenuOpen (uses a real menu-open network
round trip), which was failing in CI (fabric:client, neoforge:client) on
1.21.x.

Fix: write() now uses writeByteArray() to match read()'s framing.

Verified: the previously-failing test now passes standalone, and the
full :archie-gametest-neoforge:runGametestClient suite is clean (25/25 on
a second run; the first run's single failure was the already-documented
pre-existing "stale render state" flake, unrelated to this change).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 13, 2026 04:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@KP2048
KP2048 merged commit 9734b14 into 1.21.x Aug 13, 2026
6 checks passed
@KP2048
KP2048 deleted the worktree-fix-network-write-read-mismatch branch August 13, 2026 05:46
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.

2 participants