Skip to content

fix: let the animal scan finish when an interrupted save left a temp player file - #104

Merged
XxFran10xX merged 2 commits into
mainfrom
fix/scan-skip-temp-player-files
Oct 31, 2026
Merged

XxFran10xX merged 2 commits into
mainfrom
fix/scan-skip-temp-player-files

Conversation

@XxFran10xX

Copy link
Copy Markdown
Contributor

Problem

A player on Main had an unnamed "Cow" in /animals that took one of their 15 animal places but no longer existed. It was a calf they claimed at 10:39 on 10-28, about 20 seconds before a maintenance stop. It never came back after the restart, and nothing removed or restored it.

Restoring lost animals from their snapshots should have handled this at the next start. But every startup scan on Main since 09-29 has logged (some chunks could not be read, none dropped), so no lost animal has been restored or dropped since then.

The cause is three 10-byte files in TFMC_Map/playerdata, named <uuid>-<number>.dat. Vanilla writes player data to a temp file with that name and then swaps it in. A crash in the middle of that (09-29 twice, 10-21 once) leaves the temp file behind with only a gzip header. The scan read every *.dat, failed on these, and so counted every scan as incomplete. All entity chunks on Main read fine.

Change

  • The scan reads only real player files, named <uuid>.dat. It now skips leftover temp files, .dat_old backups and _corrupted_ copies.
  • When something can't be read, the scan logs what and why (the first 10 entries), for example Animal scan could not read 1 file or chunk: playerdata/<uuid>.dat: Not in GZIP format. Before, it only said "some chunks could not be read".
  • While a scan is incomplete, lost animals still aren't restored or dropped, but /animals now shows them as Missing instead of as if nothing were wrong. The summary line says how many were kept.

The all-or-nothing gate itself is unchanged. Allowing restores around an unreadable chunk could duplicate an animal: last spots are recorded once a minute, and a ridden horse can be far from its last spot when the save happens.

Effect on Main at the next start

Read-only checks against the live files on 10-31:

  • 9 owned animals are in no saved chunk and no player file. All 9 have snapshots, so the next start will restore 9 and drop 0. That includes Dummuy's calf (14f5298e…).
  • No other unreadable files: all 171 entity region files and the 312 real player files read cleanly.

Testing

  • mvn verify: 1316 tests pass. New tests cover temp, corrupted and non-player files being skipped; unreadable files and chunks being named with a reason; the capped log line; and lost animals marked Missing when a scan is incomplete.
  • On TFMCDev01, using this commit on top of the condiments branch Dev runs, with Cooking husbandry briefly turned on in place of BreedingBuddies:
    • I cloned an owned cow in Dev's DB under a new UUID, with its snapshot patched to match: a lost animal with a snapshot and no entity. I added a 10-byte <uuid>-<n>.dat to playerdata.
    • Old jar: (some chunks could not be read, none dropped). The bug reproduces.
    • New jar plus a corrupt real-named player file: kept 1 missing animals because some files could not be read, with the warning naming only that file and Not in GZIP format. /animals HusbandryBot showed ScanFixGhost · Cow · Happy · Missing · last seen TFMC_Map 4005, 302, 4011.
    • New jar with only the temp file: restoring 1 lost animals and Restored lost animal ScanFixGhost (COW) … from its snapshot of 2026-10-28T09:46:58.917Z. /animals no longer shows it as Missing. After save-all, exactly one copy is in entities/r.7.7.mca.
    • Afterwards I put Dev back as it was: jars, husbandry.yml, Cooking DB, playerdata.

Note: Dev-only BreedingBuddies 1.2.0 contains a copy of this scan with the same bug. It isn't in this workspace and isn't on Main.

🤖 Generated with Claude Code

XxFran10xX and others added 2 commits October 31, 2026 12:02
…player file

A crash mid-save leaves a truncated <uuid>-<number>.dat beside the real
player file. The startup scan read every *.dat, failed on those, and so
treated every scan as incomplete: since 09-29 no lost animal on Main was
restored or dropped, and their owners kept losing an animal place.

- Read only <uuid>.dat player files.
- Log which files or chunks could not be read, and why (first 10).
- While a scan is incomplete, show lost animals as Missing in /animals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0fa96bd1-9dd2-4f95-9694-e2b928ea9167
Commits

Reviewing files that changed from the base of the PR and between 523fbfe and a1a7b46.

Files selected for processing: 7
  • src/main/java/net/tfminecraft/cooking/husbandry/HusbandryEntityScan.java
  • src/main/java/net/tfminecraft/cooking/husbandry/HusbandryLocator.java
  • src/test/java/net/tfminecraft/cooking/husbandry/HusbandryEntityScanTest.java
  • src/test/java/net/tfminecraft/cooking/husbandry/HusbandryLocatorTest.java
  • src/test/java/net/tfminecraft/cooking/husbandry/HusbandryMaintenanceRegressionTest.java
  • src/test/java/net/tfminecraft/cooking/husbandry/HusbandryRemainingCoverageTest.java
  • src/test/java/net/tfminecraft/cooking/husbandry/HusbandryRuntimeCoverageTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Animal records are now retained when a world has not been scanned or scan problems prevent a reliable result, reducing the risk of incorrect restoration or removal.
    • Scans now ignore temporary, backup and unrelated player data files, and report unreadable files or chunks with reasons.
    • Scan summaries include details of retained animals and unreadable data, helping explain when results may be incomplete.

The entity scan now returns details for unreadable files and chunks. The locator uses scan completeness and world coverage when it updates animal records. Player scanning now accepts UUID-named .dat files.

Changes: Husbandry scan and reconciliation

Layer / File(s) Summary
Scan diagnostics and player-file filtering
src/main/java/net/tfminecraft/cooking/husbandry/HusbandryEntityScan.java, src/test/java/net/tfminecraft/cooking/husbandry/HusbandryEntityScanTest.java, src/test/java/net/tfminecraft/cooking/husbandry/HusbandryRemainingCoverageTest.java
Result now carries unreadable-file details and derives completeness from that list. The scan records listing, player-file and chunk failures. Player scanning accepts UUID-named .dat files. Tests cover file filtering and diagnostic details.
Locator handling of incomplete scans
src/main/java/net/tfminecraft/cooking/husbandry/HusbandryLocator.java, src/test/java/net/tfminecraft/cooking/husbandry/HusbandryLocatorTest.java, src/test/java/net/tfminecraft/cooking/husbandry/HusbandryRuntimeCoverageTest.java, src/test/java/net/tfminecraft/cooking/husbandry/HusbandryMaintenanceRegressionTest.java
The locator skips animals from worlds that were not scanned. For animals in scanned worlds, it marks records missing when scan results are incomplete and reports unreadable details. Tests cover world checks, logging and retained records.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: ryanbarlow97

Merge Risk: Minimal · up to a1a7b

No merge-blocking issue was identified in the scan and reconciliation changes.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the size:L 100-499 effective changed lines (tests excluded in mixed PRs). label Oct 31, 2026
@coderabbitai

coderabbitai Bot commented Oct 31, 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.

@XxFran10xX
XxFran10xX merged commit 7a86c8a into main Oct 31, 2026
3 checks passed
@XxFran10xX
XxFran10xX deleted the fix/scan-skip-temp-player-files branch October 31, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant