feat(admin): live tuning revisions adopted at recorded ticks (schema 66)
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (checks) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Successful in 29s
Foundation / server-image (push) Successful in 4m42s
Foundation / image (push) Successful in 5m55s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (checks) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Successful in 29s
Foundation / server-image (push) Successful in 4m42s
Foundation / image (push) Successful in 5m55s
ADR-0182 section 13. The admin portal's Tuning page edits the world's rules-13 tuning (the Git revamp file format); the admin API checks it, stores an append-only revision and queues an adopt_tuning admin command (kind 7: revision and rules digest) for every region of the world. - Lifecycle: adopt_tuning replaces the region's rules after births when a resolver names the rules for that revision and digest; the safety revision cannot change live. At most one adoption per batch. - Host: fetches the revision text, rebuilds and digests the rules before appending the command; publication and recovery name the rules from the successor state, checked against the recorded digest. - Schema 66: tuning_revisions, admin_set_tuning_v1, load_tuning_revision_v1 (runtime), admin_tuning_revisions_v1, admin_tuning_text_v1. - OpsServer: optional bounded request bodies (Content-Length, 413). - Region view: rules_sha256, so the portal shows each region's revision. - Portal: Tuning page; baseline from the mounted cellular-revamp.tuning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1469,6 +1469,51 @@ CellularLives::seed_wildlife_root(State& next, std::uint64_t world, std::uint64_
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::array<std::uint8_t, 32> cellular_admin_digest(const CellularAdminCommand& c) noexcept {
|
||||
std::array<std::uint8_t, 32> digest{};
|
||||
const std::array<std::uint64_t, 4> words{c.amount.energy.value, c.amount.matter[0].value,
|
||||
c.amount.matter[1].value, c.amount.matter[2].value};
|
||||
for (std::size_t w = 0; w < words.size(); ++w)
|
||||
for (std::size_t b = 0; b < 8; ++b)
|
||||
digest.at(w * 8 + b) = static_cast<std::uint8_t>(words.at(w) >> (8 * b));
|
||||
return digest;
|
||||
}
|
||||
|
||||
CellularAdminCommand
|
||||
cellular_adopt_tuning_command(std::uint64_t id, std::uint64_t revision,
|
||||
const std::array<std::uint8_t, 32>& digest) noexcept {
|
||||
CellularAdminCommand command{id, CellularAdminKind::adopt_tuning, 0, revision, {}};
|
||||
std::array<std::uint64_t, 4> words{};
|
||||
for (std::size_t w = 0; w < words.size(); ++w)
|
||||
for (std::size_t b = 0; b < 8; ++b)
|
||||
words.at(w) |= std::uint64_t{digest.at(w * 8 + b)} << (8 * b);
|
||||
command.amount.energy.value = words[0];
|
||||
for (std::size_t c = 0; c < 3; ++c)
|
||||
command.amount.matter.at(c).value = words.at(c + 1);
|
||||
return command;
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> encode_cellular_revamp_rules(const CellularRevampRules& r) {
|
||||
std::vector<std::uint8_t> bytes;
|
||||
Writer out{bytes};
|
||||
out.put(r.body.essential_upkeep_per_thousand, 4);
|
||||
out.put((r.step.collection_percent == 100 ? 0U : r.step.collection_percent) |
|
||||
(r.step.split_evenly ? 0x10000U : 0U),
|
||||
4);
|
||||
for (const auto rate : r.burn_pj_per_kfg)
|
||||
out.put(rate);
|
||||
out.put(r.step.membrane_collection_per_mille_per_point, 4);
|
||||
out.put(r.step.engulf_ratio_milli, 4);
|
||||
out.put(r.step.engulf_reserve_percent, 4);
|
||||
out.put(r.step.kill_bubble_per_thousand, 4);
|
||||
out.put(r.drip_interval_ticks, 4);
|
||||
out.put(r.reserve_load_per_thousand, 4);
|
||||
out.put(r.drip_bubble_pj);
|
||||
out.put(r.drip_bubble_fg);
|
||||
write_revamp_offers(out, r);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
bool cellular_admin_command_valid(const CellularAdminCommand& c) noexcept {
|
||||
const bool some = c.amount != accounting::Inventory{};
|
||||
switch (c.kind) {
|
||||
@@ -1484,13 +1529,16 @@ bool cellular_admin_command_valid(const CellularAdminCommand& c) noexcept {
|
||||
case CellularAdminKind::spawn_wildlife:
|
||||
return c.id != 0 && c.count >= 1 && c.count <= 64 && !some && c.target != 0 &&
|
||||
c.target <= cellular_bud_namespace - c.count;
|
||||
case CellularAdminKind::adopt_tuning:
|
||||
return c.id != 0 && c.count == 0 && c.target != 0 && some && c.amount.matter[3].value == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
|
||||
CellularLives::admin_candidate(std::span<const CellularAdminCommand> commands,
|
||||
std::vector<CellularAdminResult>* results) const {
|
||||
std::vector<CellularAdminResult>* results,
|
||||
const CellularTuningResolver& tuning) const {
|
||||
if (state_->format_version != cellular_lives_revamp_format ||
|
||||
state_->rules_version < cellular_lives_revamp_rules)
|
||||
return std::unexpected{CellularLivesError::version};
|
||||
@@ -1575,6 +1623,20 @@ CellularLives::admin_candidate(std::span<const CellularAdminCommand> commands,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CellularAdminKind::adopt_tuning: {
|
||||
// A revision nobody can name is not a refusal: replay would diverge.
|
||||
const auto rules =
|
||||
tuning ? tuning(command.target, cellular_admin_digest(command)) : std::nullopt;
|
||||
if (!rules)
|
||||
return std::unexpected{CellularLivesError::invalid_config};
|
||||
// The safety revision is a recorded law of the opening; it does not change live.
|
||||
if (cellular_revamp_valid(*rules) &&
|
||||
rules->safety_version == next.revamp.safety_version) {
|
||||
next.revamp = *rules;
|
||||
applied = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CellularAdminKind::spawn_wildlife: {
|
||||
if (next.lives.size() + command.count >= next.revamp.organism_cap)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user