Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

PLAN: double-fork media-job subprocesses to survive pm2 restart (treekill tree-walk)

[._.]/ Adam Eivy8b9380b5d950
diff --git a/PLAN.md b/PLAN.md
index 68134e4ab6..2d8571a0cf 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -20,6 +20,8 @@ independently.
<!-- reference-watch proposals: slug-tagged, picked up by /claim later -->
+- [ ] [media-jobs-survive-pm2-server-restart] **Isolate long media-job subprocesses (LoRA training, video gen) from pm2's restart SIGINT via spawn-side double-fork.** Surfaced 2026-06-14: a 9B LoRA training run died repeatedly with `SIGINT`/`KeyboardInterrupt` at the exact second of a `pm2 restart portos-server`. Root cause: pm2's `TreeKill.js` does `ps -e -o pid=,ppid=` and walks the **parent→child tree**, SIGINT-ing every descendant on restart/stop — and portos-server restarts routinely (was a hardcoded `max_memory_restart: 2G`, now raised + `PORTOS_SERVER_MAX_MEMORY`-configurable, default 4G). `detached: true` does NOT help (TreeKill keys on ppid, not process group); `treekill: false` on the app does NOT work either (pm2 then fails to reap the old node process → it lingers on :5555 → new instance EADDRINUSE crash-loops — tried and reverted). The correct fix is spawn-side: **double-fork the trainer/video-gen child so it reparents to launchd/init (ppid=1) and leaves pm2's tree**, while still streaming stdout for progress (e.g. an intermediate `setsid` launcher that pipes through a fifo/file the parent tails, or a tiny detached supervisor). Apply to BOTH `server/services/loraTraining/index.js:~501` AND `server/services/videoGen/local.js:~918` (same vulnerability). Validate: note the child pid, `pm2 restart portos-server`, confirm the SAME pid keeps running and the job completes. Until then, the raised memory ceiling minimizes restarts and checkpoint-resume recovers any that slip through. Estimated scope: medium.
+
- [ ] [lora-training-caption-strips-invariant-identity] **Character-LoRA captions must NOT describe invariant identity — warn/strip it, or the trigger token never learns the character.** Surfaced 2026-06-14 training Freydis (dataset `90043893`). The first 4B LoRA (run `d36562a0`) rendered a generic auburn-haired woman from the bare trigger `freydis_of_quaervarr portrait`, but rendered Freydis *correctly* when the full identity description was in the prompt — proving her identity (white hair, circlet, tooth necklace, leather armor) got bound to the caption PHRASES, not the trigger token. Every one of the 25 captions repeated her invariant features. Fix path that worked: rewrite captions to keep only the trigger + what VARIES (pose, framing, weapon, setting, style) and drop invariant identity, so the trigger absorbs it (retrain ~35 min). **Caption source matters:** Freydis's images were `source: upload` with `captionSource: manual` — i.e. **Codex authored the captions externally (from the character canon/lore — hence "Northwind Cairnblade") and they were submitted through PortOS's manual-caption path** (`loraDatasets.js:393`), NOT produced by PortOS's vision auto-captioner. Codex described *the character* (identity-first), which is backwards for trigger-binding. The root fix is the external Codex prompt that authors these captions (it must follow the character-LoRA recipe: describe only what varies); PortOS's role is a safety net (lint/strip) since it can't control external caption authors. Product improvements: (a) PortOS's own auto-captioner (`server/services/loraDatasetCaption.js`) already says "do not mention the character's name" and scopes to pose/clothing/accessories — that path is fine; the canon-generation path is the offender; (b) add a caption-lint/warn in the dataset workbench that flags when the SAME descriptive fragment (hair/eyes/skin/signature items) appears across most captions — that's identity that should move to the trigger; (c) optionally offer a one-click "strip shared identity fragments" that diffs captions and removes the common invariant block (the manual rewrite done for Freydis, generalized); (d) document the character-LoRA caption recipe in the workbench UI ("describe what changes shot-to-shot, not who she is"). Estimated scope: medium.
- [ ] [lora-training-default-base-tier-too-heavy] **Reconsider the LoRA-training memory tier + default steps — unquantized 9B is ~25× slower than 4B on a 128GB box for a character LoRA.** Surfaced 2026-06-14 training Freydis (dataset `90043893`). `deriveMfluxMemoryConfig` (`server/services/loraTraining/runtimes.js`) maps ≥96GB → `{quantize:null}` (full bf16). On the M5 Max 128GB, a `flux2-klein-9b` bf16 run at 768px/600 steps **failed to complete a single real training step in 14 min** (the 32GB base materialized for the fused `value_and_grad` forward+backward hits memory/swap pressure), whereas `flux2-klein-4b` ran steady at **~3.5s/step → ~35min total** (run `d36562a0`). The base-model size dominated; `TRAINING_DEFAULTS.steps` 600→400 was minor. Proposed: (a) for single-character LoRAs default to the 4B base (or 9B-8bit) rather than unquantized 9B even when RAM allows it — speed/fidelity tradeoff strongly favors the lighter base; (b) revisit `TRAINING_DEFAULTS.steps` (600 may be 1.5-2× more than needed for 25-image faces — the checkpoint picker lets the user grab an earlier checkpoint); (c) re-measure whether `low_ram:true` is still warranted on a 128GB box once the base is lighter (the in-RAM-cache rejection was decided during the swap-thrash that coincided with the panics). Expose base-quant/low_ram as request params (currently only steps/rank/lr/resolution/checkpointEvery/sampleEvery are in `loraTrainingParamsSchema`) so a run can opt into a heavier base without a code change. Validate fidelity: confirm a 4B Freydis LoRA is acceptable before changing the default. Estimated scope: medium.