← back to AbramsEgo

build-queue/done/11-localfleet-fallback.md

29 lines

# AbramsEgo task 11 — make "Fleet · Local" (panel 2) actually populate on Mac2

Read SPEC.md panel 2 (Fleet health — pm2 Mac2 + Kamatera up/down). RIGHT NOW the LOCAL half is dark:
`server.js` shells `~/.npm-global/bin/pm2 jlist` (~line 109–113) but that command HANGS on this Mac2
(the pm2 daemon is unresponsive under memory pressure), so the 8s timeout fires and `localFleet`
returns `{procs:[], error:"pm2 unavailable"}`. The Kamatera half works; only Mac2 is broken.

Fix: add a FALLBACK so the panel shows local procs even when `pm2 jlist` hangs. `~/.pm2/dump.pm2`
EXISTS (verified) — it's JSON pm2 writes on save, with the process list. Use it as the fallback source.

KEEP IT SURGICAL — single function, ~10 min. Do NOT refactor unrelated fleet code.

1. In `server.js`'s local-fleet collector, wrap the `pm2 jlist` call: if it errors/times out (or returns
   empty), read + `JSON.parse` `~/.pm2/dump.pm2` and map its entries to the same shape the UI expects
   (`{name, status, restarts, memMB, startedAt}` — dump entries carry `name`, and `pm2_env` with
   `status`/`restart_time`/`pm_uptime`; memory may be absent → leave null). Keep a SHORT `jlist` timeout
   (e.g. 3000ms) so the fallback kicks in fast instead of stalling the whole snapshot.
   Mark fallback rows so the UI can show they're from the last saved dump (e.g. add `note:"from pm2 dump"`
   on the fleet object, or `stale:true` per row) — Steve's "always be honest about staleness" spirit.
2. `pm2 restart abramsego`, then:
   `curl -s -u admin:'DW2024!' http://127.0.0.1:9773/api/data | python3 -c "import sys,json;d=json.load(sys.stdin)['localFleet'];print(len(d.get('procs',[])),'procs',d.get('error'),d.get('note'))"`
   — expect a non-zero proc count (from the dump) instead of `0 procs pm2 unavailable`.
3. Load http://127.0.0.1:9773/ and confirm "Fleet · Local" lists procs (not "no local pm2 procs").
4. Commit:
   `git add -A && git commit -m "fix: local fleet falls back to ~/.pm2/dump.pm2 when jlist hangs" --author="Steve <steve@designerwallcoverings.com>"`

Do NOT deploy. Local only. Do NOT try to restart/repair the pm2 daemon itself — just make the panel
resilient to it being slow.