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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user