Files
aevolution/include/evo/server/cellular_session_batch.hpp
T
dingo 817a830a8a
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m23s
Foundation / checks (tsan) (push) Successful in 10m11s
Foundation / checks (client) (push) Failing after 14m26s
Foundation / checks (network) (push) Successful in 18m54s
Foundation / checks (checks) (push) Successful in 42m9s
Foundation / checks (postgres) (push) Successful in 43m51s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
ADR 0127
2026-10-15 09:32:51 -04:00

101 lines
4.2 KiB
C++

#pragma once
#include "evo/network/intent_admission.hpp"
#include "evo/persistence/life_reservation_store.hpp"
#include "evo/persistence/region_lease.hpp"
#include "evo/server/lifecycle/cellular_batch.hpp"
#include <cstdint>
#include <expected>
#include <memory>
#include <span>
#include <utility>
#include <vector>
namespace evo::server {
enum class CellularSessionBatchError : std::uint8_t {
tick,
intents,
action,
life,
duplicate_action,
duplicate_birth,
invalid_birth,
mutation,
duplicate_mutation,
unperceived_target,
head,
batch_full,
action_limit,
biology
};
struct CellularSessionTick {
CellularTickIntents intents;
std::vector<CellularActionRecord> actions;
std::vector<CellularMutationActionRecord> mutation_actions;
};
// Overlays authenticated v7 actions and v10 durable mutation reservations onto the
// scheduler's complete per-life input set. The scheduler owns non-player and no-message
// behavior; this adapter binds each action to the one live account-owned life and preserves
// the canonical input needed for publication and replay.
[[nodiscard]] std::expected<CellularSessionTick, CellularSessionBatchError>
prepare_cellular_session_tick(
const CellularLives& state, std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const persistence::CellularMutationReservation> mutations = {});
// Builds one bounded publication from the last durable head. Its working copy is private;
// only the host may publish, and callers must discard it after uncertainty until the host
// resolves that exact prepared batch.
class CellularSessionBatchBuilder {
public:
[[nodiscard]] static std::expected<CellularSessionBatchBuilder, CellularSessionBatchError>
create(const CellularLives& committed_state, const persistence::RegionHead& committed_head);
[[nodiscard]] std::expected<void, CellularSessionBatchError>
append(std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const CellularTickIntents::Birth> births = {},
std::span<const persistence::CellularMutationReservation> mutations = {});
// Scheduler path: expected placement/funding/existing-life refusals are reported
// separately, so they cannot prevent other births or the ordinary tick. Unexpected
// failures retain append's all-or-nothing behavior. Persist reports only after publish.
[[nodiscard]] std::expected<void, CellularSessionBatchError> append_with_birth_refusals(
std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const CellularTickIntents::Birth> births = {},
std::span<const persistence::CellularMutationReservation> mutations = {});
[[nodiscard]] std::span<const CellularBirthRefusal> refused_births() const noexcept {
return refused_births_;
}
[[nodiscard]] const CellularBatch& batch() const noexcept {
return batch_;
}
[[nodiscard]] std::span<const CellularActionRecord> actions() const noexcept {
return actions_;
}
[[nodiscard]] std::span<const CellularMutationActionRecord> mutation_actions() const noexcept {
return mutation_actions_;
}
[[nodiscard]] const CellularLives& candidate() const noexcept {
return *working_;
}
private:
[[nodiscard]] std::expected<void, CellularSessionBatchError>
append_impl(std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const CellularTickIntents::Birth> births,
std::span<const persistence::CellularMutationReservation> mutations,
bool allow_refusals);
explicit CellularSessionBatchBuilder(std::unique_ptr<CellularLives> working)
: working_{std::move(working)} {}
std::unique_ptr<CellularLives> working_;
CellularBatch batch_;
std::vector<CellularActionRecord> actions_;
std::vector<CellularMutationActionRecord> mutation_actions_;
std::vector<CellularBirthRefusal> refused_births_;
};
} // namespace evo::server