You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cdk/Mixins.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1636,3 +1636,89 @@ class CachedHttpProvider {
1636
1636
}
1637
1637
}
1638
1638
```
1639
+
1640
+
---
1641
+
1642
+
## CircuitBreakerMixin
1643
+
1644
+
Implements the circuit breaker pattern to prevent cascading failures when a provider becomes unhealthy. When a provider's error count exceeds the failure threshold, the circuit opens and requests fail fast without calling the provider. After a reset timeout, a single probe request is allowed; if it succeeds, the circuit closes.
1645
+
1646
+
### States
1647
+
1648
+
| State | Description |
1649
+
| --- | --- |
1650
+
|`CLOSED`| Normal operation. Requests pass through. |
1651
+
|`OPEN`| Provider is unhealthy. Requests fail fast with `CircuitOpenError`. |
1652
+
|`HALF_OPEN`| Probe mode. A limited number of requests pass through to test recovery. |
1653
+
1654
+
### Methods
1655
+
1656
+
| Method | Signature | Description |
1657
+
| --- | --- | --- |
1658
+
|`configure_circuit_breaker`|`(failure_threshold, reset_timeout, half_open_max, success_threshold)`| Set circuit breaker parameters. |
1659
+
|`check_circuit`|`()`| Verify the circuit allows a request. Raises `CircuitOpenError` if open. |
1660
+
|`record_success`|`()`| Record a successful request. Closes circuit in half-open state. |
1661
+
|`record_failure`|`()`| Record a failed request. Opens circuit when threshold is reached. |
1662
+
|`reset_circuit`|`()`| Manually reset the circuit to CLOSED. |
1663
+
|`circuit_breaker_stats`|`()`| Return current state, failure count, and config. |
1664
+
1665
+
### Configuration
1666
+
1667
+
| Parameter | Type | Default | Description |
1668
+
| --- | --- | --- | --- |
1669
+
|`failure_threshold`|`int`|`5`| Consecutive failures to trip the circuit. |
1670
+
|`reset_timeout`|`float`|`60.0`| Seconds before OPEN transitions to HALF_OPEN. |
1671
+
|`half_open_max`|`int`|`1`| Max probe requests in HALF_OPEN state. |
1672
+
|`success_threshold`|`int`|`1`| Successes in HALF_OPEN needed to close. |
1673
+
1674
+
---
1675
+
1676
+
## TimeoutMixin
1677
+
1678
+
Enforces per-request timeouts by wrapping async operations with `asyncio.wait_for`. Raises `RequestTimeoutError` when exceeded.
1679
+
1680
+
### Methods
1681
+
1682
+
| Method | Signature | Description |
1683
+
| --- | --- | --- |
1684
+
|`configure_timeout`|`(default, streaming, streaming_total, connect)`| Set timeout values in seconds. |
1685
+
|`with_timeout`|`(coro, timeout?, operation?)`| Execute a coroutine with a timeout. |
1686
+
|`with_stream_timeout`|`(aiter, first_chunk_timeout?, total_timeout?)`| Wrap a streaming async iterator with timeouts. |
Tracks streaming response progress so that interrupted streams can be detected and potentially resumed. Buffers content and token counts per active stream.
1702
+
1703
+
### Methods
1704
+
1705
+
| Method | Signature | Description |
1706
+
| --- | --- | --- |
1707
+
|`configure_checkpoints`|`(max_buffer_tokens, checkpoint_interval, max_checkpoints)`| Set checkpoint parameters. |
1708
+
|`create_checkpoint`|`(request_id, model_id?)`| Create and register a new stream checkpoint. |
1709
+
|`get_checkpoint`|`(request_id)`| Retrieve a checkpoint by request ID. |
1710
+
|`remove_checkpoint`|`(request_id)`| Remove a completed checkpoint. |
1711
+
|`active_checkpoints`|`()`| Return all incomplete checkpoints. |
0 commit comments