Skip to content

The agent that grows with you

fix(desktop): keep Windows update hand-off hidden

joaomarcosf58605b5c63c
diff --git a/apps/desktop/electron/updater-process.test.ts b/apps/desktop/electron/updater-process.test.ts
index dcbe0914dc4..a53acb437ee 100644
--- a/apps/desktop/electron/updater-process.test.ts
+++ b/apps/desktop/electron/updater-process.test.ts
@@ -219,7 +219,7 @@ test('resolveUpdateScriptHandoff is Windows-only (POSIX updates in place)', () =
assert.equal(handoff, null)
})
-test('wrapHandoffForDetachedConsole routes through cmd start with own console', () => {
+test('wrapHandoffForDetachedConsole uses start /b without creating a console', () => {
const root = String.raw`C:\Users\hermes\AppData\Local\hermes\hermes-agent`
const expected = path.join(root, 'scripts', 'desktop-update', 'windows.ps1')
@@ -238,7 +238,7 @@ test('wrapHandoffForDetachedConsole routes through cmd start with own console',
'/c',
'start',
'',
- '/min',
+ '/b',
'powershell',
'-NoProfile',
'-ExecutionPolicy',
diff --git a/apps/desktop/electron/updater-process.ts b/apps/desktop/electron/updater-process.ts
index 6c2d18ab0b6..4b9e4583117 100644
--- a/apps/desktop/electron/updater-process.ts
+++ b/apps/desktop/electron/updater-process.ts
@@ -139,12 +139,12 @@ export function resolvePosixScriptHandoff(
* the launch side). The same spawn with a visible console, or non-detached,
* runs fine — so unit tests and foreground use hide the bug.
*
- * `cmd /c start "" /min powershell ...` was the variant that survived the
- * full detached+hidden production shape in testing: `start` allocates the
- * child its own (minimized) console and fully detaches it from cmd.exe,
- * which exits immediately. The spawned pid is therefore the WRAPPER's —
- * callers must not use it as a marker owner (the script claims the marker
- * itself with its own $PID).
+ * `cmd /c start "" /b powershell ...` is the production shape: `start /b`
+ * keeps the child in the wrapper's hidden console while still returning
+ * immediately, so the script outlives cmd.exe without creating a visible
+ * console window. The spawned pid is therefore the WRAPPER's — callers must
+ * not use it as a marker owner (the script claims the marker itself with its
+ * own $PID).
*/
export function wrapHandoffForDetachedConsole(
handoff: UpdateScriptHandoff,
@@ -155,7 +155,7 @@ export function wrapHandoffForDetachedConsole(
} {
return {
command: 'cmd.exe',
- args: ['/d', '/s', '/c', 'start', '', '/min', handoff.command, ...handoff.args, ...extraArgs]
+ args: ['/d', '/s', '/c', 'start', '', '/b', handoff.command, ...handoff.args, ...extraArgs]
}
}
diff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1
index 0dfdb9bb600..60aa605018f 100644
--- a/scripts/desktop-update/windows.ps1
+++ b/scripts/desktop-update/windows.ps1
@@ -17,7 +17,7 @@
# OS component -- is "frozen".
#
# CONTRACT (keep in sync with apps/desktop/electron/main.ts):
-# cmd /d /s /c start "" /min powershell -NoProfile -ExecutionPolicy Bypass
+# cmd /d /s /c start "" /b powershell -NoProfile -ExecutionPolicy Bypass
# -File scripts\desktop-update\windows.ps1
# -InstallRoot <path> repo checkout (HERMES_HOME\hermes-agent)
# -Branch <ref> branch to update against
@@ -61,8 +61,9 @@ if (-not $SelfTestUi -and -not $SelfTestPipeDrain -and -not $InstallRoot) {
}
$ErrorActionPreference = "Continue"
-# Foreground helpers: the script is spawned via `cmd start /min`, so its
-# WinForms window comes up backgrounded unless we explicitly claim focus --
+# Foreground helpers: the script is spawned via `cmd start /b` and inherits
+# the wrapper's hidden console, so its WinForms window comes up backgrounded
+# unless we explicitly claim focus --
# and after the update we must hand focus TO the relaunched Desktop (a
# WMI-spawned process starts unfocused). AllowSetForegroundWindow lets us
# pass our foreground right on to the new Hermes.exe pid.
@@ -438,7 +439,7 @@ function Show-ProgressWindow {
$form.Controls.Add($title)
$form.Controls.Add($sub)
$form.Show()
- # `cmd start /min` spawned us backgrounded, so the card comes up
+ # `cmd start /b` spawned us backgrounded, so the card comes up
# behind everything without one explicit activation. Claim it ONCE
# (so the user knows the update started), then never again — the
# window is decoration and competes with nothing (no TopMost).