BUILD-GAMEDATA-GRAPH-INDEX-AND-ATOMIC: gamedata_graph: index sibling parentPath lookups and write JSON atomically #897

Merged
narekshaghoyandev merged 1 commit from upstream-pr/897 into main 2026-11-24 23:22:43 +00:00
narekshaghoyandev commented 2026-11-24 15:02:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T15:02:25Z.


Improves tools/gamedata_graph.py performance and JSON report safety with identical graph output:

  1. Linear-time sibling lookup in resolve_parent_paths: Lazily indexes siblings by (id(container), tag, attribute) -> {value: [siblings]} instead of scanning every sibling per parentPath element (O(N^2) o O(N)), preserving exact resolved/ambiguous counts and link order.
  2. Atomic JSON report writes (write_json, main): Publishes --json via tempfile.mkstemp + file_mode.published_mode + replace_retry.replace with allow_nan=False, trailing LF, and read-only-safe temp cleanup on failure (preserving existing reports and permissions). Also accepts optional argv=None in main(argv=None).

Verification

  • python3 -I tests/test_gamedata_graph.py -v: 21/21 pass (negative control fails on main).
  • python3 -I scripts/check_no_game_data.py tools/gamedata_graph.py tests/test_gamedata_graph.py: clean.
  • python3 -m compileall -q tools/gamedata_graph.py tests/test_gamedata_graph.py: clean.

Claimed in the coordination issue as: BUILD-GAMEDATA-GRAPH-INDEX-AND-ATOMIC (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135309930)
AI-assisted: yes (Gemini)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474691097 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/897). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T15:02:25Z. --- Improves `tools/gamedata_graph.py` performance and JSON report safety with identical graph output: 1. **Linear-time sibling lookup in `resolve_parent_paths`**: Lazily indexes siblings by `(id(container), tag, attribute) -> {value: [siblings]}` instead of scanning every sibling per `parentPath` element ($O(N^2) o O(N)$), preserving exact resolved/ambiguous counts and link order. 2. **Atomic JSON report writes (`write_json`, `main`)**: Publishes `--json` via `tempfile.mkstemp` + `file_mode.published_mode` + `replace_retry.replace` with `allow_nan=False`, trailing LF, and read-only-safe temp cleanup on failure (preserving existing reports and permissions). Also accepts optional `argv=None` in `main(argv=None)`. ### Verification - `python3 -I tests/test_gamedata_graph.py -v`: 21/21 pass (negative control fails on `main`). - `python3 -I scripts/check_no_game_data.py tools/gamedata_graph.py tests/test_gamedata_graph.py`: clean. - `python3 -m compileall -q tools/gamedata_graph.py tests/test_gamedata_graph.py`: clean. Claimed in the coordination issue as: BUILD-GAMEDATA-GRAPH-INDEX-AND-ATOMIC (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135309930) AI-assisted: yes (Gemini)
KernelSmoker commented 2026-11-24 15:06:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T15:06:16Z.

Review: APPROVED


Reviewed exact head 755283da5980158eac5a6817e2e29340c85bd8d3. The sibling lookup index is keyed by container/tag/attribute and preserves duplicate matches (so ambiguity behavior remains intact); synthetic 2,000/4,000/8,000 sibling chains resolved all expected links with no ambiguity. Atomic JSON output preserves the previous file on replace failure, cleans its temporary file, preserves existing permissions, and writes the trailing LF. Validation on Bazzite/Linux: python3 -I tests/test_gamedata_graph.py -v (19/19 passed), isolated Python compile and git diff --check passed. No game data or GPU used.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041789738 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/897#pullrequestreview-6041789738). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T15:06:16Z. **Review:** APPROVED --- Reviewed exact head `755283da5980158eac5a6817e2e29340c85bd8d3`. The sibling lookup index is keyed by container/tag/attribute and preserves duplicate matches (so ambiguity behavior remains intact); synthetic 2,000/4,000/8,000 sibling chains resolved all expected links with no ambiguity. Atomic JSON output preserves the previous file on replace failure, cleans its temporary file, preserves existing permissions, and writes the trailing LF. Validation on Bazzite/Linux: `python3 -I tests/test_gamedata_graph.py -v` (19/19 passed), isolated Python compile and `git diff --check` passed. No game data or GPU used.
LewisStephens99 commented 2026-11-24 15:13:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by LewisStephens99 on 2026-11-24T15:13:39Z.


Independent verification on Windows 11, Python 3.14:n- python -I tests/test_gamedata_graph.py: 21/21 passed.n- No game data or GPU used. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7135667726 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/897#issuecomment-7135667726). Originally posted by [LewisStephens99](https://github.com/LewisStephens99) on 2026-11-24T15:13:39Z. --- Independent verification on Windows 11, Python 3.14:`n- `python -I tests/test_gamedata_graph.py`: 21/21 passed.`n- No game data or GPU used. AI-assisted.
QemmHD commented 2026-11-24 23:22:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T23:22:41Z.


Merging.

Why merged: BUILD-GAMEDATA-GRAPH-INDEX-AND-ATOMIC: gamedata_graph builds an index of sibling parentPath lookups (O(N) instead of O(N²)), keeping duplicate matches so ambiguity is still detected. It also catches RecursionError and writes --json atomically (mkstemp + replace_retry + published_mode). KernelSmoker approved it, and LewisStephens99 got 21/21 on Windows.

Why it's good: 26 passed. The JSON now uses allow_nan=False, which is harmless because the graph holds only counts.

Tested on Windows 11 / RTX 4070 SUPER: merged alone onto main 0f98d193c. With it in, the repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests, ctest_registration) gives 578 passed / 5 skipped / 0 failed, and check_no_game_data on the changed files is clean. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7147329932 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/897#issuecomment-7147329932). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T23:22:41Z. --- Merging. **Why merged:** BUILD-GAMEDATA-GRAPH-INDEX-AND-ATOMIC: gamedata_graph builds an index of sibling parentPath lookups (O(N) instead of O(N²)), keeping duplicate matches so ambiguity is still detected. It also catches RecursionError and writes --json atomically (mkstemp + replace_retry + published_mode). KernelSmoker approved it, and LewisStephens99 got 21/21 on Windows. **Why it's good:** 26 passed. The JSON now uses allow_nan=False, which is harmless because the graph holds only counts. Tested on Windows 11 / RTX 4070 SUPER: merged alone onto main 0f98d193c. With it in, the repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests, ctest_registration) gives 578 passed / 5 skipped / 0 failed, and check_no_game_data on the changed files is clean. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!897
No description provided.