feat(ecology): own cells and their local environment together
Foundation / checks (ecs) (push) Successful in 2m28s
Foundation / checks (deploy) (push) Successful in 4m59s
Foundation / checks (network) (push) Successful in 20m56s
Foundation / checks (client) (push) Successful in 22m1s
Foundation / checks (tsan) (push) Successful in 45m41s
Foundation / checks (postgres) (push) Successful in 1h13m35s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 1h20m34s

ADR-0172 records the maintainer's M12.5 ownership decision: one owner per
patch of space for cells and their local environment, reserves belonging
to the biological individual, and an open planet boundary whose every
crossing is a recorded import or export.

The portable CellularEnvironment owner (envelope AEVOCEN1) holds an exact
population with tagged water and dissolved compartments, refuses declared
atmosphere, imports infall from finite per-source entitlements (ADR-0136
step B) and radiates retained heat. Each tick's exchange is a validated
swap on the nested owner, undone if the biological tick refuses. Closed
and source-off regions keep their biology byte for byte; raw and cohort
representations agree under infall. No existing format, trace, golden,
default opening or live version changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-19 16:05:17 -04:00
co-authored by Claude Opus 5.5
parent a898a35e1b
commit 4c70257883
17 changed files with 1335 additions and 6 deletions
+71
View File
@@ -800,6 +800,77 @@ CellularLives::migration_replacement(std::vector<CellularOwnedLife> living,
return replacement;
}
std::expected<CellularLives::BoundarySavepoint, CellularLivesError>
CellularLives::exchange_boundary(std::span<const biology::CellularPatch> deposits,
accounting::Picojoules heat_export) {
if (state_->format_version != cellular_lives_migration_format &&
state_->format_version != cellular_lives_inheritance_format)
return std::unexpected(CellularLivesError::version);
if (heat_export.value > state_->heat.energy.value)
return std::unexpected(CellularLivesError::conservation);
auto boundary = state_->boundary;
auto heat = state_->heat;
heat.energy.value -= heat_export.value;
if (heat_export.value >
std::numeric_limits<std::uint64_t>::max() - boundary.outgoing.energy.value)
return std::unexpected(CellularLivesError::overflow);
boundary.outgoing.energy.value += heat_export.value;
if (deposits.empty()) {
// Heat alone: the total falls by exactly the recorded export, so closure holds.
BoundarySavepoint savepoint{nullptr, state_->heat, state_->current_total, state_->boundary};
state_->heat = heat;
state_->current_total.energy.value -= heat_export.value;
state_->boundary = std::move(boundary);
return savepoint;
}
std::unique_ptr<biology::CellularHabitat> habitat;
{
auto config = state_->habitat->config();
if (config.format != biology::cellular_habitat_deposit_format)
return std::unexpected(CellularLivesError::version);
for (auto deposit : deposits) {
if (config.next_deposit == std::numeric_limits<std::uint32_t>::max() ||
deposit.stock == accounting::Inventory{} ||
!add_inventory(boundary.incoming, deposit.stock))
return std::unexpected(CellularLivesError::overflow);
deposit.id = config.next_deposit++;
const auto at = std::ranges::lower_bound(config.patches, deposit.address, {},
&biology::CellularPatch::address);
if (at != config.patches.end() && at->address == deposit.address)
return std::unexpected(CellularLivesError::habitat);
config.patches.insert(at, deposit);
}
auto created = biology::CellularHabitat::create(std::move(config));
if (!created)
return std::unexpected(CellularLivesError::habitat);
habitat = std::move(*created);
}
const auto rules = state_->rules_version;
const auto total = validate_state(
state_->world, state_->region, state_->frame, state_->config, state_->nursery_config,
*habitat, state_->lives, state_->corpses, state_->archive, state_->nursery, heat,
state_->opening_total, rules >= cellular_lives_engulf_rules,
rules >= cellular_lives_bud_rules, state_->next_bud_sequence,
rules >= cellular_lives_presence_rules, &boundary,
rules == cellular_lives_inheritance_rules ? &state_->offspring_revisions : nullptr);
if (!total)
return std::unexpected(total.error());
BoundarySavepoint savepoint{std::move(state_->habitat), state_->heat, state_->current_total,
state_->boundary};
state_->habitat = std::move(habitat);
state_->heat = heat;
state_->current_total = *total;
state_->boundary = std::move(boundary);
return savepoint;
}
void CellularLives::restore_boundary(BoundarySavepoint savepoint) noexcept {
if (savepoint.habitat)
state_->habitat = std::move(savepoint.habitat);
state_->heat = savepoint.heat;
state_->current_total = savepoint.current_total;
state_->boundary = std::move(savepoint.boundary);
}
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
CellularLives::migration_upgrade_candidate() const {
if (state_->rules_version != cellular_lives_foraging_rules)