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

Open
github-bot wants to merge 1 commit from github-bot/gh-259 into main AGit
Owner

@⁠Skyfrye on GitHub · 2026-11-25 21:57 UTC · original
Skyfrye:nep/suspend-deadline → main · +167 −27 · 2 files · 1 commits · draft

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

**@⁠Skyfrye** on GitHub · 2026-11-25 21:57 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/259) `Skyfrye:nep/suspend-deadline` → `main` · +167 −27 · 2 files · 1 commits · draft **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)
Closing the window runs the title's suspend routines, in which a title
saves its state, and ended the process after a fixed 1 s. That is the
console's limit (Microsoft Learn, GDK reference for
IXtfApplicationClient::DebugEnable: "The app is terminated if it takes too
long to suspend. The limit is 1 second for an exclusive app"), but a
console title presents 30 frames or more in that second, and a title hands
the suspend to the threads that make its frames. At the 2 to 3 frames per
second we reach it gets through 2 or 3 of them: in one logged run
(measured) the title's 2 routines had not returned after 1013 ms.

A title that is still suspending after the console's second, and presented
fewer than 30 frames in it, now gets the time to present 30 at the rate it
showed: 15 s at 2 frames per second, 30 s at most. A title that presented
no frame in that second is ended then, as before, and so is one running at
the console's speed. VICTORY_SUSPEND_MS=<milliseconds> sets a fixed time
instead. The process still always ends.

The log says how it went: "title suspended in N ms" or "title did not
finish suspending, timed out after N ms", and, when the time is stretched,
the frames counted and the time given.

One thread now waits (it runs the routines on another and waits on a
channel) and then ends the process; the two threads racing for it are
gone. That makes the deadline testable without ending the test process.

victory-gpu's count of presented frames (`queue::presented`), which its
watch code reads too, becomes public for it (`pub(crate)` before).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:40:46 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 00:06 UTC · original

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.

**@⁠LooperSalty** on GitHub · 2026-11-26 00:06 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/259#issuecomment-7178411460) 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.
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 10:32 UTC · original

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.

**@⁠KainanP** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/259#issuecomment-7189497185) 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._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/259/head:github-bot/gh-259'
git switch 'github-bot/gh-259'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-259'
git switch 'github-bot/gh-259'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-259'
git switch 'github-bot/gh-259'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-259'
git switch 'main'
git merge --squash 'github-bot/gh-259'
git switch 'main'
git merge --ff-only 'github-bot/gh-259'
git switch 'main'
git merge 'github-bot/gh-259'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.