Repository navigation
Tools: preserve existing saves when an offline import fails - #4872
gabrielsteglich wants to merge 4 commits into
Conversation
|
The staging loop copies each blob in 1 MiB chunks, but import still reads the entire input in I imported a single synthetic ASAV with a 16 MiB payload at For this plain ASAV path, I changed the payload read in The PR save suite ran 67 tests with three skips and zero failures. The PR import tests on the merge base reported 11 failed assertions. To reproduce the allocation measurements on the published head, run this script from the checkout root with import gc, sys, tempfile, tracemalloc, hashlib, json
from pathlib import Path
sys.path.insert(0,str(Path("tests").resolve()))
from test_saves import make_asav, saves, quiet
for mib in (1,4,16):
with tempfile.TemporaryDirectory() as d:
src=Path(d)/"input"
src.mkdir()
p=src/"Player"
p.write_bytes(make_asav(slot="Player",payload=bytes(mib<<20)))
for dry in (True,False):
out=Path(d)/"out"
args=[str(src),"--out",str(out)]+(["--dry-run"] if dry else [])
gc.collect()
tracemalloc.start()
quiet(saves.import_saves,args)
peak=tracemalloc.get_traced_memory()[1]
tracemalloc.stop()
if dry:
assert not out.exists()
else:
e=json.loads((out/"import-manifest.json").read_bytes())["entries"][0]
assert e["sha256"]==hashlib.sha256(p.read_bytes()).hexdigest()
print(mib,dry,peak)AI-assisted. |
Keep the XGameSave container-name warning in the shared import report while preserving staged publication and rollback.
kacper-serewis
left a comment
There was a problem hiding this comment.
Windows Python 3.13 CPU review at 451fc26: all 15 import tests passed. With two synthetic saves, injecting an OSError before each of three os.replace calls restored the previous tree, blob and manifest hashes and left no staging files. Retry published both updated blobs with matching source and manifest hashes. This covers handled publication errors, not power loss. AI-assisted.
Read the fixed ASAV header and seek to a packed companion header after validating the wrapper extent. Report dry-run sizes from open file metadata. Keep full-file size checks for ASAV offsets and the existing streaming publication and rollback.
|
Tested on Windows 11 / Python 3.12.10 at head SHA
AI-assisted review (Gemini 4 Neon). |
|
Tested b33a09d merged with main 3faac55 on Linux (WSL) Python 3.12.16 and native Windows Python 3.13.1: pass on Linux, concern on Windows (pre-existing) Linux: tests/test_saves.py 70 tests OK (1 skipped); all tests/test_docs_*.py pass. |
|
Verified merge with main 3faac55 (clean, sitting on top of d974c88/de6713524): test_saves.py passes 70/70 under python -I (1 skipped, re-run), including nine new import-rollback and header-probe tests; the docs guards pass too. The only text write pins newline with utf-8, and the probe path now reads header bytes instead of whole payloads — backward compatible. If a restore fails, the backup location is reported, matching the docs. CI was pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
|
Tested
|
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested abf5363 merged with main 8575d36 on Linux (WSL2) Python 3.12.16 (-I): pass |
KotikVanil
left a comment
There was a problem hiding this comment.
Tested abf53633 on Windows x64 with a synthetic save tree. I hard-linked a current destination to a second file, then injected an os.replace failure when publishing the manifest after the blobs had been replaced. Rollback restored the same bytes to both names but left them pointing to different files (os.path.samefile became false). The backup is a copy, so publishing it cannot restore that link relationship.
Candidate guard and regression apply the existing saves.py pack policy: refuse already hard-linked destinations before any replacement, even with --force. This preserves the alias and the original contents. With that candidate, all 20 ImportTest tests pass. This edge case matters only where the destination is hard-linked.
AI-assisted (Codex). CPU only, no actual save data.
Claimed in the coordination issue #4816.
What and why
tools/saves.py importpublished blobs one at a time and wrote the manifest in place. A later failure could leave an overwritten save paired with the old manifest. The hash also came from an earlier read of the source.Stage each blob and the manifest before publication and hash the staged bytes. Replace the manifest last, restore earlier destinations if a replacement fails, and retain a recovery backup if restoration fails. Rollback assumes one writer in the destination save directory. The merge from main preserves its invalid-container-name warning.
Addressed the I/O review by reading only the metadata headers needed for ASAV and SLAYER1 and using the open file's size for the dry-run summary. The real import reads the full content in 1 MiB chunks and checks the manifest size and hash against the bytes written. As a dry run, it checks file access and the relevant headers; full body reads happen during import.
Tested
Head
b33a09dbon based974c88a. Windows 11 Pro 26300, Python 3.13.7.4e8bd8f0. Manifest sizes and SHA-256 hashes matched the source and output bytes.packand its one skip also occur onmaind974c88aon this Windows host.AI-assisted (Codex). Synthetic saves only.