Runtime Resource Guard
Protect Agent tasks and runtime hosts with token, memory, process, CPU, disk I/O, PSI thrashing, and idle monitoring.
The resource guard monitors running Agent tasks to contain excessive token use, memory leaks, CPU spin loops, disk log flooding, memory thrashing, and fork bombs. It does not allocate concurrency slots; concurrency scheduling belongs to the Daemon.
Signals
| Guard | Default limit | Behavior |
|---|---|---|
| Token budget | 2.5M net tokens, 30M total tokens, 300 turns per task | Warns at 80%; stops the task at hard limits. |
| Token burn rate | 300k tokens over 5 minutes | Detects short-term abnormal consumption. |
| Memory | 4 GiB RSS per task, 10 GiB runtime total | Warns at 80%; terminates after --memory-grace (default 60s). |
| Process count | 200 per task | Recursively limits child processes. |
| CPU runaway | 800% (8 cores full load) | Detects sustained spin loops; terminates after --cpu-grace (default 30s) with CPU_LIMIT_EXCEEDED. Resets on drop. |
| Disk write hard cap | 4 GiB per task | Immediately terminates with DISK_IO_LIMIT_EXCEEDED (0 grace) to prevent host disk exhaustion. |
| Disk write rate | 50 MB/s sustained | Detects log flooding; terminates after --disk-io-grace (default 30s) with DISK_IO_LIMIT_EXCEEDED. |
| Host free disk floor | 5 GiB available on host filesystem | Immediately terminates with HOST_DISK_SPACE_LOW (0 grace) when host free space drops below --min-host-free-disk-bytes. |
| PSI thrashing | Memory some avg10 > 25.0, I/O some avg10 > 50.0 | Detects severe page thrashing or I/O lockup; terminates after --psi-grace (default 30s) with MEMORY_THRASHING or IO_THRASHING. |
| Idle | MOPHEUS_AGENT_IDLE_WATCHDOG | Stops a task with no output and no in-flight tool call. |
Collection and Diagnostics
On Linux, the guard samples read-only counters from cgroup v2 (cpu.stat, io.stat, memory.pressure, io.pressure) and terminates the entire task cgroup upon circuit breaking. Terminated tasks preserve their execution state and session ID, enabling seamless resumption.
When cgroup v2 delegation is unavailable, the daemon gracefully degrades:
- Memory & Process Count: Sampled via procfs (
/proc/[pid]/status). - CPU & Disk I/O: Evaluated via procfs fallback (
/proc/[pid]/statfor CPU % and/proc/[pid]/iofor disk write bytes/rate). On macOS or non-Linux systems where telemetry is absent, metrics report 0 and watchdogs skip evaluation safely without false alarms. - PSI Thrashing: Linux cgroup v2 specific; safely skipped on degraded or non-Linux hosts.
Inspect a task's diagnostic record with:
mopheus runtime guard explain <task-id>Configuration
The runtime_guard feature flag controls system-level availability (disabled, selected, or enabled). Guard settings resolve from built-in defaults, workspace or runtime policy, agent-specific overrides, and finally MOPHEUS_GUARD_* host environment variables. Host variables take precedence. A task's effective memory ceiling is bounded by both its per-task and runtime-total limits.
Workspace administrators can inspect or change policy with mopheus runtime guard config {get|set|reset}. Use show, stats, events, and explain to inspect active usage and post-mortem diagnostics. config get presents thresholds and origins organized into a 3-column grouped table across all five monitoring dimensions.
When setting grace periods, use orthogonal flags: --memory-grace (note: legacy --grace is deprecated), --cpu-grace, --disk-io-grace, and --psi-grace.