Format cellular reservation adapter
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (client) (push) Successful in 13m38s
Foundation / checks (network) (push) Failing after 12m9s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 2m34s
Foundation / checks (checks) (push) Canceled after 16m54s
Foundation / checks (postgres) (push) Canceled after 3m12s

This commit is contained in:
dingo
2026-10-11 09:06:22 -04:00
parent 657ab8eb51
commit cc039b76e2
2 changed files with 30 additions and 34 deletions
@@ -41,11 +41,10 @@ struct CellularSessionTick {
// behavior; this adapter binds each action to the one live account-owned life and preserves
// the canonical input needed for publication and replay.
[[nodiscard]] std::expected<CellularSessionTick, CellularSessionBatchError>
prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const persistence::CellularMutationReservation>
mutations = {});
prepare_cellular_session_tick(
const CellularLives& state, std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const persistence::CellularMutationReservation> mutations = {});
// Builds one bounded publication from the last durable head. Its working copy is private;
// only the host may publish, and callers must discard it after uncertainty until the host
+26 -29
View File
@@ -102,8 +102,8 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
reservation.target_tick != tick || life_id == 0 || event_index == 0 ||
offer_tick == 0 || offer_tick >= tick || operator_id == 0)
return std::unexpected{CellularSessionBatchError::mutation};
const auto life = std::ranges::find(state.lives(), reservation.account,
&CellularOwnedLife::account);
const auto life =
std::ranges::find(state.lives(), reservation.account, &CellularOwnedLife::account);
if (life == state.lives().end() || life->identity.life != life_id ||
life->mutation.event_index != event_index || life->mutation.offer_tick != offer_tick ||
!life->mutation.offer ||
@@ -112,10 +112,11 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
}))
return std::unexpected{CellularSessionBatchError::mutation};
if (std::ranges::any_of(prepared.intents.mutations, [&](const auto& previous) {
return previous.life_id == life_id ||
previous.successor_id == reservation.successor_identity;
}) ||
if (std::ranges::any_of(prepared.intents.mutations,
[&](const auto& previous) {
return previous.life_id == life_id ||
previous.successor_id == reservation.successor_identity;
}) ||
std::ranges::any_of(prepared.mutation_actions, [&](const auto& previous) {
return previous.account == reservation.account &&
previous.action_id == reservation.action_id;
@@ -123,17 +124,17 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
return std::unexpected{CellularSessionBatchError::duplicate_mutation};
prepared.intents.mutations.push_back(
{life_id, event_index, offer_tick, reservation.successor_identity, operator_id});
prepared.mutation_actions.push_back(
{reservation.account, reservation.action_id, tick,
{life_id, event_index, offer_tick, operator_id}});
prepared.mutation_actions.push_back({reservation.account,
reservation.action_id,
tick,
{life_id, event_index, offer_tick, operator_id}});
}
std::ranges::sort(prepared.intents.mutations, {}, &CellularMutationSelection::life_id);
std::ranges::sort(prepared.mutation_actions,
[](const auto& left, const auto& right) {
if (left.account != right.account)
return left.account < right.account;
return left.action_id < right.action_id;
});
std::ranges::sort(prepared.mutation_actions, [](const auto& left, const auto& right) {
if (left.account != right.account)
return left.account < right.account;
return left.action_id < right.action_id;
});
return prepared;
}
@@ -159,13 +160,11 @@ CellularSessionBatchBuilder::create(const CellularLives& committed_state,
return builder;
}
std::expected<void, CellularSessionBatchError>
CellularSessionBatchBuilder::append(std::uint64_t tick,
std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const CellularTickIntents::Birth> births,
std::span<const persistence::CellularMutationReservation>
mutations) {
std::expected<void, CellularSessionBatchError> CellularSessionBatchBuilder::append(
std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions,
std::span<const CellularTickIntents::Birth> births,
std::span<const persistence::CellularMutationReservation> mutations) {
if (batch_.ticks.size() >= max_cellular_batch_ticks)
return std::unexpected{CellularSessionBatchError::batch_full};
if (actions_.size() + actions.size() > max_cellular_action_records)
@@ -182,8 +181,7 @@ CellularSessionBatchBuilder::append(std::uint64_t tick,
return std::unexpected{CellularSessionBatchError::duplicate_action};
for (const auto& action : prepared->mutation_actions)
if (std::ranges::find_if(mutation_actions_, [&](const auto& previous) {
return previous.account == action.account &&
previous.action_id == action.action_id;
return previous.account == action.account && previous.action_id == action.action_id;
}) != mutation_actions_.end())
return std::unexpected{CellularSessionBatchError::duplicate_mutation};
if (births.size() > biology::max_cellular_tick_lives)
@@ -210,8 +208,8 @@ CellularSessionBatchBuilder::append(std::uint64_t tick,
auto next = CellularLives::restore(working_->snapshot(), working_->world(), working_->region(),
working_->frame(), working_->tick());
if (!next || !(*next)->advance_tick_with_mutations(prepared->intents.lives,
prepared->intents.mutations))
if (!next ||
!(*next)->advance_tick_with_mutations(prepared->intents.lives, prepared->intents.mutations))
return std::unexpected{CellularSessionBatchError::biology};
for (const auto& birth : prepared->intents.births) {
@@ -235,9 +233,8 @@ CellularSessionBatchBuilder::append(std::uint64_t tick,
prepared->mutation_actions.end());
return records;
}();
if (!encode_cellular_mutation_action_block(next_mutation_actions,
next_batch.header.begin_tick,
next_batch.header.end_tick))
if (!encode_cellular_mutation_action_block(next_mutation_actions, next_batch.header.begin_tick,
next_batch.header.end_tick))
return std::unexpected{CellularSessionBatchError::mutation};
working_ = std::move(*next);
batch_ = std::move(next_batch);