feat: durable mutation queue (schema 59)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m24s
Foundation / postgres-tools (push) Successful in 1m31s
Foundation / server-image (push) Successful in 4m25s
Foundation / image (push) Successful in 4m50s

A mutation choice's reserved tick is now the earliest tick it may bind
at, not the only one (ADR-0121 amendment). With write-behind commits, a
choice reserved for head + 1 landed in ticks already being simulated or
committed: the batch was refused, or the reservation was orphaned for a
past tick and stalled the region.

Schema 59: a bound record carries the tick it applied at and the rest of
its input must equal the reservation's; the "omits a reserved mutation"
refusals are removed. Existing rows are unchanged, so an orphaned
reservation binds at the next commit that carries it.

The host keeps every unbound reservation queued and the open batch binds
those the commit in flight does not carry, at its next tick; the earlier
hold on new choices is removed. A choice that outlives its life binds as
life_died (owner, trace matching and recovery accept it when no life with
that ID remains). Recovery takes a bound choice's tick from its trace.

Tests: a choice skipped by one checkpoint binds a tick late and recovers;
builder late binding, refusal before the earliest tick, and a departed
life's life_died outcome. Full local PostgreSQL qualification passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-22 10:27:09 -04:00
co-authored by Claude Opus 5.5
parent 8a7e944942
commit 71d195d4e8
17 changed files with 409 additions and 114 deletions
+4 -20
View File
@@ -139,28 +139,19 @@ 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.
// Reserved choices, in reservation order (ADR-0121 amendment, schema 59: a durable
// queue; each binds at a tick at or after its reservation's).
[[nodiscard]] std::span<const persistence::CellularMutationReservation>
queued_mutations() const noexcept {
return queued_mutations_;
}
// Queued choices not carried by the commit in flight: the open batch binds these.
[[nodiscard]] std::vector<persistence::CellularMutationReservation> unbound_mutations() const;
[[nodiscard]] std::vector<FinalCellularMutation> take_finalized_mutations();
// v5 requests allocate durably, then wait for the scheduler to include the exact
// reservation in a profile-4 batch. Repeating the request is idempotent.
@@ -294,15 +285,8 @@ 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 {