# CleverAgents Resource Management Configuration
# Controls parallelism, timeouts, and resource allocation

resources:
  # Maximum parallel workers
  max_parallel_workers:
    default: 4
    min: 1
    # No maximum - can be set to any positive value (e.g., 32, 64, etc.)
    env_var: CA_MAX_PARALLEL_WORKERS
    
  # Worker allocation tiers
  # Based on fraction of max_parallel_workers
  worker_allocation:
    # Full tier (N) - Maximum throughput
    implementation-pool-supervisor: 1.0
    
    # Half tier (N/2) - Moderate parallelism
    pr-review-pool-supervisor: 0.5
    
    # Quarter tier (N/4) - Limited parallelism to prevent scope explosion
    uat-test-pool-supervisor: 0.25
    bug-hunt-pool-supervisor: 0.25
    test-infra-pool-supervisor: 0.25
    pr-fix-pool-supervisor: 0.25
    
    # Singleton agents (no parallelism)
    pr-merge-pool-supervisor: 0
    architecture-pool-supervisor: 0
    epic-planning-pool-supervisor: 0
    human-liaison-pool-supervisor: 0
    agent-evolution-pool-supervisor: 0
    architecture-guard-pool-supervisor: 0
    spec-update-pool-supervisor: 0
    backlog-grooming-pool-supervisor: 0
    documentation-pool-supervisor: 0
    timeline-update-pool-supervisor: 0
    project-owner-pool-supervisor: 0
    system-watchdog-pool-supervisor: 0
    
  # Timeout configurations (in seconds)
  timeouts:
    # Agent operation timeouts
    agent_heartbeat: 600          # 10 minutes
    work_claim_hours: 2           # Work claim duration
    bash_command_default: 120     # 2 minutes
    bash_sleep_multiplier: 1.5    # Sleep timeout = sleep_duration * multiplier
    
    # Human response timeouts (hours)
    human_response:
      needs_feedback_pr: 48       # 2 days
      question_on_issue: 24       # 1 day
      blocked_on_human: 72        # 3 days
      architecture_approval: 48   # 2 days
      verification_request: 24    # 1 day
    
    # API timeouts (milliseconds)
    forgejo_api: 30000           # 30 seconds
    git_operations: 300000       # 5 minutes
    test_execution: 900000       # 15 minutes
    
  # Queue management
  queue_limits:
    max_depth_multiplier: 3      # max_queue = workers * multiplier
    priority_queue_size: 10      # High priority items to keep ready
    
  # Retry policies
  retry_policies:
    # Network errors (API, git)
    network_errors:
      max_attempts: 3
      backoff: exponential       # 1s, 2s, 4s
      base_delay_seconds: 1
      max_delay_seconds: 60
      
    # Git conflicts
    git_conflicts:
      max_attempts: 2
      strategy: rebase_and_retry
      cleanup_on_failure: true
      
    # Test failures
    test_failures:
      max_attempts: 3
      strategy: escalate_tier    # codex -> sonnet -> opus
      
    # API rate limits
    rate_limits:
      max_attempts: 5
      backoff: fixed
      delay_seconds: 60          # Wait 1 minute between attempts
      
  # Resource pressure thresholds
  pressure_thresholds:
    # Worker utilization
    high_utilization_percent: 90
    critical_utilization_percent: 95
    
    # Failure rates (triggers backpressure)
    acceptable_failure_rate: 0.2    # 20%
    high_failure_rate: 0.5          # 50%
    critical_failure_rate: 0.8      # 80%
    
    # Queue depth
    queue_warning_threshold: 0.8    # 80% of max
    queue_critical_threshold: 1.0   # 100% of max
    
  # Monitoring intervals (seconds)
  monitoring:
    health_signal_interval: 600     # 10 minutes
    worker_status_check: 60         # 1 minute
    session_validation: 300         # 5 minutes
    resource_cleanup: 300           # 5 minutes
    
  # Cleanup policies
  cleanup:
    temp_dir_prefix: /tmp/cleveragents-
    max_temp_dir_age_hours: 24
    clean_on_exit: true
    preserve_on_failure: false      # Set true for debugging
    
  # Session management
  sessions:
    naming_pattern: "[{tag}] {display_name}"
    tag_prefixes:
      implementation: AUTO-IMP
      pr_review: AUTO-REV
      uat_test: AUTO-UAT
      bug_hunt: AUTO-BUG
      test_infra: AUTO-INF
      architecture: AUTO-ARCH
      planning: AUTO-EPIC
      human: AUTO-HUMAN
      evolution: AUTO-EVLV
      guard: AUTO-GUARD
      spec: AUTO-SPEC
      backlog: AUTO-BLOG
      docs: AUTO-DOCS
      timeline: AUTO-TIME
      owner: AUTO-OWNR
      watchdog: AUTO-WDOG