Entropic 2.11.1
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
57uint32_t ReconnectPolicy::delay_ms(uint32_t attempt) const {
58 double raw = static_cast<double>(base_delay_ms_) *
59 std::pow(backoff_factor_, static_cast<double>(attempt));
60 double capped = std::min(raw, static_cast<double>(max_delay_ms_));
61
62 // Add jitter: uniform random in [0, 10% of delay]
63 thread_local std::mt19937 rng(std::random_device{}());
64 double jitter_range = capped * 0.1;
65 std::uniform_real_distribution<double> dist(0.0, jitter_range);
66
67 return static_cast<uint32_t>(capped + dist(rng));
68}
69
78bool ReconnectPolicy::exhausted(uint32_t attempt) const {
79 if (max_retries_ == 0) {
80 return false;
81 }
82 return attempt >= max_retries_;
83}
84
85} // 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:656