[PR #6060] [MERGED] Saves: upgrade older chunk, entity and POI records as they are read #6632

Closed
opened 2026-11-03 06:24:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6060
Author: @pikammmmm
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/lazy-chunk-datafix


📝 Commits (1)

  • f4d50e3 Saves: upgrade older chunk, entity and POI records as they are read

📊 Changes

3 files changed (+332 additions, -15 deletions)

View changed files

📝 crates/horizon-client/src/save.rs (+327 -12)
📝 crates/horizon-client/src/save/gateway.rs (+2 -1)
📝 crates/horizon-world/src/datafix/files.rs (+3 -2)

📄 Description

🤖 Opened by pikammmmm's AI agent (Claude Code, Claude Opus 5.5), not by pikammmmm personally.

What and why

Fixes #5230

A world that vanilla 26.3 has opened gets a current level.dat. The chunks 26.3 didn't load keep the format of the version that last saved them. Horizon's opening upgrade (upgrade_older_world) only runs when level.dat itself is older, so it skips those chunks, and SaveDir then decoded them raw. A 1.18–26.2 palette names its states with Name, but the 26.x decoder reads id, so every such chunk loads as an empty column. This matches #5230: the areas explored just before importing (re-saved in 26.3) are there, and older terrain is void.

The fix

Vanilla upgrades every record it reads from a region file: SimpleRegionStorage.upgradeChunkTag, called from ChunkMap.upgradeChunkTag (chunks), EntityStorage (entity chunks) and SectionStorage.PackedChunk.parse (POI). SaveDir now does the same in read_record, load_far, lod_surfaces, the End gateway migration and the POI claims merge (resolve_poi). Details:

  • It reuses the ported fixes: datafix::update_chunk and update_region_tag.
  • A record with no DataVersion counts as -1 (POI: 1945), as in vanilla.
  • The __context dimension comes from the dimension folder. The generator type comes from world_gen_settings.dat (files::generators, now pub), read once per SaveDir.
  • old_chunk_bits still reads the record as saved, as IOWorker.isOldChunk does.
  • A panic inside a fix becomes a read failure (report_load_failure), not a dead worker thread.

Records Horizon writes always carry the current DataVersion, so they skip all of this at the cost of one integer compare.

Local proof (real vanilla worlds)

I made worlds with the official 1.17.1 and 1.20.1 servers, each with a marker at x=1000 z=1000: a gold block, 3 diamond blocks, and minecraft:grass (renamed to short_grass in 1.20.3). Each world was then opened once by the 26.3 server, which upgraded level.dat (DataVersion 5023) and left the chunks it didn't load untouched. A throwaway test then read the chunks through SaveDir::load:

1.20.1 world opened by 26.3 main this PR
marker chunk (62, 62), non-air blocks at y=62 0/256 256/256
(1000, 200, 1000) / (1001–1003, 200, 1000) air / air gold_block / diamond_block ×3
(1000, 201, 1000), saved as minecraft:grass air short_grass
spawn chunk (0, 0), non-air blocks at y=62 0/256 256/256

Not fixed here: chunks from before 1.18. In the 1.17.1 world, load returns None both on main and with this PR. The fixes now bring those chunks to the current layout, but the 1.18 height fix marks them below_zero_retrogen with status empty. The client's chunk loading doesn't run below-zero retrogen yet (horizon-world has BelowZeroRetrogen; decode_with/decode_proto don't use it), so they are generated again, as before. That needs a follow-up issue. The same goes for pre-1.17 chunks' own entities list, which vanilla moves into entity storage.

Tests

The tests in save.rs need no vanilla jars unless noted. Each was checked to fail with the upgrade, the raw read or the POI default reverted:

  • older_records_of_a_current_world_upgrade_as_they_are_read: a 1.20.1 chunk reads with short_grass. With HORIZON_TEST_RESOURCES it also decodes to it (raw, it's air). A 1.20.1 item entity's Count: 3b reads as count: 3.
  • old_chunks_are_found_in_the_saved_records_and_old_poi_upgrade: a 1.20.1 Nether chunk is upgraded (no blending_data) but old_chunk_bits still flags it from the saved record. A POI record without a DataVersion gets 1946's Sections.
  • a_chunk_from_before_1_18_is_brought_to_the_current_layout: a 1.17.1 chunk loses its Level wrapper and gains blending_data.

save:: passes 56/56, also with HORIZON_TEST_RESOURCES=.local/horizon-client/26.3.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

ChunkMap.upgradeChunkTag, ChunkMap.getChunkDataFixContextTag, SimpleRegionStorage.upgradeChunkTag, EntityStorage, SectionStorage.PackedChunk.parse, IOWorker.isOldChunk. Checked against the 26.3 jar's bytecode (javap); no source copied. Harness: test_save_roundtrip_parity reads a 26.3 world, whose records skip the upgrade. No harness reads older records, so the three tests above cover that.

Other projects' code

none

Self-check

pr_ready: 3 files changed since origin/main; checks on local
  Public tree: pass (0 s)
  Python tests: pass (1 min 50 s)
  Parity: still running when this was opened; the full block follows in a comment.

The datafix harness is currently red on main for an unrelated oracle failure (#5843, #5904).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/6060 **Author:** [@pikammmmm](https://github.com/pikammmmm) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/lazy-chunk-datafix` --- ### 📝 Commits (1) - [`f4d50e3`](https://github.com/horizon-rust/horizon/commit/f4d50e31225b54e0d31d2fb33ccb8274bd397d2e) Saves: upgrade older chunk, entity and POI records as they are read ### 📊 Changes **3 files changed** (+332 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/save.rs` (+327 -12) 📝 `crates/horizon-client/src/save/gateway.rs` (+2 -1) 📝 `crates/horizon-world/src/datafix/files.rs` (+3 -2) </details> ### 📄 Description > 🤖 Opened by pikammmmm's AI agent (Claude Code, Claude Opus 5.5), not by pikammmmm personally. ## What and why Fixes #5230 A world that vanilla 26.3 has opened gets a current `level.dat`. The chunks 26.3 didn't load keep the format of the version that last saved them. Horizon's opening upgrade (`upgrade_older_world`) only runs when `level.dat` itself is older, so it skips those chunks, and `SaveDir` then decoded them raw. A 1.18–26.2 palette names its states with `Name`, but the 26.x decoder reads `id`, so **every such chunk loads as an empty column**. This matches #5230: the areas explored just before importing (re-saved in 26.3) are there, and older terrain is void. ### The fix Vanilla upgrades every record it reads from a region file: `SimpleRegionStorage.upgradeChunkTag`, called from `ChunkMap.upgradeChunkTag` (chunks), `EntityStorage` (entity chunks) and `SectionStorage.PackedChunk.parse` (POI). `SaveDir` now does the same in `read_record`, `load_far`, `lod_surfaces`, the End gateway migration and the POI claims merge (`resolve_poi`). Details: - It reuses the ported fixes: `datafix::update_chunk` and `update_region_tag`. - A record with no DataVersion counts as -1 (POI: 1945), as in vanilla. - The `__context` dimension comes from the dimension folder. The generator type comes from `world_gen_settings.dat` (`files::generators`, now `pub`), read once per `SaveDir`. - `old_chunk_bits` still reads the record as saved, as `IOWorker.isOldChunk` does. - A panic inside a fix becomes a read failure (`report_load_failure`), not a dead worker thread. Records Horizon writes always carry the current DataVersion, so they skip all of this at the cost of one integer compare. ### Local proof (real vanilla worlds) I made worlds with the official 1.17.1 and 1.20.1 servers, each with a marker at x=1000 z=1000: a gold block, 3 diamond blocks, and `minecraft:grass` (renamed to `short_grass` in 1.20.3). Each world was then opened once by the 26.3 server, which upgraded `level.dat` (DataVersion 5023) and left the chunks it didn't load untouched. A throwaway test then read the chunks through `SaveDir::load`: | 1.20.1 world opened by 26.3 | main | this PR | |---|---|---| | marker chunk (62, 62), non-air blocks at y=62 | 0/256 | 256/256 | | (1000, 200, 1000) / (1001–1003, 200, 1000) | air / air | gold_block / diamond_block ×3 | | (1000, 201, 1000), saved as `minecraft:grass` | air | short_grass | | spawn chunk (0, 0), non-air blocks at y=62 | 0/256 | 256/256 | **Not fixed here: chunks from before 1.18.** In the 1.17.1 world, `load` returns `None` both on main and with this PR. The fixes now bring those chunks to the current layout, but the 1.18 height fix marks them `below_zero_retrogen` with status `empty`. The client's chunk loading doesn't run below-zero retrogen yet (horizon-world has `BelowZeroRetrogen`; `decode_with`/`decode_proto` don't use it), so they are generated again, as before. That needs a follow-up issue. The same goes for pre-1.17 chunks' own `entities` list, which vanilla moves into entity storage. ### Tests The tests in `save.rs` need no vanilla jars unless noted. Each was checked to fail with the upgrade, the raw read or the POI default reverted: - `older_records_of_a_current_world_upgrade_as_they_are_read`: a 1.20.1 chunk reads with `short_grass`. With `HORIZON_TEST_RESOURCES` it also decodes to it (raw, it's air). A 1.20.1 item entity's `Count: 3b` reads as `count: 3`. - `old_chunks_are_found_in_the_saved_records_and_old_poi_upgrade`: a 1.20.1 Nether chunk is upgraded (no `blending_data`) but `old_chunk_bits` still flags it from the saved record. A POI record without a DataVersion gets 1946's `Sections`. - `a_chunk_from_before_1_18_is_brought_to_the_current_layout`: a 1.17.1 chunk loses its `Level` wrapper and gains `blending_data`. `save::` passes 56/56, also with `HORIZON_TEST_RESOURCES=.local/horizon-client/26.3`. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `ChunkMap.upgradeChunkTag`, `ChunkMap.getChunkDataFixContextTag`, `SimpleRegionStorage.upgradeChunkTag`, `EntityStorage`, `SectionStorage.PackedChunk.parse`, `IOWorker.isOldChunk`. Checked against the 26.3 jar's bytecode (`javap`); no source copied. Harness: `test_save_roundtrip_parity` reads a 26.3 world, whose records skip the upgrade. No harness reads older records, so the three tests above cover that. ## Other projects' code none ## Self-check ``` pr_ready: 3 files changed since origin/main; checks on local Public tree: pass (0 s) Python tests: pass (1 min 50 s) Parity: still running when this was opened; the full block follows in a comment. ``` The `datafix` harness is currently red on main for an unrelated oracle failure (#5843, #5904). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:24:06 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6632
No description provided.