#pragma once #include "evo/server/lifecycle/cellular_lives.hpp" #include #include namespace evo::server { // Unowned descendants progress without sessions. Owned active/lingering cells // need ticks to enter/finish suspension; suspended cells alone need none. // Historical profiles without offline freeze are not opted into unattended work. [[nodiscard]] bool cellular_unattended_tick_needed(const CellularLives& state) noexcept; enum class CellularScheduleError : std::uint8_t { clock_regression, head_regression, authority, admission }; struct CellularScheduleStatus { bool due{}; bool retry_ready{true}; // Also permits servicing a recovered durable interval with zero debt. std::uint64_t debt{}, max_debt{}; std::uint64_t head_age_us{}; // Since the last confirmed head change/recovery. }; // Pure local pacing, not an authority or durable admission queue. The caller // supplies monotonic microseconds and only the CONFIRMED head. One due tick may // be attempted per poll. Rejected work does not consume debt. Authority loss, // restart or absence of tick demand pauses wall-time (ADR-0133); committed // intervals and uncertain outcomes remain the fenced host's responsibility. // On a new anchor, previously_admitted_ticks excludes a recovered durable prefix // from fresh wall-time accounting. It is bounded to 64 and cannot wrap the head. class CellularTickSchedule { public: [[nodiscard]] std::expected observe(std::uint64_t now_us, std::uint64_t epoch, std::uint64_t committed_tick, bool needed, bool authoritative, std::uint64_t previously_admitted_ticks = 0); void defer(std::uint64_t now_us) noexcept; [[nodiscard]] CellularScheduleStatus status() const noexcept; private: bool observed_{}, anchored_{}; bool have_receipt_{}, was_authoritative_{}; std::uint64_t last_us_{}, origin_us_{}, origin_tick_{}, head_{}, epoch_{}, retry_us_{}; std::uint64_t receipt_us_{}, receipt_tick_{}, receipt_epoch_{}; CellularScheduleStatus status_; }; } // namespace evo::server