fix(server): hold mutation choices while ticks past the head are open
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m27s
Foundation / postgres-tools (push) Successful in 25s
Foundation / server-image (push) Successful in 4m9s
Foundation / image (push) Successful in 4m33s

A choice reserves the tick after the committed head. With an open batch
or a background commit, that tick was already being simulated: the batch
committed without the choice (refused, losing its ticks) or, racing the
reservation, committed past it and left a reservation for a tick that had
gone, which stalled the region at its next fresh batch.

While a batch is open or a commit is in flight, the host now holds new
choices and answers not_ready (the client repeats them every 2 s). The
loop commits what it holds, waits for the head, then reserves the held
choices and starts a fresh batch with them. A queued choice the builder
still refuses makes the host reload its queue instead of stalling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-22 09:32:39 -04:00
co-authored by Claude Opus 5.5
parent 8ce609d344
commit d06c781819
5 changed files with 70 additions and 2 deletions
@@ -139,6 +139,23 @@ class CellularRegionHost {
std::uint64_t generation,
std::uint64_t action_id,
const CellularMutationActionInput& input);
// A choice reserves the tick after the committed head, so it must not be reserved while
// ticks past that head are simulated (an open batch, or a commit in flight): the batch
// would commit without it, or skip its tick. While held, a new choice is remembered and
// answered not_ready (the client repeats it); admit_held_selections reserves them once
// nothing is simulated past the head.
void hold_mutation_selections(bool hold) noexcept {
hold_selections_ = hold;
}
[[nodiscard]] bool selections_held() const noexcept {
return !held_selections_.empty();
}
void admit_held_selections();
// A queued choice the builder refused (its tick passed): reload the queue from the
// store, which keeps only reservations for the head's next tick.
void recheck_mutations() noexcept {
mutations_uncertain_ = true;
}
// Reserved choices for the next tick, in reservation order; pass them to the builder.
[[nodiscard]] std::span<const persistence::CellularMutationReservation>
queued_mutations() const noexcept {
@@ -277,8 +294,15 @@ class CellularRegionHost {
std::vector<CellularTickIntents::Birth> queued_births_;
std::vector<CellularBirthRefusal> pending_birth_refusals_;
std::vector<persistence::CellularMutationReservation> queued_mutations_;
struct HeldSelection {
persistence::Uuid account{};
std::uint64_t generation{}, action_id{};
CellularMutationActionInput input{};
};
std::vector<HeldSelection> held_selections_;
// A reservation may exist that the queue does not show; reload before publishing.
bool mutations_uncertain_{};
bool hold_selections_{};
std::vector<FinalCellularMutation> finalized_mutations_;
std::vector<FinalCellularMutation> recent_mutations_; // Bounded, for exact repeats.
struct Ending {