Skip to content

Fix block network hash handling - #142

Merged
HashimTheArab merged 19 commits into
stablefrom
fix/block-network-hashes
Jul 14, 2026
Merged

Fix block network hash handling#142
HashimTheArab merged 19 commits into
stablefrom
fix/block-network-hashes

Conversation

@HashimTheArab

@HashimTheArab HashimTheArab commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • decode hashed chunks, subchunks, block updates, and item block IDs into canonical registry runtime IDs for Oomph simulation
  • encode Oomph-generated block and inventory packets using the block-network mode established by the initial backend
  • require instant-transfer targets to use the same block-hash setting and reject incompatible transfers before installing the backend
  • keep chunk caches separated by payload and block-network mode
  • use cheap runtime-cache chunk compaction instead of full palette compaction
  • preserve the optional full-chunk re-encode workaround in both runtime-ID and hash modes
  • forward ordinary gameplay packets unchanged; mixed hash/runtime transfer translation is intentionally out of scope

Depends on oomph-ac/dragonfly#2 for non-mutating chunk palette conversion helpers.

This supersedes #141 while keeping the design scoped to same-mode server fleets.

Validation

  • go test -race ./... -count=1
  • go vet ./...
  • git diff --check
  • codex review --base origin/stable — no actionable regressions identified

Summary by CodeRabbit

  • New Features
    • Improved block and chunk compatibility across different server network representations.
    • Added safer backend transfers, preventing switches between incompatible block-data formats.
    • Improved chunk handling to reduce invisible or incorrectly displayed blocks.
  • Bug Fixes
    • Corrected block updates and item conversions when network identifiers differ from internal identifiers.
    • Improved chunk cache accuracy across server connections.

Note

Medium Risk
Touches core world simulation, chunk caching, and proxy backend swaps; incorrect ID mapping could desync blocks, but changes are gated by explicit mode checks and transfer rejection on mismatch.

Overview
Adds a per-session block-network codec (runtime IDs vs network hashes) fixed from the first backend’s StartGame, with DecodeBlockRuntimeID / EncodeBlockRuntimeID wired through chunk caching, block updates, inventory block IDs, and client-facing sync packets so Oomph’s world simulation always uses canonical registry IDs.

Chunk path: CacheChunk / CacheSubChunk take the codec, convert hashed palettes when needed, and include block-network mode in cache keys; optional AttemptFixChunks now uses ReencodeLevelChunk instead of inline decode/re-encode. Transfers: TransferServerConn returns an error if a new backend’s hash setting disagrees with the session; the native proxy aborts the swap and closes the dialed backend on mismatch.

Bumps the oomph-ac/dragonfly replace to pick up hash conversion / encode helpers.

Reviewed by Cursor Bugbot for commit b0deafd. Bugbot is set up for automated code reviews on this repo. Configure here.

Closes #132

@cursor

cursor Bot commented Jul 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_f66c72b1-ea78-40c0-824b-84046cfa9c16)

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Block network codecs are initialized per player session and used to translate block runtime IDs, key chunk caches by representation mode, re-encode chunk packets, and validate backend transfers. Chunk acknowledgements and world updates now pass through the session codec.

Changes

Block Network Hash Handling

Layer / File(s) Summary
Codec-aware world caching
world/world.go, world/cache.go, go.mod
World caches include codec mode in cache keys, convert chunk data between representations, and preserve mode metadata. The Dragonfly replacement is updated.
Player codec and canonical block mappings
player/player.go, player/network.go, player/world.go, player/items.go, player/component/world.go
Players retain a session codec and translate block runtime IDs across world, item, and interaction paths.
Chunk rewriting and acknowledgement wiring
player/packet.go, player/component/acknowledgement/chunks.go, player/world.go
Full chunks can be re-encoded with the player codec, while acknowledgements pass codec data into caching and world update handling.
Backend transfer validation
integration/proxy/proxy.go, integration/proxy/proxy_test.go
Backend transfers validate codec modes before swapping connections and update callers for the returned error.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Backend
  participant Player
  participant WorldCache
  participant Client
  Backend->>Player: Send chunk or block runtime IDs
  Player->>WorldCache: Decode and cache using session codec
  WorldCache-->>Player: Canonical chunk data
  Player->>Client: Encode and send client representation
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.51% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing block network hash handling across packet and transfer paths.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/block-network-hashes

Comment @coderabbitai help to get the list of available commands.

@cursor

cursor Bot commented Jul 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_8387516c-7c56-42e8-85ae-cff3c3c450aa)

@cursor

cursor Bot commented Jul 13, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_22690428-4b3d-4ec4-824b-a5e2967a1e90)

@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_d73ce6f6-c002-4431-9e70-588cc735e3b2)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
player/world.go (1)

77-120: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Asymmetric use of "Network" naming between BlockRuntimeIDFromNetwork/BlockRuntimeIDToNetwork.

BlockRuntimeIDFromNetwork (Line 78) translates using p.backendBlockNetwork, but BlockRuntimeIDToNetwork (Line 84) translates using p.clientBlockNetwork. Given the existing, clearly-named BlockRuntimeIDFromClient/BlockRuntimeIDToBackend/BlockRuntimeIDFromBackendToClient/BlockRuntimeIDFromClientToBackend counterparts, having a ...FromNetwork/...ToNetwork pair that silently means "backend" in one direction and "client" in the other is a footgun for future maintainers touching this hash-sensitive code path — a natural assumption would be that "Network" refers to the same endpoint in both methods.

Consider renaming (e.g. BlockRuntimeIDFromBackendNetwork / BlockRuntimeIDToClientNetwork) or at minimum strengthening the doc comments to explicitly flag the asymmetry.

✏️ Suggested doc/name clarification
+// BlockRuntimeIDFromNetwork converts a block ID from the current backend's network representation to Oomph's
+// canonical registry runtime ID. Note this intentionally uses the backend codec, not the client codec.
 func (p *Player) BlockRuntimeIDFromNetwork(id uint32) uint32 {
 	return blockRuntimeIDFromNetwork(p.backendBlockNetwork, id)
 }

-// BlockRuntimeIDToNetwork converts an Oomph block runtime ID to the hash expected by clients when the backend enabled
-// hashed block network IDs. Unknown values are preserved so custom block fallbacks remain intact.
+// BlockRuntimeIDToNetwork converts an Oomph block runtime ID to the network representation expected by the CLIENT
+// (not the backend) — intended for packets Oomph crafts itself and sends directly to the client (e.g. SyncBlock).
+// Unknown values are preserved so custom block fallbacks remain intact.
 func (p *Player) BlockRuntimeIDToNetwork(id uint32) uint32 {
 	return blockRuntimeIDToNetwork(p.clientBlockNetwork, id)
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@player/world.go` around lines 77 - 120, Clarify the asymmetric endpoint
meaning of BlockRuntimeIDFromNetwork and BlockRuntimeIDToNetwork, preferably by
renaming them to explicitly identify backend and client networks; otherwise
strengthen both doc comments to state which network each method uses. Update all
call sites consistently while preserving their existing translation behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@player/world.go`:
- Around line 77-120: Clarify the asymmetric endpoint meaning of
BlockRuntimeIDFromNetwork and BlockRuntimeIDToNetwork, preferably by renaming
them to explicitly identify backend and client networks; otherwise strengthen
both doc comments to state which network each method uses. Update all call sites
consistently while preserving their existing translation behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f6b69af-97a4-4881-99b0-14945deefdd4

📥 Commits

Reviewing files that changed from the base of the PR and between 6bade6f and 0b7130c.

📒 Files selected for processing (14)
  • player/block_network_packet.go
  • player/component/acknowledgement/chunks.go
  • player/component/combat.go
  • player/component/world_hash_test.go
  • player/network.go
  • player/packet.go
  • player/player.go
  • player/world.go
  • player/world_hash_test.go
  • world/blocknetwork/codec.go
  • world/blocknetwork/codec_test.go
  • world/blocknetwork/mode.go
  • world/cache.go
  • world/world.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • player/component/acknowledgement/chunks.go
  • player/component/world_hash_test.go

@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_15ea57b8-c4b1-43ac-87cc-8d821be62bd9)

@HashimTheArab

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_f33af374-acbe-4f0c-8c85-f9ca62894334)

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@player/block_network_packet.go`:
- Around line 66-106: The rewriteRecipeBlockNetworkIDs switch does not translate
outputs for protocol.FurnaceRecipe and protocol.FurnaceDataRecipe. Add cases for
both recipe types, copy each recipe, apply rewriteStackBlockNetworkID to its
Output, and return the copied recipe with modified=true only when translation
occurs; otherwise preserve the existing fallback.

In `@player/items.go`:
- Around line 21-24: Update the BlockByRuntimeID handling in the item conversion
logic to preserve the existing item when the translated backend ID cannot be
resolved; only replace it when the resolved block implements world.Item,
otherwise retain the current fallback behavior for known non-item blocks. Add
coverage for both unknown hashes and signed-negative hashes, ensuring neither
causes the item to be lost.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f2afca7c-f432-4586-80a7-27da94075a90

📥 Commits

Reviewing files that changed from the base of the PR and between 0b7130c and 8456520.

📒 Files selected for processing (5)
  • player/block_network_packet.go
  • player/component/world.go
  • player/items.go
  • player/packet.go
  • player/world.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • player/component/world.go
  • player/packet.go

Comment thread player/block_network_packet.go Outdated
Comment thread player/items.go Outdated
@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_4c508ea4-049f-4a5d-b2d1-fd4311d4333c)

@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_68db26e9-714c-4887-bdff-ee9059dac15c)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
integration/proxy/proxy_test.go (1)

203-218: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for the new mode-mismatch transfer error path.

This PR introduces block-network mode validation in TransferServerConn (erroring + backend cleanup in proxy.go's transfer()), but no test exercises a mismatched UseBlockNetworkIDHashes between the initial backend and a transfer target. fakeBackend already carries GameData, so this is easy to add alongside the existing test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integration/proxy/proxy_test.go` around lines 203 - 218, The existing
TestTransferResetSynchronizesWithPlayerTick coverage should also exercise
TransferServerConn’s block-network mode mismatch path. Add a transfer target
with UseBlockNetworkIDHashes differing from the initial fakeBackend, assert the
transfer returns the expected error, and verify the rejected backend is cleaned
up, while preserving the existing synchronization test.
world/cache.go (1)

132-140: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor: duplicate codec.Mode() check.

The same codec.Mode() == blocknetwork.Hashes condition is evaluated twice back-to-back; merging avoids the repetition.

♻️ Suggested consolidation
-	if codec.Mode() == blocknetwork.Hashes {
-		decoded.ConvertBlockNetworkHashesToRuntimeIDs()
-	}
 	var data chunk.SerialisedData
 	if codec.Mode() == blocknetwork.Hashes {
+		decoded.ConvertBlockNetworkHashesToRuntimeIDs()
 		data = chunk.EncodeWithBlockNetworkHashes(decoded)
 	} else {
 		data = chunk.Encode(decoded, chunk.NetworkEncoding)
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@world/cache.go` around lines 132 - 140, Consolidate the adjacent codec.Mode()
== blocknetwork.Hashes checks in the surrounding decode-and-encode flow:
evaluate the mode once and use that result for both
ConvertBlockNetworkHashesToRuntimeIDs and the corresponding encoding selection,
preserving the existing behavior for blocknetwork.Hashes and other modes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@integration/proxy/proxy_test.go`:
- Around line 203-218: The existing TestTransferResetSynchronizesWithPlayerTick
coverage should also exercise TransferServerConn’s block-network mode mismatch
path. Add a transfer target with UseBlockNetworkIDHashes differing from the
initial fakeBackend, assert the transfer returns the expected error, and verify
the rejected backend is cleaned up, while preserving the existing
synchronization test.

In `@world/cache.go`:
- Around line 132-140: Consolidate the adjacent codec.Mode() ==
blocknetwork.Hashes checks in the surrounding decode-and-encode flow: evaluate
the mode once and use that result for both ConvertBlockNetworkHashesToRuntimeIDs
and the corresponding encoding selection, preserving the existing behavior for
blocknetwork.Hashes and other modes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 729bf9ea-f207-45b2-ac52-e91031ce2070

📥 Commits

Reviewing files that changed from the base of the PR and between 8456520 and 8fa0826.

📒 Files selected for processing (10)
  • integration/proxy/proxy.go
  • integration/proxy/proxy_test.go
  • player/component/acknowledgement/chunks.go
  • player/component/world.go
  • player/items.go
  • player/network.go
  • player/packet.go
  • player/player.go
  • player/world.go
  • world/cache.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • player/component/world.go

@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_0ea5b316-16e6-43a7-97b7-5d198d31788a)

@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_21ca5be4-a663-461c-9b9d-1f1f64a9a54d)

@HashimTheArab
HashimTheArab merged commit ef2fc2f into stable Jul 14, 2026
3 checks passed
@HashimTheArab

Copy link
Copy Markdown
Collaborator Author

Closes #132

@HashimTheArab
HashimTheArab deleted the fix/block-network-hashes branch July 14, 2026 05:34
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 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.

Chunk compaction can be 8-14x faster using new methods

1 participant