HLE: constrain the title before suspending it (window close never suspended) #1080

Manually merged
github merged 1 commit from gh-pr/1080/head into gh-pr/1080/base 2026-11-26 04:19:14 +00:00
Owner

@⁠giusepperainone on GitHub · 2026-11-24 15:34 UTC · original
giusepperainone:fix/constrained-before-suspend → main · +100 −14 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC

Closing the title's window never suspended Grand Theft Auto VI: every close logged title did not finish suspending in time; ending the title, one second later, so the title was always killed before its suspend completed (seen in passing in the logs of #417 and #784).

Cause

The title registers two life-cycle routines with the same context:

  • a suspend routine, through RegisterAppStateChangeNotification (HLE'd here);
  • a constrained-change routine, through RegisterAppConstrainedChangeNotification (api-ms-win-core-psm-appnotify-l1-1-1), which we did not HLE, so it bound to the host's version, which never calls it: a desktop app is never constrained.

On the console a title that is suspended is constrained first. The title relies on that: its suspend routine blocks until the title reaches a state that only its constrained routine starts (the constrained routine posts an event that the title's own loop turns into that state). Called alone, the suspend routine never returns.

How I narrowed it down, on a diagnostics build with local logging only:

  • with the deadline raised to 15 s the suspend routine still never returned while the title kept presenting at 30 fps, so it was waiting, not slow;
  • calling the two registered suspend routines in parallel instead of in turn changed nothing (the second one returns at once);
  • the stacks at the deadline showed the suspend routine's thread waiting on a semaphore of the title's state object, and following who signals it led to the routine registered through RegisterAppConstrainedChangeNotification.

Change

  • RegisterAppConstrainedChangeNotification / UnregisterAppConstrainedChangeNotification are HLE'd in lifecycle, with their own registry (same shape as the suspend one; the registration code is shared).
  • end_title runs the constrained-change routines (constrained) and then the suspend routines (quiesced), under the existing one-second deadline.

Results

Windows 11 26200, RTX 4060 Ti, ffe310e + this change, window closed from the account screen:

before after
close logged window closed: suspending the title routines=2 window closed: suspending the title constrained=1 routines=2
outcome title did not finish suspending in time after 1.0 s (also with the deadline at 15 s) title suspended after ~0.1 s

With the suspend completing, the title now reaches the command queue's suspend method (method not implemented object="command queue" slot=0xb8, already noted in queue.rs). It returns E_NOTIMPL and the title still finishes suspending; implementing it is left for a follow-up.

Testing

  • New: constrained_registrations_come_and_go, constrained_routines_run_before_suspend_routines (synthetic routines, no game data).
  • cargo clippy --workspace --all-targets --locked -- -D warnings, the same with --all-features, and cargo test --workspace --locked: all pass. cargo xtask policy: 154 files ok.
  • Not tested: resume (VIctory does not resume titles), relaunch through end_title, and other titles.

🤖 Generated with Claude Code

**@⁠giusepperainone** on GitHub · 2026-11-24 15:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1080) `giusepperainone:fix/constrained-before-suspend` → `main` · +100 −14 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC Closing the title's window never suspended Grand Theft Auto VI: every close logged `title did not finish suspending in time; ending the title`, one second later, so the title was always killed before its suspend completed (seen in passing in the logs of #417 and #784). ## Cause The title registers two life-cycle routines with the same context: - a suspend routine, through `RegisterAppStateChangeNotification` (HLE'd here); - a constrained-change routine, through `RegisterAppConstrainedChangeNotification` (`api-ms-win-core-psm-appnotify-l1-1-1`), which we did not HLE, so it bound to the host's version, which never calls it: a desktop app is never constrained. On the console a title that is suspended is constrained first. The title relies on that: its suspend routine blocks until the title reaches a state that only its constrained routine starts (the constrained routine posts an event that the title's own loop turns into that state). Called alone, the suspend routine never returns. How I narrowed it down, on a diagnostics build with local logging only: - with the deadline raised to 15 s the suspend routine still never returned while the title kept presenting at 30 fps, so it was waiting, not slow; - calling the two registered suspend routines in parallel instead of in turn changed nothing (the second one returns at once); - the stacks at the deadline showed the suspend routine's thread waiting on a semaphore of the title's state object, and following who signals it led to the routine registered through `RegisterAppConstrainedChangeNotification`. ## Change - `RegisterAppConstrainedChangeNotification` / `UnregisterAppConstrainedChangeNotification` are HLE'd in `lifecycle`, with their own registry (same shape as the suspend one; the registration code is shared). - `end_title` runs the constrained-change routines (constrained) and then the suspend routines (quiesced), under the existing one-second deadline. ## Results Windows 11 26200, RTX 4060 Ti, `ffe310e` + this change, window closed from the account screen: | | before | after | |---|---|---| | close logged | `window closed: suspending the title routines=2` | `window closed: suspending the title constrained=1 routines=2` | | outcome | `title did not finish suspending in time` after 1.0 s (also with the deadline at 15 s) | `title suspended` after ~0.1 s | With the suspend completing, the title now reaches the command queue's suspend method (`method not implemented object="command queue" slot=0xb8`, already noted in `queue.rs`). It returns `E_NOTIMPL` and the title still finishes suspending; implementing it is left for a follow-up. ## Testing - New: `constrained_registrations_come_and_go`, `constrained_routines_run_before_suspend_routines` (synthetic routines, no game data). - `cargo clippy --workspace --all-targets --locked -- -D warnings`, the same with `--all-features`, and `cargo test --workspace --locked`: all pass. `cargo xtask policy`: 154 files ok. - Not tested: resume (VIctory does not resume titles), relaunch through `end_title`, and other titles. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Closing the window never suspended Grand Theft Auto VI: its suspend
routine waits for a state that only its constrained-change routine
starts, and RegisterAppConstrainedChangeNotification bound to the host's
version, which never calls it. Every close ended in the one-second
deadline.

Register constrained-change routines here and run them (constrained)
before the suspend routines (quiesced), as the console does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:19:13 +00:00
github manually merged commit a7847a5201 into gh-pr/1080/base 2026-11-26 04:19:14 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:47 UTC · original

We tested the window-close path on Wine/GE 3.2 with a test-only fixture over a7847a5. A child process resolved both notification registrations through the guest HLE resolver with host fallback disabled. It registered the suspend callback first, then the constrained callback, and sent WM_SYSCOMMAND / SC_CLOSE to a hooked Win32 window.

The parent verified that the child exited successfully and that its trace contained exactly two callbacks, in this order: constrained with flag 1, then suspend with the quiesced flag 1. Registering them in the opposite order to delivery checks that the close path enforces the lifecycle order. All seven focused tests passed. On ffe310e, the same fixture stopped before creating the window because the guest resolver lacked RegisterAppConstrainedChangeNotification. This exercises synthetic guest callbacks; the account-screen shutdown timing comes from your native title run.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1080#issuecomment-7136606320) We tested the window-close path on Wine/GE 3.2 with a test-only fixture over `a7847a5`. A child process resolved both notification registrations through the guest HLE resolver with host fallback disabled. It registered the suspend callback first, then the constrained callback, and sent `WM_SYSCOMMAND / SC_CLOSE` to a hooked Win32 window. The parent verified that the child exited successfully and that its trace contained exactly two callbacks, in this order: constrained with flag 1, then suspend with the quiesced flag 1. Registering them in the opposite order to delivery checks that the close path enforces the lifecycle order. All seven focused tests passed. On `ffe310e`, the same fixture stopped before creating the window because the guest resolver lacked `RegisterAppConstrainedChangeNotification`. This exercises synthetic guest callbacks; the account-screen shutdown timing comes from your native title run.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 16:29 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a7847a5: cargo test -p victory-hle passes, 97 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 16:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1080#issuecomment-7137757652) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a7847a5: `cargo test -p victory-hle` passes, 97 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1080
No description provided.