M10.9d: batch durable action lookups (one per poll, one per commit)
Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (client) (push) Successful in 12m41s
Foundation / checks (network) (push) Successful in 13m33s
Foundation / checks (tsan) (push) Successful in 7m54s
Foundation / checks (checks) (push) Successful in 32m56s
Foundation / checks (postgres) (push) Successful in 46m10s
Foundation / postgres-tools (push) Successful in 18s
Foundation / image (push) Successful in 2m33s
Foundation / server-image (push) Successful in 4m24s

The fourth dev drill showed a synchronous PostgreSQL round trip per action on the
simulation thread: at admission (uniqueness) and again at commit (first-record rule).
About 12 lookups landed on each commit tick (commit ticks 58-70 ms, session p99 30-39 ms).

- ActionLedger::find_all; persistence::find_region_actions applies the schema v11
  find_region_action to many pairs in one statement (no migration).
- IntentAdmission::admit/verify: actions only the ledger can refuse wait for one verify
  per poll; receipts still go out in the same poll. committed() asks once per commit.
- Tests: deferred_actions (network_control), find_region_actions and find_all (Postgres).
- ADR-0097 fourth run, ADR-0092 amendment, VALIDATION; refresh the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-08 21:35:43 -04:00
co-authored by Claude Opus 5.5
parent 3ee22694cc
commit 07d12a4d82
13 changed files with 430 additions and 45 deletions
+137 -32
View File
@@ -108,19 +108,15 @@ IntentionReceipt IntentAdmission::intention(std::uint64_t session, const Session
return r;
}
ActionReceipt IntentAdmission::action(std::uint64_t session, const SessionAction& m,
const AdmissionFacts& facts) {
ActionReceipt IntentAdmission::screen(Session& s, const SessionAction& m,
const AdmissionFacts& facts, bool& check) {
ActionReceipt r{m.action_id, AdmitStatus::admitted, facts.server_tick, m.tick};
auto* s = find(session);
if (!s) {
r.status = AdmitStatus::unknown_session;
return r;
}
count_window(*s, facts.server_tick);
const bool over = s->action_attempts >= limits_.max_actions_per_window;
check = false;
count_window(s, facts.server_tick);
const bool over = s.action_attempts >= limits_.max_actions_per_window;
if (!over)
++s->action_attempts;
const auto& account = s->account;
++s.action_attempts;
const auto& account = s.account;
const auto known_action = std::ranges::find_if(actions_, [&](const Action& a) {
return a.carried.account == account && a.carried.action_id == m.action_id;
});
@@ -129,7 +125,7 @@ ActionReceipt IntentAdmission::action(std::uint64_t session, const SessionAction
});
if (over)
r.status = AdmitStatus::rate_limited;
else if (m.session != session)
else if (m.session != s.id)
r.status = AdmitStatus::unknown_session;
else if (!facts.ready)
r.status = AdmitStatus::not_ready;
@@ -144,24 +140,107 @@ ActionReceipt IntentAdmission::action(std::uint64_t session, const SessionAction
known_action != actions_.end() ? known_action->carried.tick : known_final->outcome.tick;
} else if (!in_window(m.tick, facts.server_tick, limits_.intent_window))
r.status = AdmitStatus::outside_window;
else if (unresolved_of(*s) >= limits_.max_unresolved)
else if (unresolved_of(s) >= limits_.max_unresolved)
r.status = AdmitStatus::too_many_unresolved;
else if (ledger_) {
// Committed earlier (another epoch, process or region): never admitted again.
const auto found = lookup(account, m.action_id);
if (found.state == Record::unavailable) {
r.status = AdmitStatus::not_ready; // Uniqueness cannot be confirmed now.
} else if (found.state == Record::committed) {
r.status = AdmitStatus::duplicate;
r.tick = found.outcome.tick;
remember(account, found.outcome);
}
}
if (r.status == AdmitStatus::admitted)
actions_.push_back({{account, m.action_id, m.tick, ActionKind::probe}, Stage::scheduled});
else
check = ledger_ != nullptr;
return r;
}
void IntentAdmission::decide(const AccountId& account, ActionReceipt& r, const Found& found) {
// Committed earlier (another epoch, process or region): never admitted again.
if (found.state == Record::unavailable) {
r.status = AdmitStatus::not_ready; // Uniqueness cannot be confirmed now.
} else if (found.state == Record::committed) {
r.status = AdmitStatus::duplicate;
r.tick = found.outcome.tick;
remember(account, found.outcome);
}
}
ActionReceipt IntentAdmission::action(std::uint64_t session, const SessionAction& m,
const AdmissionFacts& facts) {
auto* s = find(session);
if (!s)
return {m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
bool check = false;
auto r = screen(*s, m, facts, check);
if (check)
decide(s->account, r, lookup(s->account, m.action_id));
if (r.status == AdmitStatus::admitted)
actions_.push_back(
{{s->account, m.action_id, m.tick, ActionKind::probe}, Stage::scheduled});
return r;
}
std::optional<ActionReceipt> IntentAdmission::admit(std::uint64_t session, const SessionAction& m,
const AdmissionFacts& facts) {
auto* s = find(session);
if (!s)
return ActionReceipt{m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
bool check = false;
const auto r = screen(*s, m, facts, check);
if (r.status != AdmitStatus::admitted)
return r;
// Held like an admitted action (duplicates and the unresolved limit see it), but never
// carried until `verify` confirms it.
actions_.push_back({{s->account, m.action_id, m.tick, ActionKind::probe},
check ? Stage::verifying : Stage::scheduled,
false,
session,
facts.epoch,
facts.server_tick});
if (check)
return std::nullopt;
return r;
}
std::vector<std::pair<std::uint64_t, ActionReceipt>>
IntentAdmission::verify(const AdmissionFacts& facts) {
std::vector<std::pair<std::uint64_t, ActionReceipt>> out;
std::vector<ActionKey> keys;
for (const auto& a : actions_)
if (a.stage == Stage::verifying)
keys.push_back({a.carried.account, a.carried.action_id});
if (keys.empty())
return out;
// Authority lost or moved on since admission: refused as admission would refuse it now.
const bool current = facts.ready;
std::expected<std::vector<std::optional<ActionOutcome>>, ActionLedgerError> answers =
std::unexpected(ActionLedgerError::unavailable);
if (current && ledger_ != nullptr)
answers = ledger_->find_all(keys);
if (answers.has_value() && answers->size() != keys.size())
answers = std::unexpected(ActionLedgerError::unavailable);
std::size_t i = 0;
for (auto& a : actions_) {
if (a.stage != Stage::verifying)
continue;
const auto index = i++;
ActionReceipt r{a.carried.action_id, AdmitStatus::admitted, a.admitted_at, a.carried.tick};
if (!current) {
r.status = AdmitStatus::not_ready;
} else if (a.epoch != facts.epoch) {
r.status = AdmitStatus::stale_epoch;
} else {
Found found;
if (answers.has_value()) {
const auto& record = (*answers)[index];
found.state = record.has_value() ? Record::committed : Record::absent;
if (record.has_value())
found.outcome = *record;
}
decide(a.carried.account, r, found);
}
if (r.status == AdmitStatus::admitted)
a.stage = Stage::scheduled;
out.emplace_back(a.session, r);
}
// Every refused one leaves (a duplicate is remembered among the finals by `decide`).
std::erase_if(actions_, [](const Action& a) { return a.stage == Stage::verifying; });
return out;
}
ActionOutcome IntentAdmission::query(std::uint64_t session, const ActionQuery& m,
const AdmissionFacts& facts) {
ActionOutcome o{m.action_id, ActionResult::unknown, 0, 0};
@@ -242,13 +321,26 @@ void IntentAdmission::remember(const AccountId& account, const ActionOutcome& ou
std::vector<AccountOutcome> IntentAdmission::committed(std::span<const CarriedAction> actions,
std::uint64_t commit_sequence) {
std::vector<AccountOutcome> out;
for (const auto& c : actions) {
// The durable record is the authority: an id carried by two batches (an account that
// moved regions with the action pending) keeps the record of the first commit. One
// request for the whole commit; unanswered, the host's own report stands.
std::expected<std::vector<std::optional<ActionOutcome>>, ActionLedgerError> records =
std::unexpected(ActionLedgerError::unavailable);
if (ledger_ != nullptr && !actions.empty()) {
std::vector<ActionKey> keys;
keys.reserve(actions.size());
for (const auto& c : actions)
keys.push_back({c.account, c.action_id});
records = ledger_->find_all(keys);
if (records.has_value() && records->size() != actions.size())
records = std::unexpected(ActionLedgerError::unavailable);
}
for (std::size_t i = 0; i < actions.size(); ++i) {
const auto& c = actions[i];
ActionOutcome o{c.action_id, ActionResult::committed_no_effect, c.tick, commit_sequence};
// The durable record is the authority: an id carried by two batches (an account that
// moved regions with the action pending) keeps the record of the first commit.
if (ledger_)
if (const auto found = lookup(c.account, c.action_id); found.state == Record::committed)
o = found.outcome;
if (records.has_value())
if (const auto& record = (*records)[i]; record.has_value())
o = *record;
std::erase_if(actions_, [&](const Action& a) {
return a.carried.account == c.account && a.carried.action_id == c.action_id;
});
@@ -297,6 +389,19 @@ std::vector<AccountOutcome> IntentAdmission::abandon() {
return out;
}
std::expected<std::vector<std::optional<ActionOutcome>>, ActionLedgerError>
ActionLedger::find_all(std::span<const ActionKey> keys) {
std::vector<std::optional<ActionOutcome>> out;
out.reserve(keys.size());
for (const auto& k : keys) {
auto found = find(k.account, k.action_id);
if (!found.has_value())
return std::unexpected(found.error());
out.push_back(*found);
}
return out;
}
IntentAdmission::Found IntentAdmission::lookup(const AccountId& account,
std::uint64_t action_id) const {
Found f;