fix(runtime): handle windowless Windows stop requests #102

Merged
HumanBean merged 3 commits from mooki/Longshot:fix/windows-graceful-stop into main 2026-11-15 20:20:31 +00:00
Member

Type: fix · Risk: medium · Tested on: Windows 11, Intel Arc (plain taskkill runs and the native stop fixture); Linux game-free checks and Windows/Linux cross-builds · Needs: other Windows versions and GPUs, and a Windows console build (T-U5KN)

Why

A windowless Windows game has no game window to receive a polite close request, so a tester had to force it and the co-op relay saw a silent disappearance instead of a leave. This change adds explicit close work for delivered window/console requests, with a four-second budget only when Windows itself is closing the console or session; quitting still does not finish a save. Two alternating runs each on Windows 11 now show plain taskkill leaving main alive and this change exiting with both required stop lines.

How to reproduce

Seen on: Windows 11 Pro 26H2, build 26300.9974; Intel Arc, driver 32.0.101.9150; Core Ultra 9 185H, 64 GB RAM.
Settings and switches: title/menu, empty disposable profiles, windowless offscreen rendering at 1920x1080; RX_VK_PRECOMPILE=0, sound muted and Discord integration off.
Steps: build the named commits, start each with the same windowless settings and a disposable profile, wait for menu state and rising frames, then issue plain taskkill in that same interactive session. Plain taskkill, without /F, ran in the same interactive Windows session as the game, against that game's exact process, and the real game process handle was observed for 60 s.
Expected: both ordered stop lines and observed game exit 0.
Actual: on main, after a plain taskkill, the game was still running at 60.129 s and 60.222 s (60.100 s and 60.108 s at the earlier pair), with both stop lines absent; taskkill itself returned 0 in all four runs, and both main processes needed a separately recorded control quit, which ended each with exit 0.

What changed

A hidden top-level window and console handlers now deliver WM_CLOSE, confirmed WM_ENDSESSION, Ctrl+C, Ctrl+Break and OS-ending events to a windowless Windows game as explicit close work, and the event worker then ends the process with TerminateProcess(GetCurrentProcess(), 0) after the close work and log flush return, never entering ExitProcess/DLL detach. Only console close, logoff, shutdown and confirmed WM_ENDSESSION arm the four-second budget; WM_CLOSE, Ctrl+C and Ctrl+Break have no forced deadline. Helper setup failure is nonfatal, control quit shares the returning close/log tail, and the fixtures and docs follow.

  • host/windows_stop.c: a hidden top-level window receives WM_CLOSE and confirmed WM_ENDSESSION; console handlers accept Ctrl+C, Ctrl+Break and OS-ending events. They request close work once, with no renderer, save, network or log work in the console handler.
  • The event worker calls rx_close_asked() and the returning hos_close_finish(), then TerminateProcess(GetCurrentProcess(), 0) after the close work and log flush return. It never enters ExitProcess/DLL detach. The earlier claim that the watchdog could bound ExitProcess was wrong: that API kills the watchdog before DLL detach. This fixes the route rather than merely weakening the claim.
  • WM_CLOSE, Ctrl+C and Ctrl+Break have no forced deadline. Preparation can wait ten seconds and frame-generation teardown two more, besides cache/driver work with no combined bound. Console close/logoff/shutdown and confirmed WM_ENDSESSION alone arm the four-second budget. Such an event can follow an ordinary close already in progress; it wakes the monitor without repeating the work. Repeats never extend the deadline, and ending-event handlers sleep only for its remaining time.
  • host/display.c: stop-helper setup failure is nonfatal and logs stop: windowless stop route unavailable; use the control bridge, without a stale error number. Partial startup releases an idle worker without closing the game and does not close handles still used by a live thread. Installation remains after renderer startup, because its temporary console can reset console handlers.
  • host/control.c and host/hos_relaunch.c: share a returning close/log tail. Control quit no longer consults a pending menu restart or logs that a window closed. Ordinary window/restart and control exits still use ExitProcess; only the event worker skips DLL detach. The completion line is now stop: close work done (the game's saves are not waited for).
  • Fixtures cover the monitor's lifetime when ExitProcess disables it, slow ordinary closes, a later OS deadline, remaining-time sleeps, cancelled shutdown, safe partial setup and control quit with a restart pending. test_menu_restart.py keeps its flush-before-relaunch-before-exit check through the new shared tail.
  • docs/development.md has a per-route deadline table and names both incomplete exits, 124 and 0xC000013A (STATUS_CONTROL_C_EXIT); docs/control.md states control quit's unchanged process-exit limits. Main's Log levels, occlusion and development-pack sections are retained.

The hidden window is never shown or activated and is not the renderer's surface. A message-only window would not suffice: it cannot be enumerated and does not receive broadcasts. Plain taskkill and a real Ctrl+C event were delivered on Windows 11 at 99f46021. Closing the console window remains unproven; the attempted message and its fallback are recorded below.

Reviewer notes: This addresses the requested changes on 98a6771ad. The real DLL-detach fix was chosen: returning from explicit cleanup and using TerminateProcess(0) avoids the known ExitProcess lifetime gap, rather than claiming an already-dead watchdog can help. No shorter total bound was invented for ordinary close: the known ten-second preparation and two-second frame-generation waits are not the only possible costs.

There is still no save-transaction drain in main. #68 is separate. Its integration must put coop_shutdown() once inside the returning hos_close_finish(), before the marker and flush, so window, control and event routes all reach it; do not leave it only in the window-exit wrapper. Its BYE/LEAVE attempt and bounded thread stop do not guarantee delivery or drain reliable messages. #47 supplies owned-process observation and explicitly reports save draining unsupported.

Windows references: ExitProcess lifetime, https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-exitprocess ; console handler return and timeout contract, https://learn.microsoft.com/en-us/windows/console/handlerroutine ; handler resets and the user32 caveat, https://learn.microsoft.com/en-us/windows/console/setconsolectrlhandler ; message-only windows, https://learn.microsoft.com/en-us/windows/win32/winmsg/window-features#message-only-windows .

The report and promise are https://github.com/NotRexed/Hookshot/pull/2274#issuecomment-6812494715 and https://github.com/NotRexed/Hookshot/pull/2274#issuecomment-6812576925 . The branch-state line under Measurements names the pushed head and its whole-suite result. T-U5KN replaced T-K24T; the remaining requests now concern other Windows versions and GPUs and the actual console-window close case. The Windows delivery evidence is at 99f46021, against main 514591a3, and is not a run of the newer carried head.

The carry kept both existing commits without a conflict. Main changed cursor handling and Toggle resets in host/display.c, and added sampled status/subscription handling in host/control.c; neither changed this PR's stop installation or quit function. Main left host/hos_relaunch.c unchanged. The development and control guides retain both main's additions and the stop documentation. The unchanged stop fixture still checks flush-before-termination and the ordinary window restart chain. No source or fixture adaptation was needed.

Measurements

Verdict: plain taskkill leaves main alive and this change exits with both required stop lines: on Windows 11 / Intel Arc, main cf605c85 was still running at 60.129 s and 60.222 s while this change 769bbea7 exited 0 after 0.588 s and 0.534 s (median 0.561 s), with the request line and the close-work line in order both times; the first pair, main 514591a3 against this change 99f46021, agrees (required stop result 0 of 2 against 2 of 2, median 0.541 s). tests/test_windows_stop.py passed on Windows with its seven PASS lines. Closing the console window remains unproven. This measures the stop fix, not game speed.

Branch state: on main 543846ebb08ded4ce75d364403bc4dcf24e83e85; head 020bb0ed6a5e34ff175dc365f78b6f7dd8309db0; whole game-free suite on this head: 555 passed, 1 failed, 16 skipped (main 543846ebb08ded4ce75d364403bc4dcf24e83e85: 554 passed, 1 failed, 16 skipped). The 1 failing test fails on main the same way: tests/test_walk_key.py. The commits are unchanged by rebases apart from the results table.

main: cf605c85bb (2026-11-14)
this PR: fix/windows-graceful-stop @ 769bbea7e5

Earlier whole-suite results, each at its own commit: Historical reviewed head 98a6771ad283c5cc50f4ed5fdca3ddb826056f3f: 506 passed, 2 failed, 15 skipped; its base 0c74253d4c6ed08d57e4f3aa8ce8634c4c017085: 505 passed, 2 failed, 15 skipped.

Windows stop results, 2026-11-13

Baseline: main @ cf605c85

Hardware: Windows 11 Pro 26H2, build 26300.9974; Intel Arc, driver 32.0.101.9150; Core Ultra 9 185H, 64 GB RAM.
Scene: title/menu, empty disposable profiles, windowless offscreen rendering at 1920x1080; RX_VK_PRECOMPILE=0, sound muted and Discord integration off. No play, save or co-op session was part of this check.
Method: native release builds in main/PR/main/PR order on the same PC and driver. Each run reached menu state with increasing frames before the request. Plain taskkill /PID <game-pid>, without /F, ran in the same interactive Windows session as the game, against that game's exact process. The real game process handle was observed for 60 s. The intervals include starting taskkill and observing exit; they are functional stop evidence, not game-speed measurements. No separate timed warm-up or frame-time comparison is claimed.
How to reproduce: build the named commits, start each with the same windowless settings and a disposable profile, wait for menu state and rising frames, then issue plain taskkill in that same interactive session. Require both ordered stop lines below and observed game exit 0. Record a no-exit result separately before using control quit to clean it up. A successful return from taskkill alone is not success.

The Windows check was repeated on the pushed head on the same PC, Windows 11 with Intel Arc, both builds made natively there: main cf605c85 then this change 769bbea7, twice in turn. After a plain taskkill, main was still running at 60.129 s and 60.222 s; this change exited 0 after 0.588 s and 0.534 s (median 0.561 s), with the request line and the close-work line in order both times. tests/test_windows_stop.py passed on Windows at 769bbea7 with its seven PASS lines.

Before: main @ cf605c85 After: this PR @ 769bbea7
Plain taskkill, run 1 (main then PR) Still alive after 60.129 s; both stop lines absent Game exit 0 after 0.588 s; both stop lines in order
Plain taskkill, run 2 (main then PR) Still alive after 60.222 s; both stop lines absent Game exit 0 after 0.534 s; both stop lines in order
Stop fixture on Windows Not run Seven PASS lines, exit 0

The first pair of runs, at the commits before the carry (main 514591a3, this change 99f46021), with the console checks that were only done then:

The baseline was the available native build of main 514591a3, not the PR's original merge base fbd42024. Those two mains have identical host/display.c, host/control.c, host/hos_relaunch.c and host/hos_main.c stop paths. This does not claim that their renderers or complete trees are identical. The newer carry retains the stop changes, but these measurements stay at their actual tested commits, not 769bbea7.

Before: main @ 514591a3 After: this PR @ 99f46021
Plain taskkill, run 1 (main then PR) Still alive after 60.100 s; both stop lines absent Game exit 0 after 0.569 s; both stop lines in order; no fallback
Plain taskkill, run 2 (main then PR) Still alive after 60.108 s; both stop lines absent Game exit 0 after 0.514 s; both stop lines in order; no fallback
Required stop result 0 of 2 2 of 2
Median request-to-exit interval Not available: neither game exited during the 60 s observation 0.541 s
Ctrl+C, separate console-build check Not run Game exit 0 after 0.446 s; Ctrl+C request then close-work line; no fallback
Native Windows stop fixture Not run on main; fixture absent there Exit 0, all 7 PASS lines below; compiled and executed on Windows
Console-window close attempt Not run Not proved: the posted close message produced no console-close request or exit after 60.011 s

taskkill itself returned 0 in all four runs. Both main processes needed a separately recorded control quit, which ended each with exit 0; that cleanup is not a taskkill pass. Neither PR process needed cleanup or a hard kill. Main's exit latency is unknown, not 60 s and not a fabricated median.

Both PR taskkill logs contain these lines, in this order:

[hos host] stop: requested by WM_CLOSE; wait for close-work marker and process exit 0; no forced deadline unless Windows later ends the session
[hos host] stop: close work done (the game's saves are not waited for)

For the optional console checks, the same PR head was relinked as a Windows console executable with RX_RELEASE=0, using its byte-identical release renderer. The Ctrl+C check attached only to the game's own console, generated the real console-control event and observed the game handle. It was not a keyboard press and was not part of the alternating taskkill comparison. It logged:

[hos host] stop: requested by Ctrl+C; wait for close-work marker and process exit 0; no forced deadline unless Windows later ends the session
[hos host] stop: close work done (the game's saves are not waited for)

The console-close attempt posted WM_CLOSE to the handle from GetConsoleWindow. The call was accepted, but no console-close request line or game exit followed within the observation. A separate control quit then ended it with exit 0; that close-work line belongs to cleanup. An actual console-window UI close remains unproven. Windows can return a non-displayed console handle, so an accepted message is not proof of that UI operation: https://learn.microsoft.com/en-us/windows/console/getconsolewindow . No terminal implementation is assumed here.

Historical Linux source checks

main: 1ef93e796b (2026-11-13)
this PR: move/fix/windows-graceful-stop-r3 @ 06cc450b929b1a7be76be6235df3d6ce99befc90

Hardware: Linux, GCC and Clang; no GPU used. These are the earlier source checks, not the Windows game runs above.
Scene: authored game-free callbacks and close-chain fixtures; no game or save.
Method: production functions compiled against Win32 stand-ins, including a stand-in ExitProcess that first disables the watchdog and then represents a stuck DLL detach. Simulated clocks exercise a twelve-second ordinary close and a later four-second OS budget; these are policy checks, not measured Windows shutdown times.
How to reproduce: python -I -B tests/test_windows_stop.py --cc gcc, then --cc clang; python -I -B tests/test_windows_display_startup.py, python -I -B tests/test_menu_restart.py, and python -I -B tests/test_control.py.

Before: main @ 1ef93e796 After: this PR @ 06cc450b9
New windowless event-route implementation Not present Source and game-free fixtures present
Reviewed event and close-chain behavior Not executed against main GCC and Clang pass

Regression comparisons are against the reviewed source where possible, or one explicit minimal reversion, not relabelled whole-build comparisons:

Review concern Negative used Observed rejection
ExitProcess kills the watchdog before detach Replace the worker's final TerminateProcess with ExitProcess Dead-watchdog/detach assertion fails
Ordinary close was killed at four seconds Restore deadline arming for every event Ordinary-event no-deadline assertion fails
Repeated ending event slept a fresh four seconds Restore the full-duration console sleep Remaining-time assertion fails
Helper failure killed the game Reviewed 98a6771ad host/display.c Nonfatal-startup and fallback-message checks fail
Control quit restarted/logged a window close Reviewed 98a6771ad host/control.c Pending-restart/no-window-log assertion fails
Completion marker used the old save jargon Restore the old marker in the returning tail Expected completion-marker-before-flush check fails

The same seven lines were also printed by tests/test_windows_stop.py at 99f46021 on native Windows, with llvm-mingw Clang, exit 0 and empty stderr. Its two executables ran there, but their Win32 calls and clocks are stand-ins. The game runs above, not this fixture, prove real delivery.

PASS: console handlers only request; OS-ending events share the remaining deadline, ordinary events have none
PASS: WM_CLOSE has no forced deadline; only confirmed end-session arms it, without repeating close work
PASS: slow ordinary closes finish; completed event close terminates after flush, never entering DLL detach
PASS: OS deadline bounds a stuck worker and queued-message flood; later OS event wakes an unbounded close
PASS: setup failures release idle resources safely or retain live handles, without closing the game
PASS: control quit flushes the shared tail, ignores pending restart and does not claim a window closed
PASS: window close still flushes before its optional relaunch and ExitProcess

The earlier f41db065c and 830b2c59 suites reported 509 passed, 0 failed, 19 skipped and 510 passed, 0 failed, 19 skipped respectively. They remain historical and are not carried as validation of these changed shutdown semantics.

Screenshots

Nothing on screen. The Windows logs confirm offscreen rendering. No screenshot is offered as proof that the added stop window never appears; the console-window close case remains unproven.

Flags and settings

No new setting is added; this PR changes what HOS_HEADLESS (the Windows stop handlers) and HOS_CONTROL (control quit's close tail) do.

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
HOS_HEADLESS Existing switch Existing Off; handlers active only when headless Existing offscreen mode gains the Windows stop handlers after renderer startup Helps: Plain taskkill and Ctrl+C on the Windows 11 / Intel Arc runs below. Doesn't help: Saving, forced kills, startup before renderer initialization; console events without a console. Untested: Other Windows versions and GPUs; actual console-window close and OS-ending events. Off by default: ordinary play needs its game window
HOS_CONTROL Existing switch Existing Unset Existing opt-in bridge quit now shares the normal-close tail Helps: Linux game-free bridge checks and the separately recorded Windows cleanup quits below. Doesn't help: Acknowledging completed saves or forcing a hung close. Untested: Integrated co-op; other Windows versions and GPUs. Off by default: enable deliberately for test sessions

No new setting is added. The four-second deadline applies only to OS-ending events, not plain WM_CLOSE, Ctrl+C, Ctrl+Break or control quit.

Testing

Tested: Windows 11 / Intel Arc at 99f46021: both plain-taskkill runs, the generated Ctrl+C event and all seven native Windows fixture checks pass as recorded above. On the carried head, all 12 focused compiled drivers pass with GCC 16.2.1 and Clang 23.1.3, plus the Python-only player-input check: 25 invocations, 0 failures. This includes the stop, display-startup, menu-restart and control drivers, as well as main's display, cursor, input, startup and sampled-control readers. No fixture or assertion was changed for the carry. The whole-suite result belongs to 769bbea7 in the branch-state line, not these focused totals.

The earlier six negative comparisons above were rejected at their original reviewed head; they were not repeated for this carry. The lifetime regression models the watchdog being gone before DLL detach rather than treating all exits as equivalent.

Historical checks, not relabelled as this head: the complete suite at 830b2c5908afa820b8a309b93c44e92a2f470a7d reports 510 passed, 0 failed, 19 skipped. At that head, the four changed host files compiled to Windows x86-64 objects with -Wall -Wextra -Werror, and the new fixtures compiled and linked without execution. The initial cross-check setup failures (link flags on compile-only commands and missing generated public runtime declarations) were corrected without suppressing a warning.

At 830b2c5908afa820b8a309b93c44e92a2f470a7d, the Vulkan renderer DLL was also cross-compiled and linked for Windows x86-64 on Linux with llvm-mingw 20261104 (Clang 23.1.5), and all 44 host translation units selected by the release build were covered by successful Windows object compilations: 6 newly compiled and 38 reused from matching, hash-verified Windows object-cache entries. host/windows_stop.c was newly compiled. At that historical head the game executable was not linked and no Windows or Wine execution was performed. That cross-build was not a hosted Windows-builder run or a Windows UTF-8-path runtime test. That production build retained the project's warning-suppression flags; it is separate from the strict four-file fixture checks and does not establish warning-clean production code. Those older binaries do not validate the reviewed stop implementation. The later builds and native Windows execution at 99f46021 are recorded separately below.

Built for Windows and Linux at the current head, not run: At 020bb0ed6a5e34ff175dc365f78b6f7dd8309db0, the Windows x86-64 Vulkan renderer DLL and all 51 selected host translation units were cross-built on Linux with llvm-mingw 20261104 (Clang 23.1.5), using the project's production flags and pinned dependencies (renderer: 1 newly compiled / 204 reused; host: 5 newly compiled / 46 reused; lifted C: 0 newly compiled / 80 reused; all Windows units: 6 newly compiled / 644 reused from matching object-cache entries), the renderer DLL linked and the full game executable linked; nothing was run on Windows or under Wine, and this is neither the project's hosted builder run nor a Windows UTF-8 run-time path test.

The exact same head 020bb0ed6a5e34ff175dc365f78b6f7dd8309db0 also compiled and linked its full native Linux executable and renderer with Clang 23.1.3 through the documented resume path (323 newly compiled units, 169 matching Linux-cache units, source stamp 8a5c6ee8), using the verified target-neutral C from lift 5c175a4727d82f85e425e85400dca17fea0750fb rather than carrying the patch onto another commit; neither Linux binary was run.

Built for Windows and Linux at the previous head: At 769bbea7e5220141138a4648c237fdbfb603c636, the Windows x86-64 Vulkan renderer DLL and all 48 selected host translation units were cross-built on Linux with llvm-mingw 20261104 (Clang 23.1.5), using the project's production flags and pinned dependencies (renderer: 35 newly compiled / 170 reused; host: 7 newly compiled / 41 reused; lifted C: 0 newly compiled / 80 reused; all Windows units: 42 newly compiled / 605 reused from matching object-cache entries), the renderer DLL linked and the full game executable linked; nothing was run on Windows or under Wine, and this is neither the project's hosted builder run nor a Windows UTF-8 run-time path test. The same head also compiled and linked its full native Linux executable and renderer with Clang 23.1.3 through the documented resume path (40 newly compiled units, 449 matching Linux-cache units, source stamp 335aaaed), using the verified target-neutral C from lift 76699aad3a6bdc4f75520c0f2c9d9c80d5731a5f rather than carrying the patch onto another commit; neither Linux binary was run. The same head was also built natively on Windows 11 (both Windows products linked) for the repeated runs.

Historical builds at 99f46021, followed by native Windows execution: At 99f46021d41e3b20e6e6e97113d54e5000289514, the Windows x86-64 Vulkan renderer DLL and all 45 selected host translation units were cross-built on Linux with llvm-mingw 20261104 (Clang 23.1.5), using the project's production flags and pinned dependencies (renderer: 1 newly compiled / 204 reused; host: 5 newly compiled / 40 reused; lifted C: 0 newly compiled / 80 reused; all Windows units: 6 newly compiled / 638 reused from matching object-cache entries), the renderer DLL linked and the full game executable linked; that Linux cross-build did not execute the Windows products and is neither a hosted builder run nor a Windows UTF-8 run-time path test. The same head also compiled and linked its full native Linux executable and renderer with Clang 23.1.3 through the documented resume path (204 newly compiled units, 282 matching Linux-cache units, source stamp cddfa164), using the verified target-neutral C from the fresh fbd420241a lift rather than carrying the patch onto another commit; neither Linux binary was run. A separate native Windows build of the same head then compiled and linked successfully: 639 newly compiled units, 0 reused, 0 failed. Its stop fixture and game runs are the Windows results above. No Wine run or UTF-8 runtime-path test is claimed. Those are the earlier head's builds; the current head's builds are named above.

Not tested: an actual console-window UI close, Ctrl+Break, logoff/shutdown, a deliberately stuck driver and the real four-second OS deadline. The failed console-message attempt remains recorded above. Completed saves, general GPU/driver teardown, co-op leave receipt, hosted-relay/session shutdown, other Windows versions and other GPUs remain unproven. The Linux game and Windows UTF-8 runtime paths were not exercised. No performance, completed-save, cache-write-success or guaranteed-delivery claim is made. The runs at the earlier head and the repeat at the pushed head are both given above, each at its own commits.

Must be tested:

  • Other Windows versions and GPUs: repeat plain taskkill without /F and the stop fixture, expecting game exit 0 with both stop lines and seven PASS lines (T-U5KN; by hand).
  • A Windows console build: close the actual console window and observe delivery and exit, expecting a completed close. A completed close needs the request line, close-work line and exit 0; 124 or 0xC000013A means incomplete close (T-U5KN; by hand).

Risks

What could break: The earlier four-second limit on every request has been removed. Ordinary WM_CLOSE/Ctrl+C/Ctrl+Break can now wait indefinitely for a stuck driver; a caller's observation timeout is not a clean-exit receipt or automatic permission to force it. This preserves slow valid close work. Only OS-ending events start the shorter budget, and Windows can impose an earlier limit.

Only the event worker skips DLL detach, with TerminateProcess(0) after explicit close hooks and log flush. It therefore does not run teardown that exists only in DLL detach. Normal window/restart and control routes still use ExitProcess and can still hang in detach; this change makes no bound claim for them.

An OS-deadline expiry can interrupt cache writes. Code 124 and 0xC000013A are both incomplete outcomes. Require the new close-work marker together with observed exit 0; even that does not prove a completed save or successful cache writes. The monitor avoids logger locks, so forced termination can leave no final timeout line.

Failure to install the helper leaves the game running with control quit available. The hidden window and waiting threads exist only for started headless Windows games.

Turning it off: Reverting the PR removes the additional event route; control quit remains available.

Compatibility:

  • Saves: unchanged. Quitting still does not finish a save: the completion line is stop: close work done (the game's saves are not waited for), and there is still no save-transaction drain in main.
  • longshot_options.ini: unchanged; no new setting is added.
  • Caches: an OS-deadline expiry can interrupt cache writes (see What could break); the diff changes no cache code.
  • The vk ABI: unchanged; the diff touches no file under gpu/vk/, so MKWVK_API_VERSION stays as it is.
  • The builder's tools: the text says nothing; the diff touches none (it changes host/, docs/ and tests/ only).
  • Scripts that stop a headless game: a completed close needs the new close-work marker together with exit 0; 124 and 0xC000013A are both incomplete outcomes (docs/development.md names both).

Issues

See #83

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. Windows 11 / Intel Arc, main 514591a3 then this PR 99f46021, twice: main stayed alive through each 60 s observation; this PR exited with both stop lines in 0.569 and 0.514 s, median 0.541 s. The same was repeated at main cf605c85 and this PR 769bbea7: 0.588 and 0.534 s, median 0.561 s. This measures the stop fix, not game speed.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A game-free test added for the fix, failing on main and passing here. The original installation regression remains; review fixes also reject the reviewed sources or the explicit minimal reversions listed above.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. Built and linked for both at 020bb0ed6a5e34ff175dc365f78b6f7dd8309db0 (under Testing); nothing was run on Windows at this head, so UTF-8 path behavior at run time is not claimed.
  • Docs updated.

New on this forge; not opened on GitHub.

Assisted-by: GPT-6 Astra
Co-Authored-By: GPT-6 Astra [email protected]

**Type:** fix · **Risk:** medium · **Tested on:** Windows 11, Intel Arc (plain taskkill runs and the native stop fixture); Linux game-free checks and Windows/Linux cross-builds · **Needs:** other Windows versions and GPUs, and a Windows console build (T-U5KN) ## Why A windowless Windows game has no game window to receive a polite close request, so a tester had to force it and the co-op relay saw a silent disappearance instead of a leave. This change adds explicit close work for delivered window/console requests, with a four-second budget only when Windows itself is closing the console or session; quitting still does not finish a save. Two alternating runs each on Windows 11 now show plain `taskkill` leaving main alive and this change exiting with both required stop lines. ## How to reproduce **Seen on:** Windows 11 Pro 26H2, build 26300.9974; Intel Arc, driver 32.0.101.9150; Core Ultra 9 185H, 64 GB RAM. **Settings and switches:** title/menu, empty disposable profiles, windowless offscreen rendering at 1920x1080; `RX_VK_PRECOMPILE=0`, sound muted and Discord integration off. **Steps:** build the named commits, start each with the same windowless settings and a disposable profile, wait for menu state and rising frames, then issue plain `taskkill` in that same interactive session. Plain `taskkill`, without `/F`, ran in the same interactive Windows session as the game, against that game's exact process, and the real game process handle was observed for 60 s. **Expected:** both ordered stop lines and observed game exit 0. **Actual:** on main, after a plain `taskkill`, the game was still running at 60.129 s and 60.222 s (60.100 s and 60.108 s at the earlier pair), with both stop lines absent; `taskkill` itself returned 0 in all four runs, and both main processes needed a separately recorded control `quit`, which ended each with exit 0. ## What changed A hidden top-level window and console handlers now deliver `WM_CLOSE`, confirmed `WM_ENDSESSION`, Ctrl+C, Ctrl+Break and OS-ending events to a windowless Windows game as explicit close work, and the event worker then ends the process with `TerminateProcess(GetCurrentProcess(), 0)` after the close work and log flush return, never entering `ExitProcess`/DLL detach. Only console close, logoff, shutdown and confirmed `WM_ENDSESSION` arm the four-second budget; `WM_CLOSE`, Ctrl+C and Ctrl+Break have no forced deadline. Helper setup failure is nonfatal, control quit shares the returning close/log tail, and the fixtures and docs follow. - `host/windows_stop.c`: a hidden top-level window receives `WM_CLOSE` and confirmed `WM_ENDSESSION`; console handlers accept Ctrl+C, Ctrl+Break and OS-ending events. They request close work once, with no renderer, save, network or log work in the console handler. - The event worker calls `rx_close_asked()` and the returning `hos_close_finish()`, then **`TerminateProcess(GetCurrentProcess(), 0)` after the close work and log flush return**. It never enters `ExitProcess`/DLL detach. The earlier claim that the watchdog could bound `ExitProcess` was wrong: that API kills the watchdog before DLL detach. This fixes the route rather than merely weakening the claim. - **`WM_CLOSE`, Ctrl+C and Ctrl+Break have no forced deadline.** Preparation can wait ten seconds and frame-generation teardown two more, besides cache/driver work with no combined bound. Console close/logoff/shutdown and confirmed `WM_ENDSESSION` alone arm the four-second budget. Such an event can follow an ordinary close already in progress; it wakes the monitor without repeating the work. Repeats never extend the deadline, and ending-event handlers sleep only for its remaining time. - `host/display.c`: stop-helper setup failure is nonfatal and logs `stop: windowless stop route unavailable; use the control bridge`, without a stale error number. Partial startup releases an idle worker without closing the game and does not close handles still used by a live thread. Installation remains after renderer startup, because its temporary console can reset console handlers. - `host/control.c` and `host/hos_relaunch.c`: share a returning close/log tail. Control quit no longer consults a pending menu restart or logs that a window closed. Ordinary window/restart and control exits still use `ExitProcess`; only the event worker skips DLL detach. The completion line is now `stop: close work done (the game's saves are not waited for)`. - Fixtures cover the monitor's lifetime when `ExitProcess` disables it, slow ordinary closes, a later OS deadline, remaining-time sleeps, cancelled shutdown, safe partial setup and control quit with a restart pending. `test_menu_restart.py` keeps its flush-before-relaunch-before-exit check through the new shared tail. - `docs/development.md` has a per-route deadline table and names both incomplete exits, 124 and `0xC000013A` (`STATUS_CONTROL_C_EXIT`); `docs/control.md` states control quit's unchanged process-exit limits. Main's Log levels, occlusion and development-pack sections are retained. The hidden window is never shown or activated and is not the renderer's surface. A message-only window would not suffice: it cannot be enumerated and does not receive broadcasts. Plain `taskkill` and a real Ctrl+C event were delivered on Windows 11 at `99f46021`. Closing the console window remains unproven; the attempted message and its fallback are recorded below. **Reviewer notes:** This addresses the requested changes on 98a6771ad. The real DLL-detach fix was chosen: returning from explicit cleanup and using TerminateProcess(0) avoids the known ExitProcess lifetime gap, rather than claiming an already-dead watchdog can help. No shorter total bound was invented for ordinary close: the known ten-second preparation and two-second frame-generation waits are not the only possible costs. There is still no save-transaction drain in main. https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/68 is separate. Its integration must put `coop_shutdown()` once inside the returning `hos_close_finish()`, before the marker and flush, so window, control and event routes all reach it; do not leave it only in the window-exit wrapper. Its BYE/LEAVE attempt and bounded thread stop do not guarantee delivery or drain reliable messages. https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/47 supplies owned-process observation and explicitly reports save draining unsupported. Windows references: ExitProcess lifetime, https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-exitprocess ; console handler return and timeout contract, https://learn.microsoft.com/en-us/windows/console/handlerroutine ; handler resets and the user32 caveat, https://learn.microsoft.com/en-us/windows/console/setconsolectrlhandler ; message-only windows, https://learn.microsoft.com/en-us/windows/win32/winmsg/window-features#message-only-windows . The report and promise are https://github.com/NotRexed/Hookshot/pull/2274#issuecomment-6812494715 and https://github.com/NotRexed/Hookshot/pull/2274#issuecomment-6812576925 . The branch-state line under Measurements names the pushed head and its whole-suite result. T-U5KN replaced T-K24T; the remaining requests now concern other Windows versions and GPUs and the actual console-window close case. The Windows delivery evidence is at `99f46021`, against main `514591a3`, and is not a run of the newer carried head. The carry kept both existing commits without a conflict. Main changed cursor handling and Toggle resets in `host/display.c`, and added sampled status/subscription handling in `host/control.c`; neither changed this PR's stop installation or quit function. Main left `host/hos_relaunch.c` unchanged. The development and control guides retain both main's additions and the stop documentation. The unchanged stop fixture still checks flush-before-termination and the ordinary window restart chain. No source or fixture adaptation was needed. ## Measurements **Verdict:** plain `taskkill` leaves main alive and this change exits with both required stop lines: on Windows 11 / Intel Arc, main `cf605c85` was still running at 60.129 s and 60.222 s while this change `769bbea7` exited 0 after 0.588 s and 0.534 s (median 0.561 s), with the request line and the close-work line in order both times; the first pair, main `514591a3` against this change `99f46021`, agrees (required stop result 0 of 2 against 2 of 2, median 0.541 s). `tests/test_windows_stop.py` passed on Windows with its seven PASS lines. Closing the console window remains unproven. This measures the stop fix, not game speed. <!-- branch-state --> Branch state: on main `543846ebb08ded4ce75d364403bc4dcf24e83e85`; head `020bb0ed6a5e34ff175dc365f78b6f7dd8309db0`; whole game-free suite on this head: `555 passed, 1 failed, 16 skipped` (main `543846ebb08ded4ce75d364403bc4dcf24e83e85`: `554 passed, 1 failed, 16 skipped`). The 1 failing test fails on main the same way: `tests/test_walk_key.py`. The commits are unchanged by rebases apart from the results table. <!-- /branch-state --> main: cf605c85bbaeaaa78176b933b3bc1a3366e13a78 (2026-11-14) this PR: fix/windows-graceful-stop @ 769bbea7e5220141138a4648c237fdbfb603c636 Earlier whole-suite results, each at its own commit: Historical reviewed head `98a6771ad283c5cc50f4ed5fdca3ddb826056f3f`: 506 passed, 2 failed, 15 skipped; its base `0c74253d4c6ed08d57e4f3aa8ce8634c4c017085`: 505 passed, 2 failed, 15 skipped. **Windows stop results, 2026-11-13** Baseline: main @ cf605c85 Hardware: Windows 11 Pro 26H2, build 26300.9974; Intel Arc, driver 32.0.101.9150; Core Ultra 9 185H, 64 GB RAM. Scene: title/menu, empty disposable profiles, windowless offscreen rendering at 1920x1080; `RX_VK_PRECOMPILE=0`, sound muted and Discord integration off. No play, save or co-op session was part of this check. Method: native release builds in main/PR/main/PR order on the same PC and driver. Each run reached menu state with increasing frames before the request. Plain `taskkill /PID <game-pid>`, without `/F`, ran in the same interactive Windows session as the game, against that game's exact process. The real game process handle was observed for 60 s. The intervals include starting `taskkill` and observing exit; they are functional stop evidence, not game-speed measurements. No separate timed warm-up or frame-time comparison is claimed. How to reproduce: build the named commits, start each with the same windowless settings and a disposable profile, wait for menu state and rising frames, then issue plain `taskkill` in that same interactive session. Require both ordered stop lines below and observed game exit 0. Record a no-exit result separately before using control `quit` to clean it up. A successful return from `taskkill` alone is not success. The Windows check was repeated on the pushed head on the same PC, Windows 11 with Intel Arc, both builds made natively there: main `cf605c85` then this change `769bbea7`, twice in turn. After a plain `taskkill`, main was still running at 60.129 s and 60.222 s; this change exited 0 after 0.588 s and 0.534 s (median 0.561 s), with the request line and the close-work line in order both times. `tests/test_windows_stop.py` passed on Windows at `769bbea7` with its seven PASS lines. | | Before: main @ cf605c85 | After: this PR @ 769bbea7 | |---|---|---| | Plain taskkill, run 1 (main then PR) | Still alive after 60.129 s; both stop lines absent | Game exit 0 after 0.588 s; both stop lines in order | | Plain taskkill, run 2 (main then PR) | Still alive after 60.222 s; both stop lines absent | Game exit 0 after 0.534 s; both stop lines in order | | Stop fixture on Windows | Not run | Seven PASS lines, exit 0 | **The first pair of runs, at the commits before the carry** (main `514591a3`, this change `99f46021`), with the console checks that were only done then: The baseline was the available native build of main `514591a3`, not the PR's original merge base `fbd42024`. Those two mains have identical `host/display.c`, `host/control.c`, `host/hos_relaunch.c` and `host/hos_main.c` stop paths. This does not claim that their renderers or complete trees are identical. The newer carry retains the stop changes, but these measurements stay at their actual tested commits, not `769bbea7`. | | Before: main @ 514591a3 | After: this PR @ 99f46021 | |---|---|---| | Plain taskkill, run 1 (main then PR) | Still alive after 60.100 s; both stop lines absent | Game exit 0 after 0.569 s; both stop lines in order; no fallback | | Plain taskkill, run 2 (main then PR) | Still alive after 60.108 s; both stop lines absent | Game exit 0 after 0.514 s; both stop lines in order; no fallback | | Required stop result | 0 of 2 | 2 of 2 | | Median request-to-exit interval | Not available: neither game exited during the 60 s observation | 0.541 s | | Ctrl+C, separate console-build check | Not run | Game exit 0 after 0.446 s; Ctrl+C request then close-work line; no fallback | | Native Windows stop fixture | Not run on main; fixture absent there | Exit 0, all 7 PASS lines below; compiled and executed on Windows | | Console-window close attempt | Not run | Not proved: the posted close message produced no console-close request or exit after 60.011 s | `taskkill` itself returned 0 in all four runs. Both main processes needed a separately recorded control `quit`, which ended each with exit 0; that cleanup is not a taskkill pass. Neither PR process needed cleanup or a hard kill. Main's exit latency is unknown, not 60 s and not a fabricated median. Both PR taskkill logs contain these lines, in this order: ```text [hos host] stop: requested by WM_CLOSE; wait for close-work marker and process exit 0; no forced deadline unless Windows later ends the session [hos host] stop: close work done (the game's saves are not waited for) ``` For the optional console checks, the same PR head was relinked as a Windows console executable with `RX_RELEASE=0`, using its byte-identical release renderer. The Ctrl+C check attached only to the game's own console, generated the real console-control event and observed the game handle. It was not a keyboard press and was not part of the alternating taskkill comparison. It logged: ```text [hos host] stop: requested by Ctrl+C; wait for close-work marker and process exit 0; no forced deadline unless Windows later ends the session [hos host] stop: close work done (the game's saves are not waited for) ``` The console-close attempt posted `WM_CLOSE` to the handle from `GetConsoleWindow`. The call was accepted, but no console-close request line or game exit followed within the observation. A separate control `quit` then ended it with exit 0; that close-work line belongs to cleanup. An actual console-window UI close remains unproven. Windows can return a non-displayed console handle, so an accepted message is not proof of that UI operation: https://learn.microsoft.com/en-us/windows/console/getconsolewindow . No terminal implementation is assumed here. ### Historical Linux source checks main: 1ef93e796bb0ec5cb95303e0096b30099b9887d8 (2026-11-13) this PR: move/fix/windows-graceful-stop-r3 @ 06cc450b929b1a7be76be6235df3d6ce99befc90 Hardware: Linux, GCC and Clang; no GPU used. These are the earlier source checks, not the Windows game runs above. Scene: authored game-free callbacks and close-chain fixtures; no game or save. Method: production functions compiled against Win32 stand-ins, including a stand-in ExitProcess that first disables the watchdog and then represents a stuck DLL detach. Simulated clocks exercise a twelve-second ordinary close and a later four-second OS budget; these are policy checks, not measured Windows shutdown times. How to reproduce: `python -I -B tests/test_windows_stop.py --cc gcc`, then `--cc clang`; `python -I -B tests/test_windows_display_startup.py`, `python -I -B tests/test_menu_restart.py`, and `python -I -B tests/test_control.py`. | | Before: main @ 1ef93e796 | After: this PR @ 06cc450b9 | |---|---|---| | New windowless event-route implementation | Not present | Source and game-free fixtures present | | Reviewed event and close-chain behavior | Not executed against main | GCC and Clang pass | Regression comparisons are against the reviewed source where possible, or one explicit minimal reversion, not relabelled whole-build comparisons: | Review concern | Negative used | Observed rejection | |---|---|---| | ExitProcess kills the watchdog before detach | Replace the worker's final TerminateProcess with ExitProcess | Dead-watchdog/detach assertion fails | | Ordinary close was killed at four seconds | Restore deadline arming for every event | Ordinary-event no-deadline assertion fails | | Repeated ending event slept a fresh four seconds | Restore the full-duration console sleep | Remaining-time assertion fails | | Helper failure killed the game | Reviewed 98a6771ad `host/display.c` | Nonfatal-startup and fallback-message checks fail | | Control quit restarted/logged a window close | Reviewed 98a6771ad `host/control.c` | Pending-restart/no-window-log assertion fails | | Completion marker used the old save jargon | Restore the old marker in the returning tail | Expected completion-marker-before-flush check fails | The same seven lines were also printed by `tests/test_windows_stop.py` at `99f46021` on native Windows, with llvm-mingw Clang, exit 0 and empty stderr. Its two executables ran there, but their Win32 calls and clocks are stand-ins. The game runs above, not this fixture, prove real delivery. ```text PASS: console handlers only request; OS-ending events share the remaining deadline, ordinary events have none PASS: WM_CLOSE has no forced deadline; only confirmed end-session arms it, without repeating close work PASS: slow ordinary closes finish; completed event close terminates after flush, never entering DLL detach PASS: OS deadline bounds a stuck worker and queued-message flood; later OS event wakes an unbounded close PASS: setup failures release idle resources safely or retain live handles, without closing the game PASS: control quit flushes the shared tail, ignores pending restart and does not claim a window closed PASS: window close still flushes before its optional relaunch and ExitProcess ``` The earlier `f41db065c` and `830b2c59` suites reported 509 passed, 0 failed, 19 skipped and 510 passed, 0 failed, 19 skipped respectively. They remain historical and are not carried as validation of these changed shutdown semantics. ### Screenshots Nothing on screen. The Windows logs confirm offscreen rendering. No screenshot is offered as proof that the added stop window never appears; the console-window close case remains unproven. ### Flags and settings No new setting is added; this PR changes what `HOS_HEADLESS` (the Windows stop handlers) and `HOS_CONTROL` (control quit's close tail) do. | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `HOS_HEADLESS` | Existing switch | Existing | Off; handlers active only when headless | Existing offscreen mode gains the Windows stop handlers after renderer startup | Helps: Plain `taskkill` and Ctrl+C on the Windows 11 / Intel Arc runs below. Doesn't help: Saving, forced kills, startup before renderer initialization; console events without a console. Untested: Other Windows versions and GPUs; actual console-window close and OS-ending events. | Off by default: ordinary play needs its game window | | `HOS_CONTROL` | Existing switch | Existing | Unset | Existing opt-in bridge quit now shares the normal-close tail | Helps: Linux game-free bridge checks and the separately recorded Windows cleanup quits below. Doesn't help: Acknowledging completed saves or forcing a hung close. Untested: Integrated co-op; other Windows versions and GPUs. | Off by default: enable deliberately for test sessions | No new setting is added. The four-second deadline applies only to OS-ending events, not plain WM_CLOSE, Ctrl+C, Ctrl+Break or control quit. ## Testing **Tested:** Windows 11 / Intel Arc at `99f46021`: both plain-taskkill runs, the generated Ctrl+C event and all seven native Windows fixture checks pass as recorded above. On the carried head, all 12 focused compiled drivers pass with GCC 16.2.1 and Clang 23.1.3, plus the Python-only player-input check: 25 invocations, 0 failures. This includes the stop, display-startup, menu-restart and control drivers, as well as main's display, cursor, input, startup and sampled-control readers. No fixture or assertion was changed for the carry. The whole-suite result belongs to `769bbea7` in the branch-state line, not these focused totals. The earlier six negative comparisons above were rejected at their original reviewed head; they were not repeated for this carry. The lifetime regression models the watchdog being gone before DLL detach rather than treating all exits as equivalent. Historical checks, not relabelled as this head: the complete suite at `830b2c5908afa820b8a309b93c44e92a2f470a7d` reports 510 passed, 0 failed, 19 skipped. At that head, the four changed host files compiled to Windows x86-64 objects with `-Wall -Wextra -Werror`, and the new fixtures compiled and linked without execution. The initial cross-check setup failures (link flags on compile-only commands and missing generated public runtime declarations) were corrected without suppressing a warning. At `830b2c5908afa820b8a309b93c44e92a2f470a7d`, the Vulkan renderer DLL was also cross-compiled and linked for Windows x86-64 on Linux with llvm-mingw 20261104 (Clang 23.1.5), and all 44 host translation units selected by the release build were covered by successful Windows object compilations: 6 newly compiled and 38 reused from matching, hash-verified Windows object-cache entries. `host/windows_stop.c` was newly compiled. At that historical head the game executable was not linked and no Windows or Wine execution was performed. That cross-build was not a hosted Windows-builder run or a Windows UTF-8-path runtime test. That production build retained the project's warning-suppression flags; it is separate from the strict four-file fixture checks and does not establish warning-clean production code. Those older binaries do not validate the reviewed stop implementation. The later builds and native Windows execution at `99f46021` are recorded separately below. **Built for Windows and Linux at the current head, not run:** At `020bb0ed6a5e34ff175dc365f78b6f7dd8309db0`, the Windows x86-64 Vulkan renderer DLL and all 51 selected host translation units were cross-built on Linux with llvm-mingw 20261104 (Clang 23.1.5), using the project's production flags and pinned dependencies (renderer: 1 newly compiled / 204 reused; host: 5 newly compiled / 46 reused; lifted C: 0 newly compiled / 80 reused; all Windows units: 6 newly compiled / 644 reused from matching object-cache entries), the renderer DLL linked and the full game executable linked; nothing was run on Windows or under Wine, and this is neither the project's hosted builder run nor a Windows UTF-8 run-time path test. The exact same head `020bb0ed6a5e34ff175dc365f78b6f7dd8309db0` also compiled and linked its full native Linux executable and renderer with Clang 23.1.3 through the documented resume path (323 newly compiled units, 169 matching Linux-cache units, source stamp `8a5c6ee8`), using the verified target-neutral C from lift `5c175a4727d82f85e425e85400dca17fea0750fb` rather than carrying the patch onto another commit; neither Linux binary was run. **Built for Windows and Linux at the previous head:** At `769bbea7e5220141138a4648c237fdbfb603c636`, the Windows x86-64 Vulkan renderer DLL and all 48 selected host translation units were cross-built on Linux with llvm-mingw 20261104 (Clang 23.1.5), using the project's production flags and pinned dependencies (renderer: 35 newly compiled / 170 reused; host: 7 newly compiled / 41 reused; lifted C: 0 newly compiled / 80 reused; all Windows units: 42 newly compiled / 605 reused from matching object-cache entries), the renderer DLL linked and the full game executable linked; nothing was run on Windows or under Wine, and this is neither the project's hosted builder run nor a Windows UTF-8 run-time path test. The same head also compiled and linked its full native Linux executable and renderer with Clang 23.1.3 through the documented resume path (40 newly compiled units, 449 matching Linux-cache units, source stamp `335aaaed`), using the verified target-neutral C from lift `76699aad3a6bdc4f75520c0f2c9d9c80d5731a5f` rather than carrying the patch onto another commit; neither Linux binary was run. The same head was also built natively on Windows 11 (both Windows products linked) for the repeated runs. **Historical builds at `99f46021`, followed by native Windows execution:** At `99f46021d41e3b20e6e6e97113d54e5000289514`, the Windows x86-64 Vulkan renderer DLL and all 45 selected host translation units were cross-built on Linux with llvm-mingw 20261104 (Clang 23.1.5), using the project's production flags and pinned dependencies (renderer: 1 newly compiled / 204 reused; host: 5 newly compiled / 40 reused; lifted C: 0 newly compiled / 80 reused; all Windows units: 6 newly compiled / 638 reused from matching object-cache entries), the renderer DLL linked and the full game executable linked; that Linux cross-build did not execute the Windows products and is neither a hosted builder run nor a Windows UTF-8 run-time path test. The same head also compiled and linked its full native Linux executable and renderer with Clang 23.1.3 through the documented resume path (204 newly compiled units, 282 matching Linux-cache units, source stamp `cddfa164`), using the verified target-neutral C from the fresh fbd420241a lift rather than carrying the patch onto another commit; neither Linux binary was run. A separate native Windows build of the same head then compiled and linked successfully: 639 newly compiled units, 0 reused, 0 failed. Its stop fixture and game runs are the Windows results above. No Wine run or UTF-8 runtime-path test is claimed. Those are the earlier head's builds; the current head's builds are named above. **Not tested:** an actual console-window UI close, Ctrl+Break, logoff/shutdown, a deliberately stuck driver and the real four-second OS deadline. The failed console-message attempt remains recorded above. Completed saves, general GPU/driver teardown, co-op leave receipt, hosted-relay/session shutdown, other Windows versions and other GPUs remain unproven. The Linux game and Windows UTF-8 runtime paths were not exercised. No performance, completed-save, cache-write-success or guaranteed-delivery claim is made. The runs at the earlier head and the repeat at the pushed head are both given above, each at its own commits. **Must be tested:** - Other Windows versions and GPUs: repeat plain `taskkill` without `/F` and the stop fixture, expecting game exit 0 with both stop lines and seven PASS lines (T-U5KN; by hand). - A Windows console build: close the actual console window and observe delivery and exit, expecting a completed close. A completed close needs the request line, close-work line and exit 0; 124 or `0xC000013A` means incomplete close (T-U5KN; by hand). ## Risks **What could break:** The earlier four-second limit on every request has been removed. Ordinary WM_CLOSE/Ctrl+C/Ctrl+Break can now wait indefinitely for a stuck driver; a caller's observation timeout is not a clean-exit receipt or automatic permission to force it. This preserves slow valid close work. Only OS-ending events start the shorter budget, and Windows can impose an earlier limit. Only the event worker skips DLL detach, with TerminateProcess(0) after explicit close hooks and log flush. It therefore does not run teardown that exists only in DLL detach. Normal window/restart and control routes still use ExitProcess and can still hang in detach; this change makes no bound claim for them. An OS-deadline expiry can interrupt cache writes. Code 124 and 0xC000013A are both incomplete outcomes. Require the new close-work marker together with observed exit 0; even that does not prove a completed save or successful cache writes. The monitor avoids logger locks, so forced termination can leave no final timeout line. Failure to install the helper leaves the game running with control quit available. The hidden window and waiting threads exist only for started headless Windows games. **Turning it off:** Reverting the PR removes the additional event route; control quit remains available. **Compatibility:** - Saves: unchanged. Quitting still does not finish a save: the completion line is `stop: close work done (the game's saves are not waited for)`, and there is still no save-transaction drain in main. - `longshot_options.ini`: unchanged; no new setting is added. - Caches: an OS-deadline expiry can interrupt cache writes (see What could break); the diff changes no cache code. - The vk ABI: unchanged; the diff touches no file under `gpu/vk/`, so `MKWVK_API_VERSION` stays as it is. - The builder's tools: the text says nothing; the diff touches none (it changes `host/`, `docs/` and `tests/` only). - Scripts that stop a headless game: a completed close needs the new close-work marker together with exit 0; 124 and `0xC000013A` are both incomplete outcomes (`docs/development.md` names both). ## Issues See #83 ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. Windows 11 / Intel Arc, main `514591a3` then this PR `99f46021`, twice: main stayed alive through each 60 s observation; this PR exited with both stop lines in 0.569 and 0.514 s, median 0.541 s. The same was repeated at main `cf605c85` and this PR `769bbea7`: 0.588 and 0.534 s, median 0.561 s. This measures the stop fix, not game speed. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A game-free test added for the fix, failing on `main` and passing here. The original installation regression remains; review fixes also reject the reviewed sources or the explicit minimal reversions listed above. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. Built and linked for both at `020bb0ed6a5e34ff175dc365f78b6f7dd8309db0` (under Testing); nothing was run on Windows at this head, so UTF-8 path behavior at run time is not claimed. - [x] Docs updated. --- New on this forge; not opened on GitHub. Assisted-by: GPT-6 Astra Co-Authored-By: GPT-6 Astra <[email protected]>
mooki force-pushed fix/windows-graceful-stop from 830b2c5908
Some checks failed
Linux AppImage / appimage (pull_request) Blocked by required conditions
Windows builder / Longshot Builder zip (pull_request) Blocked by required conditions
Windows builder / Windows Vulkan back end (llvm-mingw) (pull_request) Blocked by required conditions
Windows builder / dav1d for Windows (llvm-mingw) (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / Python source checks (windows-2022, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (windows-2022, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 98a6771ad2
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-13 14:14:31 +00:00
Compare
Author
Member

Carried onto main 0c74253d4 (head 98a6771ad): the one hand-resolved hunk is in docs/development.md, where main's new Log levels section is kept and the stop section follows it; the runtime code and its tests are unchanged. The whole game-free suite on this head: 506 passed, 2 failed, 15 skipped. One Windows test request is open, T-K24T; the Measured box and the two-platform build box stay open until Windows has run it, so this stays WIP.

Carried onto main `0c74253d4` (head `98a6771ad`): the one hand-resolved hunk is in docs/development.md, where main's new Log levels section is kept and the stop section follows it; the runtime code and its tests are unchanged. The whole game-free suite on this head: 506 passed, 2 failed, 15 skipped. One Windows test request is open, T-K24T; the Measured box and the two-platform build box stay open until Windows has run it, so this stays WIP.
HumanBean requested changes 2026-11-13 15:47:54 +00:00
Dismissed
HumanBean left a comment

Code review only: I read the diff and the code around it. I didn't build anything or run the tests.

The overall shape is sound. The console handler only sets a flag and does no work. The request happens once, through one InterlockedCompareExchange, and a repeated event doesn't move the deadline. WM_ENDSESSION waits for the confirmed case. The message wait has a cap on each batch. Linux is unaffected: windows_stop.c is all inside #ifdef _WIN32, and nx2/build.py globs host/*.c, so Linux compiles it as an empty file and needs no change to the source list. A concurrent control quit is also safe: play_cache_save and dlss_fg_close already take their own locks. A cut-off cache save loses data without corrupting anything, because play_file_write writes a .tmp and then moves it into place.

Changes requested before this can merge (details inline):

  1. The watchdog can't bound ExitProcess, and the comment and docs say it does. ExitProcess ends every other thread, the watchdog included, before the DLL detach runs. A hang in the driver's unload or in an atexit handler is therefore never cut off at 4 s. vk_main.cpp already avoids exit() for this reason. Either correct the claim (the source comment, the "If the process still runs then…" paragraph in development.md and the PR description) or change the route so it doesn't depend on ExitProcess.
  2. The 4 s kill also applies to routes where Windows sets no deadline. That covers WM_CLOSE (taskkill without /F) and Ctrl+C/Ctrl+Break. A slow close that would have finished cleanly is turned into exit 124, and the play-cache save is lost. The bound is only needed where the OS imposes one: console close/logoff/shutdown and WM_ENDSESSION.
  3. A failure to start the stop route now ends every headless run with exit 1. This is a best-effort helper, but display_start_failed makes it fatal. It also logs a meaningless GetLastError after the 4 s ready-wait times out. Log the failure and carry on, as the thread already does when the window or the console handler fails.

The rest are nits.

The description and the checklist are honest about what isn't tested: nothing ran on Windows, the Measured box is open and T-K24T is outstanding. Two things on them:

  • The Rebased on current main box is out of date. main is now fdc2840bf, 4 commits past the base 0c74253d4. Among this PR's files, those commits only touch docs/development.md, in other sections (occlusion switches, dev packs), and a three-way merge of that file is clean. So "not mergeable as it is" isn't a content conflict: the branch is just behind. A rebase before it's marked ready will settle it.
  • The paragraph in What changed that says the message thread "limits event-triggered close to four seconds" needs the same correction as point 1.

The test checks read sensibly. test_menu_restart.py still finds hos_log_flush → relaunch → ExitProcess in that order. The new fixtures exercise the production functions against stand-ins, without reimplementing the logic. They can't catch point 1, because the stand-in ExitProcess never stops the watchdog.

Code review only: I read the diff and the code around it. I didn't build anything or run the tests. The overall shape is sound. The console handler only sets a flag and does no work. The request happens once, through one `InterlockedCompareExchange`, and a repeated event doesn't move the deadline. `WM_ENDSESSION` waits for the confirmed case. The message wait has a cap on each batch. Linux is unaffected: `windows_stop.c` is all inside `#ifdef _WIN32`, and `nx2/build.py` globs `host/*.c`, so Linux compiles it as an empty file and needs no change to the source list. A concurrent control `quit` is also safe: `play_cache_save` and `dlss_fg_close` already take their own locks. A cut-off cache save loses data without corrupting anything, because `play_file_write` writes a `.tmp` and then moves it into place. Changes requested before this can merge (details inline): 1. **The watchdog can't bound `ExitProcess`, and the comment and docs say it does.** `ExitProcess` ends every other thread, the watchdog included, before the DLL detach runs. A hang in the driver's unload or in an `atexit` handler is therefore never cut off at 4 s. `vk_main.cpp` already avoids `exit()` for this reason. Either correct the claim (the source comment, the "If the process still runs then…" paragraph in development.md and the PR description) or change the route so it doesn't depend on `ExitProcess`. 2. **The 4 s kill also applies to routes where Windows sets no deadline.** That covers `WM_CLOSE` (`taskkill` without `/F`) and Ctrl+C/Ctrl+Break. A slow close that would have finished cleanly is turned into exit 124, and the play-cache save is lost. The bound is only needed where the OS imposes one: console close/logoff/shutdown and `WM_ENDSESSION`. 3. **A failure to start the stop route now ends every headless run with exit 1.** This is a best-effort helper, but `display_start_failed` makes it fatal. It also logs a meaningless `GetLastError` after the 4 s ready-wait times out. Log the failure and carry on, as the thread already does when the window or the console handler fails. The rest are nits. The description and the checklist are honest about what isn't tested: nothing ran on Windows, the Measured box is open and T-K24T is outstanding. Two things on them: - The *Rebased on current `main`* box is out of date. `main` is now `fdc2840bf`, 4 commits past the base `0c74253d4`. Among this PR's files, those commits only touch `docs/development.md`, in other sections (occlusion switches, dev packs), and a three-way merge of that file is clean. So "not mergeable as it is" isn't a content conflict: the branch is just behind. A rebase before it's marked ready will settle it. - The paragraph in *What changed* that says the message thread "limits event-triggered close to four seconds" needs the same correction as point 1. The test checks read sensibly. `test_menu_restart.py` still finds `hos_log_flush` → `relaunch` → `ExitProcess` in that order. The new fixtures exercise the production functions against stand-ins, without reimplementing the logic. They can't catch point 1, because the stand-in `ExitProcess` never stops the watchdog.
host/control.c Outdated
@ -2312,3 +2313,2 @@
hos_log("control: exiting");
hos_log_flush();
ExitProcess(0);
hos_window_closed_exit();
Owner

Nit: control quit now also logs display: window closed, exiting from hos_window_closed_exit, right after control: exiting, although no window was closed. It also honours relaunch_asked, so a quit after the Insert menu's Restart now restarts the game instead of quitting. That's unlikely, but it's a behaviour change on both OSes and deserves a line in the description.

Nit: control `quit` now also logs `display: window closed, exiting` from `hos_window_closed_exit`, right after `control: exiting`, although no window was closed. It also honours `relaunch_asked`, so a quit after the Insert menu's Restart now restarts the game instead of quitting. That's unlikely, but it's a behaviour change on both OSes and deserves a line in the description.
host/display.c Outdated
@ -516,0 +516,4 @@
/* The renderer's startup may attach/free a console, which resets Windows' console handlers.
Install the stop route afterwards; it needs neither a rendered frame nor the game's input loop. */
int hos_windows_stop_start(void);
if (!hos_windows_stop_start()) display_start_failed("windowless stop setup");
Owner

This makes a best-effort helper fatal: if the events, either thread or the 4 s ready-wait fail, every HOS_HEADLESS run on Windows now exits with code 1, where before it ran normally. stop_messages already logs and carries on when the hidden window or the console handler can't be set up, so a startup failure should do the same: log stop: windowless stop route unavailable; use the control bridge and return.

Also, after the WaitForSingleObject timeout GetLastError() holds nothing relevant, so display_start_failed logs a misleading error number. If it stays fatal, the test in windows_display_startup_test.c should change with it.

This makes a best-effort helper fatal: if the events, either thread or the 4 s ready-wait fail, every `HOS_HEADLESS` run on Windows now exits with code 1, where before it ran normally. `stop_messages` already logs and carries on when the hidden window or the console handler can't be set up, so a startup failure should do the same: log `stop: windowless stop route unavailable; use the control bridge` and return. Also, after the `WaitForSingleObject` timeout `GetLastError()` holds nothing relevant, so `display_start_failed` logs a misleading error number. If it stays fatal, the test in windows_display_startup_test.c should change with it.
@ -105,6 +105,7 @@ static void relaunch(void) {
void hos_window_closed_exit(void) {
const int again = relaunch_asked != 0;
hos_log(again ? "display: window closed for a restart (the Insert menu's Restart now)" : "display: window closed, exiting");
hos_log("stop: normal close work returned; save drain unsupported");
Owner

Nit: this line now appears in every player's log on every normal window close, on Windows and Linux. "save drain unsupported" is jargon, and it will turn up in bug reports looking like an error. Consider wording a player can read, such as display: close work done (the game's saves are not waited for), or log the marker only on the stop and control routes.

Nit: this line now appears in every player's log on every normal window close, on Windows and Linux. "save drain unsupported" is jargon, and it will turn up in bug reports looking like an error. Consider wording a player can read, such as `display: close work done (the game's saves are not waited for)`, or log the marker only on the stop and control routes.
@ -0,0 +1,125 @@
/* Windowless Windows stop requests. No renderer, save or log work runs on a console handler thread.
The hidden top-level window is never shown: unlike HWND_MESSAGE, it receives enumerated/broadcast messages.
The worker uses the normal close path. The other thread bounds it, including a stuck renderer or ExitProcess.
Owner

This isn't true for ExitProcess. ExitProcess (RtlExitUserProcess) first terminates every other thread in the process, stop_messages included, and only then runs DLL_PROCESS_DETACH and the CRT's atexit. So once the worker reaches ExitProcess(0) in hos_window_closed_exit, nothing is left to call TerminateProcess(124). A hang in the Vulkan driver's unload, or in NGX/FSR detach, isn't bounded. vk_main.cpp (the comment around line 1004) already avoids exit() because the driver's unload can wait for ever.

Two ways to fix it: correct the claim here, in development.md and in the PR description. Or, for this route only, end with TerminateProcess(GetCurrentProcess(), 0) once the close work and the log flush have returned, so that nothing depends on DLL detach. That needs a variant of hos_window_closed_exit that doesn't call ExitProcess.

This isn't true for `ExitProcess`. `ExitProcess` (RtlExitUserProcess) first terminates every other thread in the process, `stop_messages` included, and only then runs DLL_PROCESS_DETACH and the CRT's `atexit`. So once the worker reaches `ExitProcess(0)` in `hos_window_closed_exit`, nothing is left to call `TerminateProcess(124)`. A hang in the Vulkan driver's unload, or in NGX/FSR detach, isn't bounded. `vk_main.cpp` (the comment around line 1004) already avoids `exit()` because the driver's unload can wait for ever. Two ways to fix it: correct the claim here, in development.md and in the PR description. Or, for this route only, end with `TerminateProcess(GetCurrentProcess(), 0)` once the close work and the log flush have returned, so that nothing depends on DLL detach. That needs a variant of `hos_window_closed_exit` that doesn't call `ExitProcess`.
@ -0,0 +10,4 @@
void rx_close_asked(void);
void hos_window_closed_exit(void);
enum { STOP_WAIT_MS = 4000, STOP_TIMEOUT_EXIT = 124 };
Owner

This 4 s kill applies to every route, but the OS sets a deadline on only some of them. WM_CLOSE (plain taskkill) and Ctrl+C/Ctrl+Break have none: the process may take as long as it needs, and whoever asked can still use /F. Forcing exit 124 there turns a close that is slow but would have finished cleanly into an incomplete one, and the play-cache save in mkwvk_close_asked is lost. That close can take more than 4 s: dlss_fg_close alone waits up to 2 s, and the preparation stop up to 10 s.

Please arm the deadline only for console close/logoff/shutdown and WM_ENDSESSION, or give the routes without an OS deadline a separate, much longer bound. Then update the table in development.md to match.

This 4 s kill applies to every route, but the OS sets a deadline on only some of them. `WM_CLOSE` (plain `taskkill`) and Ctrl+C/Ctrl+Break have none: the process may take as long as it needs, and whoever asked can still use `/F`. Forcing exit 124 there turns a close that is slow but would have finished cleanly into an incomplete one, and the play-cache save in `mkwvk_close_asked` is lost. That close can take more than 4 s: `dlss_fg_close` alone waits up to 2 s, and the preparation stop up to 10 s. Please arm the deadline only for console close/logoff/shutdown and `WM_ENDSESSION`, or give the routes without an OS deadline a separate, much longer bound. Then update the table in development.md to match.
@ -0,0 +40,4 @@
request_stop(reason);
/* Returning from CLOSE/LOGOFF/SHUTDOWN ends the process even with TRUE. Leave the normal worker time to
finish instead. Windows may impose a shorter deadline; never promise that its shutdown can be postponed. */
if (event != CTRL_C_EVENT && event != CTRL_BREAK_EVENT) Sleep(STOP_WAIT_MS);
Owner

Nit: this sleeps a full STOP_WAIT_MS from the moment this event arrived, not until the shared deadline. On a first request, the handler's return (after which Windows ends the process with STATUS_CONTROL_C_EXIT, 0xC000013A) and the watchdog's TerminateProcess(124) fall in the same millisecond. Either exit code can win. Sleep(stop_remaining()) matches what WM_ENDSESSION does. The docs should also say that 0xC000013A is a possible incomplete exit, next to 124.

Nit: this sleeps a full `STOP_WAIT_MS` from the moment this event arrived, not until the shared deadline. On a first request, the handler's return (after which Windows ends the process with `STATUS_CONTROL_C_EXIT`, 0xC000013A) and the watchdog's `TerminateProcess(124)` fall in the same millisecond. Either exit code can win. `Sleep(stop_remaining())` matches what `WM_ENDSESSION` does. The docs should also say that 0xC000013A is a possible incomplete exit, next to 124.
mooki force-pushed fix/windows-graceful-stop from 98a6771ad2
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 99f46021d4
All checks were successful
PR description / Description follows the template (pull_request_target) Successful in 4s
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-13 17:20:16 +00:00
Compare
Author
Member

Thank you: the ExitProcess lifetime point was a real hole in both the implementation and its test. Addressed in the commit fix(runtime): finish windowless close before terminating, now head 99f46021d on main fbd420241:

  1. DLL detach: I took the implementation fix. hos_close_finish() returns after the shared close/log tail; the Windows-event worker then calls TerminateProcess(GetCurrentProcess(), 0). It never enters ExitProcess/DLL detach. Normal window/restart and control exits remain unchanged in that respect. The fixture now models ExitProcess killing the watchdog before a stuck detach; substituting that API back fails the lifetime assertion.
  2. Deadlines: WM_CLOSE, Ctrl+C and Ctrl+Break now have no forced deadline. Ten seconds for preparation plus two for frame generation is already longer than four, and cache/driver work has no combined bound. Only console close/logoff/shutdown and confirmed WM_ENDSESSION arm the four-second budget. A later OS-ending event can arm it during an ordinary close without requesting the work twice; repeats cannot extend it. Fixtures cover slow ordinary close and that transition.
  3. Setup failure: nonfatal, with exactly stop: windowless stop route unavailable; use the control bridge. No stale GetLastError. Partial startup releases the idle worker without closing the game, and retains any handles a live thread still needs. The startup fixture rejects the former fatal path.
  4. Remaining wait / exit status: ending-event handlers use Sleep(stop_remaining()). Docs and tester instructions now list both 124 and 0xC000013A as incomplete outcomes. The old full-duration sleep fails the repeat-event regression.
  5. Control quit: no longer calls the window-exit wrapper, consults relaunch_asked, or logs a window close. A pending-restart fixture rejects the reviewed behavior; the ordinary window restart still flushes before relaunch and ExitProcess.
  6. Log wording: the marker is now stop: close work done (the game's saves are not waited for). The description's What changed paragraph and route table match the corrected implementation.

GCC/Clang stop fixtures and the focused display-startup, restart and control checks pass; all six negative comparisons reject the old behavior/minimal reversions. The whole game-free suite on this head: 515 passed, 0 failed, 15 skipped. No build and nothing on Windows or in a game was run for this update. The older results retain their actual hashes; this stays WIP, with T-K24T's expectations updated for testing.

Thank you: the ExitProcess lifetime point was a real hole in both the implementation and its test. Addressed in the commit `fix(runtime): finish windowless close before terminating`, now head `99f46021d` on main `fbd420241`: 1. **DLL detach:** I took the implementation fix. `hos_close_finish()` returns after the shared close/log tail; the Windows-event worker then calls `TerminateProcess(GetCurrentProcess(), 0)`. It never enters ExitProcess/DLL detach. Normal window/restart and control exits remain unchanged in that respect. The fixture now models ExitProcess killing the watchdog before a stuck detach; substituting that API back fails the lifetime assertion. 2. **Deadlines:** WM_CLOSE, Ctrl+C and Ctrl+Break now have no forced deadline. Ten seconds for preparation plus two for frame generation is already longer than four, and cache/driver work has no combined bound. Only console close/logoff/shutdown and confirmed WM_ENDSESSION arm the four-second budget. A later OS-ending event can arm it during an ordinary close without requesting the work twice; repeats cannot extend it. Fixtures cover slow ordinary close and that transition. 3. **Setup failure:** nonfatal, with exactly `stop: windowless stop route unavailable; use the control bridge`. No stale GetLastError. Partial startup releases the idle worker without closing the game, and retains any handles a live thread still needs. The startup fixture rejects the former fatal path. 4. **Remaining wait / exit status:** ending-event handlers use `Sleep(stop_remaining())`. Docs and tester instructions now list both 124 and `0xC000013A` as incomplete outcomes. The old full-duration sleep fails the repeat-event regression. 5. **Control quit:** no longer calls the window-exit wrapper, consults `relaunch_asked`, or logs a window close. A pending-restart fixture rejects the reviewed behavior; the ordinary window restart still flushes before relaunch and ExitProcess. 6. **Log wording:** the marker is now `stop: close work done (the game's saves are not waited for)`. The description's What changed paragraph and route table match the corrected implementation. GCC/Clang stop fixtures and the focused display-startup, restart and control checks pass; all six negative comparisons reject the old behavior/minimal reversions. The whole game-free suite on this head: 515 passed, 0 failed, 15 skipped. No build and nothing on Windows or in a game was run for this update. The older results retain their actual hashes; this stays WIP, with T-K24T's expectations updated for testing.
Author
Member

The test request for this pull request is reissued as T-U5KN, replacing T-K24T, because the review fixes changed what a tester should see: the log line is now stop: close work done (the game's saves are not waited for), a plain taskkill has no forced deadline, and the optional console steps name the two exit codes (124 and 0xC000013A) that mean the close work did not finish. The description's Testing wanted line is shortened to match the request's steps.

The test request for this pull request is reissued as T-U5KN, replacing T-K24T, because the review fixes changed what a tester should see: the log line is now `stop: close work done (the game's saves are not waited for)`, a plain `taskkill` has no forced deadline, and the optional console steps name the two exit codes (124 and 0xC000013A) that mean the close work did not finish. The description's Testing wanted line is shortened to match the request's steps.
Author
Member

The reworked code builds on both platforms. At 99f46021 the Windows renderer and the full game executable cross-built and linked on Linux with llvm-mingw 20261104 (Clang 23.1.5), and the native Linux executable and renderer built and linked with Clang 23.1.3. Nothing was run from either build. The Windows-and-Linux build box is ticked with that scope. What remains for this pull request is the run on a real Windows PC (test request T-U5KN), which also decides the Measured box.

The reworked code builds on both platforms. At `99f46021` the Windows renderer and the full game executable cross-built and linked on Linux with llvm-mingw 20261104 (Clang 23.1.5), and the native Linux executable and renderer built and linked with Clang 23.1.3. Nothing was run from either build. The Windows-and-Linux build box is ticked with that scope. What remains for this pull request is the run on a real Windows PC (test request T-U5KN), which also decides the Measured box.
Author
Member

Updated to head 769bbea7e on main cf605c85b; the whole game-free suite on it: 541 passed, 3 failed, 16 skipped.

Both existing commits are kept with their authors, dates, messages and trailers. The rebase applied without a conflict. Main changed cursor handling and Toggle resets in host/display.c, added sampled status/subscription handling in host/control.c, and expanded the development and control guides. The stop setup still follows renderer startup; control quit still uses the shared returning close tail. host/hos_relaunch.c was unchanged on main. No source or fixture adaptation was needed, and no assertion was weakened.

On the carried head, the stop, display-startup, menu-restart and control drivers pass with both GCC 16.2.1 and Clang 23.1.3. Including main's affected source readers, all 12 compiled drivers pass with each compiler, plus the Python-only player-input check: 25 invocations, 0 failures. These are focused checks, not the whole-suite totals above. The known main failure in tests/test_pad_layout.py is not repaired by this carry.

The missing Windows evidence is now in the description, at the commits actually run: main 514591a30d707fe9f3ad31eae148c3cc1e750bff against this PR 99f46021d41e3b20e6e6e97113d54e5000289514. Same PC: Windows 11 Pro 26H2, build 26300.9974, Core Ultra 9 185H, 64 GB RAM, Intel Arc, driver 32.0.101.9150. Both were native release builds at the title with empty disposable profiles, offscreen 1920x1080 rendering, RX_VK_PRECOMPILE=0, sound muted and Discord integration off.

The four runs alternated main/PR/main/PR. Plain taskkill without /F, from the same interactive session as the game, left main alive after 60.100 and 60.108 s, with neither stop line. The PR exited with code 0 and both required lines after 0.569 and 0.514 s, median 0.541 s, with no fallback. Main's later control quits were cleanup only. The Measured box can be ticked for this repeated functional fix, not as a speed claim or as a measurement of the newer carried head.

The native Windows stop fixture compiled and executed at 99f46021 with all seven PASS lines and exit 0. A separate console build at that head also exited 0 after 0.446 s for a generated real Ctrl+C event. Posting WM_CLOSE to its GetConsoleWindow handle did not establish console-window-close delivery: no request line or exit after 60.011 s. Its later control quit is not a pass for that case.

The Windows check has not been repeated on the head now pushed; it is being repeated on the same PC, and the result follows here.

An actual console-window UI close, Ctrl+Break, logoff/shutdown and the real four-second deadline remain unproven, as do completed saves, co-op leave receipt and other Windows versions and GPUs. The description's remaining tester requests under T-U5KN concern other Windows versions and GPUs and the console-window close case. The older build results remain at 99f46021; the current-head build box stays open until the new build evidence is available.

Updated to head `769bbea7e` on main `cf605c85b`; the whole game-free suite on it: 541 passed, 3 failed, 16 skipped. Both existing commits are kept with their authors, dates, messages and trailers. The rebase applied without a conflict. Main changed cursor handling and Toggle resets in `host/display.c`, added sampled status/subscription handling in `host/control.c`, and expanded the development and control guides. The stop setup still follows renderer startup; control quit still uses the shared returning close tail. `host/hos_relaunch.c` was unchanged on main. No source or fixture adaptation was needed, and no assertion was weakened. On the carried head, the stop, display-startup, menu-restart and control drivers pass with both GCC 16.2.1 and Clang 23.1.3. Including main's affected source readers, all 12 compiled drivers pass with each compiler, plus the Python-only player-input check: 25 invocations, 0 failures. These are focused checks, not the whole-suite totals above. The known main failure in `tests/test_pad_layout.py` is not repaired by this carry. The missing Windows evidence is now in the description, at the commits actually run: main `514591a30d707fe9f3ad31eae148c3cc1e750bff` against this PR `99f46021d41e3b20e6e6e97113d54e5000289514`. Same PC: Windows 11 Pro 26H2, build 26300.9974, Core Ultra 9 185H, 64 GB RAM, Intel Arc, driver 32.0.101.9150. Both were native release builds at the title with empty disposable profiles, offscreen 1920x1080 rendering, `RX_VK_PRECOMPILE=0`, sound muted and Discord integration off. The four runs alternated main/PR/main/PR. Plain `taskkill` without `/F`, from the same interactive session as the game, left main alive after 60.100 and 60.108 s, with neither stop line. The PR exited with code 0 and both required lines after 0.569 and 0.514 s, median 0.541 s, with no fallback. Main's later control quits were cleanup only. The Measured box can be ticked for this repeated functional fix, not as a speed claim or as a measurement of the newer carried head. The native Windows stop fixture compiled and executed at `99f46021` with all seven PASS lines and exit 0. A separate console build at that head also exited 0 after 0.446 s for a generated real Ctrl+C event. Posting `WM_CLOSE` to its `GetConsoleWindow` handle did not establish console-window-close delivery: no request line or exit after 60.011 s. Its later control quit is not a pass for that case. The Windows check has not been repeated on the head now pushed; it is being repeated on the same PC, and the result follows here. An actual console-window UI close, Ctrl+Break, logoff/shutdown and the real four-second deadline remain unproven, as do completed saves, co-op leave receipt and other Windows versions and GPUs. The description's remaining tester requests under T-U5KN concern other Windows versions and GPUs and the console-window close case. The older build results remain at `99f46021`; the current-head build box stays open until the new build evidence is available.
mooki force-pushed fix/windows-graceful-stop from 99f46021d4
All checks were successful
PR description / Description follows the template (pull_request_target) Successful in 4s
Website / Website on Cloudflare (pull_request_target) Has been skipped
to 769bbea7e5
All checks were successful
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 6s
Third-party parts / As their notes say (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Successful in 11s
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-14 02:43:04 +00:00
Compare
Author
Member

The Windows check is repeated on the pushed head, and it builds on both platforms, so this is ready for review.

On Windows 11 with Intel Arc, with main cf605c85 and this change 769bbea7 both built natively there and run twice in turn: after a plain taskkill, main was still running at 60.129 s and 60.222 s; this change exited 0 after 0.588 s and 0.534 s, with the request line and the close-work line in order both times. tests/test_windows_stop.py passed there at 769bbea7 with its seven PASS lines. That matches the earlier result at 99f46021 (0.569 s and 0.514 s).

At 769bbea7 the Windows renderer and the full game executable also cross-built and linked on Linux, and the native Linux executable and renderer built and linked. The Windows-and-Linux build box is ticked on that basis.

Still not shown, as the description says: closing the console window itself (the test could not deliver that event), Ctrl+Break, logoff and shutdown, other Windows versions and other GPUs.

The Windows check is repeated on the pushed head, and it builds on both platforms, so this is ready for review. On Windows 11 with Intel Arc, with main `cf605c85` and this change `769bbea7` both built natively there and run twice in turn: after a plain `taskkill`, main was still running at 60.129 s and 60.222 s; this change exited 0 after 0.588 s and 0.534 s, with the request line and the close-work line in order both times. `tests/test_windows_stop.py` passed there at `769bbea7` with its seven PASS lines. That matches the earlier result at `99f46021` (0.569 s and 0.514 s). At `769bbea7` the Windows renderer and the full game executable also cross-built and linked on Linux, and the native Linux executable and renderer built and linked. The Windows-and-Linux build box is ticked on that basis. Still not shown, as the description says: closing the console window itself (the test could not deliver that event), Ctrl+Break, logoff and shutdown, other Windows versions and other GPUs.
mooki changed title from WIP: fix(runtime): handle windowless Windows stop requests to fix(runtime): handle windowless Windows stop requests 2026-11-14 03:51:30 +00:00
mooki force-pushed fix/windows-graceful-stop from 769bbea7e5
All checks were successful
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 6s
Third-party parts / As their notes say (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Successful in 11s
Website / Website on Cloudflare (pull_request_target) Has been skipped
to 32703860dd
All checks were successful
PR description / Description follows the template (pull_request_target) Successful in 15s
2026-11-14 15:03:12 +00:00
Compare
Author
Member

Carried onto main 5e072fc8c; new head 32703860d. This carry is mechanical: every commit replays unchanged, with no conflicts. The whole suite on this exact head: 543 passed, 3 failed, 16 skipped; its only failures are main's own tests/test_pad_layout.py, tests/test_module_ids.py and tests/test_framegen_resources.py. The build box is unticked until this pushed head has been built for Windows and Linux; it is ticked again then.

Carried onto main `5e072fc8c`; new head `32703860d`. This carry is mechanical: every commit replays unchanged, with no conflicts. The whole suite on this exact head: 543 passed, 3 failed, 16 skipped; its only failures are main's own `tests/test_pad_layout.py`, `tests/test_module_ids.py` and `tests/test_framegen_resources.py`. The build box is unticked until this pushed head has been built for Windows and Linux; it is ticked again then.
Author
Member

The pushed head 32703860ddfd21307a4904a3ce56d1217f888f86 is now built and linked for Windows (cross-built with llvm-mingw 20261104, Clang 23.1.5) and for Linux (Clang 23.1.3); the details are under Testing and the build box is ticked again. Nothing was run on Windows at this head.

The pushed head `32703860ddfd21307a4904a3ce56d1217f888f86` is now built and linked for Windows (cross-built with llvm-mingw 20261104, Clang 23.1.5) and for Linux (Clang 23.1.3); the details are under Testing and the build box is ticked again. Nothing was run on Windows at this head.
mooki changed title from fix(runtime): handle windowless Windows stop requests to WIP: fix(runtime): handle windowless Windows stop requests 2026-11-14 17:59:30 +00:00
Author
Member

Carried onto main 543846ebb; new head 020bb0ed6. Both original commits are kept. The conflicts came from main's new crash records: their clean-end mark now stays in the shared close tail, after the log flush and before normal window, control or completed windowless exits. The timeout path remains abnormal, and the event deadlines and DLL-detach behavior are unchanged. One separate test/documentation commit checks that ordering and real running-marker removal before termination, while keeping every host exit classified. The focused checks pass with both compilers, and the Windows-target fixture checks pass; no new Windows or game run was performed. The whole suite on this exact head: 555 passed, 1 failed, 16 skipped. The build box is unticked until this pushed head has been built for Windows and Linux; it is ticked again then.

Carried onto main `543846ebb`; new head `020bb0ed6`. Both original commits are kept. The conflicts came from main's new crash records: their clean-end mark now stays in the shared close tail, after the log flush and before normal window, control or completed windowless exits. The timeout path remains abnormal, and the event deadlines and DLL-detach behavior are unchanged. One separate test/documentation commit checks that ordering and real running-marker removal before termination, while keeping every host exit classified. The focused checks pass with both compilers, and the Windows-target fixture checks pass; no new Windows or game run was performed. The whole suite on this exact head: 555 passed, 1 failed, 16 skipped. The build box is unticked until this pushed head has been built for Windows and Linux; it is ticked again then.
mooki force-pushed fix/windows-graceful-stop from 32703860dd
All checks were successful
PR description / Description follows the template (pull_request_target) Successful in 15s
to 020bb0ed6a
All checks were successful
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 7s
Third-party parts / As their notes say (pull_request) Successful in 10s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
beanstalk/approval Test farm not requested
2026-11-14 18:13:51 +00:00
Compare
mooki changed title from WIP: fix(runtime): handle windowless Windows stop requests to fix(runtime): handle windowless Windows stop requests 2026-11-14 19:39:42 +00:00
Author
Member

Built at the current head 020bb0ed6a5e34ff175dc365f78b6f7dd8309db0 for Windows (llvm-mingw cross-build) and Linux (native); both linked without errors, nothing was run. The build box is ticked for this head and the details are under Testing. Every box is done, so this is ready for review again.

Built at the current head `020bb0ed6a5e34ff175dc365f78b6f7dd8309db0` for Windows (llvm-mingw cross-build) and Linux (native); both linked without errors, nothing was run. The build box is ticked for this head and the details are under Testing. Every box is done, so this is ready for review again.
HumanBean approved these changes 2026-11-15 20:05:54 +00:00
HumanBean left a comment

Re-reviewed at head 020bb0ed6 (code only; nothing run, and I cannot run the Windows behaviour here).

My earlier requests (on 98a6771ad) are all addressed:

  • ExitProcess killing the watchdog before DLL detach: the event worker now returns from hos_close_finish() and ends with TerminateProcess(GetCurrentProcess(), 0), so it never enters detach. The OS-deadline monitor lives in the message thread and calls TerminateProcess(..., 124) itself. Correct.
  • Four-second budget on every request: now armed only for console close, logoff, shutdown and confirmed WM_ENDSESSION, via a CAS that is never extended. A later OS-ending event during an ordinary close wakes the monitor without repeating the close work. Ending-event handlers sleep only stop_remaining().
  • Setup failure: nonfatal, with a fixed log line and no stale GetLastError. A partial start releases the idle worker with reason 0 and keeps handles alive if the worker has not exited.
  • Control quit: now goes through the shared hos_close_finish(), no relaunch check and no window-close log. hos_window_closed_exit() still flushes before a relaunch and ExitProcess.
  • Wording and docs: the completion line and the 124 / 0xC000013A exit codes are documented.

The last commit keeps the clean-end crash mark in the shared tail after the flush, so all routes (window, control, event) still mark a clean end.

The PR carries real evidence. On Windows 11 / Intel Arc, main stayed alive for 60 s after plain taskkill and this change exited 0 in about 0.5 s with both stop lines, in two alternating runs at each of two heads. Ctrl+C was delivered too. The description is honest about what is unproven (console-window UI close, Ctrl+Break, logoff/shutdown, the real 4 s deadline, other Windows versions and GPUs) and the Must-be-tested list names the T-U5KN run. Those are follow-up checks, not blockers for a fix that is off unless HOS_HEADLESS is set. The stop route is opt-in and failure is nonfatal.

Small note, no change needed: the stop_messages thread logs through hos_log only at startup, which fits the "no logging in the monitor loop" rule.

Approving. Since the previous request-changes was on a stale commit, this approval replaces it.

Re-reviewed at head `020bb0ed6` (code only; nothing run, and I cannot run the Windows behaviour here). My earlier requests (on `98a6771ad`) are all addressed: - **ExitProcess killing the watchdog before DLL detach:** the event worker now returns from `hos_close_finish()` and ends with `TerminateProcess(GetCurrentProcess(), 0)`, so it never enters detach. The OS-deadline monitor lives in the message thread and calls `TerminateProcess(..., 124)` itself. Correct. - **Four-second budget on every request:** now armed only for console close, logoff, shutdown and confirmed `WM_ENDSESSION`, via a CAS that is never extended. A later OS-ending event during an ordinary close wakes the monitor without repeating the close work. Ending-event handlers sleep only `stop_remaining()`. - **Setup failure:** nonfatal, with a fixed log line and no stale `GetLastError`. A partial start releases the idle worker with reason 0 and keeps handles alive if the worker has not exited. - **Control quit:** now goes through the shared `hos_close_finish()`, no relaunch check and no window-close log. `hos_window_closed_exit()` still flushes before a relaunch and `ExitProcess`. - **Wording and docs:** the completion line and the 124 / `0xC000013A` exit codes are documented. The last commit keeps the clean-end crash mark in the shared tail after the flush, so all routes (window, control, event) still mark a clean end. The PR carries real evidence. On Windows 11 / Intel Arc, main stayed alive for 60 s after plain `taskkill` and this change exited 0 in about 0.5 s with both stop lines, in two alternating runs at each of two heads. Ctrl+C was delivered too. The description is honest about what is unproven (console-window UI close, Ctrl+Break, logoff/shutdown, the real 4 s deadline, other Windows versions and GPUs) and the Must-be-tested list names the T-U5KN run. Those are follow-up checks, not blockers for a fix that is off unless `HOS_HEADLESS` is set. The stop route is opt-in and failure is nonfatal. Small note, no change needed: the `stop_messages` thread logs through `hos_log` only at startup, which fits the "no logging in the monitor loop" rule. Approving. Since the previous request-changes was on a stale commit, this approval replaces it.
HumanBean deleted branch fix/windows-graceful-stop 2026-11-15 20:20:32 +00:00
All checks were successful
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 7s
Third-party parts / As their notes say (pull_request) Successful in 10s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
beanstalk/approval Test farm not requested
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!102
No description provided.