fix(lifecycle): a bud's fee comes on top of its cost, or the bud is refused
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m28s
Foundation / postgres-tools (push) Successful in 22s
Foundation / server-image (push) Successful in 4m21s
Foundation / image (push) Successful in 5m1s

DEV region 14 stalled at tick 6068 with a conservation error. The bud fee was
checked against the reserve before funding the bud, then deducted with a clamp
after: a parent whose reserve covered the bud but not the fee as well paid less
than the fee while the region reclaimed all of it, creating matter. The fee
was zero until the budding playtest tuning, so it never showed.

Funding now requires the reserve left after the bud to cover the fee; a parent
that cannot is refused for insufficient funding, and the fee is subtracted
exactly. No committed tick changes: a short-fee bud never committed. The
regression runs seeded wildlife under the DEV fee until a bud (it failed with
the conservation error before this fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-26 12:46:00 -04:00
co-authored by Claude Opus 5.5
parent 467402e404
commit 8a48e405fd
3 changed files with 63 additions and 11 deletions
@@ -12,7 +12,7 @@ spec:
env:
- {name: REGION_SESSION, value: "dev"}
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
- {name: REGION_SESSION_WINDOW, value: "dev-20261026T161949-4606613a:1793045989"}
- {name: REGION_SESSION_WINDOW, value: "dev-20261026T164548-136c52b9:1793047548"}
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
ports:
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
+15 -7
View File
@@ -3242,8 +3242,18 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
for (std::size_t c = 0; surplus && c < cost->matter.size(); ++c)
surplus = parent->reserve.matter[c].value / 2 >= cost->matter[c].value;
}
const auto transition = biology::fund_offspring(*expressed, *genome, parent->growth,
parent->reserve, temperature, copies);
auto transition = biology::fund_offspring(*expressed, *genome, parent->growth,
parent->reserve, temperature, copies);
// Rules 13: the fee comes on top of the bud, so what the reserve keeps after funding
// it must still pay the fee; otherwise the bud is refused like any unaffordable one.
if (transition && revamp_rules && !twin) {
bool covered = transition->parent_reserve.energy.value >= fee.energy.value;
for (std::size_t c = 0; c < fee.matter.size(); ++c)
covered = covered &&
transition->parent_reserve.matter[c].value >= fee.matter[c].value;
if (!covered)
transition = std::unexpected{biology::BuddingError::insufficient_funding};
}
if (revamp_rules && !twin && parent->account != LifeAccount{}) {
using S = biology::CellularSignal;
auto& a = activity_of(request.life_id);
@@ -3290,11 +3300,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
parent->reserve = transition->parent_reserve;
if (revamp_rules && !twin) {
// The fee, once per bud action, returns to the region; then control, if asked.
for (std::size_t c = 0; c < fee.matter.size(); ++c)
parent->reserve.matter[c].value -=
std::min(parent->reserve.matter[c].value, fee.matter[c].value);
parent->reserve.energy.value -=
std::min(parent->reserve.energy.value, fee.energy.value);
// Funding checked that the reserve still covers it.
if (!subtract_inventory(parent->reserve, fee))
return std::unexpected{CellularLivesError::conservation};
reclaims.emplace_back(fee, parent->position);
}
CellularOwnedLife bud{};
+47 -3
View File
@@ -178,6 +178,19 @@ void starting_wildlife_is_a_funded_opening() {
closed(*seeded);
}
require(restore(*seeded)->snapshot() == seeded->snapshot(), "running fixture restore");
// A player is born into the seeded region from the nursery's remainder and plays on.
seeded = checked(seeded->birth_candidate(
{account(9), 1}, {800'000, 800'000, 800'000, 800'000, {seeded->tick()}}),
"player birth after seeding");
for (int tick = 0; tick < 40; ++tick) {
auto intents = checked(wildlife_intents(*seeded, seeded->tick() + 1), "wildlife intents");
CellularLifeIntent player{800'000, {}};
player.intent.movement = {500, 200};
intents.push_back(player);
std::ranges::sort(intents, {}, &CellularLifeIntent::life_id);
checked(seeded->advance_tick(intents), "tick with the player");
closed(*seeded);
}
auto poor = opening(77, true, 1, false);
checked(poor->advance_tick({}), "poor tick");
poor = checked(poor->migration_upgrade_candidate(), "poor boundary");
@@ -533,8 +546,10 @@ void thrust_moves_affinity() {
// Rules 13 (reproduction plan sections 6-7): Adhesion turns the cell into a two-member organism
// that holds its whole body and reserve; the organism expresses later mutations as a whole,
// buds add internal members, and at the threshold it emerges as a recorded export.
Owner adhesion_region() {
Owner adhesion_region(std::uint64_t carbon_fee = 0) {
auto rules = revamp();
rules.bud_fee.matter[0].value = carbon_fee;
rules.bud_fee_scale_percent = carbon_fee == 0 ? 0 : 100;
rules.offer_interval_ticks = 40;
rules.bounds.buds_for_adhesion = 0;
rules.emerge_members = 3;
@@ -565,10 +580,13 @@ std::vector<CellularLifeIntent> forage(const CellularLives& state, std::uint64_t
const auto& life = life_of(state, life_id);
const biology::CellularPatch* best = nullptr;
double nearest{};
// Short of energy, it heads for energy; otherwise for whatever is richest.
const bool hungry = life.reserve.energy.value < 3'000'000;
for (const auto& patch : state.habitat().patches()) {
auto richest = patch.stock.energy.value;
for (const auto& channel : patch.stock.matter)
richest = std::max(richest, channel.value);
if (!hungry)
for (const auto& channel : patch.stock.matter)
richest = std::max(richest, channel.value);
const auto distance = std::hypot(
static_cast<double>(patch.address.x_um) - static_cast<double>(life.position.x_um),
static_cast<double>(patch.address.y_um) - static_cast<double>(life.position.y_um));
@@ -585,6 +603,8 @@ std::vector<CellularLifeIntent> forage(const CellularLives& state, std::uint64_t
static_cast<double>(best->address.y_um) - static_cast<double>(life.position.y_um);
// Inside the unit circle: scale by the Euclidean length, rounded toward zero.
const auto span = std::max(1.0, std::hypot(dx, dy));
if (hungry && span < 80)
return input; // On the energy: hold still and feed rather than spend on thrust.
for (auto& entry : input)
if (entry.life_id == life_id)
entry.intent.movement = {static_cast<std::int16_t>(dx * 999.0 / span),
@@ -632,6 +652,29 @@ CellularBudExecution bud_until_funded(Owner& state, std::uint64_t life_id, int t
}
return last;
}
// The bud fee comes on top of the bud. Wildlife that can fund a bud but not the fee as well is
// refused, never charged less than the fee the region reclaims (DEV region 14 stalled on that
// conservation error at its first such bud). Seeded wildlife under the DEV fee, run until buds.
void the_bud_fee_is_paid_in_full_or_refused() {
auto rules = revamp();
rules.bud_fee = {{250'000}, {{{100'000}, {30'000}, {10'000}, {60'000}}}};
rules.bud_fee_scale_percent = 100;
auto source = opening(77, true, 64, false);
checked(source->advance_tick({}), "opening tick");
source = checked(source->migration_upgrade_candidate(), "boundary");
source = checked(source->maturation_upgrade_candidate(), "maturation");
source = checked(source->inheritance_upgrade_candidate(), "inheritance");
source = checked(source->photosynthesis_upgrade_candidate({0, 1, {0}}), "light");
source = checked(source->liquid_upgrade_candidate(liquid()), "liquid");
auto state = checked(source->revamp_upgrade_candidate(rules, 32, 900'000), "wildlife");
int tick = 0;
for (; tick < 12'000 && state->next_bud_sequence() < 2; ++tick) {
const auto intents = checked(wildlife_intents(*state, state->tick() + 1), "intents");
checked(state->advance_tick(intents), "wildlife tick under the bud fee");
}
require(state->next_bud_sequence() >= 2, "no wildlife budded under the fee");
closed(*state);
}
void an_organism_forms_grows_and_emerges() {
auto state = adhesion_region();
const auto adhesion = await_offer(state, 101, 49);
@@ -766,6 +809,7 @@ void trace_replays() {
int main() try {
starting_wildlife_is_a_funded_opening();
shown_bud_charge_includes_the_fee();
the_bud_fee_is_paid_in_full_or_refused();
upgrade_and_restore();
mixed_generations_tick_and_continue();
the_spent_pool_drips_back();