Runtimes

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

GuardDefault limitBehavior
Token budget2.5M net tokens, 30M total tokens, 300 turns per taskWarns at 80%; stops the task at hard limits.
Token burn rate300k tokens over 5 minutesDetects short-term abnormal consumption.
Memory4 GiB RSS per task, 10 GiB runtime totalWarns at 80%; terminates after --memory-grace (default 60s).
Process count200 per taskRecursively limits child processes.
CPU runaway800% (8 cores full load)Detects sustained spin loops; terminates after --cpu-grace (default 30s) with CPU_LIMIT_EXCEEDED. Resets on drop.
Disk write hard cap4 GiB per taskImmediately terminates with DISK_IO_LIMIT_EXCEEDED (0 grace) to prevent host disk exhaustion.
Disk write rate50 MB/s sustainedDetects log flooding; terminates after --disk-io-grace (default 30s) with DISK_IO_LIMIT_EXCEEDED.
Host free disk floor5 GiB available on host filesystemImmediately terminates with HOST_DISK_SPACE_LOW (0 grace) when host free space drops below --min-host-free-disk-bytes.
PSI thrashingMemory some avg10 > 25.0, I/O some avg10 > 50.0Detects severe page thrashing or I/O lockup; terminates after --psi-grace (default 30s) with MEMORY_THRASHING or IO_THRASHING.
IdleMOPHEUS_AGENT_IDLE_WATCHDOGStops 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]/stat for CPU % and /proc/[pid]/io for 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.