Files
aevolution/include/evo/server/cellular_session_batch.hpp
T
dingoandClaude Opus 5.5 b1cc3b121b
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m44s
Foundation / image (push) Successful in 5m33s
feat(admin): live admin commands in trace 5 (schema 63)
The admin portal can now spawn wildlife, add bubbles, add to or release the
spent pool, remove a cell and grant a cell's reserve on a running rules-13
region (ADR-0182 section 10). No new owner format or region opening.

- Trace 5: trace 4 plus 64-byte command records counted in the tick header's
  last word; a batch without commands stays trace 4 (older builds replay it).
  Bundle 15 admits trace 5.
- CellularLives::admin_candidate applies a tick's commands after its births,
  each on a copy kept only when it applies and closes: imports through the
  boundary ledger, removals into the spent pool with a new `removed` corpse
  cause, spawned roots via the ADR-0180 seed (now a shared helper) funded by
  an exact import. Refused commands change nothing.
- Schema 63: the immutable admin_commands queue (spawn identities from the
  life allocator), pending/history reads, and binding of every recorded
  command exactly once inside both cellular publishers; the SQL trace parsers
  read trace 5 through its trace-4 normal form.
- The region polls pending commands every 2 s and appends up to 16 per tick;
  the admin API and portal gain region actions, per-cell Remove/Grant and the
  command history.
- Fixes an existing test that did not advance its head after a tick commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:14:04 -04:00

127 lines
5.6 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 <optional>
#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 = {},
std::span<const CellularAdminCommand> admin = {});
// 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 = {},
std::span<const CellularAdminCommand> admin = {});
[[nodiscard]] std::span<const CellularBirthRefusal> refused_births() const noexcept {
return refused_births_;
}
[[nodiscard]] const CellularBatch& batch() const noexcept {
return batch_;
}
// ADR-0182: each admin command appended so far and whether it applied, in trace order.
[[nodiscard]] std::span<const CellularAdminResult> admin_results() const noexcept {
return admin_results_;
}
[[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_;
}
// Hands the working state to a commit; the builder is spent afterwards.
[[nodiscard]] std::unique_ptr<CellularLives> take_candidate() noexcept {
return std::move(working_);
}
// A batch started on an uncommitted predecessor (a commit still in flight) takes that
// predecessor's real head once it is known. The head must end where this batch begins.
[[nodiscard]] bool rebase(const persistence::RegionHead& head) noexcept {
if (head.frame != batch_.header.frame || head.end_tick != batch_.header.begin_tick)
return false;
batch_.header.predecessor = head.commit;
batch_.header.predecessor_digest = head.digest;
return true;
}
// The owner's own refusal behind the last `biology` error, for operator logs.
[[nodiscard]] std::optional<CellularLivesError> last_lives_error() const noexcept {
return last_lives_error_;
}
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,
std::span<const CellularAdminCommand> admin, 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_;
std::vector<CellularAdminResult> admin_results_;
std::optional<CellularLivesError> last_lives_error_;
};
} // namespace evo::server