Skip to content

Commit 6cf4b56

Browse files
fix(engine): a render on Windows opens no console windows (#6613)
* ci(windows): probe that a render opens no visible window * ci(windows): the probe names what opened each window * ci(windows): the probe spawns each binary alone, with and without detached * ci(windows): the probe logs the processes started during the render * ci(windows): the probe also spawns Chrome one consoleless hop down * ci(windows): the probe logs each child started without windowsHide * ci(windows): the probe logs every child process with its windowsHide and detached * fix(engine): Chrome keeps the CLI's console on Windows, so a render opens no window * fix(cli): every child the CLI starts on Windows is hidden unless it opts out * ci(windows): the probe bisects Chrome's flags and keeps each command's output * ci(windows): the probe names the Chrome process behind each window * ci(windows): the probe loads a page in Chrome directly and one hidden hop down * ci(windows): the probe prints the Chrome main command line and renders with the reporter's flags * ci(windows): the probe narrows the CLI's Chrome arguments to the ones that open a window * ci(windows): the probe launches the CLI's Chrome arguments one hidden hop down * ci(windows): the probe launches Chrome through the engine's browser pool * ci(windows): the probe varies what the engine passes to Puppeteer * fix(engine): renders on Windows launch Chrome with a Puppeteer that keeps it attached * refactor(cli): hideChildConsoles copies its arguments and keeps one comment line
1 parent 1d97ed2 commit 6cf4b56

22 files changed

Lines changed: 356 additions & 65 deletions
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Runs agent-facing commands from a launcher with no console (like an app that starts an agent), and fails if any
2+
# of them opens a visible top-level window.
3+
param([Parameter(Mandatory)][string]$Cli, [Parameter(Mandatory)][string]$Project)
4+
$ErrorActionPreference = 'Stop'
5+
6+
Add-Type @'
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Runtime.InteropServices;
10+
using System.Text;
11+
public static class Windows {
12+
delegate bool EnumProc(IntPtr h, IntPtr p);
13+
[DllImport("user32.dll")] static extern bool EnumWindows(EnumProc f, IntPtr p);
14+
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
15+
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
16+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetWindowText(IntPtr h, StringBuilder s, int n);
17+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetClassName(IntPtr h, StringBuilder s, int n);
18+
public static List<string[]> Visible() {
19+
var rows = new List<string[]>();
20+
EnumWindows((h, p) => {
21+
if (!IsWindowVisible(h)) return true;
22+
uint pid; GetWindowThreadProcessId(h, out pid);
23+
var t = new StringBuilder(256); var c = new StringBuilder(256);
24+
GetWindowText(h, t, 256); GetClassName(h, c, 256);
25+
rows.Add(new[] { h.ToString(), pid.ToString(), c.ToString(), t.ToString() });
26+
return true;
27+
}, IntPtr.Zero);
28+
return rows;
29+
}
30+
}
31+
'@
32+
33+
function Snapshot {
34+
$seen = @{}
35+
foreach ($w in [Windows]::Visible()) {
36+
$proc = Get-Process -Id ([int]$w[1]) -ErrorAction SilentlyContinue
37+
$seen[$w[0]] = [pscustomobject]@{ Process = $proc.ProcessName; Id = $w[1]; Class = $w[2]; Title = $w[3]; Cmd = '' }
38+
}
39+
$seen
40+
}
41+
42+
# Starts `node launcher.mjs <cli> <cwd> <seconds> <args...>` and reports every window that appears meanwhile.
43+
function Watch([string]$Name, [int]$Seconds, [string[]]$CliArgs) {
44+
$baseline = Snapshot
45+
$p = Start-Process -FilePath node -ArgumentList (@($launcher, $Cli, $Project, $Seconds) + $CliArgs) -WindowStyle Hidden -PassThru
46+
$found = @{}
47+
while (-not $p.HasExited) {
48+
foreach ($entry in (Snapshot).GetEnumerator()) {
49+
if (-not $baseline.ContainsKey($entry.Key) -and -not $found.ContainsKey($entry.Key)) {
50+
$row = $entry.Value
51+
if ($row.Process -match 'chrome') {
52+
$q = Get-CimInstance Win32_Process -Filter "ProcessId=$($row.Id)" -ErrorAction SilentlyContinue
53+
$parent = if ($q) { Get-CimInstance Win32_Process -Filter "ProcessId=$($q.ParentProcessId)" -ErrorAction SilentlyContinue }
54+
$row.Cmd = "pid=$($row.Id) parent=[$($parent.Name) $($parent.ProcessId) main=$((($parent.CommandLine -replace '^.*chrome-headless-shell.exe"? ',''))) ] cmd=[$((("$($q.CommandLine)") -replace '^.*chrome-headless-shell.exe"? ','').Substring(0, [Math]::Min(260, ("$($q.CommandLine)" -replace '^.*chrome-headless-shell.exe"? ','').Length)))]"
55+
}
56+
$found[$entry.Key] = $row
57+
}
58+
}
59+
Start-Sleep -Milliseconds 50
60+
}
61+
$p.WaitForExit()
62+
Write-Host ("{0,-10} exit={1} new windows={2}" -f $Name, $p.ExitCode, $found.Count)
63+
if ($p.ExitCode -ne 0) { Get-Content (Join-Path $env:RUNNER_TEMP "command.log") -Tail 12 | ForEach-Object { Write-Host " | $_" } }
64+
$found.Values | ForEach-Object { Write-Host " $($_.Process) class=$($_.Class) title=[$($_.Title)] $($_.Cmd)" }
65+
[pscustomobject]@{ Name = $Name; Exit = $p.ExitCode; Windows = $found.Count }
66+
}
67+
68+
# The launcher has no console and no window; windowsHide only reaches the CLI itself, never what the CLI starts.
69+
$launcher = Join-Path $env:RUNNER_TEMP 'launch-cli.mjs'
70+
@'
71+
import { spawn } from "node:child_process";
72+
import { openSync } from "node:fs";
73+
const [cli, cwd, seconds, ...args] = process.argv.slice(2);
74+
const log = openSync(process.env.RUNNER_TEMP + "\\command.log", "w");
75+
const child = spawn(process.execPath, [cli, ...args], { cwd, windowsHide: true, stdio: ["ignore", log, log] });
76+
const stop = Number(seconds) > 0 ? setTimeout(() => child.kill(), Number(seconds) * 1000) : undefined;
77+
child.on("exit", (code) => { clearTimeout(stop); process.exit(code ?? 0); });
78+
'@ | Set-Content -Encoding utf8 $launcher
79+
80+
81+
$runs = @(
82+
(Watch 'render' 0 @('render', '--fps', '30', '--quality', 'draft', '--workers', '2', '--output', 'renders/probe.mp4')),
83+
(Watch 'check' 0 @('check')),
84+
(Watch 'check-warm' 0 @('check')),
85+
(Watch 'snapshot' 0 @('snapshot', '--frames', '2')),
86+
(Watch 'doctor' 0 @('doctor')),
87+
(Watch 'preview' 20 @('preview', '--port', '3571'))
88+
)
89+
$bad = $runs | Where-Object { $_.Windows -gt 0 }
90+
if ($bad) { throw "windows opened by: $(($bad | ForEach-Object Name) -join ', ')" }
91+
$failed = $runs | Where-Object { $_.Name -in @('render', 'snapshot') -and $_.Exit -ne 0 }
92+
if ($failed) { throw "commands failed: $(($failed | ForEach-Object Name) -join ', ')" }
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Windows window probe
2+
3+
permissions:
4+
contents: read
5+
6+
env:
7+
HYPERFRAMES_NO_TELEMETRY: "1"
8+
9+
on:
10+
pull_request:
11+
paths:
12+
- .github/workflows/windows-window-probe.yml
13+
- .github/scripts/windows-window-probe.ps1
14+
workflow_dispatch:
15+
16+
jobs:
17+
probe:
18+
name: Agent commands open no window on windows-latest
19+
runs-on: windows-latest
20+
timeout-minutes: 30
21+
steps:
22+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
23+
- uses: ./.github/actions/install-ffmpeg-windows
24+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
25+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
26+
with:
27+
node-version: 22
28+
- run: bun install --frozen-lockfile --linker=hoisted
29+
shell: pwsh
30+
- name: Build the CLI
31+
shell: pwsh
32+
run: |
33+
bun run --filter '@hyperframes/{parsers,lint,studio-server}' build
34+
bun run --cwd packages/core build
35+
bun run --filter @hyperframes/player build
36+
bun run --filter @hyperframes/studio build
37+
bun run --filter @hyperframes/inspector build
38+
bun run --filter @hyperframes/cli build
39+
- name: Scaffold the canary
40+
shell: pwsh
41+
env:
42+
HYPERFRAMES_SKIP_SKILLS: "1"
43+
run: |
44+
$dir = "$env:RUNNER_TEMP\probe"
45+
New-Item -ItemType Directory -Force -Path $dir | Out-Null
46+
Set-Location $dir
47+
node "$env:GITHUB_WORKSPACE\packages\cli\dist\cli.js" init canary --example blank --non-interactive --skip-skills
48+
Copy-Item "$env:GITHUB_WORKSPACE\.github\workflows\fixtures\windows-canary.html" "canary\index.html" -Force
49+
- name: Install Chrome before watching
50+
shell: pwsh
51+
run: |
52+
Set-Location "$env:RUNNER_TEMP\probe\canary"
53+
node "$env:GITHUB_WORKSPACE\packages\cli\dist\cli.js" browser ensure
54+
- name: Run the commands while watching for windows
55+
shell: pwsh
56+
run: .github/scripts/windows-window-probe.ps1 -Cli "$env:GITHUB_WORKSPACE\packages\cli\dist\cli.js" -Project "$env:RUNNER_TEMP\probe\canary"

0 commit comments

Comments
 (0)