Fix newborns funding a second birth in their own tick

Births validated each parent against the progressively modified
candidate, so a child allocated earlier in the same batch was already
active and could fund a further birth. Two generations could appear in
one tick, which ADR-0028 forbids. The contract was already correct; the
implementation did not enforce it.

Fix parent eligibility on entry to the reproduction phase, after terminal
facts and feeding, and check every intent before applying any birth. A
rejected cascade leaves the whole tick unchanged, as before.

The regression test admits one intent whose parent is created by the
preceding intent and requires unborn_actor with balances, progress,
receipts and slot states untouched. It fails against the unguarded
implementation and passes with the guard. The same pair succeeds across
two ticks and records the grandchild ancestry. Native Release, clang-tidy
analysis, ASan and format checks were rerun and pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-22 17:18:18 -04:00
co-authored by Claude Opus 5
parent c84a701edf
commit 67637ac14c
4 changed files with 44 additions and 1 deletions
+3 -1
View File
@@ -130,7 +130,9 @@ run 1417 passed.
M2.5 adds funded budding (ADR-0028). A bounded list of trusted reproduction
intents runs after feeding and before decomposition, so a consumer can fund
offspring from what it ingested and a process terminated in that tick cannot
reproduce. The intent names a withdrawal from the parent; a fixed construction
reproduce. Parent eligibility is fixed on entry to the phase, so a child born in
a tick cannot itself be a parent until the next one. The intent names a
withdrawal from the parent; a fixed construction
fraction endows the child and the remainder becomes real heat and waste. Reserved
slots are pre-allocated at creation, so a birth never grows the ledger and a full
community rejects rather than funding a smaller child. Process identities are
+12
View File
@@ -296,6 +296,18 @@ and independently recomputed conservation. A u64-maximum investment endows exact
and conserves. Default zero capacity leaves the M2.4 reservoir layout, feeding,
producer, ledger and particle tests unchanged; golden `d61ad5bf0c928c76` is intact.
Review of `c84a701` found one defect (2026-09-22): births validated each parent
against the progressively modified candidate, so a child allocated earlier in the
same batch was already active and could fund a second birth. Two generations could
therefore appear in one tick, which ADR-0028 forbids. Eligibility is now fixed on
entry to the reproduction phase, after terminal facts and feeding, and checked for
every intent before any birth is applied. The contract itself was already correct
and did not change. The regression test admits one intent whose parent is created
by the preceding intent and requires `unborn_actor` with the entire tick unchanged;
it was confirmed to fail against the unguarded implementation and to pass with the
guard. The same pair succeeds across two ticks, recording the grandchild ancestry.
All four native configurations were rerun after the fix.
Allocation-failure injection, serialized recovery of states/parents/origins and
long-run ecosystem behavior were not exercised. This fixture defines no
reproductive strategy, fecundity, mutation, gestation, spatial placement or account
+10
View File
@@ -346,6 +346,16 @@ FeedingCommunity::advance(Tick target, std::span<const FeedIntent> inputs,
}
receipts.push_back(*result);
}
// Eligibility is fixed on entry to this phase, after terminal facts and feeding.
// Applying a birth activates a slot, so a child must not become a parent here.
for (const auto& birth : ordered_births) {
if (candidate.states_[birth.parent - 1] == State::unborn) {
return std::unexpected{FeedingError::unborn_actor};
}
if (candidate.states_[birth.parent - 1] != State::active) {
return std::unexpected{FeedingError::inactive_actor};
}
}
std::vector<ReproduceReceipt> delivered;
delivered.reserve(ordered_births.size());
for (const auto& birth : ordered_births) {
+19
View File
@@ -323,6 +323,25 @@ void reproduction_limits_and_rollback() {
reject(huge, FeedingError::insufficient_inventory);
const std::array reserved{ReproduceIntent{1, 3, bundle(10)}};
reject(reserved, FeedingError::unborn_actor);
// Two reserved slots, so an unchecked cascade could otherwise fund both births.
const std::array lineage{ConsumerConfig{bundle(100), bundle(100), 1000}};
auto generations =
FeedingCommunity::create(producer(), {100}, bundle(20).matter, lineage, {}, {2, 1000, {}});
CHECK(generations);
const auto untouched = copy(*generations);
const std::array cascade{ReproduceIntent{1, 2, bundle(10)}, ReproduceIntent{2, 3, bundle(5)}};
const auto chained = generations->advance(evo::Tick{1}, {}, {}, cascade);
CHECK(!chained && chained.error() == FeedingError::unborn_actor);
CHECK(copy(*generations) == untouched && generations->progress().tick.value == 0);
CHECK(generations->last_births().empty());
CHECK(!*generations->born(3) && !*generations->born(4));
// The same pair succeeds once the child has existed since the start of a tick.
const std::array parent_only{ReproduceIntent{1, 2, bundle(10)}};
CHECK(generations->advance(evo::Tick{1}, {}, {}, parent_only));
CHECK(generations->last_births()[0].child == 3);
const std::array grandchild{ReproduceIntent{1, 3, bundle(5)}};
CHECK(generations->advance(evo::Tick{2}, {}, {}, grandchild));
CHECK(generations->last_births()[0].child == 4 && *generations->parent(4) == 3);
for (const auto parent : {0U, 1U, 99U}) {
const std::array invalid{ReproduceIntent{1, parent, bundle(10)}};
reject(invalid, FeedingError::invalid_batch);