fix: give a slowly running title the time to suspend before it is ended #259

Closed
Skyfrye wants to merge 1 commit from upstream-pr/259 into main
Skyfrye commented 2026-11-25 21:57:45 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-25T21:57:45Z.


Draft: the in-game check on this base is pending (the test machine's GPU is in use for a few hours). Everything else below is done.

Change

Closing the title's window suspends the title first, as the console does before it ends a game: its suspend routines run, and it is ended when they return or after a deadline. The deadline was a fixed 1 s (SUSPEND_DEADLINE in victory-hle/src/modules/lifecycle.rs), which is also the console's figure ("The limit is 1 second for an exclusive app", Microsoft Learn, GDK reference for IXtfApplicationClient::DebugEnable). In wall-clock time that is right; in frames it is not. A title hands the suspend to the threads that make its frames and waits for them. On the console it gets about 30 frames in that second. At the 2 to 4 frames a second we reach today it gets 2 to 4, and the routines do not finish: in one log of the previous base the title is cut off at 1,013 ms (routines=2), and a frame is presented 26 ms later.

Now a title still suspending after the console's second, which presented between 1 and 29 frames in it, gets the time to present 30 at the rate it showed: 15 s at 2 fps, 10 s at 3 fps, 30 s at most. Nothing changes for a title at console speed (1 s), nor for one that presented no frame in that second (it may be stuck, and is ended at 1 s as before).

  • VICTORY_SUSPEND_MS=<milliseconds> sets a fixed time with no stretching (1000 gives the old behaviour).
  • The log says title suspended in N ms or, at WARN, title did not finish suspending, timed out after N ms, and, when stretched, the frames counted and the time granted.
  • The two racing threads (routines, timer) became one waiter, suspend(), which is what the tests drive.
  • victory_gpu::queue::presented() becomes pub so the life-cycle module can count frames.
  • The same wait applies to the XLaunchNewGame relaunch path.

To know: a script that closes the window and waits a fixed time for the process may now need up to 15 s at 2 fps. The 30 fps figure is an assumed console frame rate.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), builds and tests at below-normal priority, RTX 5080, on upstream main at affaf15 (the Neptune base, PR #243), from third_party/victory.

cargo test --locked -p victory-hle   -> main: 110 passed (+1 integration); this branch: 115 passed, 0 failed (+1)
cargo build --locked --release -p victory                              -> Finished, no new warning (the 3 of main)
cargo build --locked --profile diag -p victory --features diagnostics  -> Finished, no new warning
cargo xtask policy                                                     -> asset policy: 197 files ok

With the fixed deadline put back and the new tests kept, 3 of the 5 fail.

One run in about 24 of cargo test -p victory-hle on this branch failed in files::tests::long_title_paths_work_on_the_host (a test of the virtual drive; files.rs is not touched here); 20 runs on main and the other 23 here passed. Not investigated further.

In game: pending. My previous-base runs closed the window with WM_CLOSE, which the engine does not treat as closing the window (it acts on WM_SYSCOMMAND / SC_CLOSE, the title bar's button), so the suspend path was not reached; the next run sends SC_CLOSE after 300 s in the prologue's first interior and reads the new log lines.

Oracle and test data

None involved. Failure cases (5 new tests in lifecycle.rs): routines that return early end the suspend at once; routines still running at the deadline get the longer time; routines that never return are given up on; the stretch table (2, 3, 1, 0, 30 and more frames); parsing of the variable.

Checklist

  • The PR covers a single reviewable behaviour (the time a slowly running title gets to suspend).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Not concerned.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: the count of suspend routines it registers and the time it was cut off at, from my own run logs.
  • Code taken from another project: none.

AI assistance: written with Claude Code. Claude Fable 5.2 wrote the change and its tests; Claude Sonnet 5.5 ported it to the Neptune base and ran the checks there; Claude Opus 5.5 reviewed the port, ran the game on my machine and wrote this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5499870425 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/259). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-25T21:57:45Z. --- **Draft: the in-game check on this base is pending** (the test machine's GPU is in use for a few hours). Everything else below is done. ## Change Closing the title's window suspends the title first, as the console does before it ends a game: its suspend routines run, and it is ended when they return or after a deadline. The deadline was a fixed 1 s (`SUSPEND_DEADLINE` in `victory-hle/src/modules/lifecycle.rs`), which is also the console's figure ("The limit is 1 second for an exclusive app", Microsoft Learn, GDK reference for `IXtfApplicationClient::DebugEnable`). In wall-clock time that is right; in frames it is not. A title hands the suspend to the threads that make its frames and waits for them. On the console it gets about 30 frames in that second. At the 2 to 4 frames a second we reach today it gets 2 to 4, and the routines do not finish: in one log of the previous base the title is cut off at 1,013 ms (`routines=2`), and a frame is presented 26 ms later. Now a title still suspending after the console's second, which presented between 1 and 29 frames in it, gets the time to present 30 at the rate it showed: 15 s at 2 fps, 10 s at 3 fps, 30 s at most. Nothing changes for a title at console speed (1 s), nor for one that presented no frame in that second (it may be stuck, and is ended at 1 s as before). - `VICTORY_SUSPEND_MS=<milliseconds>` sets a fixed time with no stretching (`1000` gives the old behaviour). - The log says `title suspended in N ms` or, at WARN, `title did not finish suspending, timed out after N ms`, and, when stretched, the frames counted and the time granted. - The two racing threads (routines, timer) became one waiter, `suspend()`, which is what the tests drive. - `victory_gpu::queue::presented()` becomes `pub` so the life-cycle module can count frames. - The same wait applies to the `XLaunchNewGame` relaunch path. To know: a script that closes the window and waits a fixed time for the process may now need up to 15 s at 2 fps. The 30 fps figure is an assumed console frame rate. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), builds and tests at below-normal priority, RTX 5080, on upstream `main` at `affaf15` (the Neptune base, PR #243), from `third_party/victory`. ``` cargo test --locked -p victory-hle -> main: 110 passed (+1 integration); this branch: 115 passed, 0 failed (+1) cargo build --locked --release -p victory -> Finished, no new warning (the 3 of main) cargo build --locked --profile diag -p victory --features diagnostics -> Finished, no new warning cargo xtask policy -> asset policy: 197 files ok ``` With the fixed deadline put back and the new tests kept, 3 of the 5 fail. One run in about 24 of `cargo test -p victory-hle` on this branch failed in `files::tests::long_title_paths_work_on_the_host` (a test of the virtual drive; `files.rs` is not touched here); 20 runs on `main` and the other 23 here passed. Not investigated further. In game: pending. My previous-base runs closed the window with `WM_CLOSE`, which the engine does not treat as closing the window (it acts on `WM_SYSCOMMAND` / `SC_CLOSE`, the title bar's button), so the suspend path was not reached; the next run sends `SC_CLOSE` after 300 s in the prologue's first interior and reads the new log lines. ## Oracle and test data None involved. Failure cases (5 new tests in `lifecycle.rs`): routines that return early end the suspend at once; routines still running at the deadline get the longer time; routines that never return are given up on; the stretch table (2, 3, 1, 0, 30 and more frames); parsing of the variable. ## Checklist - [x] The PR covers a single reviewable behaviour (the time a slowly running title gets to suspend). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Not concerned.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: the count of suspend routines it registers and the time it was cut off at, from my own run logs. - [x] Code taken from another project: none. AI assistance: written with Claude Code. Claude Fable 5.2 wrote the change and its tests; Claude Sonnet 5.5 ported it to the Neptune base and ran the checks there; Claude Opus 5.5 reviewed the port, ran the game on my machine and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LooperSalty commented 2026-11-26 00:06:58 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-26T00:06:58Z.


Reviewed: this looks good to merge (tests pass, only the 3 known victory-gpu failures from main). Please mark it ready for review when you are happy with it and we will merge it.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7178411460 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/259#issuecomment-7178411460). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T00:06:58Z. --- Reviewed: this looks good to merge (tests pass, only the 3 known victory-gpu failures from main). Please mark it ready for review when you are happy with it and we will merge it.
KainanP commented 2026-11-26 10:32:15 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T10:32:15Z.


Test report for #259.

Merges cleanly onto current main. Setup: current origin/main (c4c93bd) merged with this PR, Windows 11 on the RTX 4060 Laptop machine. cargo test --locked -p victory-hle (CPU only, so I did not repeat it per adapter). Since the PR makes victory_gpu::queue::presented public, I also ran victory-gpu on the RTX.

main main + #259
victory-hle unit 110 passed 115 passed
no_dll_planting 1 passed 1 passed
victory-gpu --lib, RTX 183 passed, 3 failed 183 passed, same 3 failed (main's)

Flake check: 30 more runs of the victory-hle unit binary on the PR had 0 failures (files::tests::long_title_paths_work_on_the_host included).

Notes from reading the diff:

  • Frames are counted during the suspend. A title whose suspend routine stops its render loop presents 0 frames in that second, so it gets the old 1 s. Only a title that keeps presenting while it suspends gets the stretch. Worth checking against the log line in the game run.
  • With 1 frame in the first second the window close can take 30 s. A WARN at the stretch decision (not only INFO) would make such a wait easy to spot.
  • The tests cover suspend/stretched/asked but not end_title itself (that then() and end() run once). That is hard to unit-test because end() ends the process.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7189497185 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/259#issuecomment-7189497185). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T10:32:15Z. --- Test report for #259. Merges cleanly onto current main. Setup: current `origin/main` (c4c93bd) merged with this PR, Windows 11 on the RTX 4060 Laptop machine. `cargo test --locked -p victory-hle` (CPU only, so I did not repeat it per adapter). Since the PR makes `victory_gpu::queue::presented` public, I also ran victory-gpu on the RTX. | | main | main + #259 | |---|---|---| | `victory-hle` unit | 110 passed | 115 passed | | `no_dll_planting` | 1 passed | 1 passed | | `victory-gpu --lib`, RTX | 183 passed, 3 failed | 183 passed, same 3 failed (main's) | Flake check: 30 more runs of the victory-hle unit binary on the PR had 0 failures (`files::tests::long_title_paths_work_on_the_host` included). Notes from reading the diff: - Frames are counted *during* the suspend. A title whose suspend routine stops its render loop presents 0 frames in that second, so it gets the old 1 s. Only a title that keeps presenting while it suspends gets the stretch. Worth checking against the log line in the game run. - With 1 frame in the first second the window close can take 30 s. A WARN at the stretch decision (not only INFO) would make such a wait easy to spot. - The tests cover `suspend`/`stretched`/`asked` but not `end_title` itself (that `then()` and `end()` run once). That is hard to unit-test because `end()` ends the process. _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
LooperSalty commented 2026-11-27 13:02:52 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T13:02:52Z.


Closing: this draft conflicts with main and has had no activity from its author for more than 24 hours. Please reopen after a rebase on main if it is still wanted.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7218991472 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/259#issuecomment-7218991472). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T13:02:52Z. --- Closing: this draft conflicts with main and has had no activity from its author for more than 24 hours. Please reopen after a rebase on main if it is still wanted.

Pull request closed

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
LooperSalty/AnyXboxX!259
No description provided.