End dead lives durably so a player can start again

M11.6a (ADR-0127, schema v37): a published life is marked ended once, by a
commit of its region, through the lease-fenced end_cellular_lives. One active
life per account replaces one life per account, so after a death the account
reserves and publishes a new primitive founder while the corpse, archive and
descendants stay. The host records endings after the death's publication and
again for every founder corpse on recovery. The cellular server now refuses only
an unusable carried action, not the whole tick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-14 07:26:33 -04:00
co-authored by Claude Opus 5.5
parent 212ca14e83
commit 4130092d7a
15 changed files with 626 additions and 30 deletions
@@ -5,6 +5,7 @@
#include <chrono>
#include <cstdint>
#include <expected>
#include <span>
#include <vector>
namespace evo::persistence {
@@ -94,6 +95,13 @@ reserve_cellular_mutation(
std::uint64_t generation, std::uint64_t action_id,
const std::array<std::uint8_t, cellular_mutation_reservation_input_bytes>& input,
std::chrono::milliseconds timeout);
// Schema v37, ADR-0127: records that these published lives of this region had ended by
// `commit` (a commit of this region), so their accounts may start new lives. At most
// 256 identities; repeats are no-ops. Returns how many were newly ended.
inline constexpr std::size_t max_life_endings_per_call = 256;
[[nodiscard]] std::expected<std::uint32_t, LifeReservationFailure>
end_cellular_lives(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& commit,
std::span<const std::uint64_t> identities, std::chrono::milliseconds timeout);
// Pending selections are reloaded under the recovered region lease after restart.
[[nodiscard]] std::expected<std::vector<CellularMutationReservation>, LifeReservationFailure>
load_pending_cellular_mutations(Postgres& db, RegionKey key, const LeaseGrant& lease,
@@ -138,6 +138,10 @@ class CellularRegionHost {
void finalize_births(std::span<const CellularTickIntents::Birth> births);
void queue_birth(const CellularTickIntents::Birth& birth);
void reload_mutations();
// ADR-0127: owned lives that died record their ending so the account may start again.
void note_endings(const CellularLives& before, const CellularLives& after,
const persistence::Uuid& commit);
void flush_endings();
void finalize_mutations(std::span<const CellularMutationActionRecord> actions,
std::span<const std::uint8_t> results);
[[nodiscard]] network::PrimitiveLifeOutcome query_birth(const persistence::Uuid& account,
@@ -159,6 +163,11 @@ class CellularRegionHost {
bool mutations_uncertain_{};
std::vector<FinalCellularMutation> finalized_mutations_;
std::vector<FinalCellularMutation> recent_mutations_; // Bounded, for exact repeats.
struct Ending {
persistence::Uuid commit{};
std::uint64_t life{};
};
std::vector<Ending> pending_endings_; // Recorded endings not yet acknowledged.
HostStatus status_{};
};
} // namespace evo::server