[PR #4219] [MERGED] List worlds with an unreadable level.dat and offer recovery #5494

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4219
Author: @d3grando
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3517-corrupt-leveldat-list


📝 Commits (1)

  • 9bdb5ec List worlds with an unreadable level.dat and offer recovery

📊 Changes

5 files changed (+529 additions, -61 deletions)

View changed files

📝 crates/horizon-client/src/game/agent.rs (+12 -1)
📝 crates/horizon-client/src/game/saves_control.rs (+1 -0)
📝 crates/horizon-client/src/save.rs (+56 -3)
📝 crates/horizon-client/src/title.rs (+338 -57)
📝 crates/horizon-client/src/title/tests.rs (+122 -0)

📄 Description

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

What and why

If a world's level.dat couldn't be read, Select World left the world out, even when level.dat_old would load it. That happens when a crash during a save cuts the file short. The player thinks the world is gone. list_worlds read the summary with Level::read, then read level.dat again with metadata(...)? and read_dat(...)?. If any of these failed, the world was skipped. A folder with only level.dat_old was also skipped.

The list now works like vanilla:

  • Which folders count as worlds (findLevelCandidates): any folder with a level.dat or a level.dat_old file.
  • Reading the summary (readLevelSummary): only level.dat is read. If it doesn't read, the world is still listed as a CorruptedLevelSummary:
    • its name is the folder name
    • the info line is a red "Failed to load world summary"
    • the time comes from getFileModificationTime: the time of level.dat, or of level.dat_old if there is no level.dat
    • the primary button says "Attempt to Recover"
    • Edit and Re-Create are off; Delete stays on (canEdit / canRecreate / canDelete)
  • Opening the world (WorldOpenFlows.openWorldLoadLevelData): if level.dat doesn't read, RecoverWorldDataScreen opens instead of the world. This applies to any way of opening it from the title screen. The screen shows the title, the message with the folder name, and one line per file: "State from <date>: " followed by "No issues", "Missing file" or the read error (collectIssue / buildInfo). If level.dat_old is just missing, its line is left out.
  • Restore: "Attempt to Restore" is active only when level.dat is broken and level.dat_old reads. It runs restoreLevelDataFromOld:
    • the broken file is kept as level.dat_corrupted_<time> and level.dat_old takes its place
    • if that fails, the screen shows the "Recovery done" / "Failed to recover from previous state." alert. One small difference: vanilla calls Util.safeReplaceOrMoveFile with noRollback, so if level.dat_old can't be moved in it still reports success. Here the broken level.dat is put back and the failure alert shows.
    • if it works, the "Recovery done" / "Recovery was successful!" confirm opens: Continue opens the world, Back returns to the list
  • Nothing to restore from: before, such a world couldn't be opened from the list at all. If something did open it, Level::read returned None and a fresh level with a new random seed started in the existing folder. That path now ends on the recovery screen.

What is left out, and why:

  • Vanilla's "Report a Bug" button. It links to Mojang's snapshot bug tracker, which is the wrong place for Horizon bugs.
  • The zip backup that vanilla's attemptRestore makes before restoring (EditWorldScreen.makeBackupAndShowToast). The broken level.dat is still kept as level.dat_corrupted_<time>, so nothing is lost.
  • Symlinked worlds (SymlinkLevelSummary).

horizon-ctl worlds and the title's control-socket state now report corrupted, plus the new recover-world and recovery-done screens.

Part of #3517 (this PR's ledger row is readLevelSummary. It also covers the client side of the restoreLevelDataFromOld and collectIssues rows.)

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

I read these with javap on the 26.3 client jar:

  • LevelStorageSource.findLevelCandidates and readLevelSummary: when the read fails, the result is still a CorruptedLevelSummary. Also getFileModificationTime(LevelDirectory).
  • LevelSummary.CorruptedLevelSummary:
    • getLevelName returns the level id
    • INFO is recover_world.warning in color -65536
    • primaryActionMessage is recover_world.button
    • canEdit and canRecreate are false
  • SelectWorldScreen.updateButtonStatus.
  • LevelStorageSource.readLevelSummary also returns a CorruptedLevelSummary when there is no level.dat at all, which is why a folder with only level.dat_old is listed.
  • WorldOpenFlows.openWorld and openWorldLoadLevelData: if the data can't be read, RecoverWorldDataScreen opens. Its callback true loads the world again; false goes back.
  • RecoverWorldDataScreen:
    • the constructor builds the layout: column spacing 8, buttons 120 wide
    • collectIssue and buildInfo
    • attemptRestore and its lambdas: the ConfirmScreen with Continue/Back and the AlertScreen on failure
  • LevelStorageAccess.collectIssues, restoreLevelDataFromOld and getFileModificationTime(boolean).
  • Util.safeReplaceOrMoveFile.

No parity harness covers title-screen world loading. Unit tests in crates/horizon-client/src/title/tests.rs check the behaviour:

  • world_with_unreadable_level_dat_stays_in_the_world_list
  • world_with_unreadable_level_dat_is_listed_and_recovers_from_level_dat_old
  • world_with_nothing_to_recover_from_is_listed_but_never_opened

Self-check

tools/pr_ready.py doesn't run on Windows (it needs SIGHUP), so I ran the steps by hand, on the branch rebased onto main at 68f036059:

cargo fmt --all -- --check                                               -> clean
cargo clippy --profile fast -p horizon-client --all-targets -- -D warnings -> Finished, no warnings
cargo test -p horizon-client --lib --profile fast title::                -> 39 passed, 1 failed
cargo test -p horizon-client --lib --profile fast save::tests            -> 34 passed

The one failure, title::tests::each_world_preset_writes_its_own_generator, fails the same way on unchanged main. It panics when it writes into a folder named after the preset id (minecraft:normal), and Windows doesn't allow a : in a folder name. This change doesn't touch that code.

The new test fails without the fix. I reverted only the code and kept the test:

test title::tests::world_with_unreadable_level_dat_stays_in_the_world_list ... FAILED
  left: []
 right: ["Broken", "Old only"]
test result: FAILED. 0 passed; 1 failed

With the fix:

test title::tests::world_with_unreadable_level_dat_stays_in_the_world_list ... ok
test title::tests::world_with_unreadable_level_dat_is_listed_and_recovers_from_level_dat_old ... ok
test title::tests::world_with_nothing_to_recover_from_is_listed_but_never_opened ... ok

In game (Windows, single player on the server thread):

  1. I made two worlds, "Broken" (seed 7) and "Other", and saved "Broken" twice so it had a level.dat_old.
  2. I cut "Broken"'s level.dat to its first 100 bytes.
  3. Before the fix, Select World listed only "Other".
  4. With the fix:
    • "Broken" is listed with the red warning, and selecting it shows "Attempt to Recover", with Edit and Re-Create greyed out.
    • The recovery screen showed level.dat: "NBT at byte 3: truncated input" and level.dat_old: "No issues".
    • Attempt to Restore left level.dat (444 bytes, the old copy) next to level.dat_corrupted_2026-10-30_13-10-42 (the 100-byte broken file).
    • Continue loaded the world, and /seed printed 7.

Screenshots

before: a world with a corrupt level.dat (Broken) is missing from the list

after: it is listed with Failed to load world summary

after: selecting it opens the recovery screen, which offers level.dat_old

  • Before: Select World shows only "Other". The world whose level.dat is damaged is missing.
  • After: "Broken" is back in the list, with "Failed to load world summary" in red under its folder name.
  • After: with "Broken" selected, the primary button reads "Attempt to Recover", and Edit and Re-Create are greyed out.
  • After: the "Failed to load world" recovery screen shows each file's state: level.dat with its red read error and level.dat_old with a green "No issues". Below are "Attempt to Restore" and "Back".
  • After: "Recovery done / Recovery was successful!" with Continue and Back.

🤖 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/4219 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3517-corrupt-leveldat-list` --- ### 📝 Commits (1) - [`9bdb5ec`](https://github.com/horizon-rust/horizon/commit/9bdb5ec7fd91323ea5363dd730fc421720a2b261) List worlds with an unreadable level.dat and offer recovery ### 📊 Changes **5 files changed** (+529 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/agent.rs` (+12 -1) 📝 `crates/horizon-client/src/game/saves_control.rs` (+1 -0) 📝 `crates/horizon-client/src/save.rs` (+56 -3) 📝 `crates/horizon-client/src/title.rs` (+338 -57) 📝 `crates/horizon-client/src/title/tests.rs` (+122 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why If a world's `level.dat` couldn't be read, Select World left the world out, even when `level.dat_old` would load it. That happens when a crash during a save cuts the file short. The player thinks the world is gone. `list_worlds` read the summary with `Level::read`, then read `level.dat` again with `metadata(...)?` and `read_dat(...)?`. If any of these failed, the world was skipped. A folder with only `level.dat_old` was also skipped. The list now works like vanilla: - **Which folders count as worlds** (`findLevelCandidates`): any folder with a `level.dat` or a `level.dat_old` file. - **Reading the summary** (`readLevelSummary`): only `level.dat` is read. If it doesn't read, the world is still listed as a `CorruptedLevelSummary`: - its name is the folder name - the info line is a red "Failed to load world summary" - the time comes from `getFileModificationTime`: the time of `level.dat`, or of `level.dat_old` if there is no `level.dat` - the primary button says "Attempt to Recover" - Edit and Re-Create are off; Delete stays on (`canEdit` / `canRecreate` / `canDelete`) - **Opening the world** (`WorldOpenFlows.openWorldLoadLevelData`): if `level.dat` doesn't read, `RecoverWorldDataScreen` opens instead of the world. This applies to any way of opening it from the title screen. The screen shows the title, the message with the folder name, and one line per file: "State from \<date\>: " followed by "No issues", "Missing file" or the read error (`collectIssue` / `buildInfo`). If `level.dat_old` is just missing, its line is left out. - **Restore**: "Attempt to Restore" is active only when `level.dat` is broken and `level.dat_old` reads. It runs `restoreLevelDataFromOld`: - the broken file is kept as `level.dat_corrupted_<time>` and `level.dat_old` takes its place - if that fails, the screen shows the "Recovery done" / "Failed to recover from previous state." alert. One small difference: vanilla calls `Util.safeReplaceOrMoveFile` with `noRollback`, so if `level.dat_old` can't be moved in it still reports success. Here the broken `level.dat` is put back and the failure alert shows. - if it works, the "Recovery done" / "Recovery was successful!" confirm opens: Continue opens the world, Back returns to the list - **Nothing to restore from**: before, such a world couldn't be opened from the list at all. If something did open it, `Level::read` returned `None` and a fresh level with a new random seed started in the existing folder. That path now ends on the recovery screen. What is left out, and why: - Vanilla's "Report a Bug" button. It links to Mojang's snapshot bug tracker, which is the wrong place for Horizon bugs. - The zip backup that vanilla's `attemptRestore` makes before restoring (`EditWorldScreen.makeBackupAndShowToast`). The broken `level.dat` is still kept as `level.dat_corrupted_<time>`, so nothing is lost. - Symlinked worlds (`SymlinkLevelSummary`). `horizon-ctl worlds` and the title's control-socket state now report `corrupted`, plus the new `recover-world` and `recovery-done` screens. Part of #3517 (this PR's ledger row is `readLevelSummary`. It also covers the client side of the `restoreLevelDataFromOld` and `collectIssues` rows.) ## Kind - [x] 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 I read these with javap on the 26.3 client jar: - `LevelStorageSource.findLevelCandidates` and `readLevelSummary`: when the read fails, the result is still a `CorruptedLevelSummary`. Also `getFileModificationTime(LevelDirectory)`. - `LevelSummary.CorruptedLevelSummary`: - `getLevelName` returns the level id - `INFO` is `recover_world.warning` in color -65536 - `primaryActionMessage` is `recover_world.button` - `canEdit` and `canRecreate` are false - `SelectWorldScreen.updateButtonStatus`. - `LevelStorageSource.readLevelSummary` also returns a `CorruptedLevelSummary` when there is no `level.dat` at all, which is why a folder with only `level.dat_old` is listed. - `WorldOpenFlows.openWorld` and `openWorldLoadLevelData`: if the data can't be read, `RecoverWorldDataScreen` opens. Its callback `true` loads the world again; `false` goes back. - `RecoverWorldDataScreen`: - the constructor builds the layout: column spacing 8, buttons 120 wide - `collectIssue` and `buildInfo` - `attemptRestore` and its lambdas: the `ConfirmScreen` with Continue/Back and the `AlertScreen` on failure - `LevelStorageAccess.collectIssues`, `restoreLevelDataFromOld` and `getFileModificationTime(boolean)`. - `Util.safeReplaceOrMoveFile`. No parity harness covers title-screen world loading. Unit tests in `crates/horizon-client/src/title/tests.rs` check the behaviour: - `world_with_unreadable_level_dat_stays_in_the_world_list` - `world_with_unreadable_level_dat_is_listed_and_recovers_from_level_dat_old` - `world_with_nothing_to_recover_from_is_listed_but_never_opened` ## Self-check `tools/pr_ready.py` doesn't run on Windows (it needs SIGHUP), so I ran the steps by hand, on the branch rebased onto `main` at 68f036059: ``` cargo fmt --all -- --check -> clean cargo clippy --profile fast -p horizon-client --all-targets -- -D warnings -> Finished, no warnings cargo test -p horizon-client --lib --profile fast title:: -> 39 passed, 1 failed cargo test -p horizon-client --lib --profile fast save::tests -> 34 passed ``` The one failure, `title::tests::each_world_preset_writes_its_own_generator`, fails the same way on unchanged `main`. It panics when it writes into a folder named after the preset id (`minecraft:normal`), and Windows doesn't allow a `:` in a folder name. This change doesn't touch that code. The new test fails without the fix. I reverted only the code and kept the test: ``` test title::tests::world_with_unreadable_level_dat_stays_in_the_world_list ... FAILED left: [] right: ["Broken", "Old only"] test result: FAILED. 0 passed; 1 failed ``` With the fix: ``` test title::tests::world_with_unreadable_level_dat_stays_in_the_world_list ... ok test title::tests::world_with_unreadable_level_dat_is_listed_and_recovers_from_level_dat_old ... ok test title::tests::world_with_nothing_to_recover_from_is_listed_but_never_opened ... ok ``` In game (Windows, single player on the server thread): 1. I made two worlds, "Broken" (seed 7) and "Other", and saved "Broken" twice so it had a `level.dat_old`. 2. I cut "Broken"'s `level.dat` to its first 100 bytes. 3. Before the fix, Select World listed only "Other". 4. With the fix: - "Broken" is listed with the red warning, and selecting it shows "Attempt to Recover", with Edit and Re-Create greyed out. - The recovery screen showed `level.dat`: "NBT at byte 3: truncated input" and `level.dat_old`: "No issues". - Attempt to Restore left `level.dat` (444 bytes, the old copy) next to `level.dat_corrupted_2026-10-30_13-10-42` (the 100-byte broken file). - Continue loaded the world, and `/seed` printed 7. ## Screenshots ![before: a world with a corrupt level.dat (Broken) is missing from the list](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3517-corrupt-leveldat-list-1.png) ![after: it is listed with Failed to load world summary](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3517-corrupt-leveldat-list-2.png) ![after: selecting it opens the recovery screen, which offers level.dat_old](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3517-corrupt-leveldat-list-3.png) - Before: Select World shows only "Other". The world whose `level.dat` is damaged is missing. - After: "Broken" is back in the list, with "Failed to load world summary" in red under its folder name. - After: with "Broken" selected, the primary button reads "Attempt to Recover", and Edit and Re-Create are greyed out. - After: the "Failed to load world" recovery screen shows each file's state: `level.dat` with its red read error and `level.dat_old` with a green "No issues". Below are "Attempt to Restore" and "Back". - After: "Recovery done / Recovery was successful!" with Continue and Back. 🤖 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:12:58 +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#5494
No description provided.