Skip to content

fix(installer): create gaia shim in ~/.local/bin for AppImage users - #942

Merged
itomek merged 4 commits into
amd:mainfrom
theonlychant:fix/appimage-gaia-init-command
May 7, 2026
Merged

itomek merged 4 commits into
amd:mainfrom
theonlychant:fix/appimage-gaia-init-command

Conversation

@theonlychant

@theonlychant theonlychant commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

The issue

Summary

Creates a gaia shell shim at ~/.local/bin/gaia during AppImage
startup so users can run gaia from any terminal without manually
modifying their PATH.

Why

After installing via AppImage, users are prompted to run gaia init
but get gaia: command not found because the AppImage does not place
a binary on PATH. This fix creates a lightweight shim pointing to the
verified gaia binary, only on POSIX systems and only if no existing
gaia binary or shim is present - - so it never clobbers system packages.

Linked issue

Closes #782

Changes

  • Added shim creation logic in backend-installer.cjs (lines 1137–1168)
  • Shim is written to $XDG_BIN_HOME or ~/.local/bin/gaia
  • Skips creation if gaia already exists on PATH or shim already exists
  • Non-fatal: logs and continues if shim creation fails

Test plan

  • Ran on Debian - - gaia accessible from terminal after AppImage launch
  • Verified shim is not created if gaia already exists on PATH
  • Verified shim is not overwritten if already present

Checklist

  • I have linked a GitHub issue above (Closes #N / Fixes #N / Refs #N).
  • I have described why this change is being made, not just what changed.
  • I have run linting and tests locally.
  • I have updated documentation if user-visible behavior changed.

@github-actions github-actions Bot added the documentation Documentation changes label May 2, 2026
@kovtcharov

Copy link
Copy Markdown
Contributor

@claude review this PR.

@kovtcharov
kovtcharov enabled auto-merge May 2, 2026 14:29
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

PR review

Thanks for tackling the post-AppImage gaia: command not found issue — the shim approach is a sensible fix. A few findings below, with the safety bug being the one I'd want resolved before merge.

🔴 PID-reuse safety bug in main.cjs:265

The new pidfile cleanup calls portManager.killBackend(existingPid) with a raw PID read from disk. This is exactly the TOCTOU scenario the killBackend docstring in port-manager.cjs:57-60 warns against:

Accepts either a ChildProcess reference (preferred — lets us short-circuit via exitCode so PID reuse can never hit us) or a raw pid (useful for tests).

After a reboot or long uptime, the kernel may have reused the PID for an unrelated user process (firefox, an editor, a build job). process.kill(pid, 0) only verifies some process owns that PID — not that it's a gaia backend. We could SIGTERM/SIGKILL arbitrary processes the user owns. This is also worse than the bug being fixed.

Suggested fix: before signalling, verify the PID is actually a gaia backend, e.g. by reading /proc/<pid>/cmdline (Linux) and checking it matches gaia/python.*gaia, and falling back to no-op if it doesn't. On macOS use ps -p <pid> -o command=. Persisting {pid, started_at, cmdline} in the pidfile and re-checking on read is also defensible.

🟡 Scope creep vs. PR title/description

The title and description say "create gaia shim in ~/.local/bin", but the diff also adds:

  • PID-tracking + cleanup logic in main.cjs:253-358 (~50 lines, the safety issue above)
  • Doc section "Troubleshooting — zombie backend processes"
  • Doc section "Arch Linux and AppImage notes"

Per the Scope-clean rule in CLAUDE.md, this should either be (a) split into separate PRs (shim / pidfile cleanup / docs) or (b) the title and description updated to disclose all three threads with their own why. The shim change alone is small and easy to review; the pidfile change is the riskier one and deserves its own dedicated review.

🟡 Duplicate console.log in main.cjs

// line 251 (added by this PR)
console.log(`Starting backend: ${gaiaCmd} chat --ui --ui-port ${backendPort}`);

// ...pidfile cleanup block...

// line 280 (pre-existing)
console.log(`Starting backend: ${gaiaCmd} chat --ui --ui-port ${backendPort}`);

The new line at 251 is an exact duplicate of the existing line at 280 — please drop the new one (or move it after the cleanup if the intent was to log before killing, not log twice).

🟡 Doc inconsistencies

  • The new step in docs/deployment/ui.mdx is numbered 4., but the next existing item is also 4. To collect logs for a bug report: — list will render with two 4.s. Renumber to 5. and bump the rest.
  • Two new sections use Title\n---- underline-style headings, while the rest of the file uses #/## ATX style. Match the existing convention for consistency.

🟢 Linked issue placeholder

PR body has Closes #N. The body text up top references #782 — change to Closes #782 (or Refs #782 if it shouldn't auto-close) so the PR-issue linkage is recorded.

🟢 Tests

CLAUDE.md (Testing Requirements) calls for tests on new features. The shim path has several branches worth covering with a unit test under src/gaia/apps/webui/:

  1. XDG_BIN_HOME set → shim placed there
  2. existing gaia on PATH → no shim created
  3. existing shim at target → no overwrite
  4. mkdirSync/writeFileSync failure → non-fatal, logged

A small spec around installBackend (with commandExists + fs mocked) would catch regressions cheaply.

🟢 Minor: macOS coverage

The check process.platform !== "win32" runs the shim on macOS too. The PR body says "POSIX systems" so this is presumably intentional — but the AppImage variant is Linux-only, so on macOS this branch only fires for non-AppImage installs. Worth a comment in the code clarifying intent (Linux-only? all POSIX? AppImage-only?).

🟢 Minor: shim wrapper quoting

const wrapper = `#!/bin/sh\nexec \"${verifiedBin}\" \"$@\"\n`;

Fine for standard venv paths, but if verifiedBin ever contained ", \, or $, the wrapper would misbehave. Not a real concern today because verifiedBin is internally computed, but a one-line assert(/^[\w\-./]+$/.test(verifiedBin)) would harden it cheaply.


Net assessment: the shim itself is correct and small. The PID cleanup bundled in the same PR has a real safety bug that I'd want fixed (or split off) before merging. Happy to re-review once the pidfile path validates the process identity.

auto-merge was automatically disabled May 2, 2026 17:21

Head branch was pushed to by a user without write access

@theonlychant

Copy link
Copy Markdown
Contributor Author

auto-merge was automatically disabled May 2, 2026 12:21
Head branch was pushed to by a user without write access

I addressed the feedback fixed PID cmdline validation, removed duplicate console.log, and updated the issue link to Closes #782.

itomek-amd
itomek-amd previously approved these changes May 4, 2026

@itomek-amd itomek-amd left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theonlychant — verified the fix commit (ce84e17) at HEAD: duplicate console.log is gone, the doc step is correctly renumbered to 5, both new doc sections use ## ATX headings, the Closes #782 link is in place, the shim writer rejects suspicious verifiedBin paths, and the pidfile reader now validates the cmdline before signalling. Approving.

Optional follow-up (not blocking)

The cmdline match in main.cjs:268-279 accepts "python" as a standalone keyword. After PID reuse onto an unrelated python process (Jupyter kernel, ML run, LSP server) the AppImage would still SIGTERM it on next launch. Low-probability scenario — needs a hard Electron crash that skips the exit-handler cleanup, plus PID wrap, plus the reused PID belonging to something the user cares about — but a one-line tightening would close it:

const cmd = raw; // /proc/<pid>/cmdline, NUL-separated
const looksLikeGaiaBackend =
  cmd.includes("gaia") && (cmd.includes("chat") || cmd.includes("--ui-port"));
if (looksLikeGaiaBackend) isBackend = true;

The legitimate backend is always spawned as gaia chat --ui --ui-port <port> (main.cjs:260), so the gaia + chat pair is a tight marker. The "gaia-desktop" clause is also redundant since it's a substring of "gaia".

Worth a follow-up PR; not worth blocking this one.

@itomek itomek self-assigned this May 4, 2026
@theonlychant

Copy link
Copy Markdown
Contributor Author

@theonlychant — verified the fix commit (ce84e17) at HEAD: duplicate console.log is gone, the doc step is correctly renumbered to 5, both new doc sections use ## ATX headings, the Closes #782 link is in place, the shim writer rejects suspicious verifiedBin paths, and the pidfile reader now validates the cmdline before signalling. Approving.

Optional follow-up (not blocking)

The cmdline match in main.cjs:268-279 accepts "python" as a standalone keyword. After PID reuse onto an unrelated python process (Jupyter kernel, ML run, LSP server) the AppImage would still SIGTERM it on next launch. Low-probability scenario — needs a hard Electron crash that skips the exit-handler cleanup, plus PID wrap, plus the reused PID belonging to something the user cares about — but a one-line tightening would close it:

const cmd = raw; // /proc/<pid>/cmdline, NUL-separated
const looksLikeGaiaBackend =
  cmd.includes("gaia") && (cmd.includes("chat") || cmd.includes("--ui-port"));
if (looksLikeGaiaBackend) isBackend = true;

The legitimate backend is always spawned as gaia chat --ui --ui-port <port> (main.cjs:260), so the gaia + chat pair is a tight marker. The "gaia-desktop" clause is also redundant since it's a substring of "gaia".

Worth a follow-up PR; not worth blocking this one.

ok I am on it

@theonlychant

Copy link
Copy Markdown
Contributor Author

Ok you can look at it again now

@itomek itomek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified at HEAD — every finding from the prior review is addressed:

  • main.cjs:268-279 cmdline check now uses the tight gaia + (chat | --ui-port) match (closes the prior PID-reuse-onto-Jupyter-or-LSP concern)
  • duplicate console.log removed
  • doc step renumbered to 5., both new sections use ## ATX headings
  • Closes #782 is in the body
  • installBackend shim creation rejects suspicious paths via the /^[\w\-./]+$/.test(verifiedBin) guard before writing the wrapper

Nothing further from me — approving.


Generated by Claude Code

@itomek
itomek added this pull request to the merge queue May 7, 2026
Merged via the queue into amd:main with commit fd9fc60 May 7, 2026
29 of 30 checks passed
@itomek itomek mentioned this pull request May 7, 2026
5 of 6 tasks
theonlychant pushed a commit to theonlychant/gaia that referenced this pull request May 7, 2026
## Why this matters

Ships the v0.17.6 patch: a new Email Triage Agent with Gmail (every
email body stays on local Lemonade), the OAuth PKCE foundation that
backs it, settings UI card layout, and a sweep of installer fixes that
close the remaining first-launch failures uncovered after v0.17.5.
Custom Python agents that follow the template's
`super().__init__(**kwargs)` pattern no longer crash on the first
message in the Agent UI.

Full notes: `docs/releases/v0.17.6.mdx`.

## What's New

- **Email Triage Agent with Gmail**
([amd#965](amd#965)) — `EmailTriageAgent` with
25 tools across read / organize / reply / delete / calendar mixins.
Every email body processed locally on Lemonade; seven destructive tools
confirmation-gated; three layers of prompt-injection defense; SQLite
undo log via `DatabaseMixin`.
- **OAuth PKCE foundation for Google connections**
([amd#926](amd#926)) — Self-contained
`gaia.connections` module: refresh tokens in the OS keychain (Keychain /
DPAPI / SecretService), per-agent grants in
`~/.gaia/connections/grants.json`, async token cache with refresh
rotation. Baseline for the v0.17.7 connectors framework.
- **Settings UI card layout**
([amd#969](amd#969)) — Outlined cards with
accent left-stripe replace margin-separated blocks across all settings
sections; light + dark themes both updated.

## Bug Fixes

- **Custom Python agents crashed on first message**
([amd#974](amd#974), closes
[amd#973](amd#973)) — `python_factory` now
introspects the target class's `__init__` chain and only forwards kwargs
the chain accepts, so the bare `super().__init__(**kwargs)` template
pattern no longer crashes with `unexpected keyword argument
'rag_documents'`.
- **Windows installer failed at `ensure-uv`**
([amd#968](amd#968), closes
[amd#966](amd#966)) — `uv` binary now
bundled for `win-x64`; packaged Windows rescue installer included.
- **macOS installer failed at `ensure-uv` on clean Apple Silicon**
([amd#967](amd#967), closes
[amd#941](amd#941)) — Pinned `uv` v0.5.14
(`aarch64-apple-darwin`) shipped in the DMG; new `dmg-structural-smoke`
CI job blocks future drift.
- **AppImage users hit `gaia: command not found`**
([amd#942](amd#942), closes
[amd#782](amd#782)) — Startup writes a
`~/.local/bin/gaia` shim so `gaia` is on PATH after first launch (skips
creation if already present).
- **Windows fell back to Qwen instead of Gemma 4 default**
([amd#949](amd#949), closes
[amd#948](amd#948)) — Model-resolution logic
fixed so Gemma loads correctly on Windows.

## Tooling & Docs

- **`gaia-release` skill**
([amd#939](amd#939)) — Phased release flow
with hard gates before every irreversible step; encodes the manual
pre-tag verification that caught two release-blocking bugs in v0.17.4.
- **Internal-task issue template**
([amd#906](amd#906)) — Third issue template
for agent-assignable internal work.
- **Outlook via Power Automate plan**
([amd#954](amd#954)) — Enterprise-bypass spec
for v0.17.7 Outlook integration.
- **PR description guidance sharpened**
([amd#947](amd#947)) — `CLAUDE.md` "tight and
value-focused" rule with anti-patterns.
- **Stale `macOS uv fetch removed` orphan comment removed**
([amd#975](amd#975)).

## Thanks

External contributors in this release:

- [@theonlychant](https://github.com/theonlychant) — installer fixes
([amd#968](amd#968),
[amd#942](amd#942),
[amd#949](amd#949))
- [@BlueriteSoul](https://github.com/BlueriteSoul) — reported AppImage
`gaia: command not found`
([amd#782](amd#782))
- [@nuts23](https://github.com/nuts23) — reported Windows Gemma/Qwen
fallback ([amd#948](amd#948))

## Release checklist

- [x] `util/validate_release_notes.py docs/releases/v0.17.6.mdx --tag
v0.17.6` passes
- [x] `src/gaia/version.py` → `0.17.6`
- [x] `src/gaia/apps/webui/package.json` → `0.17.6`
- [x] Navbar label in `docs/docs.json` → `v0.17.6 · Lemonade 10.2.0`
- [x] All 14 commits in the range (v0.17.5..HEAD) are represented in the
notes
- [ ] Review from @kovtcharov-amd addressed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: AppImage not working on Ubuntu 24.04 LTS

4 participants