15#include <asio/awaitable.hpp>
30 std::uint64_t cpu_millis = 0;
31 std::uint64_t memory_bytes = 0;
32 std::uint64_t gpu_slots = 0;
33 std::uint64_t gpu_memory_bytes = 0;
34 std::uint64_t processes = 0;
35 std::uint64_t threads = 0;
36 std::uint64_t file_descriptors = 0;
37 std::uint64_t disk_bytes = 0;
38 std::uint64_t network_connections = 0;
39 std::uint64_t tool_slots = 0;
40 std::uint64_t provider_requests = 0;
41 std::uint64_t model_tokens = 0;
42 std::uint64_t monetary_microunits = 0;
43 std::uint64_t wall_time_ms = 0;
47 [[nodiscard]]
bool empty()
const noexcept;
60enum class HostResourceConfidence : std::uint8_t {
66NEOGRAPH_API std::string_view to_string(HostResourceConfidence confidence)
noexcept;
71 HostResourceConfidence confidence = HostResourceConfidence::ConservativeFallback;
72 std::int64_t observed_at_ms = 0;
73 bool cgroup_limited =
false;
94 static constexpr std::uint32_t SCHEMA_VERSION = 1;
104 std::string profile_id);
107 std::string profile_id)
const;
108 const std::string& profile_id() const noexcept;
113 std::
string serialize_canonical() const;
120enum class HostPressureLevel : std::uint8_t {
125NEOGRAPH_API std::string_view to_string(HostPressureLevel level)
noexcept;
127struct NEOGRAPH_API HostPressureSample {
128 HostPressureLevel level = HostPressureLevel::Normal;
129 std::int64_t observed_at_ms = 0;
133enum class HostAdmissionFailure : std::uint8_t {
141NEOGRAPH_API std::string_view to_string(HostAdmissionFailure failure)
noexcept;
143class NEOGRAPH_API HostAdmissionError final :
public std::runtime_error {
145 HostAdmissionError(HostAdmissionFailure failure, std::string detail);
146 [[nodiscard]] HostAdmissionFailure failure() const noexcept;
149 HostAdmissionFailure failure_;
154 std::string owner_scope;
155 std::string operation_id;
158 std::uint8_t priority = 0;
160 std::uint32_t max_pending = 0;
161 std::chrono::milliseconds queue_timeout{0};
163 std::uint8_t fairness_weight = 1;
166struct NEOGRAPH_API HostAdmissionSnapshot {
170 std::uint32_t queued = 0;
171 bool overcommitted =
false;
172 HostPressureLevel pressure = HostPressureLevel::Normal;
173 std::uint8_t pressure_scale_percent = 100;
174 std::int64_t pressure_changed_at_ms = 0;
175 std::string pressure_source;
178struct NEOGRAPH_API HostAdmissionControllerConfig {
179 std::optional<HostResourceProfile> profile;
180 std::uint32_t max_pending = 1024;
182 std::chrono::milliseconds aging_quantum{100};
184 std::uint8_t elevated_capacity_percent = 75;
186 std::uint8_t critical_capacity_percent = 50;
188 std::uint8_t recovery_step_percent = 10;
190 std::chrono::milliseconds recovery_quiet_period{5000};
194class HostAdmissionControllerImpl;
207 [[nodiscard]]
bool held()
const noexcept;
211 void release() noexcept;
216 std::uint64_t reservation_id,
219 std::shared_ptr<detail::HostAdmissionControllerImpl> impl_;
220 std::uint64_t reservation_id_ = 0;
239 asio::awaitable<HostResourceLease> reserve_async(
241 std::shared_ptr<graph::CancelToken> cancel_token = {});
252 [[nodiscard]] HostAdmissionSnapshot snapshot()
const;
253 void shutdown() noexcept;
256 std::shared_ptr<detail::HostAdmissionControllerImpl> impl_;
NEOGRAPH_API export/import macro for shared-library builds.
Cooperative cancellation primitive for graph runs.
Shared asynchronous capacity scheduler.
void observe_pressure(HostPressureSample sample)
Apply an observed pressure state.
std::optional< HostResourceLease > try_reserve(HostAdmissionRequest request)
Non-blocking admission; never bypasses an existing waiter.
std::uint8_t priority_hint() const noexcept
Dynamic priority including a waiter that is blocked by this lease.
Immutable capacity snapshot.
static HostResourceProfile intersect(const std::vector< HostResourceProfile > &profiles, std::string profile_id)
Intersect independently enforced sources; the tightest limit wins per dimension.
HostResourceProfile scaled_available(std::uint8_t percent, std::string profile_id) const
Scale only schedulable capacity, preserving the immutable safety reserve.
static HostResourceProfile detect_current()
Detect cgroup-v2 / process limits on Linux and return conservative, bounded fallbacks elsewhere.
One atomic request to hold a vector of local host resources.
Provenance pinned with a profile so later scheduling decisions are auditable.
Construction input for an immutable local host resource profile.
HostResourceVector safety_reserve
Never admitted. It reserves host headroom for the operating system and recovery.
std::string profile_id
Host-controlled generation token; it changes whenever configured limits change.
Vector of independently reserved host resources.
static HostResourceVector saturating_add(const HostResourceVector &lhs, const HostResourceVector &rhs) noexcept
Saturating addition prevents an impossible request from wrapping into admission.
static HostResourceVector subtract_clamped(const HostResourceVector &lhs, const HostResourceVector &rhs) noexcept
Clamped subtraction is used only to expose an available diagnostic snapshot.
bool fits_within(const HostResourceVector &limit) const noexcept
True only when every requested component is at most the corresponding limit.