Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

Pulse: no Linux service install path — launchctl-only manage.sh, security-keychain start script, no systemd unit

Open klausagnoletti opened this issue 7 months ago • 3 comments

Summary

Every supervisor primitive shipped for Pulse is macOS-only:

  • PAI/PULSE/manage.sh uses launchctl load/unload against com.pai.pulse.plist
  • PAI/PULSE/start-pulse.sh calls security unlock-keychain ~/Library/Keychains/login.keychain-db and falls back to /opt/homebrew/bin/bun
  • com.pai.pulse.plist is launchd XML

There is no systemd unit, no ~/.bashrc autostart helper, no Windows-Task-Scheduler / WSL /etc/wsl.conf example. After installation Pulse can be started by hand (bun pulse.ts) but the moment WSL/Linux restarts, Pulse is dead and there is no documented path to keep it running.

Repro

# WSL Ubuntu
curl -fsSL https://ourpai.ai/install.sh | bash
~/.claude/PAI/PULSE/manage.sh start
# → launchctl: command not found  (and the keychain command, etc.)
wsl --shutdown
wsl
curl localhost:31337/api/pulse/health
# → connection refused — Pulse is gone

Suggested fix

  1. Ship pulse.service as a user systemd unit:

    [Unit]
    Description=PAI Pulse
    After=network.target
    
    [Service]
    ExecStart=%h/.bun/bin/bun run pulse.ts
    WorkingDirectory=%h/.claude/PAI/PULSE
    Environment=PATH=%h/.bun/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
    Restart=on-failure
    
    [Install]
    WantedBy=default.target
    

    Works on regular Linux desktops and on WSL2 with [boot] systemd=true.

  2. Ship a Linux branch of start-pulse.sh that just exec bun pulse.ts — no keychain calls, falls back to bun on $PATH rather than /opt/homebrew/bin.

  3. Document a Windows-Task-Scheduler approach for WSL users not running systemd: wsl.exe -- ~/.claude/PAI/PULSE/start-pulse.sh at logon.

  4. install.sh detects platform (uname) and installs the right supervisor.

Related

  • #1130 — partial overlap (manage.sh timeout / DA subsystem cron errors). This issue is the broader gap: there's no Linux supervisor at all.
  • #1159 — assumes systemd already running and only addresses the cron PATH issue under it.

Environment

PAI v5.0.0, Ubuntu on WSL2 + standalone Linux.

klausagnoletti avatar May 05 '26 09:05 klausagnoletti

Confirming this also bit on WSL2 Ubuntu running systemd-user. Adding a worked unit file in case it's useful as a reference for what option (1) (systemd user-unit) looks like end-to-end — particularly the two gotchas that aren't obvious from a vanilla [Service] ExecStart=... template.

Unit file used locally (~/.config/systemd/user/pai-pulse.service, mode 600)

[Unit]
Description=PAI Pulse
After=network.target

[Service]
Type=simple
ExecStart=%h/.bun/bin/bun run pulse.ts
WorkingDirectory=%h/.claude/PAI/PULSE
# PATH must be pinned — systemd-user inherits from the master env, which
# depends on .bashrc ordering at user login. Without this, every Pulse cron
# job dies on cold restarts with: `bash: bun: command not found`.
Environment="PATH=%h/.bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
# Optional env file for ELEVENLABS_API_KEY etc., mode 600.
# Dash prefix makes the file optional so the unit starts cleanly before
# the user has populated it.
EnvironmentFile=-%h/.config/pai-pulse.env
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

Enabling:

systemctl --user daemon-reload
systemctl --user enable --now pai-pulse
systemctl --user status pai-pulse   # active, NRestarts=0
journalctl --user -u pai-pulse -f

Two gotchas worth pinning in the suggested fix

  1. EnvironmentFile=-%h/.config/pai-pulse.env (note the leading dash). Makes the file optional so the unit starts on a fresh install before the user has populated their env file. Without the dash, a missing env file is a fatal start error.

  2. PATH must be pinned in the unit (not just inherited from the user's shell). Without Environment="PATH=...", systemd-user inherits PATH from whatever interactive shell happened to be logged in when systemd-user first started — which is non-deterministic across boots. On cold WSL2 restarts after wsl --shutdown, bun was missing from PATH and every cron job died with bash: bun: command not found. This is the sibling failure mode to #1159's posix_spawn 'bash' ENOENT — both are PATH-inheritance issues that surface differently.

Once both were in place, all 7 cron jobs ran clean across a wsl --shutdown reboot cycle.

Pointer to in-flight PR

PR #1126 (@dmcgoldrd) ships a pai-pulse.service template alongside a refactor of manage.sh to be OS-aware. It looks like it addresses the supervisor-on-Linux gap that this issue is about; flagging in case the unit file above (with EnvironmentFile=- and PATH pinning) is useful evidence for what details should ship in the upstreamed template.

Environment

  • PAI v5.0.0
  • Ubuntu 24.04 on WSL2 (/etc/wsl.conf has [boot] systemd=true)
  • bun v1.3.x

JElliottMiller avatar May 12 '26 14:05 JElliottMiller

Tested on: Ubuntu 24.04.4 LTS, PAI v5.0.0, bun v1.3.9

Confirmed this issue. On a fresh Ubuntu install, bash manage.sh install exits immediately with launchctl: command not found because every code path calls launchctl — there's no Linux branch at all. Pulse never starts, port 31337 never binds.

Fix

Two files need to be added/updated. The approach is uname -s OS detection at the top of manage.sh; every case block then branches on $OS — Darwin takes the existing launchctl path, Linux takes a new systemd --user path. macOS behavior is unchanged.

PULSE/manage.sh — OS detection block (add near top, after BUN_PATH resolution)

OS=$(uname -s)

# Linux-specific paths — harmless to define on macOS; Darwin branches never reference them
SERVICE_DIR="$HOME/.config/systemd/user"
SERVICE_FILE="$SERVICE_DIR/pai-pulse.service"
SERVICE_SRC="$PULSE_DIR/pai-pulse.service"

# systemctl --user needs XDG_RUNTIME_DIR to find the user bus
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"

PULSE/manage.sh — updated install case (Linux branch)

install)
  if [ "$OS" = "Linux" ]; then
    mkdir -p "$PULSE_DIR/state" "$PULSE_DIR/logs" "$SERVICE_DIR"
    if [ -f "$SERVICE_FILE" ]; then
      systemctl --user stop pai-pulse.service 2>/dev/null || true
    fi
    pkill -9 -f "bun.*pulse.ts" 2>/dev/null || true
    sleep 1
    sed -e "s|__HOME__|$HOME|g" -e "s|__BUN_PATH__|$BUN_PATH|g" "$SERVICE_SRC" > "$SERVICE_FILE"
    systemctl --user daemon-reload
    systemctl --user enable pai-pulse.service
    systemctl --user start pai-pulse.service
    for _ in $(seq 1 20); do
      sleep 0.5
      if curl -sS --max-time 1 -o /dev/null -X POST http://localhost:31337/notify \
           -H "Content-Type: application/json" \
           -d '{"message":"","voice_enabled":false}' 2>/dev/null; then
        echo "PAI Pulse installed and verified on port 31337"
        exit 0
      fi
    done
    echo "ERROR: port 31337 did not bind within 10s" >&2
    exit 1
  else
    # ... existing macOS/launchctl path unchanged ...
  fi

PULSE/manage.sh — remaining cases (Linux branch for each)

start)   [ "$OS" = "Linux" ] && systemctl --user start pai-pulse.service ;;
stop)    [ "$OS" = "Linux" ] && systemctl --user stop pai-pulse.service 2>/dev/null ;;
restart) [ "$OS" = "Linux" ] && systemctl --user restart pai-pulse.service ;;
status)  [ "$OS" = "Linux" ] && systemctl --user is-active pai-pulse.service ;;
uninstall)
  if [ "$OS" = "Linux" ]; then
    systemctl --user stop pai-pulse.service 2>/dev/null || true
    systemctl --user disable pai-pulse.service 2>/dev/null || true
    rm -f "$SERVICE_FILE"
    systemctl --user daemon-reload
  fi

PULSE/pai-pulse.service — new file (template, ship alongside the plist)

[Unit]
Description=PAI Pulse
After=network.target

[Service]
Type=simple
ExecStart=__BUN_PATH__ run pulse.ts
WorkingDirectory=__HOME__/.claude/PAI/PULSE
Restart=always
RestartSec=30
StandardOutput=append:__HOME__/.claude/PAI/PULSE/logs/pulse-stdout.log
StandardError=append:__HOME__/.claude/PAI/PULSE/logs/pulse-stderr.log
Environment=HOME=__HOME__
Environment=PATH=__HOME__/.bun/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

[Install]
WantedBy=default.target

install substitutes __HOME__ and __BUN_PATH__ at install time via sed, writes to ~/.config/systemd/user/pai-pulse.service, and runs daemon-reload + enable + start. Same placeholder pattern as the existing plist.

Verification

$ bash manage.sh install
PAI Pulse installed and verified on port 31337

$ systemctl --user is-active pai-pulse.service
active

$ curl -s http://localhost:31337/notify -X POST \
    -H "Content-Type: application/json" \
    -d '{"message":"test","voice_enabled":false}'
{"status":"success","message":"Notification sent"}

Service survives reboots (WantedBy=default.target + loginctl enable-linger if you want auto-start without login).

Happy to open a PR with the full diff if this approach looks right.

bgturner avatar Jun 10 '26 05:06 bgturner

Hey @klausagnoletti, thanks for raising this, and sorry it sat for a while.

We're changing how LifeOS ships. Instead of cloning a full ~/.claude directory and running it as a complete system, LifeOS is becoming a skill you install through an agentic installer. The installer hands integration to your own AI, which reads your actual machine (your OS, your paths, your harness) and wires the hooks and system prompt in where they belong.

That's aimed right at what you hit here. The old "one directory, one layout, hope it matches your setup" approach is exactly what broke for so many people, and the new model should handle it far better because your AI does the integration per machine instead of us guessing.

So we're closing this in prep for that release. If it still bites you once the skill-based version is out, reopen or file a fresh one and we'll jump on it. Appreciate you taking the time.

danielmiessler avatar Jun 21 '26 03:06 danielmiessler