Overview
Loop mode runs the evolver continuously in a daemon-like process, automatically analyzing history, applying changes, and adapting to system load. It includes built-in protection against memory leaks, singleton enforcement, and intelligent backoff when the system is idle or saturated.What is Loop Mode?
Loop mode transforms the evolver from a one-shot command into a long-running background process that:- Runs evolution cycles continuously
- Adapts sleep intervals based on system activity
- Prevents duplicate daemon instances (singleton lock)
- Automatically restarts itself to prevent memory leaks
- Increases sleep time when evolution saturates
- Respects pending solidify operations (Ralph-loop gating)
Starting Loop Mode
Direct Execution
Run the evolver with the--loop flag:
- Acquires a singleton lock (
evolver.pid) - Registers signal handlers for graceful shutdown
- Starts the A2A heartbeat (keeps node alive in network)
- Begins the evolution cycle loop
Alternative Flag
The--mad-dog flag is an alias for --loop:
Daemon Behavior
Singleton Lock
Only one evolver loop can run at a time. The daemon createsevolver.pid with its process ID:
Evolution Cycle Loop
Check Pending Solidify
Skip the cycle if the previous run is awaiting solidification:This prevents Ralph-loop conflicts where multiple cycles try to modify the same state.
Adaptive Sleep
Calculate sleep time based on cycle duration:
- Fast cycle (less than 500ms): Double sleep time (idle detection)
- Normal cycle: Reset to minimum sleep
- Saturation signal: Multiply sleep by 5x or 10x
Adaptive Sleep and Backoff
Base Configuration
Control sleep intervals with environment variables:| Variable | Default | Description |
|---|---|---|
EVOLVER_MIN_SLEEP_MS | 2000 | Minimum sleep between cycles (2s) |
EVOLVER_MAX_SLEEP_MS | 300000 | Maximum sleep (5 minutes) |
EVOLVER_IDLE_THRESHOLD_MS | 500 | Cycles faster than this trigger backoff |
EVOLVE_PENDING_SLEEP_MS | 120000 | Sleep when awaiting solidify (2 minutes) |
Backoff Algorithm
Saturation Detection
When signals indicate evolution saturation, sleep time is multiplied:evolution_saturationsignal: 5x sleepforce_steady_statesignal: 10x sleep
Jitter
A random jitter (0-250ms) is added to each sleep to prevent lockstep restarts:Suicide and Restart Mechanism
Why Suicide?
Long-running Node.js processes can accumulate memory leaks from:- Loaded modules and closures
- Cached file buffers
- Internal V8 heap fragmentation
Restart Triggers
Restart Process
Disable Suicide
For debugging or special environments:Cron and External Runners
Best Practices
When running loop mode via cron or external process managers, use simple commands: Recommended:What to Avoid
Don’t compose multiple shell segments inside cron payloads:Process Manager Integration
For production deployments, use a process manager:Lifecycle Management
For production deployments, use the operations module:Monitoring Loop Mode
Check Process Status
View Live Logs
Check Memory Usage
Inspect State File
Stopping Loop Mode
Graceful Shutdown
Send SIGTERM to the process:Force Kill
If the process doesn’t exit:Configuration Reference
Sleep and Timing
Restart Thresholds
Strategy Control
Troubleshooting
Loop Won’t Start
Problem: “Evolver loop already running (PID 12345). Exiting.” Solution: Check if process is actually running:Loop Restarts Too Frequently
Problem: Daemon restarts every few cycles. Solution: Increase restart thresholds:High Memory Usage
Problem: RSS grows beyond expected levels. Solution: Lower restart threshold or investigate memory leaks:Loop Becomes Idle
Problem: Evolver sleeps indefinitely. Solution: Check for saturation signals:force_steady_state or evolution_saturation are present, the system is in low-frequency mode. This is intentional to avoid thrashing a mature system.
Best Practices
- Use process managers: pm2, systemd, or Docker for production
- Monitor logs: Set up log rotation and alerting
- Set CPU limits: Use
EVOLVE_LOAD_MAXto prevent overload - Start conservatively: Begin with high sleep times, then tune down
- Enable health checks: Run
lifecycle.js checkperiodically - Version control: Always run in a git repository with remote backups
Next Steps
Operations
Lifecycle commands and health monitoring
Strategy Presets
Control evolution focus in loop mode
Review Mode
Alternative: manual approval workflow
Running Evolver
Single-run execution basics