# Genesis PRD: Advanced Scale-Down Strategies

This PRD defines stories to enhance AIVA's scale-down capabilities beyond simple threshold-based actions, incorporating cooldown periods and other advanced strategies.

### GPM-059: Implement Basic Cooldown Period for Scale-Down
**Goal:** Prevent rapid oscillations in resource allocation by introducing a cooldown period after a scale-down event.
**Acceptance Criteria:**
- After a scale-down event is triggered, no further scale-down events can occur for a configurable cooldown period (e.g., 5 minutes).
- The cooldown period is configurable via a global setting.
- Log entries indicate when a scale-down event is blocked due to the cooldown.
**Files:** `aiva/autoscaler.py`, `config/aiva_config.yaml`
**Spawns:** Implement different cooldown strategies (linear, exponential backoff).

### GPM-060: Add Configuration for Cooldown Period Length
**Goal:** Allow users to customize the cooldown period length.
**Acceptance Criteria:**
- The `config/aiva_config.yaml` file includes a parameter to set the cooldown period length in seconds.
- The autoscaler reads the cooldown period length from the configuration.
- The cooldown period length can be set to a value between 60 seconds and 3600 seconds (1 hour).
**Files:** `config/aiva_config.yaml`, `aiva/config_loader.py`
**Spawns:** Implement dynamic cooldown period adjustment based on system behavior.

### GPM-061: Implement Linear Backoff Cooldown
**Goal:** Increase the cooldown period linearly after each scale-down event, up to a maximum duration.
**Acceptance Criteria:**
- A new configuration parameter determines whether to use a fixed or linear backoff cooldown.
- When linear backoff is enabled, the cooldown period increases by a fixed amount (configurable) after each scale-down.
- The maximum cooldown period for linear backoff is also configurable.
**Files:** `aiva/autoscaler.py`, `config/aiva_config.yaml`
**Spawns:** Implement exponential backoff cooldown strategy.

### GPM-062: Implement Exponential Backoff Cooldown
**Goal:** Increase the cooldown period exponentially after each scale-down event, up to a maximum duration.
**Acceptance Criteria:**
- A new configuration parameter determines whether to use a fixed, linear, or exponential backoff cooldown.
- When exponential backoff is enabled, the cooldown period increases by a factor (configurable) after each scale-down.
- The maximum cooldown period for exponential backoff is also configurable.
**Files:** `aiva/autoscaler.py`, `config/aiva_config.yaml`
**Spawns:** Implement a combined linear and exponential backoff.

### GPM-063: Add Logging for Cooldown Status
**Goal:** Provide detailed logging information about the cooldown status and its impact on scale-down decisions.
**Acceptance Criteria:**
- Log messages indicate when a scale-down event is skipped due to the cooldown period.
- Log messages include the remaining cooldown time.
- Log messages include the type of cooldown being used (fixed, linear, exponential).
**Files:** `aiva/autoscaler.py`
**Spawns:** Add metrics reporting for cooldown events and durations.

### GPM-064: Implement Minimum Resource Allocation Check
**Goal:** Prevent scale-down from reducing resource allocation below a pre-defined minimum.
**Acceptance Criteria:**
- A configuration parameter specifies the minimum CPU allocation.
- The autoscaler will not scale-down below this minimum, even if utilization is low.
- Log messages indicate when a scale-down is prevented due to the minimum allocation limit.
**Files:** `aiva/autoscaler.py`, `config/aiva_config.yaml`
**Spawns:** Implement dynamic adjustment of the minimum resource allocation.

### GPM-065: Implement Hysteresis for Scale-Down Threshold
**Goal:** Prevent rapid oscillations by requiring the CPU utilization to stay below the scale-down threshold for a sustained period before scaling down.
**Acceptance Criteria:**
- A new configuration parameter defines the duration (in seconds) that CPU utilization must remain below the scale-down threshold before a scale-down is triggered.
- The autoscaler tracks the history of CPU utilization.
- Scale-down is only triggered if the utilization has been below the threshold for the specified duration.
**Files:** `aiva/autoscaler.py`, `config/aiva_config.yaml`
**Spawns:** Add a scale-up hysteresis threshold.
