* test: add comprehensive recovery tests for agent loop Add recovery test coverage for all edge cases and failure scenarios in the agentic loop, addressing the missing test coverage for recovery use cases. Tool Call Parsing Edge Cases: - Empty tool_result tags - Empty tool_calls arrays - Whitespace-only tool names - Empty string arguments History Management: - Trimming without system prompt - Role ordering consistency after trim - Only system prompt edge case Arguments Parsing: - Invalid JSON string fallback - None arguments handling - Null value handling JSON Extraction: - Empty input handling - Whitespace only input - Multiple JSON objects - JSON arrays Tool Call Value Parsing: - Missing name field - Non-OpenAI format - Empty tool_calls array - Missing tool_calls field fallback - Top-level array format Constants Validation: - MAX_TOOL_ITERATIONS bounds (prevent runaway loops) - MAX_HISTORY_MESSAGES bounds (prevent memory bloat) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(security): Add Phase 1 security features - sandboxing, resource limits, audit logging Phase 1 security enhancements with zero impact on the quick setup wizard: - ✅ Pluggable sandbox trait system (traits.rs) - ✅ Landlock sandbox support (Linux kernel 5.13+) - ✅ Firejail sandbox support (Linux user-space) - ✅ Bubblewrap sandbox support (Linux/macOS user namespaces) - ✅ Docker sandbox support (container isolation) - ✅ No-op fallback (application-layer security only) - ✅ Auto-detection logic (detect.rs) - ✅ Audit logging with HMAC signing support (audit.rs) - ✅ SecurityConfig schema (SandboxConfig, ResourceLimitsConfig, AuditConfig) - ✅ Feature-gated implementation (sandbox-landlock, sandbox-bubblewrap) - ✅ 1,265 tests passing Key design principles: - Silent auto-detection: no new prompts in wizard - Graceful degradation: works on all platforms - Feature flags: zero overhead when disabled - Pluggable architecture: swap sandbox backends via config - Backward compatible: existing configs work unchanged Config usage: ```toml [security.sandbox] enabled = false # Explicitly disable backend = "auto" # auto, landlock, firejail, bubblewrap, docker, none [security.resources] max_memory_mb = 512 max_cpu_time_seconds = 60 [security.audit] enabled = true log_path = "audit.log" sign_events = false ``` Security documentation: - docs/sandboxing.md: Sandbox implementation strategies - docs/resource-limits.md: Resource limit approaches - docs/audit-logging.md: Audit logging specification - docs/security-roadmap.md: 3-phase implementation plan - docs/frictionless-security.md: Zero-impact wizard design - docs/agnostic-security.md: Platform/hardware agnostic approach Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
100 lines
2 KiB
Markdown
100 lines
2 KiB
Markdown
# Resource Limits for ZeroClaw
|
|
|
|
## Problem
|
|
ZeroClaw has rate limiting (20 actions/hour) but no resource caps. A runaway agent could:
|
|
- Exhaust available memory
|
|
- Spin CPU at 100%
|
|
- Fill disk with logs/output
|
|
|
|
---
|
|
|
|
## Proposed Solutions
|
|
|
|
### Option 1: cgroups v2 (Linux, Recommended)
|
|
Automatically create a cgroup for zeroclaw with limits.
|
|
|
|
```bash
|
|
# Create systemd service with limits
|
|
[Service]
|
|
MemoryMax=512M
|
|
CPUQuota=100%
|
|
IOReadBandwidthMax=/dev/sda 10M
|
|
IOWriteBandwidthMax=/dev/sda 10M
|
|
TasksMax=100
|
|
```
|
|
|
|
### Option 2: tokio::task::deadlock detection
|
|
Prevent task starvation.
|
|
|
|
```rust
|
|
use tokio::time::{timeout, Duration};
|
|
|
|
pub async fn execute_with_timeout<F, T>(
|
|
fut: F,
|
|
cpu_time_limit: Duration,
|
|
memory_limit: usize,
|
|
) -> Result<T>
|
|
where
|
|
F: Future<Output = Result<T>>,
|
|
{
|
|
// CPU timeout
|
|
timeout(cpu_time_limit, fut).await?
|
|
}
|
|
```
|
|
|
|
### Option 3: Memory monitoring
|
|
Track heap usage and kill if over limit.
|
|
|
|
```rust
|
|
use std::alloc::{GlobalAlloc, Layout, System};
|
|
|
|
struct LimitedAllocator<A> {
|
|
inner: A,
|
|
max_bytes: usize,
|
|
used: std::sync::atomic::AtomicUsize,
|
|
}
|
|
|
|
unsafe impl<A: GlobalAlloc> GlobalAlloc for LimitedAllocator<A> {
|
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
let current = self.used.fetch_add(layout.size(), std::sync::atomic::Ordering::Relaxed);
|
|
if current + layout.size() > self.max_bytes {
|
|
std::process::abort();
|
|
}
|
|
self.inner.alloc(layout)
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Config Schema
|
|
|
|
```toml
|
|
[resources]
|
|
# Memory limits (in MB)
|
|
max_memory_mb = 512
|
|
max_memory_per_command_mb = 128
|
|
|
|
# CPU limits
|
|
max_cpu_percent = 50
|
|
max_cpu_time_seconds = 60
|
|
|
|
# Disk I/O limits
|
|
max_log_size_mb = 100
|
|
max_temp_storage_mb = 500
|
|
|
|
# Process limits
|
|
max_subprocesses = 10
|
|
max_open_files = 100
|
|
```
|
|
|
|
---
|
|
|
|
## Implementation Priority
|
|
|
|
| Phase | Feature | Effort | Impact |
|
|
|-------|---------|--------|--------|
|
|
| **P0** | Memory monitoring + kill | Low | High |
|
|
| **P1** | CPU timeout per command | Low | High |
|
|
| **P2** | cgroups integration (Linux) | Medium | Very High |
|
|
| **P3** | Disk I/O limits | Medium | Medium |
|