Skip to content

Fix gaia init version checks and MSI reliability - #478

Merged
kovtcharov merged 7 commits into
mainfrom
kalin/fix-gaia-init-checks
Mar 13, 2026
Merged

kovtcharov merged 7 commits into
mainfrom
kalin/fix-gaia-init-checks

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Summary

  • Accept newer Lemonade versions — gaia init no longer prompts to downgrade when a newer version is installed (e.g., v9.3.4 with v9.3.0 expected). Only prompts upgrade when below the profile's minimum version.
  • Fix misleading prompt — No more "Upgrade to v9.3.0?" when it's actually a downgrade.
  • Improve MSI uninstall reliability — Uses Windows registry ProductCode lookup first, falls back to trying both minimal and full MSI variants. Fixes "Lemonade Server is not installed" error when MSI variant doesn't match.
  • Prevent MSI collisions — Adds wait_for_msi_mutex() between uninstall and install to prevent msiexec process conflicts (error 1618).
  • Fix gaia install --lemonade — Uses >= tuple comparison instead of strict string equality.

Test plan

  • 54 unit tests pass (12 new tests added)
  • Manual test: gaia init with newer Lemonade version installed — should accept silently
  • Manual test: gaia init with older version above profile minimum — should accept with optional upgrade offer
  • Manual test: gaia init with version below profile minimum — should prompt upgrade (default: yes)
  • Manual test: gaia install --lemonade with newer version — should report already installed

… MSI reliability

- Rewrite _check_version_compatibility to accept newer versions silently
  instead of prompting for a downgrade (v9.3.4 >= v9.3.0 is fine)
- Only prompt upgrade when installed version is below profile minimum
- Fix misleading "Upgrade to v9.3.0?" prompt when it's actually a downgrade
- Add registry-based ProductCode lookup for reliable MSI uninstall
- Add wait_for_msi_mutex() to prevent msiexec collisions during upgrade
- Handle MSI error 1618 (another installation in progress)
- Try both minimal and full MSI variants as uninstall fallback
- Fix gaia install --lemonade to use >= comparison instead of strict equality
- Add 12 new unit tests for version compatibility, MSI mutex, and ProductCode
@github-actions github-actions Bot added cli CLI changes tests Test changes labels Mar 9, 2026
Karim13014 and others added 2 commits March 9, 2026 16:13
- Fix pylint protected-access: use public needs_install() instead of
  private _parse_version() in cli.py
- Tighten registry match from "lemonade" to "lemonade server" to avoid
  matching unrelated products
- Validate ProductCode as GUID format before passing to msiexec
- Add log.warning when version parsing fails (aids debugging)
- Show warning (not success) for newer-than-expected versions with
  helpful guidance message
- Only print "Version is compatible" for exact match (avoid redundant
  message after warning)
- Point users to lemonade-server.ai when installation completely fails
- Restore emoji in cli.py success message
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

@claude review this PR.

@github-actions

github-actions Bot commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kovtcharov-amd's task —— View job


PR Review Complete

  • Read PR diff and changed files
  • Review src/gaia/cli.py changes
  • Review src/gaia/installer/init_command.py changes
  • Review src/gaia/installer/lemonade_installer.py changes
  • Review tests/unit/test_init_command.py changes
  • Provide comprehensive review feedback

Summary

This is a well-structured PR that fixes important UX issues with gaia init version handling and improves MSI reliability on Windows. The code is clean, well-documented, and includes comprehensive test coverage.

Review Findings

🟢 Strengths

  1. Clear version policy - The three-tier approach (newer/equal, older-acceptable, older-required) is well-documented in both code and docstrings (init_command.py:519-526)

  2. Robust MSI handling - Multiple fallback strategies for Windows uninstall:

    • Registry ProductCode lookup first (most reliable)
    • Fallback to MSI download with both minimal/full variants
    • Proper MSI mutex waiting to prevent error 1618
  3. Good test coverage - 12 new tests covering all version comparison scenarios (test_init_command.py:427-546)

  4. Security - GUID validation in _is_valid_product_code() prevents registry traversal issues

  5. User-friendly messaging - Clear distinction between "older but acceptable" vs "older and incompatible" versions

🟡 Suggestions (non-blocking)

  1. lemonade_installer.py:406 - In wait_for_msi_mutex, the except Exception catching all exceptions could mask issues. Consider logging when an exception occurs:

    except Exception as e:
        log.debug(f"Could not check for msiexec processes: {e}")
        return True  # Can't check, proceed anyway
  2. Test coverage for find_product_code - The Windows registry test only verifies non-Windows returns None. Consider adding a test with mocked winreg to verify the registry lookup logic (though this may be overkill for a fallback path).

  3. init_command.py:683 - The MSI mutex wait after uninstall always proceeds even if it times out. This is fine, but the warning message could mention the specific timeout value for debugging:

    "Another MSI operation still running after 30s — proceeding anyway..."

🟢 Code Quality

  • Clear separation of concerns between version checking and installation
  • Good use of early returns to reduce nesting
  • Consistent error handling with informative messages
  • Proper logging at debug level for troubleshooting

Verified Behavior

  • needs_install() correctly returns False when current >= target (tuple comparison)
  • _check_version_compatibility() accepts newer versions silently
  • Profile minimum version fallback is properly handled
  • MSI ProductCode validation prevents injection via malformed registry keys

Verdict

LGTM - This PR is ready to merge. The suggestions above are minor improvements that can be addressed in follow-up work if desired.


- Fix logger.py: use stream.reconfigure() instead of creating new
  TextIOWrapper instances, which detached buffers and broke pytest capture
- Add debug logging to wait_for_msi_mutex exception handler
- Include timeout value in MSI mutex warning message
- Add mocked winreg tests for find_product_code registry lookup
@kovtcharov
kovtcharov enabled auto-merge March 13, 2026 02:38
@kovtcharov
kovtcharov added this pull request to the merge queue Mar 13, 2026
Merged via the queue into main with commit e11e4a0 Mar 13, 2026
23 checks passed
@kovtcharov
kovtcharov deleted the kalin/fix-gaia-init-checks branch March 13, 2026 02:40
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Jul 8, 2026
…md#1940)

Closes amd#316

Modern Lemonade (10.7+, including the 10.8.1 GAIA installs) removed the
`lemonade-server` CLI — the server is now `LemonadeServer.exe --silent`
on Windows (ctx size via the `LEMONADE_CTX_SIZE` env var) and a systemd
`lemond` service on Linux. GAIA still hard-coded `lemonade-server serve`
everywhere, so on a modern install `gaia init` reported a working
Lemonade as **not installed**, and after any install it told the user to
start the server by hand (amd#316's "never started it") — interactive mode
could never auto-start because of an indentation bug that made the
manual prompt unconditional. Now detection finds modern and legacy
installs, and `gaia init` auto-starts the server in both interactive and
CI modes, falling back to a prompt (showing the *correct* per-tooling
command) only if auto-start fails. (amd#316's uninstall failure was
previously fixed by amd#478; verified still working — the registry
ProductCode lookup finds modern installs.)

All changes route through one new stdlib-only primitive,
`gaia.llm.lemonade_launcher` (`resolve_lemonade` /
`get_installed_version` / `build_start_command`), consumed by the
installer and `LemonadeClient` — legacy `lemonade-server` behavior is
pinned byte-identical by tests, and CI's `LEMONADE_SERVER_PATH` override
is honored first.

## Evidence (real-world, Windows 11 + Ryzen AI box, Lemonade 10.7.0)

Tested by deploying this branch to the machine's editable GAIA install
and running the real CLI over SSH.

**Detection — before:** `main`'s check is
`shutil.which("lemonade-server")`, which is `NOT ON PATH` on this modern
install → "not installed" → forced reinstall over a working setup.
**After:**

```
resolve_lemonade: found=True kind=modern
  client_path     = C:\Users\...\AppData\Local\lemonade_server\bin\lemonade.exe
  server_launcher = C:\Users\...\AppData\Local\lemonade_server\bin\LemonadeServer.exe
check_installation: installed=True version=10.7.0
build_start_command: argv=['C:\\Users\\...\\LemonadeServer.exe', '--silent'] env={'LEMONADE_CTX_SIZE': '32768'}
```

**Auto-start — `LemonadeServer.exe` stopped, then interactive `gaia init
--profile minimal --skip-models` (stdin-driven, `yes` not set):**

```
Step 1/4: Checking Lemonade Server installation...
   ✓ Lemonade Server found: v10.7.0
   Upgrade to v10.8.1? [y/N]:    ✓ Continuing with v10.7.0

Step 2/4: Checking Lemonade Server...
   Lemonade Server is not running — starting it...
   | INFO | ..._auto_start_server | Starting Lemonade Server: C:\Users\...\LemonadeServer.exe --silent
   ✓ Server started and ready (waited 2s)

Step 4/4: Verifying setup...
   ✓ Server health: OK
   ✓ Context size verified: 32768 tokens
GAIA initialization complete!   (exit code 0)
```

No "Please start Lemonade Server" prompt appeared; `LemonadeServer.exe`
alive (pid captured) and `/api/v1/health` = 200 afterwards. The ctx-size
env path is proven end-to-end by the Step-4 32768-token model preload.

## Test plan

- [x] `python -m pytest tests/unit/test_init_command.py
tests/unit/installer/ tests/unit/test_lemonade_launcher.py
tests/test_lemonade_client.py -q` → 245 passed; the 4 failures are
pre-existing environment artifacts (3 tests short-circuited by a live
local Lemonade on :13305 — fail identically on `main` — plus 1
live-server integration test), none in changed code
- [x] `python util/lint.py --all` → exit 0
- [x] Real-world Windows validation (above): modern detection +
interactive auto-start + health + ctx preload
- [ ] CI green (note: CI workflows start Lemonade externally, so the
auto-start path itself is exercised by the real-world run above, not CI)

<details>
<summary>Reviewer notes — bundled behavior deltas & rationale</summary>

- Tests were written first as a fixed contract (28 new/updated across 4
files), including falsifying assertions: `input()` never called on
auto-start success, Popen env must retain the parent environment (merge,
not replace), legacy argv pinned byte-identical, `LEMONADE_SERVER_PATH`
honored before any PATH probe with modern-beats-stale-legacy precedence.
- `launch_server()` now skips `kill_process_on_port` when a healthy
server is already listening (never restarts a tray/systemd-managed
server the user didn't ask to restart), raises an actionable error when
no tooling is found, and its `background="terminal"` branch is argv-only
(`CREATE_NEW_CONSOLE`) instead of a `shell=True` string.
- `check_installation()` no longer returns installed=False on a
version-probe timeout (that could trigger a pointless reinstall); a
found install with a failed probe stays installed=True with a diagnostic
error. `LemonadeInfo` shape and `find_product_code()` are unchanged (all
five callers unaffected).
- Windows legacy `launch_server` now passes `--no-tray` (aligning with
what `gaia init` always did); `--log-level` is appended for legacy only
(the modern launcher has no such flag — logged and ignored, not silently
dropped).
- User-facing "start/restart with:" hints render the resolved tooling's
real command (env prefix + argv) instead of the removed
`lemonade-server` CLI.
- `_find_lemonade_server()` retained as a compat surface (delegates to
the primitive) though it has no remaining callers.
- Modern-Linux auto-start (`systemctl --user start lemond`) is
best-effort and unit-tested only — the daemon is normally already
running under systemd.
- Follow-up (tracked separately): the PowerShell-side detection in
`.github/actions/install-lemonade/action.yml` and
`installer/scripts/*.ps1` duplicates this logic and has one stale search
path; consolidating PS/Python detection is out of scope here.

</details>

---------

Co-authored-by: Tomasz Iniewicz <[email protected]>
Co-authored-by: Tomasz Iniewicz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants