Skip to content

fix(installer): keep a failed Windows install from closing the user's terminal - #4298

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/install-ps1-own-scope
Sep 26, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/install-ps1-own-scope

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4294. Merge that first.

The documented irm https://amd-gaia.ai/install.ps1 | iex runs the installer inside the user's own PowerShell session. Any failure's exit 1 closed 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-in Write-Error/Write-Warning. Now the script runs in its own scope and fails with throw, so the error and its hint stay on screen and the session is left as it was. Running it with pwsh -File install.ps1 still exits 1 on failure.

It also stops shadowing Write-Error for uv's own irm | iex installer, which runs inside this script's scope.

Test plan

  • With pwsh 7.6.6 on macOS, pytest tests/unit/installer/test_install_scripts_terminal_hub.py -q passed 47, with 1 skip (wget not installed). The script's real non-Windows failure path covers these checks:
    • After the iex run fails, the session survives, $ErrorActionPreference is Continue, Write-Error and Write-Warning resolve to the cmdlets, and no installer function is left behind. This failed on the base branch because the process exited.
    • pwsh -File install.ps1 exits non-zero and still prints the reason.
    • A static check finds no exit left in the script (the base branch has 11) and confirms the script still parses.
  • A real Windows irm | iex install, both one that succeeds and one that fails partway (for example with the network off before the hub download)

Fixes #4224

Kalin Ovtcharov added 2 commits September 24, 2026 22:45
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
@github-actions github-actions Bot added installer Installer changes tests Test changes labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

This makes a failed irm … | iex install print its error and leave the user's terminal open instead of closing it, and stops the installer leaving its own settings and function overrides behind in the session. I reproduced both the fix and the regression it replaces — it works.

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 /hub → /agents banner fix plus the test that cross-checks banner commands against the TUI's real command list is a nice catch — it would have caught the original typo.

Real-world evidence

No evidence-bundle.md was produced for this PR, so I exercised the script directly with pwsh 7 on this Linux runner (the installer's non-Windows refusal is a real failure path needing no stubs):

$ pwsh -NoProfile -Command "$src = Get-Content -Raw installer/scripts/install.ps1; try { iex $src } catch { … }"
[X] This installer is for Windows. Detected: Unix
On Linux and macOS, run instead:
  curl -fsSL https://amd-gaia.ai/install.sh | sh
caught: GAIA install failed - see the error above.
alive
eap=Continue
write-error=Cmdlet
write-warning=Cmdlet
leaked=False

$ pwsh -NoProfile -File installer/scripts/install.ps1 ; echo exit=$?
exit=1

Both of the PR's headline claims hold. I also reproduced the remaining uv path above: a nested iex of a script ending in exit 1 terminated the host process through both the & { } wrapper and the try/catch. Pytest isn't installed on this runner, so the new tests weren't run here; a real Windows irm | iex install (the unchecked test-plan item) is still outstanding and this verdict rests on static review plus the pwsh runs above for that surface.

🔍 Technical details

🟡 Important — uv's installer still kills the session (installer/scripts/install.ps1:74)

irm https://astral.sh/uv/install.ps1 | iex runs in this script's scope. uv's installer (line 671–676 of the live script) ends with:

try { Install-Binary "$Args" } catch { Write-Information $_; exit 1 }

exit inside Invoke-Expression is not scoped to a scriptblock, so it blows past both & { } and the surrounding try/catch and terminates the host. Reproduced on pwsh 7.6 (Linux) with a stand-in script:

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 $ErrorActionPreference and the Write-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 → throw preserved the one invariant that mattered. The checksum mismatch at install.ps1:282 still throws even under -Optional, matching the updated comment at line 232, and Install-HubBinary's finally temp-dir cleanup now runs on every failure path.
  • test_banner_slash_commands_exist_in_the_tui tests the actual failure. Cross-checking the banner's /command against paletteCommands in tui/internal/ui/chat/palette.go catches the class of bug (/hub doesn'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 -File still exits non-zero (confirmed above), so CI and scripted callers aren't silently regressed by the move to throw.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit a903cb6 Sep 26, 2026
38 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/install-ps1-own-scope branch September 26, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

installer Installer changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(installer): a failed irm | iex install closes the user's PowerShell window

2 participants