Skip to content

saves: one explicit JSON nesting limit, not the decoder's RecursionError (test_saves fails on Python 3.14/3.15) - #5240

Open
sovljanskii wants to merge 7 commits into
ItsNotRexed:mainfrom
sovljanskii:saves-json-depth
Open

sovljanskii wants to merge 7 commits into
ItsNotRexed:mainfrom
sovljanskii:saves-json-depth

Conversation

@sovljanskii

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: claim. A new BUILD item.

What failed

tests/test_saves.py fails 7 subtests on main 3faac557 under Python 3.14 and 3.15. It passes on 3.12. The nesting guards from #3565 relied on json raising RecursionError, and how deep the decoder goes depends on the version.

Python deepest array nesting that decodes indenting encoder (json.dump(indent=1))
3.12.16 9,996 994
3.14.10 116,219 about 104,600
3.15.2 130,746 about 104,600

So from 3.14 on, the 100,000-level fixtures are accepted:

  • info, verify and diff exit 0 on the deep JSAV body;
  • extract dies with a RecursionError traceback in json.dump(indent=1);
  • pack reads the deep index.json and reports "index must be an object" instead of the invalid JSON.

On 3.12 too: a body between 994 and 9,996 levels passes info and gives a traceback from extract. extract's ASAV payload path catches only ValueError, so a deep plain-text payload ends in a traceback on any version.

Change

tools/saves.py measures the decoded value without recursion (json_depth) and refuses anything deeper than MAX_JSON_DEPTH = 512, well below the encoder's limit on every version:

  • A JSAV body: the existing JSAV body is not valid UTF-8 JSON error, exit 2, for info, verify, diff and extract. Prior exports are untouched.
  • pack's index.json: the existing invalid JSON error, naming the file.
  • An ASAV payload: the existing "did not parse as JSON" note. payload.bin is kept and payload.json is not written. 3.12's own RecursionError is caught there too.

json_depth takes about 130 ms on a 6.4 MB body.

Tested

macOS, Apple M4, synthetic containers only.

  • tests/test_saves.py: 66 tests OK on Python 3.12.16, 3.14.10 and 3.15.2 (on 3.14 and 3.15, main fails 7).
  • New tests:
    • a body exactly at the limit is read and extracted by all four commands;
    • one level over is refused by all four with one ERROR line and no change to a prior export;
    • ASAV payloads at the limit (written as payload.json), one over it and at 20,000 levels (kept as binary only, no traceback);
    • json_depth on scalars, mixed values and a 100,000-level value.
  • Negative control: without the saves.py change, the 13 new checks fail and the 7 old subtests fail again on 3.15.
  • python -m compileall -q tools tests and git diff --check: clean. The test runs under python -I in CI's standard-library job (it has __main__, no pytest).

AI-assisted.

  • No game data, keys or decryption.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

At 8270d27, extracting a second ASAV into an existing export folder leaves two different revisions of the payload. The command exits 0. The new payload.bin contains the second input. The generated payload.json still contains revision 1 from the first input.

Run this from the repository root with py -3.14 -I probe.py on Windows, CPython 3.14.7:

from pathlib import Path
import runpy, sys, tempfile, subprocess
t=runpy.run_path("tests/test_saves.py")
with tempfile.TemporaryDirectory() as tmp:
    src=Path(tmp)/"input.asav"
    out=Path(tmp)/"export"
    for body in (b'{"revision":1}', b'{"a":'+b'['*512+b'0'+b']'*512+b'}'):
        src.write_bytes(t["make_asav"](kind=2,payload=body))
        r=subprocess.run([sys.executable,"-I","tools/saves.py","extract",str(src),str(out)],capture_output=True,text=True)
        print(r.returncode,(out/"payload.bin").read_bytes()==body,(out/"payload.json").read_text()[:24],r.stdout.splitlines()[0])

Expected: after the binary-only fallback, the folder contains the new payload.bin and no stale generated payload.json. The test for a 513-level payload currently starts with an empty folder. On merge base 3faac55, the second extract accepts that depth and updates both files.

I also measured the new depth check with a wide, shallow array. In a fresh process, run:

import json, sys, tracemalloc
sys.path.insert(0, "tools")
from saves import json_depth
for count in (10000, 100000, 250000):
    value = json.loads("[" + ",".join(["[]"] * count) + "]")
    tracemalloc.start()
    depth = json_depth(value)
    print(count, depth, tracemalloc.get_traced_memory()[1])
    tracemalloc.stop()

Depth stays at 2. Peak additional Python allocation is 725,048 bytes for 10,000 children, 7,073,376 bytes for 100,000, and 17,927,904 bytes for 250,000. The measurement starts after decoding. stack.extend queues one tuple per child. Keeping one child iterator per active level would make the traversal storage depend on depth.

The head suite ran 66 tests with three skips. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 8270d27a6 on Windows 11: pytest tests/test_saves.py -q -> 63 passed, 3 skipped, 90 subtests passed; git diff --check clean.

The saves JSON reader now enforces one explicit nesting limit and reports it as the tool's error, instead of letting the decoder's RecursionError escape (which fails test_saves on Python 3.14/3.15); the added cases cover the limit boundary, the over-limit document and the ordinary save. No blocking issue.

@sovljanskii

Copy link
Copy Markdown
Contributor Author

@shdann both are right, thanks. Fixed in 41abf003.

  • Stale payload.json: when a payload isn't written as JSON, extract now removes the folder's payload.json. That covers a payload that is too deep (new here), one that isn't valid JSON, and one that isn't text, the last two already so on main. Your probe now ends with the new payload.bin and no payload.json. A test runs all three second inputs after a {"revision": 1} extract.

  • Memory: json_depth keeps one child iterator per open level instead of one tuple per child. Your measurement on Python 3.15.2:

    children at depth 2 peak before peak after time before → after
    10,000 725,184 B 120 B 42 → 1 ms
    100,000 7,073,384 B 64 B 165 → 18 ms
    250,000 17,927,912 B 64 B 350 → 50 ms

    A 100,000-level value still measures without recursion (20 ms). A test pins the peak below 64 KiB for 100,000 children.

tests/test_saves.py: 67 OK on Python 3.12.16, 3.14.10 and 3.15.2 (macOS, Apple M4). Without the saves.py change, the 4 new checks fail. AI-assisted.

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently reviewed exact head 41abf003dd7417eabea11840d3da53825c9a4e4e on Windows 11 x64 with CPython 3.14.6. No actionable finding in the changed save-reader/extraction paths.

  • python -I tests/test_saves.py: 68 tests run, 65 passed and 3 skipped.
  • Source review confirms that depth traversal keeps one iterator per active container level and that binary-only ASAV extraction removes a preceding generated payload.json.
  • The actual CLI tests cover the 512-level boundary, rejection one level above it, unchanged prior JSAV exports on rejection, ASAV binary fallback, and repeated extraction after a valid JSON payload.

I reran the two new follow-up methods unchanged against a separate copy of the preceding PR implementation, 8270d27a6e2ee0ad2b3d617affe3277cff162801. They produce four failures: the wide-array allocation bound and stale JSON after each of the three binary-only replacement cases. The same methods pass against this head, with no errors in either run.

For a decoded 100,000-child array at depth 2, a separate tracemalloc measurement around json_depth records 7,074,072 bytes of additional peak allocation on the preceding head and 64 bytes on this head. Decoding is outside that measurement.

The exact-head worktree stays clean, git diff --check passes, and the remote head was rechecked before posting. CPU-only synthetic saves; no game files.

AI-assisted: yes.

@King1565

Copy link
Copy Markdown

Tested 41abf00 on Linux, Python 3.13 (CPU only, no GPU, no game files): pass with notes

Ran

  • python3 -I tests/test_saves.py: PR 68 OK (1 skipped) on 3.11.18, 3.12.3, 3.13.18 and 3.14.6. Main 61 OK on 3.12, 3.13 and 3.14.6.
  • I couldn't get the 7 main failures to show up. On 3.14.6 the decoder still stops at 40,071 levels, so the 100,000-level fixtures still raise RecursionError. Limits I measured (decode / indent=1 encode): 3.11 994/994, 3.12 9,997/995, 3.13 9,998/9,998, 3.14.6 40,071/74,417.
  • Negative control: the PR's saves.py with the three depth checks turned off fails 3 of the new tests on 3.13 (body over the limit, ASAV at 513 levels, stale payload.json).
  • Without the PR, a 20,000-level ASAV payload makes extract crash with a RecursionError traceback on 3.12. With the PR, it prints the note and keeps payload.bin.
  • compileall and git diff --check: clean.

Read
No defect found. json_depth keeps its place in each parent's iterator, so it measures correctly and uses no recursion. Non-blocking notes:

  1. pack doesn't apply the limit to blocks. A 600-level block packs fine (exit 0), but info then refuses the file it wrote ("nests 603 levels deep", exit 2); main's info reads it. Either refuse it in pack or say in the docs that this is expected.
  2. The comment above MAX_JSON_DEPTH says the indenting encoder "stops at 994 levels ... (3.12, 3.14 and 3.15 alike)". That doesn't match the PR's own table (about 104,600 on 3.14) or my numbers above. 512 is still under every limit, so only the wording needs fixing.

AI-assisted (Claude Code).

sovljanskii added a commit to sovljanskii/Leonida that referenced this pull request Nov 23, 2026
King1565's review on ItsNotRexed#5240: a block nested 511 to 600 levels packed with exit 0, and then info refused the file
pack had written ("nests 513 levels deep"). The body puts each block two levels down, so pack now refuses a block
deeper than MAX_JSON_DEPTH - 2 and names it. A block that isn't JSON is still copied verbatim, as before.

The comment above MAX_JSON_DEPTH said the indenting encoder stops at 994 levels on 3.12, 3.14 and 3.15 alike. It
goes tens of thousands of levels from 3.14 on, so the comment now gives the measured figures per release.
docs/saves.md states the limit and the block rule.
@sovljanskii

Copy link
Copy Markdown
Contributor Author

@King1565 thanks, both notes were right. c1466fbc fixes them.

  1. pack and deep blocks: reproduced. A block nested 511 levels packed with exit 0, and info then refused the file (513 levels); 510 still read back. The body puts each block two levels down, so pack now refuses a block nested more than MAX_JSON_DEPTH - 2 and names the file. It exits 2 and leaves an existing output untouched. A block that isn't JSON is still copied verbatim, as on main. docs/saves.md now states the limit and this rule.
  2. The comment above MAX_JSON_DEPTH: it now gives the per-release figures instead of claiming 994 everywhere, including your 40,071 on 3.14.6. That also explains why you didn't see the 7 failures there: 3.14.6's decoder still raises RecursionError on the 100,000-level fixtures, and 3.14.10's doesn't.

Tests: tests/test_saves.py passes 72 OK (1 skipped) on Python 3.12.16, 3.14.10 and 3.15.2 (macOS, Apple M4). The new tests cover a block at the limit, one level over, 100,000 levels, the CLI keeping the old output, and a non-JSON block. With the PR's previous saves.py, 3 of them fail. compileall and git diff --check are clean. AI-assisted.

@King1565

Copy link
Copy Markdown

Re-tested c1466fb on Linux, Python 3.13 (CPU only, no game files): pass

  • python3 -I tests/test_saves.py: 72 OK (1 skipped); compileall and git diff --check clean.
  • My earlier repro, a 600-level block in a pack folder: now exits 2 with "the block nests 601 levels deep; the save body adds 2 levels and this tool reads at most 512", and the existing output file is left untouched. A 510-level block still packs (exit 0) and info reads it back (exit 0).
  • The MAX_JSON_DEPTH comment now matches the measured per-release limits, and the 3.14.6 vs 3.14.10 decoder difference explains why I didn't see the 7 failures on main. Thanks for the quick fix.

AI-assisted (Claude Code).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted independent review. Windows recheck of earlier head 41abf00, CPython 3.13.15 and 3.14.2. JSAV info/verify/diff/extract and index packing accepted depth 512 and rejected 513, preserving prior outputs on failure. ASAV retained the binary at 513 and cleared stale pretty JSON. Both 68-test runs had one skip and two pre-existing symlink-spelling subtest failures. The PR has since moved to c1466fb.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted Windows recheck of c1466fb on CPython 3.13.15 and 3.14.2. The earlier synthetic save round-tripped byte for byte, including three code and two script blocks. Both accepted body depth 512 and rejected 513. An edited block at depth 511 was rejected before output replacement. All 17 focused tests passed on each interpreter. I separately verified that pack also checks index.json itself: depth 513 exited 2, named the 512 limit, and preserved the existing output. The full suite retained the two Windows symlink-spelling subtest failures and one skip.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested c1466fb on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_saves.py -> Ran 72 tests, FAILED (failures=2, skipped=1) - the 2 failures are test_destination_symlinks_update_the_target_and_remain_links, identical on upstream/main (pre-existing Windows symlink-path-spelling quirk)
  • Negative control (tools/saves.py swapped to upstream/main): FAILED (failures=2, errors=18)
  • Verdict: pass aside from the pre-existing platform failures.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Reviewed c1466fb (CPU, Linux, Python 3.13): 1 issues

  • Ran on the RunPod (Linux, CPython 3.13.18), PR head on top of main 3faac55 (no merge needed). python3.13 -I tests/test_saves.py: 72 OK (1 skipped).
  • Negative control: the PR's tests against main's tools/saves.py: 18 errors (the new depth limit, json_depth and the pack check do not exist on main).
  • Issue 1, tools/saves.py:276 (info on a save folder) and :510 (save_slot). Both do json.loads(read(chives.json)) with no depth check and no RecursionError handling. docs/saves.md now says "Every command reads JSON nested at most 512 levels deep". Scenario: a chives.json of 100,000 nested [ next to a valid save. python3.13 -I tools/saves.py info <folder> exits 1 with a RecursionError traceback (run on the pod). On 3.14+ it would be accepted with no limit. Either run it through json_depth and the one-line ERROR path, or narrow the doc sentence to "save bodies, payloads, index.json and blocks".
  • Checked the rest: json_depth is iterative, the 512 / 510 limits match build_jsav, and the stale payload.json removal works for the three cases in the test.
  • No game files.
  • AI-assisted (Claude Code).

sovljanskii added a commit to sovljanskii/Leonida that referenced this pull request Nov 23, 2026
tedin7's review on ItsNotRexed#5240: info on a save folder and import (save_slot) read chives.json with a bare json.loads,
so 100,000 nested arrays gave a RecursionError traceback on 3.13 and were accepted from 3.14 on, while
docs/saves.md says every command reads at most 512 levels.

read_json() decodes a file, turns a decode error or RecursionError into the existing "<path>: invalid JSON (...)"
ValueError, and refuses anything deeper than MAX_JSON_DEPTH. info, save_slot and pack's index.json use it, so all
three report one ERROR line (exit 2), and import writes nothing.
@sovljanskii

Copy link
Copy Markdown
Contributor Author

@tedin7 thanks, right. The doc sentence was true for the save formats but not for chives.json. e1e99ecb fixes the code rather than narrowing the sentence.

Change: read_json() decodes a file and turns a decode error or RecursionError into the existing <path>: invalid JSON (...) error. It also refuses anything deeper than MAX_JSON_DEPTH. info on a save folder (:276), save_slot (:510) and pack's index.json all use it now, so each reports one ERROR: line naming the file (exit 2). import checks every folder before it writes, so it writes nothing. The other json.loads calls read only values that are already bounded: the checked body, blocks inside it, and the checked ASAV payload.

Tests: tests/test_saves.py passes 75 OK (1 skipped) on Python 3.12.16, 3.14.10 and 3.15.2 (macOS, Apple M4). The new ChivesJsonDepthTest covers a chives.json at 512 levels (read), at 513 and at 100,000 levels (one error line from info and save_slot), and import writing nothing. With the previous head's saves.py, 3 of them fail. compileall and git diff --check are clean. AI-assisted.

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Reviewed e1e99ec (code read + CPU tests on Linux, Python 3.14.8): pass.

  • Delta since the checked c1466fb: a new read_json (tools/saves.py:63-73) holds the decode / RecursionError / MAX_JSON_DEPTH check that pack_from_dir had inline. pack's index.json (:356), info on a save folder (:289) and save_slot (:517) all use it now. The remaining json.loads calls (:316, :331, :396, :446) read the already depth-checked body, its blocks, or the ASAV payload that extract handles.
  • python3 -I tests/test_saves.py: 75 tests OK (1 skipped). On this 3.14 the main tool fails 1 and errors 20 against the PR suite.
  • Negative control: the new ChivesJsonDepthTest against tools/saves.py from c1466fb gives 2 failures and 1 error: 513 levels is not refused, 100,000 levels raises a traceback, and import gets past the check. All 3 pass on this head.
  • test_docs_links, test_docs_table_rows and test_text_write_line_endings are OK.

Pre-existing, not from this PR: a chives.json that is valid JSON but not an object (for example []) still gives an AttributeError: 'list' object has no attribute 'get' traceback from info (:290) and import (via save_slot). It does the same on main. A follow-up could have read_json callers check isinstance(meta, dict).

AI-assisted (Claude Code).

@sovljanskii

Copy link
Copy Markdown
Contributor Author

Thanks @cynbun. The non-object chives.json is fixed in 32f46b3c, since read_json is new in this PR and the fix sits in its callers:

  • read_chives (tools/saves.py) reads the file through read_json, then requires an object whose save_directory is a string, null or absent. Otherwise it raises one ValueError that names the file and what it found. info and save_slot (and so import) use it.
  • While checking your [] case I found a second traceback on main: {"save_directory": ["a"]} makes import stop with TypeError: cannot use 'list' as a dict key, because the label is looked up in the --map table. A number goes through info but can never match a --map key, so it is refused too.
  • A missing, null or empty save_directory still falls back to the folder name.
  • ChivesShapeTest runs five non-object bodies and four non-string labels through save_slot, info and import: exit 2, one ERROR: line, no traceback, nothing written. It also covers the fallback. Against e1e99ecb's tools/saves.py, those nine cases give 4 failures and 5 errors.
  • test_saves gives 78 OK (1 skipped) on Python 3.15.2, 3.14.10 and 3.12.16 (macOS, Apple M4). The ten test_docs_* and test_text_write_line_endings pass, and git diff --check is clean.
  • docs/saves.md has one added sentence.

AI-assisted.

tests/test_saves.py failed 7 subtests on main (3faac55) under Python 3.14
and 3.15, and passed on 3.12. The nesting guards from ItsNotRexed#3565 relied on json
raising RecursionError, and how deep the decoder goes depends on the version.
Measured as the deepest array nesting that decodes: 9,996 levels on 3.12.16,
116,219 on 3.14.10 and 130,746 on 3.15.2. So from 3.14 on, the 100,000-level
fixtures were accepted:
- info, verify and diff exited 0 on the deep JSAV body;
- extract died with a RecursionError traceback in json.dump(indent=1);
- pack read the deep index.json and reported "index must be an object"
  instead of naming the invalid JSON.

The indenting encoder that extract writes with stops at 994 levels on every
one of these versions. So on 3.12 too, a body between 994 and 9,996 levels
passed info and gave a traceback from extract. extract's ASAV payload path
only caught ValueError, so a deep plain-text payload ended in a traceback
on any version.

saves.py now measures the decoded value without recursion (json_depth) and
refuses anything deeper than MAX_JSON_DEPTH = 512, well below the encoder's
limit:
- a JSAV body: the same "JSAV body is not valid UTF-8 JSON" error, exit 2,
  for info, verify, diff and extract;
- pack's index.json: the same "invalid JSON" error;
- an ASAV payload: the existing "did not parse as JSON" note. payload.bin is
  kept, payload.json is not written, and 3.12's own RecursionError is caught
  there too.

json_depth takes about 130 ms on a 6.4 MB body.

Tests: a body exactly at the limit is read and extracted, and one level over
is refused by all four read commands with a prior export left alone; ASAV
payloads at the limit, one over it, and at 20,000 levels; json_depth on
scalars, mixed values and a 100,000-level value. tests/test_saves.py: 66
tests OK on Python 3.12.16, 3.14.10 and 3.15.2 (macOS, Apple M4). Without the
saves.py change, the new tests fail and the 7 old subtests fail again on
3.15.
…keeps one iterator per level

Two points from shdann's review of 8270d27:

- Extracting an ASAV into a folder that already held a payload.json kept
  that file next to the new payload.bin whenever the new payload wasn't
  written as JSON: too deep (new in this branch), not valid JSON, or not
  text at all (both already so on main). extract now removes payload.json
  in that case, so the folder never holds two revisions of the payload.
- json_depth queued one tuple per child, so a wide, shallow array cost
  memory in proportion to its width. It now keeps one child iterator per
  open level. Peak allocation on 100,000 empty arrays at depth 2: 7,073,384
  bytes before, 64 after (250,000: 17.9 MB -> 64 bytes). Time: 165 -> 18
  ms. A 100,000-level value still measures without recursion.

tests/test_saves.py: 67 OK on Python 3.12.16, 3.14.10 and 3.15.2 (macOS,
Apple M4). Without the saves.py change, the 4 new checks fail.
King1565's review on ItsNotRexed#5240: a block nested 511 to 600 levels packed with exit 0, and then info refused the file
pack had written ("nests 513 levels deep"). The body puts each block two levels down, so pack now refuses a block
deeper than MAX_JSON_DEPTH - 2 and names it. A block that isn't JSON is still copied verbatim, as before.

The comment above MAX_JSON_DEPTH said the indenting encoder stops at 994 levels on 3.12, 3.14 and 3.15 alike. It
goes tens of thousands of levels from 3.14 on, so the comment now gives the measured figures per release.
docs/saves.md states the limit and the block rule.
tedin7's review on ItsNotRexed#5240: info on a save folder and import (save_slot) read chives.json with a bare json.loads,
so 100,000 nested arrays gave a RecursionError traceback on 3.13 and were accepted from 3.14 on, while
docs/saves.md says every command reads at most 512 levels.

read_json() decodes a file, turns a decode error or RecursionError into the existing "<path>: invalid JSON (...)"
ValueError, and refuses anything deeper than MAX_JSON_DEPTH. info, save_slot and pack's index.json use it, so all
three report one ERROR line (exit 2), and import writes nothing.
cynbun's review of e1e99ec found that a chives.json holding valid JSON
other than an object ([], "story", 5, null) still made info and import
stop with an AttributeError traceback, and that a save_directory array
made import stop with a TypeError, because the label is looked up in the
--map table. Both happen on main as well.

read_chives() reads the file through read_json() and then requires an
object whose save_directory is a string, null or absent, naming the file
and what it found otherwise. info and save_slot (and so import) use it.
A missing, null or empty save_directory still falls back to the folder
name.

ChivesShapeTest covers the five non-object bodies and four non-string
labels through save_slot, info and import (exit 2, one ERROR line, no
traceback, nothing written), plus the fallback. Against the previous
tools/saves.py those nine cases fail or error. test_saves gives 78 OK
(1 skipped) on Python 3.15.2, 3.14.10 and 3.12.16 on macOS (Apple M4).
main's ASSET-262 (c2aff9c) made extract write profile.json for a kind-3
ASAV payload. That is a second file describing payload.bin, so it can go
stale exactly like payload.json did before this branch: extract a profile
record into a folder, then extract another ASAV into the same folder, and
the old profile.json stays next to the new payload.bin.

extract now removes whichever of payload.json and profile.json this run
did not write. The test extracts a profile, then a kind-2 JSON payload or
a kind-3 payload with a bad version, into the same folder. Either way
profile.json is gone. A profile extracted over a JSON payload removes
payload.json. Without the removal, both stale-profile cases fail.

test_saves gives 83 OK (1 skipped) on Python 3.15.2, 3.14.10 and 3.12.16
on macOS (Apple M4), after rebasing onto main 561b65a.
@sovljanskii

Copy link
Copy Markdown
Contributor Author

Rebased onto main 561b65a8 after the merge round, now 54dcf195.

  • Conflict: one, in extract. main's ASSET-262 (c2aff9c4) added the kind-3 profile.json branch where this branch removes a stale payload.json. I kept both.
  • New commit 54dcf195: profile.json is a second file that describes payload.bin, so it can go stale the same way payload.json could. extract now removes whichever of the two this run did not write. The new test runs two cases into one folder: a profile record, then a kind-2 JSON payload; and a profile record, then a kind-3 payload with a bad version. It also extracts a profile over a JSON payload. Without the removal, both stale-profile cases fail.
  • Checks: main's new saves.py code adds no JSON read that skips read_json or the depth limit, and neither file has a duplicated definition.
  • Tests: test_saves gives 83 OK (1 skipped) on Python 3.15.2, 3.14.10 and 3.12.16 (macOS, Apple M4). The ten test_docs_* pass, and git diff --check is clean.

AI-assisted.

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Re-checked 54dcf19 (the rebase of 32f46b3 onto main 561b65a; code read + CPU tests on Linux, Python 3.14.8): confirmed.

  • read_chives (tools/saves.py, from be5a097) is what info and save_slot call now, so import goes through it too.
  • python3 -I tests/test_saves.py: 83 OK (1 skipped). No failures on this host. test_docs_links, test_docs_table_rows, test_text_write_line_endings, compileall and git diff --check are clean.
  • Negative control: ChivesShapeTest against ecbeca8's tools/saves.py (the rebased e1e99ec) gives 4 failures and 5 errors. All of them pass at this head.
  • By hand, on a save folder story/ holding one make_asav(kind=3) payload, I ran info story, import story --out saves --dry-run, and the same with --map a=x:
    • []: exit 2, one ERROR: …/chives.json: chives.json must hold a JSON object, not an array, no traceback. On main it's an AttributeError traceback.
    • {"save_directory": ["a"]}: exit 2, one save_directory must be a string, not an array line. On main, info printed dir ['a'], and import gave the TypeError: cannot use 'list' as a dict key traceback with or without --map.
    • {"save_directory": 5}: exit 2, one line. Main accepted it and labelled the folder 5. That's an intended tightening, and docs/saves.md says so.
    • Nothing was written under saves/ in any of these runs.
    • {"save_directory": "story"}, {}, {"save_directory": null} and an object with an extra key give the same stdout as main, exit 0.
  • saves: a non-object chives.json is one ERROR line, not a traceback #4968 (SebSilent) adds an isinstance(meta, dict) check to info() only. This PR covers all of that, and also covers import and a non-string save_directory. So once this lands, saves: a non-object chives.json is one ERROR line, not a traceback #4968's code change is redundant. The two conflict in tools/saves.py (info). saves: a non-object chives.json is one ERROR line, not a traceback #4968's InfoChivesTest passes on this head for exit code, no traceback and the ERROR: line. It fails only on its exact wording (chives.json must be an object vs must hold a JSON object, not …). If saves: a non-object chives.json is one ERROR line, not a traceback #4968 merges first, this PR needs a rebase that keeps read_chives and adjusts that assertion.

AI-assisted (Claude Code). No game files.

…checks

The two PRs report the same mistake, so they should use the same words for it. This one only adds
the kind that was found ("not an array"). With this change ItsNotRexed#4968's InfoChivesTest passes on this
branch as it stands. Whichever of the two lands second rebases only the code in info(), not a test.

AI-assisted.
@sovljanskii

Copy link
Copy Markdown
Contributor Author

Thanks @cynbun. Pushed 6c93a77e for the #4968 overlap. The error now reads chives.json must be an object, not <kind>, the same words #4968 checks, plus the kind that was found.

I added #4968's InfoChivesTest to this head unchanged, and it passes: 5 tests together with ChivesShapeTest. python3 -I tests/test_saves.py gives 83 OK (1 skipped) on Python 3.15.2, 3.14.10 and 3.12.16 (macOS, M4). compileall and git diff --check are clean.

If #4968 lands first, the rebase keeps read_chives in info(). Its test then stays as it is.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 6c93a77 merged with main 561b65a on Linux (WSL2) Python 3.12.16: pass

tests/test_saves.py: 83 run, 82 passed, 0 failed, 1 skipped. Also tests/test_save_keys.py, tests/test_saves_import_args.py and all 11 tests/test_docs_*.py exit 0.

Negative control: restoring tools/saves.py from upstream/main (keeping the PR's tests) gives 83 run, 8 failures + 25 errors, 1 skipped: the new JsonDepthTest, ChivesJsonDepthTest, ChivesShapeTest and the PackIndexValidationTest depth cases error out (no MAX_JSON_DEPTH / read_chives / json_depth on main). With the PR's tools/saves.py they pass. File restored afterwards.

The doc paragraph in docs/saves.md matches the code (MAX_JSON_DEPTH = 512; pack refuses nesting above 512 - JSAV_BLOCK_NESTING = 510; chives.json must be an object with a string/null/absent save_directory). Python 3.12.16 only; I did not run it on 3.14/3.15, where the decoder's own limit is far higher, so the cross-version table in the PR body is not independently checked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants