Files
legal-ai/scripts/legal-reaper.config.cjs
Chaim e186183527 fix(X13): harden court-fetch against browser leaks + reaper for task-master-mcp leak
שלוש שכבות-הגנה נגד דליפת-זיכרון מדפדפנים יתומים, + טיפול בדליפה הגדולה
בפועל בשרת (task-master-mcp).

- camofox_client.py:
  - asyncio.wait_for קשיח סביב כל ה-fetch (COURT_FETCH_HARD_TIMEOUT_S=180ש')
    — hang → ביטול → async-with tear-down → reap.
  - _reap_orphan_browsers(): הורג camoufox-bin יתומים (ppid=1) לפני ואחרי כל
    fetch. סדרתיות (INV-CF4) → כל ppid=1 הוא שארית בטוחה.
- scripts/reap_orphan_procs.py: reaper כללי ל-task-master-mcp (~3GB יתומים)
  + camoufox-bin. רק ppid=1; /proc טהור. --dry-run / --loop N.
- scripts/legal-reaper.config.cjs: דמון pm2 (loop 180s, max_memory_restart 100M).
- X13 spec + SCRIPTS.md: תיעוד שכבות-ההגנה.

max_memory_restart בשירות (1.5G) כבר נותן רשת-ביטחון ברמת-התהליך.
Invariants: מקיים INV-CF4 (politeness/serial) — ללא שינוי חוזה.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 19:43:53 +00:00

36 lines
1.2 KiB
JavaScript

/**
* pm2 ecosystem entry for legal-reaper — a host-side daemon that periodically
* reaps orphaned, runaway processes that saturate the Nautilus box:
* - task-master-mcp (Node) orphaned to ppid=1, ballooning to ~3GB each
* (memory: project_taskmaster_mcp_memory_leak).
* - camoufox-bin (Firefox) leftover from a crashed/killed X13 court fetch.
* Only ppid=1 orphans are killed — live, parented processes are never touched.
* See scripts/reap_orphan_procs.py for the safety rationale.
*
* Install (once):
* pm2 start /home/chaim/legal-ai/scripts/legal-reaper.config.cjs
* pm2 save
* Logs:
* pm2 logs legal-reaper --lines 50
*
* Interval defaults to 180s; override with REAP_INTERVAL_S.
*/
const interval = process.env.REAP_INTERVAL_S || "180";
module.exports = {
apps: [
{
name: "legal-reaper",
cwd: "/home/chaim/legal-ai",
script: "/home/chaim/legal-ai/mcp-server/.venv/bin/python",
args: `scripts/reap_orphan_procs.py --loop ${interval}`,
env: { HOME: "/home/chaim", PYTHONUNBUFFERED: "1" },
autorestart: true,
max_restarts: 20,
restart_delay: 5000,
// The reaper itself is tiny and must never be the thing that leaks.
max_memory_restart: "100M",
},
],
};