Skip to content

fragment_children: isolate parallel record shards - #8130

Open
coenflict wants to merge 1 commit into
ItsNotRexed:mainfrom
coenflict:fix/fragment-children-record-shards
Open

coenflict wants to merge 1 commit into
ItsNotRexed:mainfrom
coenflict:fix/fragment-children-record-shards

Conversation

@coenflict

Copy link
Copy Markdown

Parallel fragment_children.py --records jobs wrote and deleted predictable paths such as r.jsonl.0. If a file already occupied that path, a successful scan could erase it.

Stage the worker records in a unique temporary directory beside the report. Merge them in range order and let the temporary directory clean up after the workers finish.

Coordination claim in #8047. AI-assisted (Codex).

Verification

Windows 11 Pro Insider Preview, Python 3.14.7. CPU-only with synthetic input.

  • Red on origin/main at dde82f27e: 1 of 21 tests failed because the parallel scan removed the pre-existing file.
  • Green with the fix: all 21 tests passed via python -I tests/test_fragment_children.py, including ordered JSONL records and preservation of the neighboring file.
  • python -m compileall -q make_game.py tools tests, git diff --check, and python -I scripts/check_no_game_data.py tools/fragment_children.py tests/test_fragment_children.py passed.
  • No game files or GPU used.

The repository-wide newline check reports existing failures in tools/leonida_tui.py:753 and tools/wave_diff.py:373, tracked in #7857.

@cryptocxeq cryptocxeq left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Independent CPU regression review of 9cca15f98e2d640c068a9c4d5ad541016948b088, patch applied to main dde82f27e994337094afc476ded0b1426f6e87e2. No blocking findings in the reviewed change.

Worker shards are now confined to one uniquely created temporary directory beside the report; the pool closes before concatenation and cleanup. Range order is retained, and copyfileobj avoids loading each shard into one large string. The no-records path uses nullcontext and passes None to workers. The synthetic two-worker regression proves a pre-existing report.0 file survives; the original implementation removes it.

Native Windows / CPython 3.11.15; synthetic inputs only, no game files or hardware oracle.

  • python -I tests/test_fragment_children.py: exit 0, 21 tests.
  • Same test with only implementation files restored to main: exit 1, failures=1.

git diff --check passed. This is a focused CPU review, not a full-project or GPU validation run.

Claim: #8047 (comment)
AI-assisted (OpenAI Codex).

@AsgerCode

Copy link
Copy Markdown

Tested 9cca15f on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

  • python -I tests/test_fragment_children.py: 21 tests, OK. No other test imports fragment_children.
  • Negative control (merge-base tools/fragment_children.py): 1 failure, test_json_and_records_are_written ("the scan removed an unrelated file").
  • Merge with current main (3c8889e): clean. main has not changed fragment_children.py, its test or skin_streams.py since the base.
  • scripts/check_no_game_data.py on both files: exit 0. git diff --check: clean. tests/test_text_write_line_endings.py fails only on tools/leonida_tui.py:753 and tools/wave_diff.py:373, the same as on main.

By hand, with a synthetic archive built from the test's fragment()/archive() helpers (48 resources in 50 pages, 40 fragments with children, strays, part elements and a broken record):

  • --records r.jsonl --json t.json --jobs N for N = 2, 3, 4, 5, 7, 16, 61: r.jsonl and t.json are byte-identical to --jobs 1, and the output folder holds only those two files afterwards. Same result on the base.
  • One shard fails: a wrapper that makes scan_range raise in the second of 4 ranges, after it writes a partial line, with an unrelated r.jsonl.1 already in place. Exit 1 on both. This PR leaves only the unrelated r.jsonl.1, unchanged, and no .fragment-children-* folder. The base leaves r.jsonl.0, r.jsonl.1 (overwritten) and r.jsonl.2.
  • --records names a read-only file, so the join step fails (PermissionError, exit 1 on both). This PR leaves only the old r.jsonl. The base also leaves r.jsonl.0 to r.jsonl.3.

Overlap with open PRs:

AI-assisted (Claude Code).

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.

3 participants