ADR 0127
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m23s
Foundation / checks (tsan) (push) Successful in 10m11s
Foundation / checks (client) (push) Failing after 14m26s
Foundation / checks (network) (push) Successful in 18m54s
Foundation / checks (checks) (push) Successful in 42m9s
Foundation / checks (postgres) (push) Successful in 43m51s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-15 09:32:51 -04:00
parent 0a0f6c3bb1
commit 817a830a8a
20 changed files with 474 additions and 28 deletions
+49
View File
@@ -612,6 +612,10 @@ CellularRegionHost::publish(const CellularBatch& batch,
}
void CellularRegionHost::queue_birth(const CellularTickIntents::Birth& birth) {
if (std::ranges::any_of(pending_birth_refusals_, [&](const auto& refusal) {
return refusal.birth.account == birth.account && refusal.birth.request == birth.request;
}))
return;
const auto found = std::ranges::find_if(queued_births_, [&](const auto& queued) {
return queued.account == birth.account && queued.request == birth.request;
});
@@ -627,6 +631,27 @@ void CellularRegionHost::finalize_births(std::span<const CellularTickIntents::Bi
});
}
void CellularRegionHost::refuse_births(std::span<const CellularBirthRefusal> refusals) {
for (const auto& refusal : refusals) {
if (refusal.reason != CellularLivesError::insufficient_funding &&
refusal.reason != CellularLivesError::no_placement &&
refusal.reason != CellularLivesError::life_exists)
continue;
if (std::ranges::find(queued_births_, refusal.birth) == queued_births_.end())
continue;
// Remove before the database call: an uncertain refusal must never race a spawn.
std::erase(queued_births_, refusal.birth);
std::erase_if(pending_birth_refusals_, [&](const auto& previous) {
return previous.birth.account == refusal.birth.account;
});
if (pending_birth_refusals_.size() == biology::max_cellular_tick_lives)
pending_birth_refusals_.erase(pending_birth_refusals_.begin());
pending_birth_refusals_.push_back(refusal);
static_cast<void>(query_birth(refusal.birth.account, refusal.birth.generation,
refusal.birth.request, false));
}
}
network::PrimitiveLifeOutcome CellularRegionHost::query_birth(const persistence::Uuid& account,
std::uint64_t generation,
std::uint64_t request, bool enqueue) {
@@ -661,6 +686,30 @@ network::PrimitiveLifeOutcome CellularRegionHost::query_birth(const persistence:
if (outcome.reservation.region != config_.key.region)
return unknown();
const auto result = life_result(outcome.reservation.refusal);
const auto refused = std::ranges::find_if(pending_birth_refusals_, [&](const auto& entry) {
return entry.birth.account == account && entry.birth.request == request;
});
if (refused != pending_birth_refusals_.end()) {
if (result != PrimitiveLifeResult::pending) {
pending_birth_refusals_.erase(refused);
} else {
const auto reason = refused->reason == CellularLivesError::insufficient_funding
? persistence::LifeRefusal::insufficient_funding
: refused->reason == CellularLivesError::no_placement
? persistence::LifeRefusal::no_placement
: persistence::LifeRefusal::existing_life;
const auto recorded =
persistence::reject_primitive_life(*db_, config_.key, *grant, account, generation,
request, reason, config_.lease.commit_timeout);
if (!recorded) {
db_.reset();
++status_.store_failures;
return unknown();
}
pending_birth_refusals_.erase(refused);
return {request, life_result(*recorded), outcome.reservation.identity, 0};
}
}
if (result == PrimitiveLifeResult::pending && enqueue)
queue_birth({account, request, generation, outcome.reservation.identity});
return {request, result, outcome.reservation.identity, 0};