Repository navigation
fix(installer): keep a failed Windows install from closing the user's terminal - #4298
Conversation
The Windows installer's last line told new users to type /hub, which the terminal UI does not have, so their first command went to the model as a question. It now says /agents, matching install.sh, and a test checks every /command in both closing banners against the TUI's command list. Fixes amd#4231
… terminal The documented `irm | iex` runs install.ps1 inside the user's own PowerShell session, so every failure's `exit 1` closed their window and took the "Fix:" hint with it, and a finished run left $ErrorActionPreference = Stop and shadowed Write-Error/Write-Warning in their session. The script now runs in its own scope, fails with `throw`, and names its output helpers Write-GaiaError/Write-GaiaWarning. `pwsh -File install.ps1` still exits 1 on failure. Fixes amd#4224
Verdict: Request changesThis makes a failed One failure path still closes the terminal, and it's the first one a user hits. If uv isn't installed yet and installing it fails, GAIA hands control to uv's own installer, which ends by quitting outright — that quit takes the user's window down with it, along with the "install uv manually from …" hint, exactly as before. The fix is to run uv's installer as a separate process and check its result, so its exit can't reach the user's session. The new guard test only scans GAIA's own script text, so it can't see this; worth also asserting the installer never runs a downloaded script inside its own scope. Everything else checks out: no remaining hard exits, the renamed helpers are applied consistently at all 24 call sites, a checksum mismatch still aborts, and temp-directory cleanup still runs on the new failure path. The Real-world evidenceNo Both of the PR's headline claims hold. I also reproduced the remaining uv path above: a nested 🔍 Technical details🟡 Important — uv's installer still kills the session (
|
| how uv's script is run | result |
|---|---|
Get-Content | iex inside & { } inside a try/catch |
host terminated, exit 1, nothing after it ran |
& ([scriptblock]::Create($src)) |
host terminated, exit 1 |
& $psExe -NoProfile -Command "… | iex" |
child exited 1, parent alive, $LASTEXITCODE = 1 |
Only the child process survives. Suggested replacement for lines 72–84:
Write-Step "Installing uv package manager..."
# Child process: uv's installer ends in `exit 1`, which under `iex` in this
# scope closes the user's session instead of failing this install.
$psExe = (Get-Process -Id $PID).Path
& $psExe -NoProfile -Command "irm https://astral.sh/uv/install.ps1 | iex"
if ($LASTEXITCODE -ne 0) {
Write-GaiaError "Failed to install uv (exit $LASTEXITCODE)."
Write-Host " Fix: install uv manually from" -ForegroundColor $COLOR_YELLOW
Write-Host " https://docs.astral.sh/uv/getting-started/installation/" -ForegroundColor $COLOR_YELLOW
throw "GAIA install failed - see the error above."
}
# Refresh PATH to include uv
$env:PATH = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine")
(Get-Process -Id $PID).Path resolves to powershell.exe on 5.1 and pwsh.exe on 7, so it works on both hosts. The PATH refresh still works from a child, since uv persists the User PATH to the registry.
tests/unit/installer/test_install_scripts_terminal_hub.py:387 (test_ps1_never_calls_exit) can't catch this — it only greps GAIA's own text. Worth a companion assertion that no remote script is iex'd in-scope, e.g. no line matching irm\s+http\S+\s*\|\s*iex outside a -Command string.
🟢 Nit — the failure literal is repeated 11 times (installer/scripts/install.ps1:83)
throw "GAIA install failed - see the error above." appears verbatim at lines 83, 88, 109, 134, 146, 248, 272, 282, 296, 316, 436. A one-line helper next to Write-GaiaError would keep the wording in one place and read slightly better at each call site:
function Stop-Install {
throw "GAIA install failed - see the error above."
}Cosmetic only — the current form is correct.
🟢 Note — the uncaught throw renders a PowerShell exception block
At an interactive prompt the unhandled throw prints Exception: … Line | 436 | throw "GAIA install failed …" under the [X] message. The [X] line and its Fix: hint stay on screen, which is the point of the PR, so this is acceptable — just flagging that the last thing the user sees is the internal line number, not the hint. If that bothers you, Write-GaiaError the summary and throw a bare [System.Exception] — or leave it; not worth churn.
Strengths
- The scope fix is the right shape.
& { … }containing both$ErrorActionPreferenceand theWrite-Gaia*helpers means a successful run is now invisible in the user's session, and the test asserts that directly (eap=Continue,write-error=Cmdlet,leaked=False) rather than grepping for the pattern. exit→throwpreserved the one invariant that mattered. The checksum mismatch atinstall.ps1:282still throws even under-Optional, matching the updated comment at line 232, andInstall-HubBinary'sfinallytemp-dir cleanup now runs on every failure path.test_banner_slash_commands_exist_in_the_tuitests the actual failure. Cross-checking the banner's/commandagainstpaletteCommandsintui/internal/ui/chat/palette.gocatches the class of bug (/hubdoesn't exist, so the TUI would have sent it to the model as a question) rather than pinning the current string. I verified the extraction: both banners yield{/agents}and the palette parse yields all 10 commands.- Both invocation modes kept working.
pwsh -Filestill exits non-zero (confirmed above), so CI and scripted callers aren't silently regressed by the move tothrow.
Stacked on #4294. Merge that first.
The documented
irm https://amd-gaia.ai/install.ps1 | iexruns the installer inside the user's own PowerShell session. Any failure'sexit 1closed their window and took the "Fix:" hint with it, and even a successful run left their session with$ErrorActionPreference = "Stop"and custom functions shadowing the built-inWrite-Error/Write-Warning. Now the script runs in its own scope and fails withthrow, so the error and its hint stay on screen and the session is left as it was. Running it withpwsh -File install.ps1still exits 1 on failure.It also stops shadowing
Write-Errorfor uv's ownirm | iexinstaller, which runs inside this script's scope.Test plan
pytest tests/unit/installer/test_install_scripts_terminal_hub.py -qpassed 47, with 1 skip (wget not installed). The script's real non-Windows failure path covers these checks:iexrun fails, the session survives,$ErrorActionPreferenceisContinue,Write-ErrorandWrite-Warningresolve to the cmdlets, and no installer function is left behind. This failed on the base branch because the process exited.pwsh -File install.ps1exits non-zero and still prints the reason.exitleft in the script (the base branch has 11) and confirms the script still parses.irm | iexinstall, both one that succeeds and one that fails partway (for example with the network off before the hub download)Fixes #4224