Skip to content

startup: close the rendered session from the output window - #2344

Open
SuperCraft3M wants to merge 2 commits into
R0Y00:mainfrom
SuperCraft3M:codex/startup-output-window
Open

SuperCraft3M wants to merge 2 commits into
R0Y00:mainfrom
SuperCraft3M:codex/startup-output-window

Conversation

@SuperCraft3M

@SuperCraft3M SuperCraft3M commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Change

Closing the output window of a rendered run.ps1 session signals its debugger. The debugger owns the Windows job, terminates the child and verifies that the process handle becomes signaled before returning. Minimize keeps the session active. In a direct shim host, Close hides the output and the host remains active.

The source-built presenter exercises minimize, restore and Close in both modes. The managed probe requires a debugger return and a zero child exit. The direct probe verifies that the window is hidden and the host can continue issuing presents.

Verification

Changes at 0465ba6d on 18f2f85c. Release, MSVC 19.44.35230, Windows 11 build 26300.9711. Hardware used an NVIDIA RTX 4070 with driver 32.0.16.2114. The D3D12 debug layer was unavailable.

cmake --build --preset release --target startup_present_producer --parallel 3
ctest --preset release --no-tests=error -R '^(startup_output_window_close|startup_present_producer_(warp|hardware)|startup_run_ps1)$' --output-on-failure

4 passed, 0 failed, 0 skipped. The launcher check ran on Windows PowerShell 5.1 and PowerShell 7.

AI-assisted (Codex).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 5633a0d3f2b75f32ffcfb7a536d502d0f05fe9f5 (Linux host; no PowerShell, no Windows).

Commands executed locally (in a worktree of the PR head):

git diff --stat origin/main...HEAD            -> 6 files, +84/-10
python3 tests/docs_links_check.py             -> Checked 19 Markdown files and 453 links
python3 tests/bidi_controls_check.py          -> no bidirectional controls
git diff --check origin/main...HEAD           -> clean
python3 tests/startup_run_ps1_check.py        -> "text only: not a Windows host" (0 failed)

CI at review time: Windows and Linux jobs still pending. The PR is mergeable.

Findings: P1=0, P2=0.

Read-through:

  • run.ps1: -not $env:X2W_HIDE_TITLE_WINDOW treats the string "0" as set (non-empty string is truthy), so an explicit 0 still opts out. The new test case with -Render -LiveConsole and hide_env="0" covers that. --console 0 matches debug_launch.py (opts.get("--console", "1") == "1").
  • d3d12_present.inl: WM_CLOSE now calls ExitProcess(0) after logging. Minimize is unaffected because it goes through WM_SYSCOMMAND. Nit: the exit skips any flush of the shader cache or logs, which the PR text already says is intended.
  • startup_present_producer.cpp (window-close): the fixture finds the output window by class and PID, checks that the guest window is hidden, then minimize, restore and SC_CLOSE. Reaching the 5 s sleep and returning 19 means the process did not exit, so the test fails closed. startup_output_window_close runs with the new CMake line, which links user32 and adds the src include path.
  • startup_run_ps1_check.py: the expectations (--console 0 unless -LiveConsole, and the inherited env value) match run.ps1.

Nits:

  • The -Translate path only gets the --console 0 and hide default through $Render. That is correct, since -Translate needs -Render. The test's rendering = translate or ... is a slightly looser model than the script, but it is harmless.

Not done:

  • No mutation run. The launcher test needs PowerShell and the close probe needs Windows, and neither is available on this host. The claimed Win2025 results in the PR body were not re-run here.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presenter is inside the shared D3D12 shim. WM_CLOSE currently calls ExitProcess in every host that creates that window, including hosts launched without run.ps1. That also runs DLL detach after stopping the other threads, which can hang if a stopped thread holds a lock needed by detach. Keep session shutdown owned by the launcher or an explicitly enabled session owner. In other hosts, closing the presenter should leave the host alive.

Please keep the existing minimize check and add both close cases: a managed source-built child whose process handle becomes signaled and whose launcher returns, and a direct shim host that stays alive on presenter close. The window visibility and live-console change can proceed independently if you want to land that first. Microsoft ExitProcess documentation

@KelboLive

Copy link
Copy Markdown
Contributor

APPROVED. Closes rendered session from the output window.

@SuperCraft3M
SuperCraft3M force-pushed the codex/startup-output-window branch from 5633a0d to 0465ba6 Compare November 25, 2026 21:30
Resolved conflicts:
- src/startup_stubs/d3d12_present.inl: kept main's plane-surface present_to_window and added the branch's output_closed check to its early return.
- tests/startup_run_ps1_check.py: kept the branch's --managed-window expectation and main's longer debugger record; main's native-shader case also runs with -Render, so it expects --managed-window too.
- tools/startup/debug_launch.py: kept main's grab_window/capture_window split and capture-thread shutdown, with the branch's "not window_close" condition on the final capture.
- tools/startup/run.ps1: pass both --capture-every and --managed-window arguments.
@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

I merged main 38129ba3 into this branch as 44f14769 (a merge commit on top of 0465ba6d; no rebase and no force-push). It also merges cleanly with the current main 86beae95.

Conflicts and how I resolved them.

  • src/startup_stubs/d3d12_present.inl: I kept main's plane-surface present_to_window and added this branch's output_closed check to its early return:
    if (p.failed || !queue || !steps || !count || !plane_surfaces || InterlockedCompareExchange(&output_closed, 0, 0)) return false;
  • tests/startup_run_ps1_check.py: I kept this branch's --managed-window expectation and main's longer debugger record. main's native-shader case also runs with -Render, so the condition is now if "-Render" in switches or translate or native:.
  • tools/startup/debug_launch.py: I kept main's grab_window/capture_window split and capture-thread shutdown. The final capture keeps this branch's condition, if exit_code is None and not window_close:.
  • tools/startup/run.ps1: both argument lists are passed, @traceArgs @captureArgs @windowArgs.

What I ran. I built the whole tree in dev and release, then ran (under the shared GPU lock, -j 1):

ctest --test-dir out/build/<preset> --no-tests=error -j 1 --output-on-failure -R '^(startup_output_window_close|startup_present.*|startup_plane.*|startup_debug.*|startup_hook.*|startup_run_ps1.*|startup_run_sh.*|startup_host_cpu_debug.*|startup_window_capture.*|startup_launch.*|startup_runtime_target.*)$'
  • 35 of 36 pass in Debug and in Release /O2.
  • startup_run_sh reports a capability skip (77), as on every Windows host.
  • startup_run_ps1 failed on my first resolution of its check, because an assignment was mis-indented. I fixed that before committing. On 44f14769 it reports 0 failed with both powershell and pwsh.
  • git diff --check origin/main...HEAD is clean.

This needs a review from someone other than me before it can be merged.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10.

This reply was AI-assisted.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 44f14769 (0465ba6d plus a merge of main) trial-merged over current main 7364e6a9. The merge is clean and git diff --cached --check is clean.

R0Y00's request on 5633a0d3. 0465ba6d answers all three points:

  • The shared presenter no longer ends the process. WM_CLOSE calls neither ExitProcess nor ShowWindow(SW_MINIMIZE). If X2W_SESSION_CLOSE_EVENT names an event it can open and set, it returns, and the launcher ends the run. Otherwise it hides the output window, stops the hide-title timer, shows any hidden title windows again, and sets output_closed so present_to_window refuses from then on. The host keeps running.
  • The launcher owns the session's end. debug_launch.py --managed-window 1 creates a random Local\X2W-session-close-<uuid> event and passes its name only to its child; an inherited value is dropped first. When the event is set, the launcher calls TerminateJobObject(job, 0), which skips the DLL detach R0Y00 pointed at. It then keeps reading debug events for up to 10 s, until EXIT_PROCESS. It returns 2 if the process handle hasn't signalled within 2 s.
  • run.ps1 passes --managed-window 1 only with -Render. -Translate and -NativeShaders both need -Render.
  • Tests: both close cases now have one. window-close in startup_present_producer minimizes, restores and closes the window, then checks the direct host survives and the managed child is ended. The existing minimize check is kept.

The merge of main (44f14769, three files):

  • d3d12_present.inl: present_to_window keeps main's plane-steps signature and adds the output_closed check. That's right.
  • startup_run_ps1_check.py: the condition becomes "-Render" in switches or translate or native. The or native part is needed: the native case passes -Render -NativeShaders inside run_case, not through switches. The tuple keeps main's fields.
  • debug_launch.py: main moved capture_window out of this spot. The merge keeps main's version and adds this PR's and not window_close guard.

What I ran. I did a full build in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -E '(_hardware$|startup_audio_)' -R '^(startup_output_window_close|startup_present.*|startup_run_ps1|startup_debug.*|startup_title_window.*|startup_overlay.*|startup_hide.*)$'
# with X2W_TEST_DEBUG_LAYER=1, one at a time
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_present.*_hardware$'
  • Without _hardware: 21 of 21 pass in each preset, including startup_output_window_close and startup_run_ps1.
  • _hardware: startup_present_producer_hardware and startup_present_view_hardware pass in each preset.
  • Full non-hardware suite (dev, -j 6 -E '(_hardware$|startup_audio_)'): 1977 of 1980 pass. The other three are startup_inflate, shader_sgd5_effects_cli_check and pixel_aot_comparisons_warp. All three timed out under load and pass when rerun alone with -j 1.

Mutants. For each, I rebuilt dev where needed and ran startup_output_window_close, startup_run_ps1 and startup_present_producer_warp:

Mutant Result
Close minimizes instead of hiding killed (startup_output_window_close)
launcher ignores the close event killed (startup_output_window_close)
event name not passed to the child killed (startup_output_window_close)
no grace wait after TerminateJobObject killed (no exit 0x00000000 in events.txt)
run.ps1 never passes --managed-window killed (startup_run_ps1)
present_to_window ignores output_closed survives
direct Close doesn't show the title windows again (title_hider.step removed) survives
hide-title timer kept after Close survives
launcher returns 0 when the child doesn't signal exit survives
an inherited X2W_SESSION_CLOSE_EVENT not dropped survives (the test drops it itself)

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking.

  1. After Close, a direct host goes down the "not shown" path. present_to_window refuses, so shown_in_window is false. The title windows the hider hid come back, and every sixth frame does read_back_presented and draw_overlay into them. That's a reasonable way to keep a direct host visible, but no test pins it, and the docs line says only "Close hides the output". A direct-mode check that a present after Close doesn't reach the output window, and that a hidden title window is shown again, would pin the first two survivors.
  2. The launcher's "process did not signal exit" path (return 2) is unpinned. It can't be reached with the current child. A note in the PR text that it's only a safeguard would be enough.
  3. startup_output_window_close sets SKIP_RETURN_CODE 77, but nothing in it returns 77. That's harmless, but it may mislead a reader.

Verdict: approve on 44f14769. R0Y00's changes request on 5633a0d3 still stands, so this needs R0Y00's re-review before it can merge.

Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088; D3D12 WARP; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; debug layer on for the hardware runs.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 44f14769.

This reply was AI-assisted.

@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner

I verified the earlier close handling feedback with 44f1476 integrated over main 4d7265c (local tree b4db0b8895ee06c4109f4c2b1ecffa9af90813f5). The only conflict is in tools/startup/run.ps1. Keep #2867's scoped Continue and script:debuggerExit capture, and append @windowArgs to the debugger call inside that scope. The existing -Render guard and managed-window argument stay.

Release /O2: all four checks passed with no skips. The synthetic managed presenter exits through the debugger, the direct presenter hides and keeps the host alive, and minimize/restore still works. The launcher fixture passed in Windows PowerShell 5.1 and PowerShell 7, including stderr status handling and the managed flag.

cmake --build <release-build> --target startup_present_producer d3d12_xs_shim
ctest --test-dir <release-build> --no-tests=error --output-on-failure -j 1 -R "^(startup_output_window_close|startup_present_producer_(warp|hardware))$"
python -B tests/startup_run_ps1_check.py

Windows 11 26200.9974, inbox WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. Please merge current main into this PR and retain both launcher behaviors. I can then recheck and update my earlier review on the published head.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for the close-handling rework. I reviewed head 44f14769 against current main (1f07b2c1). The code answers R0Y00's changes request on 5633a0d3 (grep -c ExitProcess src/startup_stubs/d3d12_present.inl → 0), but one thing still blocks the merge:

  1. Please merge current main and resolve tools/startup/run.ps1 as R0Y00 asked at 02:50Z. git merge-tree --write-tree 1f07b2c1 44f14769 exits 1 with CONFLICT (content): Merge conflict in tools/startup/run.ps1. Keep startup: preserve debugger stderr and exit status #2867's scoped & { $ErrorActionPreference = "Continue" ... $script:debuggerExit } block and append @windowArgs after @captureArgs inside it. Please merge rather than rebase. On a scratch resolution done that way, startup_run_ps1_check.py (text-only on Linux), docs_links_check.py and bidi_controls_check.py pass. R0Y00 then needs to re-review, because the changes request still stands.

Also worth fixing:

  • CI runs none of the affected tests. The pr test preset's regex matches none of startup_output_window_close, startup_run_ps1 or startup_present_producer_warp, and grep -c startup_output_window_close on the Windows job log → 0. On Linux, a mutant that drops @windowArgs from run.ps1 still passes startup_run_ps1_check.py (0 failed (text only: not a Windows host)). That is the conflicted line, so please post Windows startup_run_ps1 (powershell and pwsh) and startup_output_window_close runs on the new head.
  • Nothing pins the direct-host case. Its last step, present(), is ok(call(queue, 32, ...)) && finish(), which observes the queue fence and not the window. That leaves three of pigalot's surviving mutants unpinned: present_to_window ignores output_closed, title_hider.step removed, and the hide-title timer kept. Asserting that the output window gets no new frame after Close, and that a hidden title window is shown again, would pin them.
  • Minor: the process did not signal exit path (return 2) can't be reached with the test child, so please say in a comment or the PR text that it is only a safeguard. SKIP_RETURN_CODE 77 is set, but the check never returns 77 (grep -c 77 → 0). --managed-window and X2W_SESSION_CLOSE_EVENT appear in neither debug_launch.py's docstring nor docs/ (0 and 0). Dropping an inherited X2W_SESSION_CLOSE_EVENT is pinned only by the test's own env.pop; a case that sets a stale name before launch would pin it.

Environment: Linux, static review of git objects, git merge-tree, a scratch merge (never pushed) and the CI job logs. I did no Windows, WARP or GPU run.

This comment was AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants