fix(runtime): handle windowless Windows stop requests #102
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!102
Loading…
Reference in a new issue
No description provided.
Delete branch "mooki/Longshot:fix/windows-graceful-stop"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
taskkillleaving 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
taskkillin that same interactive session. Plaintaskkill, 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;taskkillitself returned 0 in all four runs, and both main processes needed a separately recorded controlquit, which ended each with exit 0.What changed
A hidden top-level window and console handlers now deliver
WM_CLOSE, confirmedWM_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 withTerminateProcess(GetCurrentProcess(), 0)after the close work and log flush return, never enteringExitProcess/DLL detach. Only console close, logoff, shutdown and confirmedWM_ENDSESSIONarm 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 receivesWM_CLOSEand confirmedWM_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.rx_close_asked()and the returninghos_close_finish(), thenTerminateProcess(GetCurrentProcess(), 0)after the close work and log flush return. It never entersExitProcess/DLL detach. The earlier claim that the watchdog could boundExitProcesswas 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 confirmedWM_ENDSESSIONalone 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 logsstop: 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.candhost/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 useExitProcess; only the event worker skips DLL detach. The completion line is nowstop: close work done (the game's saves are not waited for).ExitProcessdisables 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.pykeeps its flush-before-relaunch-before-exit check through the new shared tail.docs/development.mdhas a per-route deadline table and names both incomplete exits, 124 and0xC000013A(STATUS_CONTROL_C_EXIT);docs/control.mdstates 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
taskkilland a real Ctrl+C event were delivered on Windows 11 at99f46021. 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 returninghos_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 main514591a3, 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 inhost/control.c; neither changed this PR's stop installation or quit function. Main lefthost/hos_relaunch.cunchanged. 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
taskkillleaves main alive and this change exits with both required stop lines: on Windows 11 / Intel Arc, maincf605c85was still running at 60.129 s and 60.222 s while this change769bbea7exited 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, main514591a3against this change99f46021, agrees (required stop result 0 of 2 against 2 of 2, median 0.541 s).tests/test_windows_stop.pypassed 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; head020bb0ed6a5e34ff175dc365f78b6f7dd8309db0; whole game-free suite on this head:555 passed, 1 failed, 16 skipped(main543846ebb08ded4ce75d364403bc4dcf24e83e85: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 @
769bbea7e5Earlier whole-suite results, each at its own commit: Historical reviewed head
98a6771ad283c5cc50f4ed5fdca3ddb826056f3f: 506 passed, 2 failed, 15 skipped; its base0c74253d4c6ed08d57e4f3aa8ce8634c4c017085: 505 passed, 2 failed, 15 skipped.Windows stop results, 2026-11-13
Baseline: main @
cf605c85Hardware: 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 startingtaskkilland 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
taskkillin that same interactive session. Require both ordered stop lines below and observed game exit 0. Record a no-exit result separately before using controlquitto clean it up. A successful return fromtaskkillalone 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
cf605c85then this change769bbea7, twice in turn. After a plaintaskkill, 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.pypassed on Windows at769bbea7with its seven PASS lines.cf605c85769bbea7The first pair of runs, at the commits before the carry (main
514591a3, this change99f46021), 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 basefbd42024. Those two mains have identicalhost/display.c,host/control.c,host/hos_relaunch.candhost/hos_main.cstop 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, not769bbea7.514591a399f46021taskkillitself returned 0 in all four runs. Both main processes needed a separately recorded controlquit, 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:
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:The console-close attempt posted
WM_CLOSEto the handle fromGetConsoleWindow. The call was accepted, but no console-close request line or game exit followed within the observation. A separate controlquitthen 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, andpython -I -B tests/test_control.py.1ef93e796Regression comparisons are against the reviewed source where possible, or one explicit minimal reversion, not relabelled whole-build comparisons:
98a6771adhost/display.c98a6771adhost/control.cThe same seven lines were also printed by
tests/test_windows_stop.pyat99f46021on 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.The earlier
f41db065cand830b2c59suites 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) andHOS_CONTROL(control quit's close tail) do.HOS_HEADLESStaskkilland 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.HOS_CONTROLNo 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 to769bbea7in 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
830b2c5908afa820b8a309b93c44e92a2f470a7dreports 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.cwas 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 at99f46021are 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
020bb0ed6a5e34ff175dc365f78b6f7dd8309db0also 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 stamp8a5c6ee8), using the verified target-neutral C from lift5c175a4727d82f85e425e85400dca17fea0750fbrather 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 stamp335aaaed), using the verified target-neutral C from lift76699aad3a6bdc4f75520c0f2c9d9c80d5731a5frather 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: At99f46021d41e3b20e6e6e97113d54e5000289514, 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 stampcddfa164), using the verified target-neutral C from the freshfbd420241alift 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:
taskkillwithout/Fand the stop fixture, expecting game exit 0 with both stop lines and seven PASS lines (T-U5KN; by hand).0xC000013Ameans 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:
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.gpu/vk/, soMKWVK_API_VERSIONstays as it is.host/,docs/andtests/only).0xC000013Aare both incomplete outcomes (docs/development.mdnames both).Issues
See #83
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.514591a3then this PR99f46021, 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 maincf605c85and this PR769bbea7: 0.588 and 0.534 s, median 0.561 s. This measures the stop fix, not game speed.mainand passing here. The original installation regression remains; review fixes also reject the reviewed sources or the explicit minimal reversions listed above.tests/that reads changed source updated in this PR, not weakened.020bb0ed6a5e34ff175dc365f78b6f7dd8309db0(under Testing); nothing was run on Windows at this head, so UTF-8 path behavior at run time is not claimed.New on this forge; not opened on GitHub.
Assisted-by: GPT-6 Astra
Co-Authored-By: GPT-6 Astra [email protected]
830b2c590898a6771ad2Carried onto main
0c74253d4(head98a6771ad): 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.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_ENDSESSIONwaits for the confirmed case. The message wait has a cap on each batch. Linux is unaffected:windows_stop.cis all inside#ifdef _WIN32, andnx2/build.pyglobshost/*.c, so Linux compiles it as an empty file and needs no change to the source list. A concurrent controlquitis also safe:play_cache_saveanddlss_fg_closealready take their own locks. A cut-off cache save loses data without corrupting anything, becauseplay_file_writewrites a.tmpand then moves it into place.Changes requested before this can merge (details inline):
ExitProcess, and the comment and docs say it does.ExitProcessends every other thread, the watchdog included, before the DLL detach runs. A hang in the driver's unload or in anatexithandler is therefore never cut off at 4 s.vk_main.cppalready avoidsexit()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 onExitProcess.WM_CLOSE(taskkillwithout/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 andWM_ENDSESSION.display_start_failedmakes it fatal. It also logs a meaninglessGetLastErrorafter 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:
mainbox is out of date.mainis nowfdc2840bf, 4 commits past the base0c74253d4. Among this PR's files, those commits only touchdocs/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 test checks read sensibly.
test_menu_restart.pystill findshos_log_flush→relaunch→ExitProcessin 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-inExitProcessnever stops the watchdog.@ -2312,3 +2313,2 @@hos_log("control: exiting");hos_log_flush();ExitProcess(0);hos_window_closed_exit();Nit: control
quitnow also logsdisplay: window closed, exitingfromhos_window_closed_exit, right aftercontrol: exiting, although no window was closed. It also honoursrelaunch_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.@ -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");This makes a best-effort helper fatal: if the events, either thread or the 4 s ready-wait fail, every
HOS_HEADLESSrun on Windows now exits with code 1, where before it ran normally.stop_messagesalready 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: logstop: windowless stop route unavailable; use the control bridgeand return.Also, after the
WaitForSingleObjecttimeoutGetLastError()holds nothing relevant, sodisplay_start_failedlogs 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");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.This isn't true for
ExitProcess.ExitProcess(RtlExitUserProcess) first terminates every other thread in the process,stop_messagesincluded, and only then runs DLL_PROCESS_DETACH and the CRT'satexit. So once the worker reachesExitProcess(0)inhos_window_closed_exit, nothing is left to callTerminateProcess(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 avoidsexit()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 ofhos_window_closed_exitthat doesn't callExitProcess.@ -0,0 +10,4 @@void rx_close_asked(void);void hos_window_closed_exit(void);enum { STOP_WAIT_MS = 4000, STOP_TIMEOUT_EXIT = 124 };This 4 s kill applies to every route, but the OS sets a deadline on only some of them.
WM_CLOSE(plaintaskkill) 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 inmkwvk_close_askedis lost. That close can take more than 4 s:dlss_fg_closealone 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 tofinish 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);Nit: this sleeps a full
STOP_WAIT_MSfrom the moment this event arrived, not until the shared deadline. On a first request, the handler's return (after which Windows ends the process withSTATUS_CONTROL_C_EXIT, 0xC000013A) and the watchdog'sTerminateProcess(124)fall in the same millisecond. Either exit code can win.Sleep(stop_remaining())matches whatWM_ENDSESSIONdoes. The docs should also say that 0xC000013A is a possible incomplete exit, next to 124.98a6771ad299f46021d4Thank 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 head99f46021don mainfbd420241:hos_close_finish()returns after the shared close/log tail; the Windows-event worker then callsTerminateProcess(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.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.Sleep(stop_remaining()). Docs and tester instructions now list both 124 and0xC000013Aas incomplete outcomes. The old full-duration sleep fails the repeat-event regression.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.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.
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 plaintaskkillhas 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 reworked code builds on both platforms. At
99f46021the 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.Updated to head
769bbea7eon maincf605c85b; 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 inhost/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.cwas 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.pyis not repaired by this carry.The missing Windows evidence is now in the description, at the commits actually run: main
514591a30d707fe9f3ad31eae148c3cc1e750bffagainst this PR99f46021d41e3b20e6e6e97113d54e5000289514. 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
taskkillwithout/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
99f46021with 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. PostingWM_CLOSEto itsGetConsoleWindowhandle 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.99f46021d4769bbea7e5The 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
cf605c85and this change769bbea7both built natively there and run twice in turn: after a plaintaskkill, 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.pypassed there at769bbea7with its seven PASS lines. That matches the earlier result at99f46021(0.569 s and 0.514 s).At
769bbea7the 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.
WIP: fix(runtime): handle windowless Windows stop requeststo fix(runtime): handle windowless Windows stop requests769bbea7e532703860ddCarried onto main
5e072fc8c; new head32703860d. 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 owntests/test_pad_layout.py,tests/test_module_ids.pyandtests/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.The pushed head
32703860ddfd21307a4904a3ce56d1217f888f86is 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.fix(runtime): handle windowless Windows stop requeststo WIP: fix(runtime): handle windowless Windows stop requestsCarried onto main
543846ebb; new head020bb0ed6. 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.32703860dd020bb0ed6aWIP: fix(runtime): handle windowless Windows stop requeststo fix(runtime): handle windowless Windows stop requestsBuilt at the current head
020bb0ed6a5e34ff175dc365f78b6f7dd8309db0for 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.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:hos_close_finish()and ends withTerminateProcess(GetCurrentProcess(), 0), so it never enters detach. The OS-deadline monitor lives in the message thread and callsTerminateProcess(..., 124)itself. Correct.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 onlystop_remaining().GetLastError. A partial start releases the idle worker with reason 0 and keeps handles alive if the worker has not exited.hos_close_finish(), no relaunch check and no window-close log.hos_window_closed_exit()still flushes before a relaunch andExitProcess.0xC000013Aexit 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
taskkilland 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 unlessHOS_HEADLESSis set. The stop route is opt-in and failure is nonfatal.Small note, no change needed: the
stop_messagesthread logs throughhos_logonly 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.
mooki referenced this pull request2026-11-15 22:24:10 +00:00