Isolated PM2 process for spawning Claude CLI agents, preventing orphaned processes when portos-server restarts.
When multiple CoS agents are running and the main portos-server restarts (due to code changes, crashes, or manual restart), child processes spawned via child_process.spawn() become orphaned. The parent loses track of them because the activeAgents Map is in memory.
A separate portos-cos PM2 process that:
- Runs independently from
portos-server - Manages agent spawning via HTTP/Socket.IO bridge
- Doesn't restart when
portos-serverrestarts - Maintains its own state file for PID tracking
┌─────────────────┐ HTTP/Socket.IO ┌─────────────────┐
│ portos-server │ ──────────────────► │ portos-cos │
│ (5555) │ spawn/terminate │ (5558) │
│ │ ◄────────────────── │ │
│ subAgentSpawner│ events/output │ cos-runner │
└─────────────────┘ └────────┬────────┘
│
│ spawn
▼
┌───────────────┐
│ Claude CLI │
│ Processes │
└───────────────┘
- Process Isolation: Agent processes survive server restarts
- State Persistence: PIDs tracked in state file for recovery
- Bridge Communication: HTTP/Socket.IO for cross-process messaging
- Orphan Detection: Automatic cleanup of orphaned agent processes
- Chief of Staff - Main orchestration system
- Error Handling - Agent error recovery