[PR #4286] [CLOSED] Datafix: level.dat is stamped only after the world is converted #5543

Closed
opened 2026-11-03 05:13:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4286
Author: @WhyFovius
Created: 10/30/2026
Status: ❌ Closed

Base: main ← Head: fix/world-upgrade-stamp-order


📝 Commits (1)

  • 9395d60 Datafix: level.dat is stamped only after the world is converted

📊 Changes

3 files changed (+130 additions, -17 deletions)

View changed files

📝 crates/horizon-client/src/save.rs (+8 -5)
📝 crates/horizon-world/src/datafix/files.rs (+35 -12)
📝 crates/horizon-world/src/datafix/tests.rs (+87 -0)

📄 Description

> 🤖 Opened by WhyFovius's AI agent (Claude), not by WhyFovius personally.

Fixes #3882

What happens

Opening a pre-1.16/1.20 world stamped level.dat with the current DataVersion before upgrade_world_data converted the chunks, entity chunks, POI chunks, players and saved data. If the conversion stopped on a bad chunk, the next open read DataVersion == CURRENT, returned Ok, and never retried — the world was permanently a mix of a current level.dat and old-format chunks, which the game then reads with the wrong schemas. Silent data loss, reported High severity.

The fix

FileFixerUpper's work is split where vanilla splits it:

  • fix_world_files (now private — upgrade_world was its only caller) runs the file fixes and prepares the rewritten level data, but returns it as a held-back LevelStamp instead of writing level.dat.
  • upgrade_world converts every file (upgrade_world_data) first and applies the stamp — addVersionsToLevelData + the write — only on success, the way vanilla's upgrader marks the level after the whole conversion completes.
  • A failed conversion leaves the old DataVersion on disk, so the next open retries from there. The file fixes' own intermediate level.dat writes (e.g. 4772's LevelDatToSavedDataFileFix) are untouched.
  • A world already at the current version gets no stamp written at all, exactly as the previous immediate return behaved.

Test

a_failed_conversion_leaves_the_old_data_version builds a minimal world at DataVersion 4903 twice: a good one (upgrade succeeds → level.dat and the region's chunk are stamped CURRENT) and one with a corrupt region record (upgrade fails → level.dat still reads 4903, ready to retry).

Self-check

python tools/pr_ready.py --quick

Check Result
Scope ✅ 3 files, +130 −17
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 444 passed (49 s)
rustfmt ✅ (7 s)
clippy ✅ (25 s)
tests: horizon-client, horizon-world ✅ 1138 passed (1 min 30 s)
doc tests ✅ 0 passed (2 s)
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses

🤖 Generated with Claude Code


🔄 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/4286 **Author:** [@WhyFovius](https://github.com/WhyFovius) **Created:** 10/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/world-upgrade-stamp-order` --- ### 📝 Commits (1) - [`9395d60`](https://github.com/horizon-rust/horizon/commit/9395d6000fe475399bb68b2e6e4b27698c82beca) Datafix: level.dat is stamped only after the world is converted ### 📊 Changes **3 files changed** (+130 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/save.rs` (+8 -5) 📝 `crates/horizon-world/src/datafix/files.rs` (+35 -12) 📝 `crates/horizon-world/src/datafix/tests.rs` (+87 -0) </details> ### 📄 Description > 🤖 Opened by WhyFovius's AI agent (Claude), not by WhyFovius personally. Fixes #3882 ## What happens Opening a pre-1.16/1.20 world stamped `level.dat` with the current `DataVersion` **before** `upgrade_world_data` converted the chunks, entity chunks, POI chunks, players and saved data. If the conversion stopped on a bad chunk, the next open read `DataVersion == CURRENT`, returned `Ok`, and never retried — the world was permanently a mix of a current `level.dat` and old-format chunks, which the game then reads with the wrong schemas. Silent data loss, reported High severity. ## The fix `FileFixerUpper`'s work is split where vanilla splits it: - `fix_world_files` (now private — `upgrade_world` was its only caller) runs the file fixes and prepares the rewritten level data, but returns it as a held-back `LevelStamp` instead of writing `level.dat`. - `upgrade_world` converts every file (`upgrade_world_data`) first and applies the stamp — `addVersionsToLevelData` + the write — only on success, the way vanilla's upgrader marks the level after the whole conversion completes. - A failed conversion leaves the old `DataVersion` on disk, so the next open retries from there. The file fixes' own intermediate `level.dat` writes (e.g. 4772's `LevelDatToSavedDataFileFix`) are untouched. - A world already at the current version gets no stamp written at all, exactly as the previous immediate return behaved. ## Test `a_failed_conversion_leaves_the_old_data_version` builds a minimal world at DataVersion 4903 twice: a good one (upgrade succeeds → `level.dat` and the region's chunk are stamped `CURRENT`) and one with a corrupt region record (upgrade fails → `level.dat` still reads 4903, ready to retry). ## Self-check `python tools/pr_ready.py --quick` | Check | Result | | --- | --- | | Scope | ✅ 3 files, +130 −17 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 444 passed (49 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (25 s) | | tests: horizon-client, horizon-world | ✅ 1138 passed (1 min 30 s) | | doc tests | ✅ 0 passed (2 s) | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:13:18 +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#5543
No description provided.