Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
reconnect_policy.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
9
10#include <algorithm>
11#include <cmath>
12#include <random>
13
14namespace entropic {
15
26 uint32_t base_delay_ms,
27 uint32_t max_delay_ms,
28 uint32_t max_retries,
29 double backoff_factor)
30 : base_delay_ms_(base_delay_ms),
31 max_delay_ms_(max_delay_ms),
32 max_retries_(max_retries),
33 backoff_factor_(backoff_factor) {}
34
42 : base_delay_ms_(config.base_delay_ms),
43 max_delay_ms_(config.max_delay_ms),
44 max_retries_(config.max_retries),
45 backoff_factor_(config.backoff_factor) {}
46
54uint32_t ReconnectPolicy::delay_ms(uint32_t attempt) const {
55 double raw = static_cast<double>(base_delay_ms_) *
56 std::pow(backoff_factor_, static_cast<double>(attempt));
57 double capped = std::min(raw, static_cast<double>(max_delay_ms_));
58
59 // Add jitter: uniform random in [0, 10% of delay]
60 thread_local std::mt19937 rng(std::random_device{}());
61 double jitter_range = capped * 0.1;
62 std::uniform_real_distribution<double> dist(0.0, jitter_range);
63
64 return static_cast<uint32_t>(capped + dist(rng));
65}
66
74bool ReconnectPolicy::exhausted(uint32_t attempt) const {
75 if (max_retries_ == 0) {
76 return false;
77 }
78 return attempt >= max_retries_;
79}
80
81} // namespace entropic
ReconnectPolicy(uint32_t base_delay_ms=1000, uint32_t max_delay_ms=60000, uint32_t max_retries=5, double backoff_factor=2.0)
Construct with explicit parameters.
bool exhausted(uint32_t attempt) const
Check if retries are exhausted.
uint32_t delay_ms(uint32_t attempt) const
Compute delay for the given attempt number.
Activate model on GPU (WARM → ACTIVE).
Exponential backoff reconnection policy.
Reconnection policy configuration for external MCP servers.
Definition config.h:433