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
+48
View File
@@ -184,6 +184,11 @@ void CellularRegionHost::acquire() {
committed_ = std::move(recovered->committed);
queued_mutations_.clear();
mutations_uncertain_ = true; // Reserved choices are reloaded under the new lease.
// ADR-0127: every founder corpse is an ended life; record any ending a crash lost.
pending_endings_.clear();
for (const auto& corpse : state_->corpses())
if (corpse.parent_life == 0)
pending_endings_.push_back({committed_->head.commit, corpse.life_id});
status_.phase = HostPhase::running;
status_.simulated_tick = committed_->head.end_tick;
status_.committed_tick = committed_->head.end_tick;
@@ -301,6 +306,7 @@ void CellularRegionHost::resolve() {
}
return;
}
note_endings(*state_, *pending_->candidate, retried->head.commit);
state_ = std::move(pending_->candidate);
committed_ = std::move(*retried);
for (const auto& action : pending_->actions)
@@ -338,10 +344,50 @@ const HostStatus& CellularRegionHost::step() {
acquire();
if (!pending_ && state_ && mutations_uncertain_ && status_.phase == HostPhase::running)
reload_mutations();
if (!pending_ && state_ && status_.phase == HostPhase::running)
flush_endings();
refresh();
return status_;
}
void CellularRegionHost::note_endings(const CellularLives& before, const CellularLives& after,
const persistence::Uuid& commit) {
for (const auto& life : before.lives())
if (life.account != LifeAccount{} &&
std::ranges::find(after.lives(), life.identity.life, [](const CellularOwnedLife& next) {
return next.identity.life;
}) == after.lives().end())
pending_endings_.push_back({commit, life.identity.life});
}
void CellularRegionHost::flush_endings() {
while (!pending_endings_.empty()) {
const auto grant = authority_.grant();
if (!grant || !authority_.may_begin_commit(LeaseClock::now()) || !database())
return;
// One call per commit, at most the SQL bound of identities.
const auto commit = pending_endings_.front().commit;
std::vector<std::uint64_t> lives;
for (const auto& ending : pending_endings_)
if (ending.commit == commit && lives.size() < persistence::max_life_endings_per_call)
lives.push_back(ending.life);
const auto recorded = persistence::end_cellular_lives(*db_, config_.key, *grant, commit,
lives, config_.lease.commit_timeout);
if (!recorded) {
if (recorded.error().kind == persistence::LifeReservationError::fenced) {
authority_.fence();
status_.ready = false;
}
db_.reset();
++status_.store_failures;
return; // Retried on a later step; a new life waits for it.
}
std::erase_if(pending_endings_, [&](const Ending& ending) {
return ending.commit == commit && std::ranges::find(lives, ending.life) != lives.end();
});
}
}
void CellularRegionHost::reload_mutations() {
const auto grant = authority_.grant();
if (!grant || !committed_ || !database())
@@ -515,8 +561,10 @@ CellularRegionHost::publish(const CellularBatch& batch,
CellularPublishFailure{CellularHostError::publication, published.error().kind,
published.error().store, published.error().object}};
}
note_endings(*state_, **candidate, published->committed.head.commit);
state_ = std::move(*candidate);
committed_ = published->committed;
flush_endings();
for (const auto& action : actions)
finalized_actions_.push_back({action, committed_->head.sequence});
const auto births = births_in(batch);