[PR #79] [CLOSED] Keep query recording state consistent after allocation failure #131

Closed
opened 2026-11-26 20:16:53 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/79
Author: @Andretuta
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: old-pr/9806


📝 Commits (1)

  • d1a1e24 Keep query recording state consistent after allocation failure

📊 Changes

3 files changed (+105 additions, -1 deletions)

View changed files

📝 runtime/CMakeLists.txt (+2 -0)
📝 runtime/src/command_list.h (+8 -1)
➕ runtime/test/command_list_query_oom_test.cpp (+95 -0)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/79 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `old-pr/9806` --- ### 📝 Commits (1) - [`d1a1e24`](https://github.com/ubiquitarianism/leonida/commit/d1a1e249f4fafbb9d9d7d8129c1f2438c9ad2608) Keep query recording state consistent after allocation failure ### 📊 Changes **3 files changed** (+105 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+2 -0) 📝 `runtime/src/command_list.h` (+8 -1) ➕ `runtime/test/command_list_query_oom_test.cpp` (+95 -0) </details> ### 📄 Description > 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:16:53 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#131
No description provided.