Skip to content

fix(deployments): tolerate pm2 jlist warning banners before the JSON - #609

Merged
alari76 merged 1 commit into
mainfrom
fix/pm2-jlist-banner
Aug 30, 2026
Merged

fix(deployments): tolerate pm2 jlist warning banners before the JSON#609
alari76 merged 1 commit into
mainfrom
fix/pm2-jlist-banner

Conversation

@alari76

@alari76 alari76 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Found during the prod deploy verification of #606#608: GET /api/deployments/discover returned an empty pm2 list on a box running three pm2 processes. Cause: this host's pm2 daemon predates the CLI (node was upgraded via nvm), so pm2 jlist prints an 'In-memory PM2 is out-of-date' banner on stdout before the JSON, ANSI color codes included. JSON.parse threw and discovery swallowed it into [] — the exact silent-broken-probe failure mode the monitor design forbids.

Fix

  • parsePm2Jlist(): clean parse first; on failure, locate the line the JSON array starts on (lastIndexOf('\n[') — ANSI escape sequences contain [, so a plain indexOf('[') would hit the color codes) and parse from there; throw a descriptive error when no array exists.
  • Used by both the pm2 probe (where a parse failure correctly becomes a visible breach) and discovery (which now logs the error instead of failing silently).
  • Test reproduces the real banner bytes.

9 monitor tests pass; lint + build clean.

🤖 Generated with Claude Code

Found live on prod: pm2 prints an 'In-memory PM2 is out-of-date' banner on
stdout ahead of the JSON when the daemon predates the CLI (post node
upgrade), with ANSI color codes. JSON.parse failed and discovery silently
returned an empty list — exactly the silent-broken-probe failure mode the
design forbids.

- parsePm2Jlist: try clean parse, then scan for the line the array starts
  on (ANSI escapes contain '[', so plain indexOf is wrong); throw loudly
  when no array is present
- pm2 probe and discovery both use it; discovery failures now log instead
  of vanishing

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@alari76
alari76 merged commit cb6929d into main Aug 30, 2026
2 checks passed
@alari76
alari76 deleted the fix/pm2-jlist-banner branch August 30, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant