Fix clw-agent-exhausted: CloudWatch Agent Resource Pool Exhaustion

OpenClaw intermediate Linux macOS Windows AWS EC2 AWS ECS AWS Fargate

1. Symptoms

The clw-agent-exhausted error manifests when the OpenClaw CloudWatch agent reaches its maximum concurrent log processing capacity. This error typically appears during high-volume log ingestion scenarios or when the agent is configured with insufficient worker threads to handle the incoming log stream volume.

Common indicators include:

  • Error message: clw-agent-exhausted: Maximum concurrent requests exceeded for CloudWatch Logs agent
  • Log entries showing partial log delivery or dropped log lines
  • CloudWatch agent process consuming excessive CPU and memory
  • Intermittent log gaps in CloudWatch Logs console despite logs being generated
  • API throttling responses from the CloudWatch Logs endpoint (ThrottlingException)
  • Agent status showing “running” but with degraded throughput performance

Shell output examples:

[ERROR] openclaw.collector - Failed to flush buffer: clw-agent-exhausted
[ERROR] openclaw.agent - Worker pool saturated, rejecting batch of 500 lines
[WARN] openclaw.cwagent - Queue depth exceeds threshold: 15000 pending entries
[ERROR] openclaw.transport - CloudWatch API returned 429: Rate exceeded

When monitoring with standard tooling, you may observe the CloudWatch Logs agent API call latency spiking to several seconds, while the process memory footprint grows beyond expected bounds due to queued but unprocessed log entries.


2. Root Cause

The clw-agent-exhausted error originates from a fundamental bottleneck in the OpenClaw CloudWatch agent’s internal architecture. Understanding this requires examining how OpenClaw interfaces with the AWS CloudWatch Logs API and manages concurrent HTTP connections.

OpenClaw utilizes a connection pooling mechanism to communicate with CloudWatch Logs, maintaining a configurable number of concurrent workers that handle log batch submission. Each worker represents an active HTTP connection capable of sending log entries to the PutLogEvents API endpoint. The CloudWatch Logs service imposes strict API limits on both a per-stream and account-wide basis, and when the volume of incoming log data exceeds what the worker pool can accommodate, the queue of pending log entries grows until the agent signals exhaustion.

The root causes typically trace to one or more of the following scenarios:

Insufficient worker pool sizing: The default configuration allocates only a small number of concurrent workers, which proves inadequate for high-throughput applications generating thousands of log lines per second.

Unoptimized batch configuration: OpenClaw batches log entries before submission, but if the batch size is too small, the overhead of numerous API calls consumes available worker capacity inefficiently.

High log volume spikes: Applications experiencing burst traffic generate log volume that temporarily overwhelms a properly-sized worker pool designed for average throughput.

Network latency compounding: When the agent communicates with CloudWatch Logs across regions or through high-latency network paths, each worker remains occupied for longer durations, reducing effective throughput.

Concurrent log stream writes: The agent may be configured to write to multiple CloudWatch log groups simultaneously, each stream consuming worker capacity from the shared pool.

The underlying AWS constraint is the PutLogEvents API rate limit, which permits approximately 5 requests per second per log stream, with each request handling up to 1MB of payload. When OpenClaw’s worker pool cannot cycle through requests fast enough to drain the incoming queue, exhaustion occurs.


3. Step-by-Step Fix

Resolving the clw-agent-exhausted error requires adjusting both the OpenClaw agent configuration and potentially the CloudWatch Logs API invocation patterns. The following steps address the root causes systematically.

Step 1: Increase Worker Pool Size

Modify the OpenClaw configuration file to allocate additional concurrent workers for CloudWatch Logs submission.

Before:

cloudwatch:
  workers: 4
  batch_size: 10000
  queue_size: 50000

After:

cloudwatch:
  workers: 16
  batch_size: 10000
  queue_size: 200000

The worker count should scale with your log volume. For applications generating more than 50,000 log lines per minute, consider setting workers to 24 or higher. The queue size must increase proportionally to accommodate bursts without dropping logs.

Step 2: Optimize Batch Configuration

Increase the batch size to reduce the frequency of API calls and improve worker efficiency.

Before:

cloudwatch:
  batch_size: 5000
  flush_interval: 5s

After:

cloudwatch:
  batch_size: 15000
  flush_interval: 10s

Larger batches reduce API call overhead. Ensure individual batch payloads remain under the 1MB CloudWatch Logs limit, calculating: batch_size ร— average_log_line_bytes < 1MB.

Step 3: Implement Exponential Backoff

Configure retry behavior with exponential backoff to handle temporary throttling gracefully.

Before:

cloudwatch:
  retry:
    enabled: false

After:

cloudwatch:
  retry:
    enabled: true
    max_attempts: 5
    initial_backoff: 1s
    max_backoff: 60s
    backoff_multiplier: 2.0

Step 4: Enable Compression

Activate gzip compression for API payloads to reduce network occupancy time per worker.

Before:

cloudwatch:
  compression: false

After:

cloudwatch:
  compression: true
  compression_level: 6

Step 5: Restart the Agent

Apply changes by restarting the OpenClaw CloudWatch agent.

Linux (systemd):

sudo systemctl restart openclaw-agent

Direct process management:

sudo pkill -f openclaw-agent
sudo nohup /usr/local/bin/openclaw-agent --config /etc/openclaw/config.yaml > /var/log/openclaw-agent.log 2>&1 &

Step 6: Verify Configuration

Confirm the new settings are active and monitor the agent’s throughput metrics.

openclaw-agent status --verbose
curl -s http://localhost:9090/metrics | grep -E "openclaw_cw_workers|openclaw_cw_queue"

4. Verification

After implementing the configuration changes, verify that the clw-agent-exhausted error no longer occurs and that log ingestion operates normally.

Method 1: Monitor Error Logs

Check for the absence of the exhaustion error in recent logs.

journalctl -u openclaw-agent --since "10 minutes ago" | grep -i "exhausted"
grep "clw-agent-exhausted" /var/log/openclaw/collector.log

A successful fix results in zero occurrences of the error message during normal operation.

Method 2: Verify Queue Drain

Monitor the queue depth metric to confirm pending logs are processed without backlog accumulation.

watch -n 5 'curl -s http://localhost:9090/metrics | grep openclaw_cw_queue_depth'

The queue depth should remain below 10,000 entries during steady-state operation and should drain to near-zero during low-activity periods.

Method 3: Confirm Worker Utilization

Check that workers complete requests efficiently without saturation.

curl -s http://localhost:9090/metrics | grep openclaw_cw_worker_busy

Busy worker percentage should remain below 80% during peak load. Sustained values above 90% indicate the pool remains undersized.

Method 4: Validate Log Delivery

Confirm that all expected logs appear in CloudWatch Logs within the anticipated timeframe.

aws logs tail /aws/openclaw/your-log-group --filter-pattern "ERROR" --since 15m

Compare the count of error logs in CloudWatch against application error logs to identify any gaps indicating dropped entries.

Method 5: Stress Test

Generate a high-volume log burst to verify the agent handles peak loads without exhaustion.

for i in {1..100}; do
  logger "test-log-entry-$i-$(date +%s%N)"
done
sleep 30
grep "clw-agent-exhausted" /var/log/openclaw/collector.log

5. Common Pitfalls

Avoid these frequent mistakes when addressing the clw-agent-exhausted error:

Setting workers excessively high: Allocating too many workers can exhaust file descriptors and system memory. Each worker maintains an HTTP connection and associated buffers. A reasonable ceiling is 64 workers on standard instances, with monitoring for resource constraints.

Ignoring the batch size memory footprint: Increasing batch size multiplies memory consumption during queue buildup. If memory becomes constrained, the agent may crash rather than exhaust workers. Balance batch size against available RAM.

Neglecting IAM permissions: The agent requires logs:PutLogEvents with appropriate throughput limits. Insufficient IAM policies cause authentication failures that appear similar to exhaustion errors.

Misconfiguring log group retention: When CloudWatch Log Groups have short retention periods, the API may reject events that fall outside the retention window, causing apparent throughput degradation.

Using regional endpoints with cross-region traffic: Configure the agent to use the nearest CloudWatch Logs endpoint. Cross-region API calls introduce latency that occupies workers longer.

Forgetting to increase queue persistence: If the agent crashes during high load, unsaved queue contents are lost. Enable queue persistence to disk if log durability is critical.

Overlooking instance type constraints: t2.micro and similar small instances have limited CPU and network capacity that no configuration tuning can overcome. Upgrade to instances with higher network performance for extreme throughput requirements.


The following errors share common infrastructure and configuration patterns with clw-agent-exhausted:

clw-agent-timeout: This error occurs when individual CloudWatch Logs API calls exceed the configured timeout threshold. Unlike exhaustion, which indicates a capacity problem, timeout indicates latency or connectivity problems. Both errors can occur simultaneously when the worker pool becomes saturated waiting for timed-out requests.

clw-connection-refused: This error indicates the OpenClaw agent cannot establish a TCP connection to the CloudWatch Logs endpoint. Common causes include network routing issues, firewall rules blocking outbound HTTPS, or the CloudWatch Logs endpoint being temporarily unavailable. This error prevents any log submission and will eventually cause queue buildup leading to exhaustion.

clw-stream-throttled: This error specifically relates to per-stream rate limiting within CloudWatch Logs. Each log stream has independent throughput limits, and writing to many streams simultaneously can trigger throttling on individual streams while overall capacity remains available. Optimizing log stream partitioning strategies resolves this issue.

# Example: Improved stream partitioning to avoid per-stream throttling
cloudwatch:
  stream_name_template: "{hostname}-{container_id}-{date}"
  # Previously used static stream names causing concentrated throttling

Understanding the relationships between these errors helps diagnose complex failures where multiple symptoms appear simultaneously, ensuring that fixes address the true root cause rather than merely treating symptoms.