Keep query recording state consistent after allocation failure #79

Closed
github-bot wants to merge 1 commit from gh-pr/79/head into gh-pr/79/base
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:13 UTC · original
ubiquitarianism:old-pr/9806 → main · +105 −1 · 3 files · 1 commits · closed without merging

Carried over from old PR 9806 by WebIdentity1 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9806, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
WebIdentity1: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claim: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115417536

Problem and fix

CommandList::begin_query adds an active query before recording its command. If command-vector allocation throws, the active entry remains without a recorded begin, and a retry is refused. end_query removes the active entry before recording the end; an allocation failure then leaves an unmatched begin and refuses a retry.

Roll back the active entry when begin-command append throws. For EndQuery, append the command before removing the active entry. This keeps the command stream and active state consistent after allocation failure without changing successful recording or timestamp behavior.

The COM BeginQuery and EndQuery methods do not currently catch std::bad_alloc; this patch protects the portable CommandList helper and any caller that can catch and retry. It does not add COM-level recovery.

Tests

  • New CPU-only synthetic fault-injection test fails on current main 2d53a8055 at the first stale-state assertion, then passes with this fix. It covers first command allocation, later growth, failed EndQuery, retries, normal pairs, and repeated timestamps.
  • The focused test passes optimized and with AppleClang 21 ASan + UBSan. Before rebasing, the same test passed with #6077 head b91f90f8ea84d643488de2403182804d387f3543 composed in a disposable copy. #6077 is closed unmerged, so there is no current dependency.
  • Portable runtime CTest on rebased head: 69 passed, 2 expected skips, 0 failed (71 registered tests).
  • Full semantic suite on current main and rebased head: 459 files / 6,046 tests, with exactly the same 49 failure IDs in the same two files (test_exec_computed, test_image_atomics_guard). No translator code changed.
  • Python compileall, make_game.py --help, changed-file no-game-data scan, and git diff --check passed.

Tested on macOS 27.2 arm64 / Apple M5 Ultra. The allocation-failure regression is CPU-only. The full portable CTest run included Vulkan-capable tests on this host; no dedicated real-GPU allocation-failure test or native MSVC Debug test was performed. The allocation filter targets command-vector storage by size to avoid smaller MSVC Debug iterator-proxy allocations.

AI-assisted: yes.

**@⁠Andretuta** on GitHub · 2026-11-24 02:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/79) `ubiquitarianism:old-pr/9806` → `main` · +105 −1 · 3 files · 1 commits · closed without merging > Carried over from **old PR 9806** by `WebIdentity1` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9806`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `WebIdentity1`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claim: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115417536 ## Problem and fix `CommandList::begin_query` adds an active query before recording its command. If command-vector allocation throws, the active entry remains without a recorded begin, and a retry is refused. `end_query` removes the active entry before recording the end; an allocation failure then leaves an unmatched begin and refuses a retry. Roll back the active entry when begin-command append throws. For EndQuery, append the command before removing the active entry. This keeps the command stream and active state consistent after allocation failure without changing successful recording or timestamp behavior. The COM `BeginQuery` and `EndQuery` methods do not currently catch `std::bad_alloc`; this patch protects the portable `CommandList` helper and any caller that can catch and retry. It does not add COM-level recovery. ## Tests - New CPU-only synthetic fault-injection test fails on current main `2d53a8055` at the first stale-state assertion, then passes with this fix. It covers first command allocation, later growth, failed EndQuery, retries, normal pairs, and repeated timestamps. - The focused test passes optimized and with AppleClang 21 ASan + UBSan. Before rebasing, the same test passed with `#6077` head `b91f90f8ea84d643488de2403182804d387f3543` composed in a disposable copy. `#6077` is closed unmerged, so there is no current dependency. - Portable runtime CTest on rebased head: 69 passed, 2 expected skips, 0 failed (71 registered tests). - Full semantic suite on current main and rebased head: 459 files / 6,046 tests, with exactly the same 49 failure IDs in the same two files (`test_exec_computed`, `test_image_atomics_guard`). No translator code changed. - Python compileall, `make_game.py --help`, changed-file no-game-data scan, and `git diff --check` passed. Tested on macOS 27.2 arm64 / Apple M5 Ultra. The allocation-failure regression is CPU-only. The full portable CTest run included Vulkan-capable tests on this host; no dedicated real-GPU allocation-failure test or native MSVC Debug test was performed. The allocation filter targets command-vector storage by size to avoid smaller MSVC Debug iterator-proxy allocations. AI-assisted: yes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:43:28 +00:00
github-bot closed this pull request 2026-11-26 08:43:28 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:17 UTC · original

This carry-over of old upstream PR 9806 has been taken over in #1107, so I'm closing this draft as #17 describes. The branch old-pr/9806 stays.

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

**@⁠aslan2142** on GitHub · 2026-11-24 19:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/79#issuecomment-7141890169) This carry-over of old upstream PR 9806 has been taken over in #1107, so I'm closing this draft as #17 describes. The branch `old-pr/9806` stays. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.