From b73ccbae9a222dd182cced864acb6da8fb2dff79 Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 19 Oct 2026 23:04:34 -0400 Subject: [PATCH] feat(ecology): make photosynthesis regions playable on DEV ADR-0176 and schema 57 admit raw cellular bundle 13 (rules 11 on owner format 9) through parser-local normalization to bundle 12, and a fenced no-tick 12 -> 13 upgrade that declares the region's light; recovery reads the light from the target and re-derives the whole target from the source. The resumable cellular-v8 opening provisions a cellular-v7 genesis, one empty tick and the durable upgrades to bundle 13. Session v12 adds the owner's captured light and the producers it can see to its perception, and lets offers name photosynthesis; older sessions keep their layouts and never receive photosynthesis candidates. The client draws chloroplasts by efficiency, shows sunlight in the HUD and offers photosynthesis cards. DEV now provisions and serves region 9 with the trial light; region 8 stays stored but unserved. Co-Authored-By: Claude Opus 5.5 --- apps/evo-client/main.cpp | 17 ++ apps/evo-client/panels.cpp | 33 ++- apps/evo-client/panels.hpp | 2 + apps/evo-client/remote_session.hpp | 3 +- apps/evo-server/cellular_bridge.hpp | 56 ++++- apps/evo-world-clone/main.cpp | 141 ++++++++++- .../grant-broker-dev/deployment.yaml | 4 +- .../region/dev-session-route/listener.yaml | 2 +- .../kubernetes/region/dev/kustomization.yaml | 2 +- .../kubernetes/region/dev/region-values.yaml | 20 +- docs/STATUS.md | 13 +- .../adr/0176-durable-photosynthesis-region.md | 42 ++++ docs/adr/README.md | 2 + docs/engineering/M12_REMAINING_GATES.md | 2 +- docs/engineering/VALIDATION.md | 36 +++ include/evo/network/session_protocol.hpp | 31 ++- include/evo/persistence/checkpoint_store.hpp | 7 + include/evo/persistence/region_checkpoint.hpp | 20 +- .../evo/server/lifecycle/cellular_lives.hpp | 1 + migrations/0057_photosynthesis_bundle.sql | 223 ++++++++++++++++++ migrations/apply.sql | 15 +- .../network/session-v12-cellular-producers.md | 29 +++ schemas/region-commit.md | 5 + src/network/protocol/session_protocol.cpp | 90 ++++++- src/persistence/cellular_checkpoint_store.cpp | 53 ++++- src/persistence/population_checkpoint.cpp | 27 +++ src/persistence/region_checkpoint.cpp | 10 +- src/server/lifecycle/cellular_lives.cpp | 8 + src/server/session/region_sessions.cpp | 22 +- tests/cellular_intent_protocol_tests.cpp | 57 +++++ tests/environment_checkpoint_tests.cpp | 25 ++ tests/environment_publication_tests.cpp | 94 +++++++- tests/network_control.cpp | 2 +- tests/region_migration_tests.cpp | 3 +- tests/region_store_tests.cpp | 128 ++++++---- tools/ci/history-domain-check.sh | 8 +- tools/ci/postgres-check.sh | 10 +- tools/migrate-postgres.sh | 3 + 38 files changed, 1106 insertions(+), 140 deletions(-) create mode 100644 docs/adr/0176-durable-photosynthesis-region.md create mode 100644 migrations/0057_photosynthesis_bundle.sql create mode 100644 schemas/network/session-v12-cellular-producers.md diff --git a/apps/evo-client/main.cpp b/apps/evo-client/main.cpp index b74c2ae..f566c5c 100644 --- a/apps/evo-client/main.cpp +++ b/apps/evo-client/main.cpp @@ -840,6 +840,18 @@ int main(int argc, char** argv) try { } } const auto own = cellular_remote->cellular_play().life(); + // ADR-0176: the owner's view lists the producers it can see, by organism. + const auto* seen = cellular_remote->cellular_perception(); + const auto photosynthesis = [&](std::uint64_t organism) -> std::uint32_t { + if (!seen) + return 0; + const auto found = std::ranges::lower_bound( + seen->producers, organism, {}, + &evo::network::CellularPerceivedProducer::organism); + return found != seen->producers.end() && found->organism == organism + ? found->photosynthesis_per_thousand + : 0; + }; if (orgs) for (const auto& cell : orgs->cells()) { const auto bounds = evo::render::organism_bounds(cell, *camera); @@ -863,6 +875,11 @@ int main(int argc, char** argv) try { c.membrane = static_cast(std::clamp(1.0 + wall * 6.0, 1.0, 7.0)); c.organelles = 2 + static_cast(std::min( 3, ph.conversion_per_thousand / 250)); + c.photosynthesis_per_thousand = photosynthesis(cell.id); + c.chloroplasts = c.photosynthesis_per_thousand == 0 + ? 0 + : 1 + static_cast(std::min( + 5, c.photosynthesis_per_thousand / 200)); c.own = own != 0 && cell.id == own; c.dead = cell.state == evo::client::OrganismState::dead; c.stale = diff --git a/apps/evo-client/panels.cpp b/apps/evo-client/panels.cpp index 0835ccd..60a21c8 100644 --- a/apps/evo-client/panels.cpp +++ b/apps/evo-client/panels.cpp @@ -740,6 +740,15 @@ void draw_cell(ImDrawList& list, const SceneCell& c, float time) { add(add(centre, times(axis, u * radius.x * 1.1F)), times(normal, v * radius.y * 0.9F)), std::max(1.5F, r * 0.16F), organelle); } + // Producers (ADR-0176): chloroplasts, more of them for more efficient cells. + for (int k = 0; k < c.chloroplasts; ++k) { + const auto key = c.seed * 53U + 11U + static_cast(k); + const float u = unit_of(key) - 0.55F, v = unit_of(key + 5U) - 0.5F; + const ImVec2 at = + add(add(centre, times(axis, u * radius.x * 1.1F)), times(normal, v * radius.y * 0.9F)); + list.AddCircleFilled(at, std::max(1.8F, r * 0.18F), IM_COL32(64, 168, 84, 230)); + list.AddCircleFilled(at, std::max(0.8F, r * 0.08F), IM_COL32(150, 222, 128, 230)); + } const ImVec2 nucleus = add(centre, times(axis, radius.x * 0.42F)); list.AddCircleFilled(nucleus, std::max(2.0F, r * 0.3F), IM_COL32(224, 86, 63, 220)); list.AddCircleFilled(nucleus, std::max(1.0F, r * 0.14F), IM_COL32(255, 156, 134, 235)); @@ -895,6 +904,8 @@ void inspect_cell(ImDrawList& list, const SceneCell& c) { c.mass_fg == 0 ? 0U : static_cast(c.membrane_fg * 100 / c.mass_fg)); ImGui::Text("Intake %s/s", mass_text(c.ingestion_fg_s).c_str()); ImGui::Text("Converts %u%% of food energy", c.conversion_per_thousand / 10); + if (c.photosynthesis_per_thousand != 0) + ImGui::Text("Light %u%% photosynthesis", c.photosynthesis_per_thousand / 10); } ImGui::EndTooltip(); } @@ -1059,6 +1070,8 @@ void hud_vitals(const PanelView& v, bool compact) { movement.at(static_cast(d->movement)), intake.at(static_cast(d->intake)), energy_text(d->maintenance_cost_pj).c_str()); + if (d->light_pj != 0) + ImGui::TextDisabled("Sunlight +%s", energy_text(d->light_pj).c_str()); } ImGui::End(); } @@ -1259,11 +1272,11 @@ void hud_callout(const PanelView& v, FormBuffers& form) { ImGui::PopStyleColor(3); ImGui::End(); } -constexpr std::array capability_names{"Energy conversion", "Membrane", "Movement", - "Ingestion", "Reproduction", "Size", - "Thermal tolerance"}; -constexpr std::array capability_kinds{"Metabolism", "Defense", "Movement", "Feeding", - "Reproduction", "Size", "Environment"}; +constexpr std::array capability_names{"Energy conversion", "Membrane", "Movement", + "Ingestion", "Reproduction", "Size", + "Thermal tolerance", "Photosynthesis"}; +constexpr std::array capability_kinds{"Metabolism", "Defense", "Movement", "Feeding", + "Reproduction", "Size", "Environment", "Producer"}; constexpr std::array effect_names{"Increase", "Decrease", "Acquire", "Shed"}; constexpr std::array increase_text{"Convert more of what you eat into usable energy.", "A thicker wall: prey must be much larger to engulf you.", @@ -1271,14 +1284,16 @@ constexpr std::array increase_text{"Convert more of what you eat into usable ene "Take food faster from every patch you touch.", "Better at budding: cheaper buds, more twins (+10%).", "Grow toward a larger body: harder to engulf, slower to fill.", - "Tolerate a wider range of temperatures."}; + "Tolerate a wider range of temperatures.", + "Capture 10% more light while still; heavier and slower."}; constexpr std::array decrease_text{"Convert less of what you eat into energy.", "A thinner, cheaper wall that is easier to breach.", "Swim 10% slower and spend less on movement.", "Take food more slowly from each patch.", "Worse at budding: dearer buds, fewer twins (-10%).", "Grow toward a smaller body that is cheaper to keep.", - "Tolerate a narrower range of temperatures."}; + "Tolerate a narrower range of temperatures.", + "Capture 10% less light; lighter and a little faster."}; // A small before/after drawing of the cell for one candidate. void candidate_glyph(const network::CellularOfferedCandidate& c, float width) { const ImVec2 at = ImGui::GetCursorScreenPos(); @@ -1303,6 +1318,10 @@ void candidate_glyph(const network::CellularOfferedCandidate& c, float width) { case 0: after.organelles = up ? 5 : 1; break; + case 7: + after.chloroplasts = c.effect == 3 ? 0 : up ? 5 : 2; + before.chloroplasts = c.effect == 2 ? 0 : 3; + break; default: break; } diff --git a/apps/evo-client/panels.hpp b/apps/evo-client/panels.hpp index 7387f4b..1aed144 100644 --- a/apps/evo-client/panels.hpp +++ b/apps/evo-client/panels.hpp @@ -35,6 +35,8 @@ struct SceneCell { // What hovering the cell shows (its replicated phenotype; no hidden state). std::uint32_t extent_um{}, speed_um_s{}, conversion_per_thousand{}, grown_per_thousand{}; std::uint64_t mass_fg{}, membrane_fg{}, ingestion_fg_s{}; + std::uint32_t photosynthesis_per_thousand{}; // Zero unless the owner's view lists it. + int chloroplasts{}; // ADR-0176: green organelles in proportion to photosynthesis. }; struct ScenePatch { float x{}, y{}, half{}; // Centre and half side of the 1 mm contact footprint. diff --git a/apps/evo-client/remote_session.hpp b/apps/evo-client/remote_session.hpp index ee8e272..88a0919 100644 --- a/apps/evo-client/remote_session.hpp +++ b/apps/evo-client/remote_session.hpp @@ -499,7 +499,8 @@ class RemoteSession { return false; client::RegionSessionClientConfig config; if (cellular_trial_) - config.protocol_version = network::session_protocol_v11; // ADR-0136 deposits. + // ADR-0176: v12 is v11 (deposits) plus captured light and visible producers. + config.protocol_version = network::session_protocol_v12; const auto route = routes_.find(target_region_); config.transport = route != routes_.end() ? route->second : transport_; if (ticket_) { // A handoff: the ticket replaces a grant, once. diff --git a/apps/evo-server/cellular_bridge.hpp b/apps/evo-server/cellular_bridge.hpp index 2e4cf33..970e2e8 100644 --- a/apps/evo-server/cellular_bridge.hpp +++ b/apps/evo-server/cellular_bridge.hpp @@ -284,13 +284,11 @@ class CellularBridge { const auto before = deposit_stock_.find(patch.id); deposit.drained = before != deposit_stock_.end() && (patch.available.energy.value < before->second.energy.value || - std::ranges::any_of( - std::array{0, 1, 2, 3}, - [&](int c) { - const auto i = static_cast(c); - return patch.available.matter.at(i).value < - before->second.matter.at(i).value; - })); + std::ranges::any_of(std::array{0, 1, 2, 3}, [&](int c) { + const auto i = static_cast(c); + return patch.available.matter.at(i).value < + before->second.matter.at(i).value; + })); seen_stock_[patch.id] = patch.available; const auto dx = std::int64_t{patch.address.x_um} - centre_x; const auto dy = std::int64_t{patch.address.y_um} - centre_y; @@ -320,6 +318,50 @@ class CellularBridge { visible.matter_fg[i] = patch.available.matter[i].value; view.patches.push_back(visible); } + // ADR-0176 (v12): light this cell captured, and the photosynthetic cells it can + // see within its perception radius (nearest 256), by ascending organism. + if (view.diagnostics && feedback != state.last_tick_feedback().end() && + feedback->life_id == life.identity.life) + view.diagnostics->light_pj = feedback->light.value; + if (life.account != server::LifeAccount{}) { + std::vector> seen; + for (const auto& other : state.lives()) { + if (other.presence == server::CellularPresence::suspended) + continue; + const auto genome = state.archive().find(other.identity.genome); + if (!genome || !genome->carries(biology::Capability::photosynthesis)) + continue; + const auto dx = static_cast(other.position.x_um) - centre_x; + const auto dy = static_cast(other.position.y_um) - centre_y; + const auto distance = static_cast(dx * dx + dy * dy); + constexpr auto radius = + std::uint64_t{biology::cellular_trial_perception_radius_um}; + if (distance > radius * radius) + continue; + const auto efficiency = + genome->parameter(biology::Capability::photosynthesis).value_or(0); + if (efficiency == 0 || efficiency > 1000) + continue; + seen.emplace_back(distance, network::CellularPerceivedProducer{ + other.identity.organism, + static_cast(efficiency)}); + } + if (seen.size() > network::max_cellular_perceived_producers) { + std::ranges::nth_element( + seen, + seen.begin() + + static_cast(network::max_cellular_perceived_producers), + [](const auto& a, const auto& b) { + return std::pair{a.first, a.second.organism} < + std::pair{b.first, b.second.organism}; + }); + seen.resize(network::max_cellular_perceived_producers); + } + for (const auto& [distance, producer] : seen) + view.producers.push_back(producer); + std::ranges::sort(view.producers, {}, + &network::CellularPerceivedProducer::organism); + } (void)sessions_->send_cellular_perception(network::AccountId{life.account}, view); send_offer(state, life, tick); } diff --git a/apps/evo-world-clone/main.cpp b/apps/evo-world-clone/main.cpp index 8155b33..b985991 100644 --- a/apps/evo-world-clone/main.cpp +++ b/apps/evo-world-clone/main.cpp @@ -10,7 +10,7 @@ // evo-world-clone check-store --world W --region R --pg-* ... --objects DIR // [--reserve-mib N] // evo-world-clone provision --world W --region R --opening -// development-v1|primitive-v1|cellular-v1 to cellular-v7 +// development-v1|primitive-v1|cellular-v1 to cellular-v8 // --pg-* ... --objects DIR --build HEX [--commit HEX32] [--retain-build] // primitive-v1 also requires --frame N --source-id N, every --funding-*-* channel, // and one or more ordered --site X,Y values. @@ -70,6 +70,7 @@ // Exit: 0 done, 2 usage, 3 source/history/database failure, 4 target/objects refused, // 5 target unknown, 6 compared histories differ. #include "evo/biology/cellular_habitat.hpp" +#include "evo/persistence/checkpoint_store.hpp" #include "evo/persistence/region_clone.hpp" #include "evo/persistence/sha256.hpp" #include "evo/processes/development_opening.hpp" @@ -116,7 +117,8 @@ struct Options { std::optional cellular_width_um, cellular_height_um, cellular_temperature_mk; std::vector cellular_patches; std::vector cellular_pools; // cellular-v7 - std::optional cellular_motes; // cellular-v7 + std::optional cellular_motes; // cellular-v7 and v8 + std::optional light_pj; // cellular-v8: pJ per square um per tick std::optional life_allocator_start; std::optional build; bool retain_build{}; @@ -333,8 +335,11 @@ std::optional parse(int argc, char** argv) { else if (o.command == "provision" && flag == "--opening" && (value == "development-v1" || value == "primitive-v1" || value == "cellular-v1" || value == "cellular-v2" || value == "cellular-v3" || value == "cellular-v4" || - value == "cellular-v5" || value == "cellular-v6" || value == "cellular-v7")) + value == "cellular-v5" || value == "cellular-v6" || value == "cellular-v7" || + value == "cellular-v8")) o.opening = value; + else if (o.command == "provision" && flag == "--light-pj" && n && *n > 0) + o.light_pj = n; else if (o.command == "provision" && flag == "--frame" && n) o.primitive_frame = n; else if (o.command == "provision" && flag == "--source-id" && n) @@ -418,8 +423,11 @@ std::optional parse(int argc, char** argv) { return std::nullopt; if (cellular_options) return std::nullopt; - } else if (o.opening == "cellular-v7") { - // Pools and bubbles only: square patches belong to the earlier openings. + } else if (o.opening == "cellular-v7" || o.opening == "cellular-v8") { + // Pools and bubbles only: square patches belong to the earlier openings. Only + // cellular-v8 (ADR-0176) declares light. + if ((o.opening == "cellular-v8") != o.light_pj.has_value()) + return std::nullopt; if (!o.primitive_frame || *o.primitive_frame == 0 || !o.primitive_source || *o.primitive_source == 0 || o.primitive_sites.empty() || !std::ranges::all_of(o.primitive_funding, @@ -540,12 +548,104 @@ std::vector probe_bytes() { return out; } +// ADR-0176 cellular-v8: a cellular-v7 genesis taken through one empty tick and the durable +// bundle 9 -> 10 -> 11 -> 12 -> 13 upgrades, declaring the region's light. Resumable: it +// continues from whichever bundle the head has reached, and does nothing at bundle 13. +int finish_photosynthesis_opening(const Options& o, persistence::Postgres& db, + const persistence::FilesystemObjectStore& store, + std::uint64_t frame, const persistence::Sha256Digest& build, + std::uint64_t light_pj) { + const auto& key = o.source.key; + auto lease = + persistence::acquire_region_lease(db, key, build, std::chrono::seconds{60}, timeout); + if (!lease) { + std::puts("photosynthesis opening lease refused"); + return 3; + } + const auto finish = [&](int code) { + // A failed release only delays the next owner until the lease expires. + if (!persistence::release_region_lease(db, key, *lease, timeout)) + std::puts("photosynthesis opening lease left to expire"); + return code; + }; + auto head = persistence::load_region_checkpoint(db, key, timeout); + if (!head) + return finish(3); + for (unsigned step = 0; step < 6; ++step) { + const auto manifest = persistence::decode_manifest(head->manifest); + if (!manifest || manifest->profile != persistence::CheckpointProfile::cellular_lives_v1 || + manifest->frame != frame) + return finish(4); + const auto& versions = manifest->cellular_versions; + if (versions == persistence::cellular_v13_versions) + return finish(0); + const auto id = [&] { + persistence::Uuid made{}; + if (::getrandom(made.data(), made.size(), 0) != static_cast(made.size())) + made = {}; + return made; + }(); + if (id == persistence::Uuid{}) + return finish(4); + if (manifest->sequence == 0) { + // Upgrades follow a committed tick, never the genesis itself. + const std::array builds{build}; + auto opening = + persistence::recover_cellular_checkpoint(db, store, key, *lease, builds, timeout); + if (!opening) + return finish(4); + const server::CellularBatchHeader h{key.world, + key.region, + frame, + head->head.commit, + head->head.digest, + head->head.end_tick, + head->head.end_tick + 1}; + const server::CellularBatch tick{h, {{}}}; + auto next = server::replay_cellular_batch(*opening->state, tick); + if (!next) + return finish(4); + auto published = persistence::publish_cellular_batch(db, store, *lease, *head, tick, + **next, id, build, timeout); + if (!published) + return finish(4); + head = std::move(published->committed); + continue; + } + std::expected + upgraded = std::unexpected(persistence::CellularProfileMigrationFailure{}); + if (versions == persistence::cellular_v9_versions) + upgraded = persistence::migrate_cellular_boundary_profile(db, store, *lease, *head, id, + build, timeout); + else if (versions == persistence::cellular_v10_versions) + upgraded = persistence::migrate_cellular_maturation_profile(db, store, *lease, *head, + id, build, timeout); + else if (versions == persistence::cellular_v11_versions) + upgraded = persistence::migrate_cellular_inheritance_profile(db, store, *lease, *head, + id, build, timeout); + else if (versions == persistence::cellular_v12_versions) + upgraded = persistence::migrate_cellular_photosynthesis_profile( + db, store, *lease, *head, id, build, + {light_pj, 1, {std::numeric_limits::max() / 2}}, timeout); + else + return finish(4); + if (!upgraded) { + std::printf("photosynthesis opening upgrade refused %u\n", + static_cast(upgraded.error().kind)); + return finish(4); + } + head = std::move(*upgraded); + } + return finish(4); +} + int provision(const Options& o) { const bool primitive = o.opening == "primitive-v1"; const bool cellular = o.opening == "cellular-v1" || o.opening == "cellular-v2" || o.opening == "cellular-v3" || o.opening == "cellular-v4" || o.opening == "cellular-v5" || o.opening == "cellular-v6" || - o.opening == "cellular-v7"; + o.opening == "cellular-v7" || o.opening == "cellular-v8"; const auto primitive_frame = o.primitive_frame.value_or(0); if ((primitive || cellular) && primitive_frame == 0) return 2; @@ -640,7 +740,7 @@ int provision(const Options& o) { habitat_config.width_um = cellular_width_um; habitat_config.height_um = cellular_height_um; habitat_config.patches = o.cellular_patches; - if (o.opening == "cellular-v7") { + if (o.opening == "cellular-v7" || o.opening == "cellular-v8") { // ADR-0136 step A: pools and bubbles scattered from the genesis commit's bytes. auto field = o.cellular_motes.value_or(biology::CellularMoteField{0, 1, {}, 0}); const auto commit = o.commit.value_or(persistence::Uuid{}); @@ -662,7 +762,8 @@ int provision(const Options& o) { auto opening = server::CellularLives::create( *primitive_opening, std::move(*habitat), {{cellular_width_um, cellular_height_um}, 0, cellular_temperature_mk}, - o.opening == "cellular-v7" ? server::CellularLivesProfile::foraging + o.opening == "cellular-v7" || o.opening == "cellular-v8" + ? server::CellularLivesProfile::foraging : o.opening == "cellular-v6" ? server::CellularLivesProfile::reproduction : o.opening == "cellular-v5" ? server::CellularLivesProfile::balance : o.opening == "cellular-v4" ? server::CellularLivesProfile::presence @@ -705,6 +806,22 @@ int provision(const Options& o) { std::puts("provision refused existing profile/frame mismatch"); return 4; } + if (o.opening == "cellular-v8") { + if (manifest->sequence == 0 && + !persistence::provision_cellular_region(*db, *store, o.source.key, + primitive_frame, *cellular_opening, + commit, manifest->build, timeout)) { + std::puts("provision refused existing cellular region; use its original " + "--commit to resolve genesis"); + return 4; + } + if (const auto finished = finish_photosynthesis_opening( + o, *db, *store, primitive_frame, build, o.light_pj.value_or(0)); + finished != 0) + return finished; + auto head = persistence::load_region_checkpoint(*db, o.source.key, timeout); + return head ? report("already-provisioned", head->head) : 3; + } if (manifest->sequence > 0) return report("already-provisioned", existing->head); auto same_genesis = persistence::provision_cellular_region( @@ -751,6 +868,14 @@ int provision(const Options& o) { static_cast(made.error().kind)); return 4; } + if (o.opening == "cellular-v8") { + if (const auto finished = finish_photosynthesis_opening(o, *db, *store, primitive_frame, + build, o.light_pj.value_or(0)); + finished != 0) + return finished; + auto head = persistence::load_region_checkpoint(*db, o.source.key, timeout); + return head ? report("provisioned", head->head) : 3; + } return report("provisioned", made->head); } if (primitive) { diff --git a/deploy/kubernetes/grant-broker-dev/deployment.yaml b/deploy/kubernetes/grant-broker-dev/deployment.yaml index e54a481..00143dd 100644 --- a/deploy/kubernetes/grant-broker-dev/deployment.yaml +++ b/deploy/kubernetes/grant-broker-dev/deployment.yaml @@ -47,9 +47,9 @@ spec: - {name: BROKER_WORLD, value: "100"} - {name: BROKER_FRAME, value: "9"} # New accounts start here; an account with a live life goes to its region. - - {name: BROKER_DEFAULT_REGION, value: "8"} + - {name: BROKER_DEFAULT_REGION, value: "9"} # Space-separated REGION=HOST:PORT=TLS_NAME, every region a grant may name. - - {name: BROKER_ROUTES, value: "8=void.aeternalisgames.com:7400=void.aeternalisgames.com"} + - {name: BROKER_ROUTES, value: "9=void.aeternalisgames.com:7400=void.aeternalisgames.com"} # Must not exceed the region's REGION_M10_MAX_GRANT_LIFETIME. - {name: BROKER_GRANT_LIFETIME, value: "600"} - {name: BROKER_OIDC_ISSUER, value: "https://auth.aeternalisgames.com/realms/aeternalis"} diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index c98b1ad..c10cd98 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -12,7 +12,7 @@ spec: env: - {name: REGION_SESSION, value: "dev"} - {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"} - - {name: REGION_SESSION_WINDOW, value: "dev-20261019T215818-e009abce:1792461498"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261020T025729-1af37481:1792479449"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/deploy/kubernetes/region/dev/kustomization.yaml b/deploy/kubernetes/region/dev/kustomization.yaml index 3ebe04d..e522c6b 100644 --- a/deploy/kubernetes/region/dev/kustomization.yaml +++ b/deploy/kubernetes/region/dev/kustomization.yaml @@ -1,4 +1,4 @@ -# Region host for evolution-dev: world 100, region 8, frame 9 (cellular-v7 opening, ADR-0136). +# Region host for evolution-dev: world 100, region 9, frame 9 (cellular-v8 opening, ADR-0176). # The server image digest appears twice on purpose: as the image and as the build # identity the region records in every commit. The policy check requires they match. apiVersion: kustomize.config.k8s.io/v1beta1 diff --git a/deploy/kubernetes/region/dev/region-values.yaml b/deploy/kubernetes/region/dev/region-values.yaml index 545b1f3..e6f4942 100644 --- a/deploy/kubernetes/region/dev/region-values.yaml +++ b/deploy/kubernetes/region/dev/region-values.yaml @@ -1,7 +1,8 @@ # Region identity and build (the server image digest without "sha256:"). -# M11.9 playtests: region 8 holds a cellular-v7 genesis (rules 8, ADR-0136 step A: pools and -# bubbles fed by contact, on rules 7) on 30 x 30 mm with a 64-founder nursery. Regions 1-7 -# stay in the stores untouched; they are simply not served while dev runs region 8. +# Producer playtests (ADR-0175/0176): region 9 holds a cellular-v8 opening, region 8's +# cellular-v7 food and nursery taken durably to rules 11 (photosynthesis) with light at the +# trial 40 pJ per square um per tick. Regions 1-8 stay in the stores untouched; they are +# simply not served while dev runs region 9. apiVersion: apps/v1 kind: Deployment metadata: @@ -13,11 +14,11 @@ spec: - name: evo-server env: - {name: REGION_WORLD, value: "100"} - - {name: REGION_ID, value: "8"} + - {name: REGION_ID, value: "9"} - {name: REGION_BUILD, value: 815153514ca4a53967932bb46456ff4cb4e1784f9db247bc3b613b7e8365c59f} - {name: REGION_PROFILE, value: cellular} # The whole world's catalog: dev world 100 has only this region. - - {name: REGION_LIFE_ROUTES, value: "8=void.aeternalisgames.com:7400=void.aeternalisgames.com"} + - {name: REGION_LIFE_ROUTES, value: "9=void.aeternalisgames.com:7400=void.aeternalisgames.com"} # Keep the currently promoted build plus prior committed builds recoverable. - {name: REGION_RETAINED, value: "21507d4369cebef83ee05152daea5ac2f581ea86a9dc85276ef54e3f9f6388c5 5a77cf9e96e7a0e40ea07e9394a3fa458184ce54f8f774a8fb59cbec1db75c54 e17c62bc8dbad089da57e8b30adc391ff8b947cc7182b3160f5e2709103ded78 6c96629eb3c26513d55207b109fe2a9873a58f43510bd067b7d5422572e3fb42 7952185d5ef96504b5793b76fe72e42cbe9c9ac19149bf912adb2c3a735f8dbf f378a43d6146eeed864110b90848df0bec9672fa4c9941a2d04de249068a4a09 ecac8f9f2489c547ce58f12ed01baaa3939c8adbf8aed05c313abbf422cdc855 4af7209941643e0c6a100e2b4e2fef8a959b87fdbfac2173b7867cfc1808bd66 edb39f956df1f481d7ba724cac4ceb3a4fe494efc02f994d31d6c96dfae04a78 0ded41070dd3e0c0daa43e13dadc58c449865eec00530cfceff3c1579c66e916 754446fe4e5f33e9c0d5a1a74a02444a01de1700673442c90827c708aba62cee c597c0bac8b4a796e1e8b70344f9866cb047cc90cfb15af774d38860594ea27a e83c333a87056c678b5e835947647ef42370b43dbfc31997744f28d993f9c4aa db2b0e6a6071502381a768d70fd9bab8c08c64e4717fc23da45dbe8adc5fa3d6 cdc10712ff8bf956f8f5900709500046493523b51dc670d5b2d01eaf604bcd38 028571f257b485acafbe79b704a80f273d899485c4bb264d9c8137bf51e33217 566c29329433934f1436faf94652a7b925df8b4587ab04470322172f47c31c02 1dd640eba3e9dbdd10106698215a0a06df89c5cdf801c53c4c26fb923116552a faeb26fc5db5c4aae9ae9eb4388e807ab4d59499d7639fcab3d878843a740037 5e13e0096eb4010253c270ab98f0e9bbc11571c221eb779d428333e8cd63c955 e891f9427d5ec81b32595d70be9d00bb66c6d8223b4747d12be8c388c2fc0c8e 58aab8aaa538c0c6e5ad7281fd27e50374b489942aa317296dbf9c2ec5ca3434 4a8b0a9dc9f6be491e9eacb464aa7ef7c0d449de3018c4172c01448ce39a5108 3e5b8cef06838821113c8bba064e9415e8c627bca552fb978f830d40027b80f2"} --- @@ -32,19 +33,20 @@ spec: - name: provision env: - {name: REGION_WORLD, value: "100"} - - {name: REGION_ID, value: "8"} + - {name: REGION_ID, value: "9"} - {name: REGION_BUILD, value: 815153514ca4a53967932bb46456ff4cb4e1784f9db247bc3b613b7e8365c59f} - # Region 8 (ADR-0136 step A): a rules-8 cellular-v7 opening, 30 x 30 mm at 20 C. Food is + # Region 9 (ADR-0176): region 8's cellular-v7 opening as cellular-v8, 30 x 30 mm at 20 C, + # taken through one empty tick and the durable upgrades to rules 11 with light. Food is # region 7's total, half in 9 pools (500 um radius; a pool feeds at a quarter rate) # and half in 1,800 single-nutrient bubbles scattered from the genesis commit (360 # per channel: 7e7 pJ energy, 4.2e6 fg C, 9.4e5 N, 4.9e5 P, 2e6 other each). The # nursery funds 64 primitive founders at 9 spawn sites. # Genesis is written once: keep --commit stable so every sync resolves it. The world 100 # life allocator starts far above the unserved lineage region 1 identities (ADR-0123). - - {name: REGION_OPENING, value: cellular-v7} + - {name: REGION_OPENING, value: cellular-v8} - name: REGION_OPENING_ARGS value: >- - --frame 9 --source-id 1 --commit 4feb146db50238dde18e64a0ec332d87 + --frame 9 --source-id 1 --commit 6a6cdbfca8e3fc777110ed677de9dc2a --light-pj 40 --life-allocator-start 1000000000000 --width-um 30000 --height-um 30000 --ambient-temperature-mk 293150 --funding-energy-pj 528588800 --funding-carbon-fg 385024000 diff --git a/docs/STATUS.md b/docs/STATUS.md index 90f08d3..7238ad7 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -8,9 +8,16 @@ and cellular rules 11. A region declares light in owner format 9; each tick a st active producer captures cross-section x irradiance x efficiency (a quarter while moving), booked as boundary inflow inside the same atomic tick. A founder earns the capability as its offspring plan; its children express it and capture light. Every -earlier genome, offer, owner and environment byte keeps its meaning. Durable bundle, -session wire, client look and a DEV opening follow next. Numbers are trial values to -balance after playtesting. +earlier genome, offer, owner and environment byte keeps its meaning. Numbers are trial +values to balance after playtesting. + +[ADR-0176](adr/0176-durable-photosynthesis-region.md)/schema 57 makes producers +playable: raw bundle 13 with a durable light-declaring upgrade, the resumable +`cellular-v8` opening, and session v12, whose owner view carries captured light and +the producers it can see, and whose offers may name photosynthesis. The client draws +green chloroplasts by efficiency, shows sunlight in the HUD and offers photosynthesis +cards. DEV now provisions and serves region 9 (`cellular-v8`, light 40); region 8 stays +stored but unserved. A push alone does not establish the deployed result. ## Cellular environment ownership (M12.5a-b) - 2026-10-19 diff --git a/docs/adr/0176-durable-photosynthesis-region.md b/docs/adr/0176-durable-photosynthesis-region.md new file mode 100644 index 0000000..e12e449 --- /dev/null +++ b/docs/adr/0176-durable-photosynthesis-region.md @@ -0,0 +1,42 @@ +# ADR-0176: Durable photosynthesis regions and session v12 + +## Status and scope + +Accepted 2026-10-19. Makes ADR-0175's rules-11 producers playable on the existing +profile-4 path: schema 57, the `cellular-v8` opening and session protocol v12. Trial +numbers stay tunable. No World0 operation; DEV deployment is a separate manifest change. + +## Decision + +**Bundle 13.** Cellular bundle 13 `(11, 9, 2, 1, 1, 5, 4, 2, 1)` is rules 11 on owner +format 9 with development 5 and founder 4, raw profile 4 only, history profile 4 and raw +trace 4. Schema 57 admits it by parser-local normalization to bundle 12 (every common +field validated exactly as before), the same births wrapper, and bundle 12's mutation +results (1 died, 3 declined, 4 offspring plan applied). Population and joint profiles do +not admit it yet. + +**Upgrade 12 -> 13.** An explicit fenced, no-tick version upgrade through the existing +immutable version-upgrade journal declares the region's light. Unlike earlier upgrades it +has an input that the source cannot supply; recovery reads the light from the target +payload, re-derives the complete target from the source with it and requires the exact +bytes, so only the declaration itself is new. Pending intervals or unpublished mutation +choices block it, as for bundle 12. + +**Opening `cellular-v8`.** The provisioning tool writes a `cellular-v7` genesis, then +under a short lease publishes one empty tick (upgrades never follow a genesis directly) +and runs the durable 9 -> 10 -> 11 -> 12 -> 13 upgrades with `--light-pj` (irradiance per +square micrometre per tick; entitlement effectively unbounded). It is resumable from any +intermediate bundle and idempotent at 13. Founders born afterwards are founder 4. + +**Session v12.** v12 is v11 plus, in the owner's perception, the light its cell captured +on the last tick and the photosynthesis level of every producer it can see (by organism, +so the client can draw green organelles), and mutation offers may name capability 7. +Older sessions keep their exact layouts: they receive no producer data, and photosynthesis +candidates are dropped from the offers sent to them (their other choices stay valid). + +## Consequences + +A DEV region can be provisioned with photosynthesis and played with a v12 client. Light +has no durable state beyond the owner payload, which is fully replayed. Remaining before +the integrated 12.5 gate: census/migration/population support for bundle 13, a joint +region over a rules-11 owner on the durable path, and playtest balance. diff --git a/docs/adr/README.md b/docs/adr/README.md index 698671d..f6b83b5 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -1,5 +1,7 @@ # Architecture decision records +- [ADR-0176: Durable photosynthesis regions and session v12](0176-durable-photosynthesis-region.md) - schema 57 raw bundle 13 (rules 11, owner format 9) with a light-declaring 12 -> 13 upgrade, the resumable `cellular-v8` opening and session v12 (captured light, visible producers, photosynthesis offers). + - [ADR-0175: Photosynthesis producers](0175-photosynthesis-producers.md) - genome schema 5 photosynthesis with trial organelle costs, founder 4/rules 11, light booked by the cell owner (format 9) from recorded intentions, light-aware wildlife; earlier bytes unchanged. - [ADR-0174: Durable cellular environment profile](0174-durable-cellular-environment-profile.md) - schema 56 checkpoint profile 6 nesting population envelope 2; explicit one-way 5 -> 6 entry, fenced joint publication with owned intervals and SQL flow totals, exact replayed recovery. diff --git a/docs/engineering/M12_REMAINING_GATES.md b/docs/engineering/M12_REMAINING_GATES.md index 498d9cf..2506951 100644 --- a/docs/engineering/M12_REMAINING_GATES.md +++ b/docs/engineering/M12_REMAINING_GATES.md @@ -66,7 +66,7 @@ or authorize production enablement. | 12.2 | Exact cellular model and paired matrix; local samples through 256 lives; bounded four-generation rules-9 predation/twin matrix | Deployment-host tail costs including publication; larger wildlife cohorts and fuller contention coverage; useful compression remains unimplemented. | | 12.3 | Dedicated population profile/trace/store/owning host; exact recovery and private PostgreSQL fault tests | Population-specific executable/network fault drills and target-host publication/capacity qualification. | | 12.4 | Owned intervals; exact transfer/accounting; durable atomic pair/recovery; independent loopback TLS path loss and owner expiry/replacement/heal; local object sync/read-failure matrix | Multi-host/kernel-network, storage-host and orchestrator drills, linked-boundary contracts and integrated ownership/stock audits at scale. | -| 12.5 | ADR-0175 photosynthesis producers (portable rules 11/format 9); ADR-0172 portable joint owner: one budget for cells and local environment, effective depth, tagged water/dissolved compartments, refused atmosphere, finite infall entitlements, radiative export; closed/source-off/open/exhaustion and raw/cohort comparisons; ADR-0173 joint batch with exact unattended replay; ADR-0174/schema 56 durable profile 6 with owned intervals and exact recovery | Durable rules-11 bundle, producer session wire/client and DEV opening; joint fault drills (deferred by the maintainer), worker/census/migration integration and escrowed cross-worker sources (12.5d), target-host qualification (12.5e). | +| 12.5 | ADR-0175 photosynthesis producers (portable rules 11/format 9); ADR-0172 portable joint owner: one budget for cells and local environment, effective depth, tagged water/dissolved compartments, refused atmosphere, finite infall entitlements, radiative export; closed/source-off/open/exhaustion and raw/cohort comparisons; ADR-0173 joint batch with exact unattended replay; ADR-0174/schema 56 durable profile 6 with owned intervals and exact recovery | Producer playtests and balance (DEV region 9); bundle 13 in population/joint/census/migration; joint fault drills (deferred by the maintainer), worker/census/migration integration and escrowed cross-worker sources (12.5d), target-host qualification (12.5e). | | 12.6 | Retained archive, regional census/lineage queries, replayed history, scoped multi-region queries and consistent database head snapshots (12.6a-d); registered coverage/history domains follow in 12.7a-b | Cross-domain clone provenance, retained historical coverage/other viable stores, target-host query/index qualification and client permission/presentation; no account power or invented precise statistical ancestry. | | 12.7 | Viability/unknown policy; consistent cuts, registered coverage, history domains/restore forks and verified pending handoff evidence (12.7a-c/schema 52) | Cross-domain clone provenance, other viable-store coverage and durable accepted global evidence records/freshness. Missing/stale/unsupported owners must prevent terminal extinction. | | 12.8 | Deterministic seed/regime drivers, separate-process exact continuation and bounded unscripted generations | Reproducible integrated worlds running for actual days, real restarts/clone comparisons and retained accounting/diversity/cost audits. Accelerated tests cannot supply elapsed days. | diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index fcc1319..3838e64 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -1,5 +1,41 @@ # Validation report +## 2026-10-19 - Durable photosynthesis regions and session v12 (ADR-0176) + +[ADR-0176](../adr/0176-durable-photosynthesis-region.md)/schema 57 adds raw bundle 13, +the light-declaring 12 -> 13 upgrade, the `cellular-v8` opening and session v12 with +client support, and switches DEV to producer region 9. + +Executed locally: + +- GCC 14.2 Release **96/96**; Linux network-clang **102/102** and quic-linux + **106/106**; MSVC 19.44 Release **96/96**; Windows quic **8/8** and client-network **17/18** in + parallel, the remaining `motion-trace-smoke` passing alone (its impaired-link setup + failed while ten network tests shared the machine). Two Windows quic runs were + interrupted by a VS ninja dyndep assertion and a parallel `msquic.dll` copy race; the + tree was cleared and the build finished serially. No source change was needed. +- Private PostgreSQL qualification `--full` passes in **626 s** (twice; once before the + final provisioning fixes). One run made while the Windows quic build saturated the + machine failed an M10 probe duplicate-receipt check after a process restart; the idle + rerun passed it unchanged. +- Joint-environment PostgreSQL suite: durable 9 -> 10 -> 11 -> 12 -> 13 with declared + light on a funded raw region, exact upgrade retry, a reused identity with other light + refused, recovery with rules 11, format 9 and the declared light, an unattended + interval on bundle 13 recovered exactly, and a funded birth on bundle 13 that recovers + as founder 4 (genome schema 5). +- `cellular-v8` process test: refused without `--light-pj`; provisions to sequence 5 at + tick 1 on bundle 13 and reports already-provisioned on rerun. +- Session v12 contract: light and producers round-trip; v11 refuses both; producers must + ascend by organism with efficiency 1..1000 and zero reserved bytes; capability 7 offers + only in v12, capability 8 nowhere. +- clang-tidy 19 and clang-format 19 on every changed source and test. Tidy found an + optional copied through a dereference, an unchecked optional and a discarded lease + release in the new provisioning code; all fixed. + +The client builds with the producer drawing, sunlight HUD line and photosynthesis cards; +the visual result has not been seen in a running client. No deployment result is claimed: +the DEV region 9 opening runs only after Argo applies the pushed manifests. + ## 2026-10-19 - Photosynthesis producers (ADR-0175) [ADR-0175](../adr/0175-photosynthesis-producers.md) adds genome schema 5, development 5, diff --git a/include/evo/network/session_protocol.hpp b/include/evo/network/session_protocol.hpp index cba1231..1bdbd26 100644 --- a/include/evo/network/session_protocol.hpp +++ b/include/evo/network/session_protocol.hpp @@ -38,12 +38,26 @@ inline constexpr std::uint16_t session_protocol_v10 = 10; // v11 (ADR-0136 step A) is v10 with the owner's view of pools and bubbles (deposits) // instead of square patches; every other message is v10's. inline constexpr std::uint16_t session_protocol_v11 = 11; -// v10 and v11 share every cellular message but the perception's food list. +// v12 (ADR-0176) is v11 plus the owner's captured light and visible producers in its +// perception, and the photosynthesis capability (7) in mutation offers. +inline constexpr std::uint16_t session_protocol_v12 = 12; +// v10, v11 and v12 share every cellular message but the perception's contents. [[nodiscard]] constexpr bool cellular_v10_family(std::uint16_t version) noexcept { - return version == session_protocol_v10 || version == session_protocol_v11; + return version == session_protocol_v10 || version == session_protocol_v11 || + version == session_protocol_v12; +} +// Versions whose perception lists pools and bubbles (ADR-0136) instead of square patches. +[[nodiscard]] constexpr bool cellular_deposit_version(std::uint16_t version) noexcept { + return version == session_protocol_v11 || version == session_protocol_v12; +} +// The highest capability a version's mutation offers may name. +[[nodiscard]] constexpr std::uint8_t +cellular_offer_capability_limit(std::uint16_t version) noexcept { + return version == session_protocol_v12 ? 7 : 6; } inline constexpr std::size_t max_cellular_perceived_patches = 256; inline constexpr std::size_t max_cellular_perceived_deposits = 512; +inline constexpr std::size_t max_cellular_perceived_producers = 256; inline constexpr std::size_t session_address_bytes = 64; // Endpoint or server name field. inline constexpr std::size_t session_datagram_bytes = 1200; // Whole message, ADR-0089. inline constexpr std::size_t session_header_bytes = 8; @@ -230,7 +244,7 @@ struct CellularMutationOffer { std::vector candidates; friend bool operator==(const CellularMutationOffer&, const CellularMutationOffer&) = default; }; -// v10 (ADR-0129): the owner's life ended in ick. Cause 1 starved, 2 engulfed, 0 not +// v10 (ADR-0129): the owner's life ended in `tick`. Cause 1 starved, 2 engulfed, 0 not // recorded (rules below 3). Death is final; a new life is a new request. enum class CellularDeathReason : std::uint8_t { unrecorded, starved, engulfed }; struct CellularLifeEnded { @@ -324,9 +338,18 @@ struct CellularLifeDiagnostics { // when this cell's genome cannot bud. Independent of tick effects. std::uint64_t bud_cost_energy_pj{}; std::array bud_cost_matter_fg{}; + std::uint64_t light_pj{}; // v12 only (ADR-0176): light this cell captured last tick. friend bool operator==(const CellularLifeDiagnostics&, const CellularLifeDiagnostics&) = default; }; +// v12 (ADR-0176): a visible cell that carries photosynthesis, by organism, and its +// efficiency per thousand, so a client can draw its organelles. +struct CellularPerceivedProducer { + std::uint64_t organism{}; + std::uint16_t photosynthesis_per_thousand{}; + friend bool operator==(const CellularPerceivedProducer&, + const CellularPerceivedProducer&) = default; +}; struct CellularPerception { std::uint64_t tick{}, life_identity{}; // zero life plus no patches clears the view. std::vector patches; // strictly ordered by (x_um, y_um). @@ -335,6 +358,8 @@ struct CellularPerception { std::optional diagnostics; // v11 only (then `patches` is empty): pools and bubbles in range, by ascending id. std::vector deposits{}; + // v12 only: visible producers by ascending organism. + std::vector producers{}; friend bool operator==(const CellularPerception&, const CellularPerception&) = default; }; struct IntentionReceipt { diff --git a/include/evo/persistence/checkpoint_store.hpp b/include/evo/persistence/checkpoint_store.hpp index ac1228c..5c28bd0 100644 --- a/include/evo/persistence/checkpoint_store.hpp +++ b/include/evo/persistence/checkpoint_store.hpp @@ -279,6 +279,13 @@ migrate_cellular_inheritance_profile(Postgres&, const FilesystemObjectStore&, co const CommittedCheckpoint&, Uuid commit, const Sha256Digest& build, std::chrono::milliseconds timeout, const PublishHooks& hooks = {}); +// ADR-0176: explicit raw-only bundle 12 -> 13, declaring the region's light. +[[nodiscard]] std::expected +migrate_cellular_photosynthesis_profile(Postgres&, const FilesystemObjectStore&, const LeaseGrant&, + const CommittedCheckpoint&, Uuid commit, + const Sha256Digest& build, server::CellularLight light, + std::chrono::milliseconds timeout, + const PublishHooks& hooks = {}); // Verify the recorded no-tick operation under current authority, replaying its // entire source/target payload. Version upgrades and profile transitions retain // separate evidence; neither is inferred solely from the target tuple. diff --git a/include/evo/persistence/region_checkpoint.hpp b/include/evo/persistence/region_checkpoint.hpp index c9bb320..eae4795 100644 --- a/include/evo/persistence/region_checkpoint.hpp +++ b/include/evo/persistence/region_checkpoint.hpp @@ -85,6 +85,12 @@ inline constexpr CellularVersionBundle cellular_v10_versions{8, 7, 2, 1, 1, 4, 3 inline constexpr CellularVersionBundle cellular_v11_versions{9, 7, 2, 1, 1, 4, 3, 2, 1}; // ADR-0167: portable raw-only retained plans. SQL/publication admission is separate. inline constexpr CellularVersionBundle cellular_v12_versions{10, 8, 2, 1, 1, 4, 3, 2, 1}; +// ADR-0175/0176: rules 11 on owner format 9 (declared light), development 5, founder 4. +inline constexpr CellularVersionBundle cellular_v13_versions{11, 9, 2, 1, 1, 5, 4, 2, 1}; +// Raw-only retained-plan bundles, which use trace 4 and their own SQL admission. +[[nodiscard]] constexpr bool cellular_plan_bundle(const CellularVersionBundle& b) noexcept { + return b == cellular_v12_versions || b == cellular_v13_versions; +} // Zero means this bundle has no population representation. [[nodiscard]] constexpr std::uint32_t population_envelope_version(const CellularVersionBundle& b) noexcept { @@ -102,7 +108,7 @@ population_envelope_version(const CellularVersionBundle& b) noexcept { // Exact raw trace version for admitted cellular tuples; bundle 12 has its own semantics. [[nodiscard]] constexpr std::uint32_t cellular_checkpoint_trace_format(const CellularVersionBundle& b) noexcept { - return b == cellular_v12_versions ? server::cellular_batch_inheritance_format + return cellular_plan_bundle(b) ? server::cellular_batch_inheritance_format : cellular_revision_bundle(b) ? server::cellular_batch_format : server::cellular_batch_v2_format; } @@ -275,6 +281,18 @@ cellular_inheritance_upgrade_manifest(const CheckpointManifest& predecessor, [[nodiscard]] std::expected, CheckpointError> cellular_inheritance_upgrade_payload(std::span payload, const CheckpointManifest& predecessor); +// ADR-0176: explicit raw-only bundle 12 -> 13 upgrade declaring the region's light. The +// light is an input; recovery reads it from the target and re-derives everything else. +[[nodiscard]] std::expected +cellular_photosynthesis_upgrade_manifest(const CheckpointManifest& predecessor, + const Sha256Digest& predecessor_digest, Uuid commit, + const LeaseGrant& lease, const Sha256Digest& build, + std::uint64_t payload_bytes, + const Sha256Digest& payload_sha256); +[[nodiscard]] std::expected, CheckpointError> +cellular_photosynthesis_upgrade_payload(std::span payload, + const CheckpointManifest& predecessor, + const server::CellularLight& light); // ADR-0174: explicit one-way, no-tick profile 5 -> 6 transition. The payload wraps the // identical population with its declared environment; bundle and policy are unchanged. [[nodiscard]] std::expected diff --git a/include/evo/server/lifecycle/cellular_lives.hpp b/include/evo/server/lifecycle/cellular_lives.hpp index 7d31845..1fe3882 100644 --- a/include/evo/server/lifecycle/cellular_lives.hpp +++ b/include/evo/server/lifecycle/cellular_lives.hpp @@ -211,6 +211,7 @@ struct CellularLifeTickFeedback { // Rules 5: presence after the tick, and whether a requested resume found no clear spot. CellularPresence presence{CellularPresence::active}; bool resume_blocked{}; + accounting::Picojoules light{}; // Rules 11 (ADR-0175): light captured this tick. auto operator<=>(const CellularLifeTickFeedback&) const = default; }; // Which owner version a new region starts on. Offers: format 2, rules 2 (the M11.3/11.4 diff --git a/migrations/0057_photosynthesis_bundle.sql b/migrations/0057_photosynthesis_bundle.sql new file mode 100644 index 0000000..6412f6f --- /dev/null +++ b/migrations/0057_photosynthesis_bundle.sql @@ -0,0 +1,223 @@ +-- ADR-0176: raw-only bundle 13 (rules 11 on owner format 9: photosynthesis and declared +-- light) and exact bundle 12 -> 13 upgrades. Normalization is parser-local; stored +-- evidence and retries retain real bytes. Raw trace 4 is unchanged. +ALTER FUNCTION evolution.parse_checkpoint_manifest(bytea) RENAME TO parse_checkpoint_manifest_v56; +REVOKE ALL ON FUNCTION evolution.parse_checkpoint_manifest_v56(bytea) FROM PUBLIC, :"runtime_role"; +CREATE FUNCTION evolution.parse_checkpoint_manifest(m bytea) +RETURNS evolution.checkpoint_manifest LANGUAGE plpgsql IMMUTABLE +SET search_path=pg_catalog,pg_temp AS $$ +DECLARE c evolution.checkpoint_manifest; + b12 constant bytea := '\x0a0000000800000002000000010000000100000004000000030000000200000001000000'; + b13 constant bytea := '\x0b0000000900000002000000010000000100000005000000040000000200000001000000'; +BEGIN + IF m IS NOT NULL AND octet_length(m)=360 AND evolution.manifest_uint(m,12,4)=4 + AND substring(m FROM 161 FOR 36)=b13 THEN + c := evolution.parse_checkpoint_manifest_v56(overlay(m PLACING b12 FROM 161 FOR 36)); + c.versions := b13; + RETURN c; + END IF; + RETURN evolution.parse_checkpoint_manifest_v56(m); +END $$; +REVOKE ALL ON FUNCTION evolution.parse_checkpoint_manifest(bytea) FROM PUBLIC; + +ALTER FUNCTION evolution.cellular_births(bytea,bytea) RENAME TO cellular_births_v56; +REVOKE ALL ON FUNCTION evolution.cellular_births_v56(bytea,bytea) FROM PUBLIC, :"runtime_role"; +CREATE FUNCTION evolution.cellular_births(t bytea,m bytea) +RETURNS TABLE(account_id uuid,request_id evolution.u64,generation evolution.u64,identity evolution.u64,born evolution.u64) +LANGUAGE plpgsql IMMUTABLE SET search_path=pg_catalog,pg_temp AS $$ +DECLARE c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(m); +BEGIN + IF c.versions='\x0b0000000900000002000000010000000100000005000000040000000200000001000000'::bytea THEN + m := overlay(m PLACING '\x0a0000000800000002000000010000000100000004000000030000000200000001000000'::bytea FROM 161 FOR 36); + END IF; + RETURN QUERY SELECT * FROM evolution.cellular_births_v56(t,m); +END $$; +REVOKE ALL ON FUNCTION evolution.cellular_births(bytea,bytea) FROM PUBLIC; + +-- Results 1 life died, 3 declined, 4 offspring plan applied, for bundles 12 and 13. +CREATE OR REPLACE FUNCTION evolution.check_cellular_mutation_block(p_manifest bytea, p_trace bytea, + p_mutations bytea, p_results bytea) +RETURNS integer LANGUAGE plpgsql STABLE SECURITY INVOKER +SET search_path = pg_catalog, pg_temp AS $$ +DECLARE + c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest); + n integer; + account uuid; + account_bytes bytea; + action numeric; + tick numeric; + input bytea; + previous_tick numeric := -1; + previous_account bytea := ''::bytea; + previous_action numeric := -1; + r evolution.cellular_mutation_reservations%ROWTYPE; +BEGIN + IF p_mutations IS NULL OR p_results IS NULL OR octet_length(p_mutations) = 0 + OR octet_length(p_mutations) % 64 <> 0 OR octet_length(p_mutations) / 64 > 1024 + OR octet_length(p_results) <> octet_length(p_mutations) / 64 THEN + RAISE EXCEPTION 'invalid cellular mutation block' USING ERRCODE = '22023'; + END IF; + n := octet_length(p_mutations) / 64; + IF (SELECT count(*) FROM evolution.cellular_mutation_selections(p_trace, p_manifest)) <> n THEN + RAISE EXCEPTION 'cellular mutation block does not cover the trace' USING ERRCODE = '22023'; + END IF; + FOR i IN 0 .. n - 1 LOOP + account_bytes := substring(p_mutations FROM 64 * i + 1 FOR 16); + account := encode(account_bytes, 'hex')::uuid; + action := evolution.manifest_uint(p_mutations, 64 * i + 16, 8); + input := substring(p_mutations FROM 64 * i + 25 FOR 34); + tick := evolution.manifest_uint(input, 0, 8); + IF account = '00000000-0000-0000-0000-000000000000' OR action = 0 + OR NOT evolution.valid_cellular_mutation_input(input) + OR substring(p_mutations FROM 64 * i + 59 FOR 6) <> '\x000000000000' + OR (c.versions IN ('\x0a0000000800000002000000010000000100000004000000030000000200000001000000'::bytea, + '\x0b0000000900000002000000010000000100000005000000040000000200000001000000'::bytea) + AND (get_byte(p_results,i) NOT IN (1,3,4) + OR (evolution.manifest_uint(input,32,2)=0 AND get_byte(p_results,i) NOT IN (1,3)) + OR (evolution.manifest_uint(input,32,2)<>0 AND get_byte(p_results,i) NOT IN (1,4)))) + OR (c.versions NOT IN ('\x0a0000000800000002000000010000000100000004000000030000000200000001000000'::bytea, + '\x0b0000000900000002000000010000000100000005000000040000000200000001000000'::bytea) + AND get_byte(p_results,i)>3) + OR tick <= c.begin_tick OR tick > c.end_tick + OR (tick, account_bytes, action) <= (previous_tick, previous_account, previous_action) THEN + RAISE EXCEPTION 'invalid cellular mutation record' USING ERRCODE = '22023'; + END IF; + previous_tick := tick; + previous_account := account_bytes; + previous_action := action; + SELECT * INTO r FROM evolution.cellular_mutation_reservations x + WHERE x.world_id = c.world_id AND x.account_id = account AND x.action_id = action; + IF NOT FOUND OR r.region_id <> c.region_id OR r.input_bytes <> input + OR r.target_tick <> evolution.manifest_uint(input, 0, 8) THEN + RAISE EXCEPTION 'cellular mutation reservation conflicts' USING ERRCODE = 'EVL16'; + END IF; + IF NOT EXISTS (SELECT 1 FROM evolution.cellular_mutation_selections(p_trace, p_manifest) s + WHERE s.tick = r.target_tick AND s.successor_identity = r.successor_identity + AND s.life_id = evolution.manifest_uint(input, 8, 8) + AND s.event_index = evolution.manifest_uint(input, 16, 8) + AND s.offer_tick = evolution.manifest_uint(input, 24, 8) + AND s.operator_id = evolution.manifest_uint(input, 32, 2)) THEN + RAISE EXCEPTION 'cellular mutation differs from its trace' USING ERRCODE = '22023'; + END IF; + END LOOP; + RETURN n; +END $$; + +ALTER FUNCTION evolution.publish_cellular_profile_migration(bytea) RENAME TO publish_cellular_profile_migration_v56; +REVOKE ALL ON FUNCTION evolution.publish_cellular_profile_migration_v56(bytea) FROM PUBLIC, :"runtime_role"; +CREATE OR REPLACE FUNCTION evolution.publish_cellular_profile_migration(p_manifest bytea) +RETURNS TABLE(region_frame evolution.u64, head_sequence evolution.u64, head_commit uuid, + head_digest text, head_tick evolution.u64) +LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$ +DECLARE + c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest); + s evolution.checkpoint_manifest; + h evolution.region_heads%ROWTYPE; + p evolution.region_commits%ROWTYPE; + old evolution.region_commits%ROWTYPE; + frame evolution.u64; + d bytea := sha256(p_manifest); + source_bundle constant bytea := '\x0a0000000800000002000000010000000100000004000000030000000200000001000000'; + target_bundle constant bytea := '\x0b0000000900000002000000010000000100000005000000040000000200000001000000'; + zero32 constant bytea := decode(repeat('00', 32), 'hex'); +BEGIN + IF c.versions <> target_bundle THEN + RETURN QUERY SELECT * FROM evolution.publish_cellular_profile_migration_v56(p_manifest); + RETURN; + END IF; + IF c.profile <> 4 OR c.commit_sequence = 0 OR c.begin_tick <> c.end_tick + OR c.end_tick = 0 OR c.versions <> target_bundle + OR evolution.manifest_uint(p_manifest, 228, 4) <> 0 + OR evolution.manifest_uint(p_manifest, 232, 4) <> (CASE c.profile WHEN 4 THEN 4 ELSE 5 END) + OR evolution.manifest_uint(p_manifest, 236, 4) <> 1 + OR c.trace_bytes <> 0 OR c.trace_sha256 <> zero32 + OR c.decision_count <> 0 OR c.decisions_sha256 <> zero32 THEN + RAISE EXCEPTION 'invalid photosynthesis profile migration' USING ERRCODE = '22023'; + END IF; + PERFORM evolution.check_region_lease(c.world_id, c.region_id, c.holder, c.epoch); + SELECT * INTO old FROM evolution.region_commits r WHERE r.commit_id = c.commit_id; + IF FOUND THEN + IF old.manifest <> p_manifest THEN + RAISE EXCEPTION 'cellular profile migration identity reused' USING ERRCODE = 'EVL07'; + END IF; + SELECT * INTO p FROM evolution.region_commits r + WHERE r.world_id = old.world_id AND r.region_id = old.region_id + AND r.commit_sequence = old.commit_sequence - 1; + IF NOT FOUND OR NOT EXISTS ( + SELECT 1 FROM evolution.cellular_profile_migrations m + WHERE m.target_commit = c.commit_id AND m.world_id = c.world_id + AND m.region_id = c.region_id AND m.source_sequence = p.commit_sequence + AND m.source_commit = p.commit_id AND m.source_manifest_sha256 = p.commit_digest + AND m.source_payload_sha256 = p.payload_sha256 AND m.source_versions = p.versions + AND m.target_sequence = old.commit_sequence AND m.target_manifest_sha256 = d + AND m.target_payload_sha256 = old.payload_sha256 AND m.target_versions = old.versions + AND m.source_commit = c.predecessor_commit + AND m.source_manifest_sha256 = c.predecessor_digest) THEN + RAISE EXCEPTION 'cellular profile migration identity reused' USING ERRCODE = 'EVL07'; + END IF; + SELECT l.frame_id INTO frame FROM evolution.region_leases l + WHERE l.world_id = c.world_id AND l.region_id = c.region_id; + RETURN QUERY SELECT frame, old.commit_sequence, old.commit_id, + encode(old.commit_digest, 'hex'), old.end_tick; + RETURN; + END IF; + IF EXISTS (SELECT 1 FROM evolution.population_interval_pending x + WHERE x.world_id = c.world_id AND x.region_id = c.region_id) THEN + RAISE EXCEPTION 'photosynthesis upgrade waits for interval' USING ERRCODE = 'EVL18'; + END IF; + IF EXISTS (SELECT 1 FROM evolution.cellular_mutation_reservations x + WHERE x.world_id=c.world_id AND x.region_id=c.region_id AND NOT EXISTS + (SELECT 1 FROM evolution.cellular_mutation_action_publications a + WHERE a.world_id=x.world_id AND a.account_id=x.account_id AND a.action_id=x.action_id)) THEN + RAISE EXCEPTION 'photosynthesis upgrade waits for mutation choice' USING ERRCODE='EVL18'; + END IF; + SELECT * INTO h FROM evolution.region_heads r + WHERE r.world_id = c.world_id AND r.region_id = c.region_id FOR UPDATE; + IF NOT FOUND OR h.commit_sequence = 18446744073709551615 + OR c.commit_sequence <> h.commit_sequence + 1 OR c.predecessor_commit <> h.commit_id + OR c.predecessor_digest <> h.digest OR c.begin_tick <> h.end_tick THEN + RAISE EXCEPTION 'region head moved' USING ERRCODE = 'EVL03'; + END IF; + SELECT * INTO p FROM evolution.region_commits r + WHERE r.world_id = c.world_id AND r.region_id = c.region_id + AND r.commit_sequence = h.commit_sequence; + IF NOT FOUND THEN + RAISE EXCEPTION 'missing migration predecessor' USING ERRCODE = 'XX000'; + END IF; + s := evolution.parse_checkpoint_manifest(p.manifest); + IF s.profile <> c.profile OR s.versions <> source_bundle OR p.versions <> source_bundle + OR c.frame_id <> s.frame_id OR c.tick_microseconds <> s.tick_microseconds + OR s.commit_id <> c.predecessor_commit OR s.end_tick <> c.end_tick + OR evolution.manifest_uint(p.manifest, 232, 4) <> (CASE c.profile WHEN 4 THEN 4 ELSE 5 END) + OR NOT EXISTS (SELECT 1 FROM evolution.retained_builds b + WHERE b.build_identity = c.build_identity) THEN + RAISE EXCEPTION 'unsupported photosynthesis profile migration' USING ERRCODE = 'EVL06'; + END IF; + SELECT l.frame_id INTO frame FROM evolution.region_leases l + WHERE l.world_id = c.world_id AND l.region_id = c.region_id; + IF c.frame_id <> frame THEN + RAISE EXCEPTION 'foreign frame' USING ERRCODE = '22023'; + END IF; + INSERT INTO evolution.cellular_profile_migrations(target_commit, world_id, region_id, + source_sequence, source_commit, source_manifest_sha256, source_payload_sha256, + source_versions, target_sequence, target_manifest_sha256, target_payload_sha256, + target_versions) + VALUES (c.commit_id, c.world_id, c.region_id, p.commit_sequence, p.commit_id, + p.commit_digest, p.payload_sha256, p.versions, c.commit_sequence, d, + c.payload_sha256, c.versions); + INSERT INTO evolution.region_commits(world_id, region_id, commit_sequence, commit_id, + commit_digest, manifest, begin_tick, end_tick, published_epoch, tick_microseconds, + versions, build_identity, payload_bytes, payload_sha256) + VALUES (c.world_id, c.region_id, c.commit_sequence, c.commit_id, d, p_manifest, + c.begin_tick, c.end_tick, c.epoch, c.tick_microseconds, c.versions, + c.build_identity, c.payload_bytes, c.payload_sha256); + UPDATE evolution.region_heads r + SET commit_sequence = c.commit_sequence, commit_id = c.commit_id, digest = d, + end_tick = c.end_tick, published_epoch = c.epoch + WHERE r.world_id = c.world_id AND r.region_id = c.region_id; + RETURN QUERY SELECT frame, c.commit_sequence, c.commit_id, encode(d, 'hex'), c.end_tick; +END $$; +REVOKE ALL ON FUNCTION evolution.publish_cellular_profile_migration(bytea) FROM PUBLIC; +GRANT EXECUTE ON FUNCTION evolution.publish_cellular_profile_migration(bytea) TO :"runtime_role"; + +INSERT INTO evolution.schema_migrations(version,sha256) VALUES(57,:'migration_sha_57'); diff --git a/migrations/apply.sql b/migrations/apply.sql index 0db8a72..f35047d 100644 --- a/migrations/apply.sql +++ b/migrations/apply.sql @@ -132,6 +132,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution') SELECT :'history_v53' || ',54:' || :'migration_sha_54' AS history_v54 \gset SELECT :'history_v54' || ',55:' || :'migration_sha_55' AS history_v55 \gset SELECT :'history_v55' || ',56:' || :'migration_sha_56' AS history_v56 \gset + SELECT :'history_v56' || ',57:' || :'migration_sha_57' AS history_v57 \gset SELECT :'history' = :'history_v22' AS at_v22, :'history' = :'history_v23' AS at_v23, :'history' = :'history_v24' AS at_v24, @@ -166,8 +167,10 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution') :'history' = :'history_v53' AS at_v53, :'history' = :'history_v54' AS at_v54, :'history' = :'history_v55' AS at_v55, - :'history' = :'history_v56' AS at_v56 \gset - \if :at_v56 + :'history' = :'history_v56' AS at_v56, + :'history' = :'history_v57' AS at_v57 \gset + \if :at_v57 + \elif :at_v56 \elif :at_v55 \elif :at_v54 \elif :at_v53 @@ -573,7 +576,8 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24, coalesce(max(version), 0) = 53 AS at_v53, coalesce(max(version), 0) = 54 AS at_v54, coalesce(max(version), 0) = 55 AS at_v55, - coalesce(max(version), 0) = 56 AS at_v56 + coalesce(max(version), 0) = 56 AS at_v56, + coalesce(max(version), 0) = 57 AS at_v57 FROM evolution.schema_migrations \gset \if :at_v24 \ir 0025_cellular_v2_bundle.sql @@ -798,6 +802,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24, \elif :at_v54 \elif :at_v55 \elif :at_v56 +\elif :at_v57 \else \echo 'Unknown or changed migration history after v43' DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$; @@ -854,6 +859,10 @@ SELECT coalesce(max(version), 0) = 55 AS needs_v56 FROM evolution.schema_migrati \if :needs_v56 \ir 0056_cellular_environment_publication.sql \endif +SELECT coalesce(max(version), 0) = 56 AS needs_v57 FROM evolution.schema_migrations \gset +\if :needs_v57 + \ir 0057_photosynthesis_bundle.sql +\endif -- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes -- alone are insufficient: predefined roles such as pg_write_all_data, PUBLIC -- grants or SET-able memberships would bypass the fenced functions. Checks the diff --git a/schemas/network/session-v12-cellular-producers.md b/schemas/network/session-v12-cellular-producers.md new file mode 100644 index 0000000..7a2fc86 --- /dev/null +++ b/schemas/network/session-v12-cellular-producers.md @@ -0,0 +1,29 @@ +# Session v12: captured light and visible producers + +Authority: [ADR-0176](../../docs/adr/0176-durable-photosynthesis-region.md). v12 is v11 +(ADR-0136 deposits) with two additions; every other message and layout is v11's. v1-v11 +layouts are unchanged. + +**Mutation offers** may name capability 7 (photosynthesis); v10 and v11 offers stay +limited to 0..6, and a server withholds photosynthesis candidates from those sessions. + +**Owner perception.** After v10's 40-byte bud cost, the prefix adds: + +| Bytes | Field | +|---:|---| +| 8 | Light this cell captured on the last tick, pJ (zero when none or no life) | +| 2 | Producer count, at most 256 | +| 6 | Reserved zero | + +Deposits follow as in v11, then producers, 16 bytes each: + +| Bytes | Field | +|---:|---| +| 8 | Organism ID, nonzero, strictly ascending | +| 2 | Photosynthesis per thousand, 1..1000 | +| 6 | Reserved zero | + +A cleared view (life 0) carries no producers and zero light. Producers are visible cells +carrying photosynthesis within the owner's perception radius, nearest first when more +than 256 are in range, then sorted by organism. The values are authoritative +observations for drawing, not client claims. diff --git a/schemas/region-commit.md b/schemas/region-commit.md index 83a035c..5c8be6b 100644 --- a/schemas/region-commit.md +++ b/schemas/region-commit.md @@ -1,5 +1,10 @@ # Region commit manifest contract v1 (M7.1 design, M7.4a encoding) +M12.5/schema 57 adds raw cellular bundle 13 `(11,9,2,1,1,5,4,2,1)`: rules 11 on owner +format 9 with declared light, history 4, trace 4, profile 4 only. It arises only from the +fenced no-tick 12 -> 13 upgrade, whose light recovery reads from the target and re-derives +from the source. See [ADR-0176](../docs/adr/0176-durable-photosynthesis-region.md). + M12.5c/schema 56 adds profile 6, `cellular_environment_v1`, with history profile 6. Its payload is the [joint envelope](cellular-environment-v1.md) nesting population envelope 2 (bundles 10 and 11 only), capped at 16,782,416 bytes. A nonempty trace is diff --git a/src/network/protocol/session_protocol.cpp b/src/network/protocol/session_protocol.cpp index 4ce1ad0..2456cee 100644 --- a/src/network/protocol/session_protocol.cpp +++ b/src/network/protocol/session_protocol.cpp @@ -27,6 +27,11 @@ constexpr std::size_t cellular_perception_v9_prefix_bytes = constexpr std::size_t cellular_bud_cost_bytes = std::size_t{5} * 8; constexpr std::size_t cellular_perception_v10_prefix_bytes = cellular_perception_v9_prefix_bytes + cellular_bud_cost_bytes; +// v12 (ADR-0176) appends the captured light, the producer count and 6 reserved bytes. +constexpr std::size_t cellular_perception_v12_prefix_bytes = + cellular_perception_v10_prefix_bytes + 8 + 2 + 6; +// v12: organism, photosynthesis per thousand and 6 reserved bytes. +constexpr std::size_t cellular_perceived_producer_bytes = 8 + 2 + 6; constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8); // v11: id, centre, radius, shape, drained flag and five 16-bit amount codes. constexpr std::size_t cellular_perceived_deposit_bytes = 4 + 4 + 4 + 2 + 1 + 1 + (5 * 2); @@ -48,15 +53,17 @@ constexpr std::size_t life_receipt_bytes = 17; constexpr std::size_t life_outcome_bytes = 25; constexpr std::size_t life_query_bytes = 8; -// Seven capabilities and four effects (biology genome/mutation enums, frozen on the wire). -bool valid_offer(const CellularMutationOffer& offer) { +// Seven capabilities (eight from v12) and four effects (biology genome/mutation enums, +// frozen on the wire per version). +bool valid_offer(const CellularMutationOffer& offer, std::uint16_t version) { if (offer.tick == 0 || offer.candidates.size() > max_cellular_offered_candidates) return false; if (offer.candidates.empty()) return offer.event_index == 0 && offer.offer_tick == 0; std::uint16_t previous = 0; for (const auto& candidate : offer.candidates) { - if (candidate.operator_id <= previous || candidate.capability > 6 || candidate.effect > 3) + if (candidate.operator_id <= previous || + candidate.capability > cellular_offer_capability_limit(version) || candidate.effect > 3) return false; previous = candidate.operator_id; } @@ -195,7 +202,7 @@ std::vector encode_session(const SessionMessage& message, std::uin if (!cellular_v10_family(version) && std::holds_alternative(message)) return {}; if (const auto* offer = std::get_if(&message); - offer && (!cellular_v10_family(version) || !valid_offer(*offer))) + offer && (!cellular_v10_family(version) || !valid_offer(*offer, version))) return {}; if (const auto* ended = std::get_if(&message); ended && (!cellular_v10_family(version) || ended->tick == 0 || ended->life_identity == 0 || @@ -220,9 +227,24 @@ std::vector encode_session(const SessionMessage& message, std::uin !cellular_v10_family(version) && std::holds_alternative(message)) return {}; if (const auto* perception = std::get_if(&message)) { + // v12 alone carries captured light and producers (ADR-0176). + const bool producers = version == session_protocol_v12; + if ((!producers && (!perception->producers.empty() || + (perception->diagnostics && perception->diagnostics->light_pj))) || + perception->producers.size() > max_cellular_perceived_producers || + (!perception->life_identity && !perception->producers.empty()) || + std::ranges::adjacent_find(perception->producers, + [](const auto& a, const auto& b) { + return a.organism >= b.organism; + }) != perception->producers.end() || + std::ranges::any_of(perception->producers, [](const auto& p) { + return p.organism == 0 || p.photosynthesis_per_thousand == 0 || + p.photosynthesis_per_thousand > 1000; + })) + return {}; // v11 (ADR-0136) lists deposits by ascending id, never patches; earlier versions the // reverse. - if (version == session_protocol_v11 + if (cellular_deposit_version(version) ? !perception->patches.empty() || perception->deposits.size() > max_cellular_perceived_deposits || (!perception->life_identity && !perception->deposits.empty()) || @@ -364,15 +386,17 @@ std::vector encode_session(const SessionMessage& message, std::uin std::vector operator()(const CellularPerception& m) const { auto out = header(SessionMessageType::cellular_perception, - (cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes + (version == session_protocol_v12 ? cellular_perception_v12_prefix_bytes + : cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes : version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes : cellular_perception_prefix_bytes) + m.patches.size() * cellular_perceived_patch_bytes + - m.deposits.size() * cellular_perceived_deposit_bytes, + m.deposits.size() * cellular_perceived_deposit_bytes + + m.producers.size() * cellular_perceived_producer_bytes, version); put(out, m.tick, 8); put(out, m.life_identity, 8); - put(out, version == session_protocol_v11 ? m.deposits.size() : m.patches.size(), 2); + put(out, cellular_deposit_version(version) ? m.deposits.size() : m.patches.size(), 2); if (version == session_protocol_v9 || cellular_v10_family(version)) { const auto& d = m.diagnostics; put(out, d ? d->reserve_energy_pj : 0, 8); @@ -393,6 +417,11 @@ std::vector encode_session(const SessionMessage& message, std::uin for (const auto value : d ? d->bud_cost_matter_fg : std::array{}) put(out, value, 8); + if (version == session_protocol_v12) { + put(out, d ? d->light_pj : 0, 8); + put(out, m.producers.size(), 2); + put(out, 0, 6); + } } else { put(out, 0, 5); } @@ -414,6 +443,11 @@ std::vector encode_session(const SessionMessage& message, std::uin for (const auto code : deposit.amount_codes) put(out, code, 2); } + for (const auto& producer : m.producers) { + put(out, producer.organism, 8); + put(out, producer.photosynthesis_per_thousand, 2); + put(out, 0, 6); + } return out; } std::vector operator()(const IntentionReceipt& m) const { @@ -727,7 +761,7 @@ std::expected decode_session(std::span decode_session(std::span= prefix + ? static_cast(get( + payload, cellular_perception_v10_prefix_bytes + 8, 2)) + : 0; if (count > (deposits ? max_cellular_perceived_deposits : max_cellular_perceived_patches) || - payload.size() != prefix + count * entry) + producer_count > max_cellular_perceived_producers || + payload.size() != + prefix + count * entry + producer_count * cellular_perceived_producer_bytes) return std::unexpected(SessionCodecError::wrong_length); + if (lit && + std::ranges::any_of(payload.subspan(cellular_perception_v10_prefix_bytes + 10, 6), + [](std::uint8_t value) { return value != 0; })) + return std::unexpected(SessionCodecError::invalid_value); CellularPerception m; m.tick = get(payload, 0, 8); m.life_identity = get(payload, 8, 8); @@ -785,6 +831,8 @@ std::expected decode_session(std::span(payload[74]); d.intake = static_cast(payload[75]); @@ -799,6 +847,7 @@ std::expected decode_session(std::span decode_session(std::span(get(payload, offset + 16 + c * 2, 2)); m.deposits.push_back(d); } + if (!m.life_identity && producer_count) + return std::unexpected(SessionCodecError::invalid_value); + m.producers.reserve(producer_count); + for (std::size_t i = 0; i < producer_count; + ++i, offset += cellular_perceived_producer_bytes) { + CellularPerceivedProducer p; + p.organism = get(payload, offset, 8); + p.photosynthesis_per_thousand = + static_cast(get(payload, offset + 8, 2)); + if (p.organism == 0 || p.photosynthesis_per_thousand == 0 || + p.photosynthesis_per_thousand > 1000 || + std::ranges::any_of(payload.subspan(offset + 10, 6), + [](std::uint8_t value) { return value != 0; }) || + (!m.producers.empty() && m.producers.back().organism >= p.organism)) + return std::unexpected(SessionCodecError::invalid_value); + m.producers.push_back(p); + } return m; } m.patches.reserve(count); diff --git a/src/persistence/cellular_checkpoint_store.cpp b/src/persistence/cellular_checkpoint_store.cpp index 153455b..7492dcc 100644 --- a/src/persistence/cellular_checkpoint_store.cpp +++ b/src/persistence/cellular_checkpoint_store.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -96,7 +97,7 @@ bool prepared_mutations_are_canonical(const CellularPreparedCommit& prepared, prepared.mutations, manifest.begin_tick, manifest.end_tick); if (!decoded || decoded->size() != selections || prepared.results.size() != selections || std::ranges::any_of(prepared.results, [&](std::uint8_t result) { - return manifest.cellular_versions == cellular_v12_versions + return cellular_plan_bundle(manifest.cellular_versions) ? result != 1 && result != 3 && result != 4 : result > 3; })) @@ -243,7 +244,7 @@ retry_cellular_profile_migration(Postgres& db, const CellularProfileMigrationPre !((manifest->profile == CheckpointProfile::cellular_lives_v1 && (manifest->cellular_versions == cellular_v2_versions || manifest->cellular_versions == cellular_v3_versions || - manifest->cellular_versions == cellular_v12_versions)) || + cellular_plan_bundle(manifest->cellular_versions))) || ((manifest->profile == CheckpointProfile::cellular_lives_v1 || manifest->profile == CheckpointProfile::cellular_population_v1) && (manifest->cellular_versions == cellular_v10_versions || @@ -281,12 +282,13 @@ retry_cellular_profile_migration(Postgres& db, const CellularProfileMigrationPre } namespace { -std::expected -migrate_rules_profile(Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease, - const CommittedCheckpoint& predecessor, Uuid commit, - const Sha256Digest& build, milliseconds timeout, const PublishHooks& hooks, - decltype(&cellular_maturation_upgrade_payload) upgrade_payload, - decltype(&cellular_maturation_upgrade_manifest) derive) { +std::expected migrate_rules_profile( + Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease, + const CommittedCheckpoint& predecessor, Uuid commit, const Sha256Digest& build, + milliseconds timeout, const PublishHooks& hooks, + const std::function, CheckpointError>( + std::span, const CheckpointManifest&)>& upgrade_payload, + decltype(&cellular_maturation_upgrade_manifest) derive) { const auto previous = decode_manifest(predecessor.manifest); const auto previous_digest = sha256(predecessor.manifest); if (!previous || !previous_digest || predecessor.head.digest != *previous_digest || @@ -347,6 +349,19 @@ migrate_cellular_inheritance_profile(Postgres& db, const FilesystemObjectStore& cellular_inheritance_upgrade_payload, cellular_inheritance_upgrade_manifest); } +std::expected +migrate_cellular_photosynthesis_profile(Postgres& db, const FilesystemObjectStore& objects, + const LeaseGrant& lease, + const CommittedCheckpoint& predecessor, Uuid commit, + const Sha256Digest& build, server::CellularLight light, + milliseconds timeout, const PublishHooks& hooks) { + return migrate_rules_profile( + db, objects, lease, predecessor, commit, build, timeout, hooks, + [light](std::span payload, const CheckpointManifest& previous) { + return cellular_photosynthesis_upgrade_payload(payload, previous, light); + }, + cellular_photosynthesis_upgrade_manifest); +} std::expected migrate_cellular_profile_to_v2(Postgres& db, const FilesystemObjectStore& objects, @@ -634,10 +649,12 @@ verify_cellular_no_tick_checkpoint(Postgres& db, const FilesystemObjectStore& ob const bool boundary = m.cellular_versions == cellular_v10_versions; const bool maturation = m.cellular_versions == cellular_v11_versions; const bool inheritance = m.cellular_versions == cellular_v12_versions; - const auto derive = inheritance ? cellular_inheritance_upgrade_manifest - : maturation ? cellular_maturation_upgrade_manifest - : boundary ? cellular_boundary_upgrade_manifest - : cellular_profile_migration_manifest; + const bool photosynthesis = m.cellular_versions == cellular_v13_versions; + const auto derive = photosynthesis ? cellular_photosynthesis_upgrade_manifest + : inheritance ? cellular_inheritance_upgrade_manifest + : maturation ? cellular_maturation_upgrade_manifest + : boundary ? cellular_boundary_upgrade_manifest + : cellular_profile_migration_manifest; auto expected = derive(*source, *source_digest, m.commit, recorded, m.build, m.payload_bytes, m.payload_sha256); if (!expected || *expected != m) @@ -645,7 +662,17 @@ verify_cellular_no_tick_checkpoint(Postgres& db, const FilesystemObjectStore& ob auto bytes = objects.get({source->payload_sha256, source->payload_bytes}); if (!bytes) return fail(RecoveryError::tail); - if (boundary || maturation || inheritance) { + if (photosynthesis) { + // The declared light is the upgrade's only input: read it from the target, then + // require the source to re-derive the exact target bytes with it. + auto target = restore_cellular_payload(payload, m); + if (!target) + return fail(RecoveryError::payload); + auto upgraded = + cellular_photosynthesis_upgrade_payload(*bytes, *source, (*target)->light()); + if (!upgraded || !std::ranges::equal(*upgraded, payload)) + return fail(RecoveryError::history); + } else if (boundary || maturation || inheritance) { auto upgraded = inheritance ? cellular_inheritance_upgrade_payload(*bytes, *source) : maturation ? cellular_maturation_upgrade_payload(*bytes, *source) : cellular_boundary_upgrade_payload(*bytes, *source); diff --git a/src/persistence/population_checkpoint.cpp b/src/persistence/population_checkpoint.cpp index 32314a8..55b3bd6 100644 --- a/src/persistence/population_checkpoint.cpp +++ b/src/persistence/population_checkpoint.cpp @@ -197,4 +197,31 @@ cellular_inheritance_upgrade_payload(std::span payload, return std::unexpected(CheckpointError::payload); return (*upgraded)->snapshot(); } +std::expected +cellular_photosynthesis_upgrade_manifest(const CheckpointManifest& previous, + const Sha256Digest& previous_digest, Uuid commit, + const LeaseGrant& lease, const Sha256Digest& build, + std::uint64_t bytes, const Sha256Digest& digest) { + if (previous.profile != CheckpointProfile::cellular_lives_v1) + return std::unexpected(CheckpointError::unsupported); + return upgrade_manifest(previous, previous_digest, commit, lease, build, bytes, digest, + cellular_v12_versions, cellular_v13_versions); +} +std::expected, CheckpointError> +cellular_photosynthesis_upgrade_payload(std::span payload, + const CheckpointManifest& previous, + const server::CellularLight& light) { + if (!supported(previous) || previous.profile != CheckpointProfile::cellular_lives_v1 || + previous.cellular_versions != cellular_v12_versions) + return std::unexpected(CheckpointError::unsupported); + if (!encode_manifest(previous) || previous.sequence == 0 || previous.end_tick == 0) + return std::unexpected(CheckpointError::chain); + auto state = restore_cellular_payload(payload, previous); + if (!state) + return std::unexpected(state.error()); + auto upgraded = (*state)->photosynthesis_upgrade_candidate(light); + if (!upgraded) + return std::unexpected(CheckpointError::payload); + return (*upgraded)->snapshot(); +} } // namespace evo::persistence diff --git a/src/persistence/region_checkpoint.cpp b/src/persistence/region_checkpoint.cpp index 528f854..54ba906 100644 --- a/src/persistence/region_checkpoint.cpp +++ b/src/persistence/region_checkpoint.cpp @@ -69,7 +69,7 @@ bool structural(const CheckpointManifest& m) noexcept { m.cellular_versions == cellular_v9_versions || m.cellular_versions == cellular_v10_versions || m.cellular_versions == cellular_v11_versions || - m.cellular_versions == cellular_v12_versions) && + cellular_plan_bundle(m.cellular_versions)) && m.begin_tick == m.end_tick && m.end_tick > 0 && b == BatchDigests{}; const auto joint_min = @@ -99,7 +99,7 @@ bool structural(const CheckpointManifest& m) noexcept { m.cellular_versions != cellular_v9_versions && m.cellular_versions != cellular_v10_versions && m.cellular_versions != cellular_v11_versions && - m.cellular_versions != cellular_v12_versions) || + !cellular_plan_bundle(m.cellular_versions)) || (cellular && m.versions != environmental_v1_versions)) return false; if (primitive && (m.manifest_version != 2 || m.tick_microseconds != 50000 || @@ -115,7 +115,7 @@ bool structural(const CheckpointManifest& m) noexcept { // upgrade. Provisioning cannot skip its original opening-stock history. if (cellular && (m.cellular_versions == cellular_v10_versions || m.cellular_versions == cellular_v11_versions || - m.cellular_versions == cellular_v12_versions)) + cellular_plan_bundle(m.cellular_versions))) return false; const bool genesis = zero(m.holder) && m.epoch == 0 && m.begin_tick == m.end_tick && b.trace_bytes == 0 && zero(b.trace_sha256); @@ -206,7 +206,7 @@ bool supported(const CheckpointManifest& m) noexcept { m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development; if (m.profile == CheckpointProfile::cellular_lives_v1) { const bool revision = cellular_revision_bundle(m.cellular_versions) || - m.cellular_versions == cellular_v12_versions; + cellular_plan_bundle(m.cellular_versions); const bool history_matches = (!revision && m.history_profile == cellular_history_profile) || (revision && m.history_profile == cellular_revision_history_profile); @@ -222,7 +222,7 @@ bool supported(const CheckpointManifest& m) noexcept { m.cellular_versions == cellular_v9_versions || m.cellular_versions == cellular_v10_versions || m.cellular_versions == cellular_v11_versions || - m.cellular_versions == cellular_v12_versions) && + cellular_plan_bundle(m.cellular_versions)) && m.versions == environmental_v1_versions && m.tick_microseconds == 50000 && m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development; } diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index 5b93430..5207e0a 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -2202,6 +2202,7 @@ CellularLives::advance_tick_with_mutations(std::span i next->captured = state_->captured; // ADR-0175: light, from this tick's own intentions, credited to every active, // unfrozen photosynthetic survivor's reserve and to the boundary inflow together. + std::vector> lit_lives; if (next->light.numerator != 0) { for (auto& life : next->lives) { const auto left = next->light.entitlement.value - next->captured.value; @@ -2240,6 +2241,8 @@ CellularLives::advance_tick_with_mutations(std::span i next->boundary.incoming.energy.value += granted; next->current_total.energy.value += granted; next->captured.value += granted; + if (granted != 0) + lit_lives.emplace_back(life.identity.life, granted); } } std::vector feedback; @@ -2289,6 +2292,11 @@ CellularLives::advance_tick_with_mutations(std::span i entry->resume_blocked = std::ranges::find(resume_blocked, life.identity.life) != resume_blocked.end(); } + for (const auto& [life, energy] : lit_lives) { + const auto entry = std::ranges::find(feedback, life, &CellularLifeTickFeedback::life_id); + if (entry != feedback.end()) + entry->light = {energy}; + } std::ranges::sort(feedback, {}, &CellularLifeTickFeedback::life_id); state_.swap(next); last_tick_feedback_ = std::move(feedback); diff --git a/src/server/session/region_sessions.cpp b/src/server/session/region_sessions.cpp index 1609185..56a914a 100644 --- a/src/server/session/region_sessions.cpp +++ b/src/server/session/region_sessions.cpp @@ -157,7 +157,15 @@ struct RegionSessions::Impl { if (c.state != State::established || !network::cellular_v10_family(c.protocol_version) || c.account_id != account) continue; - const auto bytes = network::encode_session(message, c.protocol_version); + auto delivered = message; + // ADR-0176: before v12 an offer cannot name photosynthesis; its other choices + // stay valid, so those candidates alone are withheld. + if (auto* offer = std::get_if(&delivered)) + std::erase_if(offer->candidates, [&](const auto& candidate) { + return candidate.capability > + network::cellular_offer_capability_limit(c.protocol_version); + }); + const auto bytes = network::encode_session(delivered, c.protocol_version); return !bytes.empty() && endpoint->send_message(c.id, bytes).has_value(); } return false; @@ -620,7 +628,7 @@ struct RegionSessions::Impl { wire_version == network::session_protocol_v9 || network::cellular_v10_family(wire_version)) && !cellular_actions) || - wire_version > network::session_protocol_v11) + wire_version > network::session_protocol_v12) return close(c, SessionCloseReason::unsupported_version, now); } else if (wire_version != c.protocol_version) { return close(c, SessionCloseReason::unsupported_version, now); @@ -941,11 +949,17 @@ bool RegionSessions::send_cellular_perception(const network::AccountId& account, continue; c.perceived_tick = perception.tick; auto delivered = perception; - // v11 sees deposits (ADR-0136), earlier versions square patches; never both. - if (c.protocol_version == network::session_protocol_v11) + // v11+ see deposits (ADR-0136), earlier versions square patches; never both. + if (network::cellular_deposit_version(c.protocol_version)) delivered.patches.clear(); else delivered.deposits.clear(); + // Only v12 carries captured light and visible producers (ADR-0176). + if (c.protocol_version != network::session_protocol_v12) { + delivered.producers.clear(); + if (delivered.diagnostics) + delivered.diagnostics->light_pj = 0; + } if (c.protocol_version == network::session_protocol_v8) delivered.diagnostics.reset(); if (c.protocol_version == network::session_protocol_v9 && delivered.diagnostics) { diff --git a/tests/cellular_intent_protocol_tests.cpp b/tests/cellular_intent_protocol_tests.cpp index a547df2..fbc4a71 100644 --- a/tests/cellular_intent_protocol_tests.cpp +++ b/tests/cellular_intent_protocol_tests.cpp @@ -486,6 +486,62 @@ void v11_perception_carries_deposits() { std::get(*decode_session(ended_bytes)) == ended); } +// ADR-0176: v12 is v11 plus captured light and visible producers in the owner's view, and +// capability 7 (photosynthesis) in offers. Earlier versions refuse both. +void v12_perception_carries_light_and_producers() { + CellularLifeDiagnostics d; + d.reserve_energy_pj = 9; + d.light_pj = 1'600; + CellularPerception view{77, 7, {}, d}; + view.deposits.push_back( + {9, 9'000, 400, 1'200, CellularDepositShape::pool, false, {1, 2, 3, 4, 5}}); + view.producers.push_back({5, 100}); + view.producers.push_back({41, 1'000}); + const auto bytes = encode_session(SessionMessage{view}, session_protocol_v12); + CHECK(bytes.size() == session_header_bytes + 18 + 64 + 40 + 16 + 26 + std::size_t{2} * 16); + std::uint16_t version{}; + const auto decoded = decode_session(bytes, &version); + CHECK(decoded && version == session_protocol_v12 && + std::get(*decoded) == view); + // v11 has room for neither light nor producers. + CHECK(encode_session(SessionMessage{view}, session_protocol_v11).empty()); + auto plain = view; + plain.producers.clear(); + plain.diagnostics->light_pj = 0; + CHECK(!encode_session(SessionMessage{plain}, session_protocol_v11).empty()); + CHECK(std::get(*decode_session( + encode_session(SessionMessage{plain}, session_protocol_v12))) == plain); + // Producers ascend by organism with an efficiency in 1..1000; reserved bytes are zero. + auto unordered = view; + std::swap(unordered.producers[0], unordered.producers[1]); + CHECK(encode_session(SessionMessage{unordered}, session_protocol_v12).empty()); + auto excessive = view; + excessive.producers[1].photosynthesis_per_thousand = 1'001; + CHECK(encode_session(SessionMessage{excessive}, session_protocol_v12).empty()); + auto bad = bytes; + bad[bytes.size() - 1] = 1; // Last producer's reserved byte. + CHECK(!decode_session(bad)); + bad = bytes; + bad[bytes.size() - 7] = 0xFF; // Last producer's efficiency high byte. + CHECK(!decode_session(bad)); + // A cleared view carries no producers. + CHECK(decode_session(encode_session(SessionMessage{CellularPerception{78, 0, {}, std::nullopt}}, + session_protocol_v12))); + // Offers name photosynthesis only from v12. + CellularMutationOffer offer{90, 7, 3, 80, {}}; + CellularOfferedCandidate candidate{}; + candidate.operator_id = 31; + candidate.capability = 7; + candidate.effect = 2; + candidate.parameter = 100; + offer.candidates.push_back(candidate); + const auto offered = encode_session(SessionMessage{offer}, session_protocol_v12); + CHECK(!offered.empty() && std::get(*decode_session(offered)) == offer); + CHECK(encode_session(SessionMessage{offer}, session_protocol_v11).empty()); + offer.candidates[0].capability = 8; + CHECK(encode_session(SessionMessage{offer}, session_protocol_v12).empty()); +} + int main() { try { round_trip_and_version_gate(); @@ -499,6 +555,7 @@ int main() { v10_mutation_offer_is_owner_only_and_canonical(); v10_effects_and_life_end_are_owner_only(); v11_perception_carries_deposits(); + v12_perception_carries_light_and_producers(); std::puts( "PASS cellular protocol: v6 intention, v7 action, v8-v10 perception/action framing"); } catch (const std::exception& error) { diff --git a/tests/environment_checkpoint_tests.cpp b/tests/environment_checkpoint_tests.cpp index cd75c7f..a1ab1e8 100644 --- a/tests/environment_checkpoint_tests.cpp +++ b/tests/environment_checkpoint_tests.cpp @@ -160,6 +160,31 @@ int main() { require(restore_environment_payload(payload, unsupported).error() == CheckpointError::unsupported, "rules mismatch accepted"); + // ADR-0176: bundle 13 follows bundle 12 only, on raw profile 4. + auto plans = head; + plans.profile = CheckpointProfile::cellular_lives_v1; + plans.history_profile = cellular_revision_history_profile; + plans.cellular_versions = cellular_v12_versions; + require(supported(plans) && encode_manifest(plans), "bundle 12 fixture head"); + const auto lit = checked(cellular_photosynthesis_upgrade_manifest( + plans, filled<32>(20), filled<16>(21), lease, filled<32>(12), + payload.size(), filled<32>(22)), + "bundle 13 manifest"); + require(lit.cellular_versions == cellular_v13_versions && supported(lit) && + lit.begin_tick == lit.end_tick && + cellular_checkpoint_trace_format(lit.cellular_versions) == + server::cellular_batch_inheritance_format, + "bundle 13 manifest changed tick or trace format"); + auto skipped = plans; + skipped.cellular_versions = cellular_v11_versions; + require(!cellular_photosynthesis_upgrade_manifest(skipped, filled<32>(20), filled<16>(21), + lease, filled<32>(12), payload.size(), + filled<32>(22)), + "bundle 11 skipped to bundle 13"); + require(!cellular_photosynthesis_upgrade_manifest(head, filled<32>(20), filled<16>(21), + lease, filled<32>(12), payload.size(), + filled<32>(22)), + "population profile entered bundle 13"); std::cout << "environment checkpoint contracts passed\n"; return 0; } catch (const std::exception& error) { diff --git a/tests/environment_publication_tests.cpp b/tests/environment_publication_tests.cpp index 70ed81f..2eaec6c 100644 --- a/tests/environment_publication_tests.cpp +++ b/tests/environment_publication_tests.cpp @@ -89,7 +89,8 @@ struct Fixture { }; // A real funded raw region with player-derived wildlife and fully suspended players. -void funded_source(Fixture& f) { +// `nursery` founders are funded; four are born here, so any extra stay funded for later. +void funded_source(Fixture& f, std::uint32_t nursery = 4) { f.build.fill(0xE6); const std::array build{hexadecimal(f.build)}; take(f.owner->query("INSERT INTO evolution.retained_builds(build_identity) VALUES($1::bytea) " @@ -103,7 +104,7 @@ void funded_source(Fixture& f) { f.objects = take(FilesystemObjectStore::open(variable("PGHOST"), f.key, max_cellular_environment_bytes), "environment object namespace"); - f.raw = opening(f.key.world - 200, true, 4, false, f.key.region); + f.raw = opening(f.key.world - 200, true, nursery, false, f.key.region); f.head = take(provision_cellular_region(*f.owner, *f.objects, f.key, 1, *f.raw, f.id(), f.build, 5s), "empty cellular genesis"); @@ -399,9 +400,98 @@ void forged_evidence(Fixture& f) { require(!refused && refused.error().kind == RecoveryError::tail, "recovery accepted forged environmental flows"); } +// ADR-0176: durable bundle 9 -> 10 -> 11 -> 12 -> 13 on raw profile 4, declaring light; +// exact retry, reused-identity conflict, continued publication and recovery. +void photosynthesis_bundle(Fixture& f) { + f.head = take( + migrate_cellular_boundary_profile(*f.db, *f.objects, f.lease, f.head, f.id(), f.build, 5s), + "durable boundary upgrade"); + f.head = take(migrate_cellular_maturation_profile(*f.db, *f.objects, f.lease, f.head, f.id(), + f.build, 5s), + "durable maturation upgrade"); + f.head = take(migrate_cellular_inheritance_profile(*f.db, *f.objects, f.lease, f.head, f.id(), + f.build, 5s), + "durable inheritance upgrade"); + const auto source = f.head; + const CellularLight light{cellular_light_trial_irradiance, 1, {1ULL << 50}}; + const auto upgrade_id = f.id(); + f.head = take(migrate_cellular_photosynthesis_profile(*f.db, *f.objects, f.lease, source, + upgrade_id, f.build, light, 5s), + "durable photosynthesis upgrade"); + const auto upgraded = decode_manifest(f.head.manifest).value(); + require(upgraded.cellular_versions == cellular_v13_versions && + upgraded.profile == CheckpointProfile::cellular_lives_v1 && + upgraded.begin_tick == upgraded.end_tick, + "bundle 13 upgrade changed profile or tick"); + const auto retried = + take(retry_cellular_profile_migration(*f.db, {f.key, upgrade_id, f.head.manifest}, 5s), + "exact photosynthesis upgrade retry"); + require(retried.head == f.head.head, "photosynthesis upgrade retry changed its receipt"); + const auto conflicting = migrate_cellular_photosynthesis_profile( + *f.db, *f.objects, f.lease, source, upgrade_id, f.build, + {light.numerator * 2, 1, {1ULL << 50}}, 5s); + require(!conflicting && conflicting.error().kind == PublicationError::rejected, + "photosynthesis upgrade identity reused with other light"); + const auto builds = f.builds(); + auto recovered = + take(recover_cellular_checkpoint(*f.db, *f.objects, f.key, f.lease, builds, 5s), + "bundle 13 recovery"); + require(recovered.state->rules_version() == cellular_lives_photosynthesis_rules && + recovered.state->format_version() == cellular_lives_light_format && + recovered.state->light() == light, + "recovered region lost its rules or light"); + // An unattended raw interval continues on bundle 13 and recovers exactly. + auto inputs = take(unattended_population_inputs(*recovered.state, f.header(64)), + "bundle 13 interval inputs"); + auto next = take(replay_cellular_batch(*recovered.state, inputs), "bundle 13 interval"); + f.head = take(publish_cellular_batch(*f.db, *f.objects, f.lease, f.head, inputs, *next, f.id(), + f.build, 5s), + "bundle 13 interval publication") + .committed; + auto again = take(recover_cellular_checkpoint(*f.db, *f.objects, f.key, f.lease, builds, 5s), + "bundle 13 interval recovery"); + require(again.state->snapshot() == next->snapshot(), "bundle 13 interval recovery diverged"); + // A funded birth on bundle 13 is founder 4 (genome schema 5), through the same journals. + Uuid account{}; + account[0] = 0xE6; + account.back() = 9; + const auto control = + take(claim_account_control(*f.db, f.key, f.lease, account, 1, 9, 60000ms, 5s), + "bundle 13 account control"); + const auto reserved = + take(reserve_primitive_life(*f.db, f.key, f.lease, account, control.generation, 1, 1, 5s), + "bundle 13 funded reservation"); + auto birth = take(unattended_population_inputs(*again.state, f.header(1)), "birth tick"); + birth.ticks.front().births.push_back({account, 1, control.generation, reserved.identity}); + auto born = take(replay_cellular_batch(*again.state, birth), "bundle 13 birth"); + f.head = take(publish_cellular_batch(*f.db, *f.objects, f.lease, f.head, birth, *born, f.id(), + f.build, 5s), + "bundle 13 birth publication") + .committed; + auto with_birth = + take(recover_cellular_checkpoint(*f.db, *f.objects, f.key, f.lease, builds, 5s), + "bundle 13 birth recovery"); + const auto life = std::ranges::find(with_birth.state->lives(), reserved.identity, + [](const auto& l) { return l.identity.life; }); + require(life != with_birth.state->lives().end(), "bundle 13 birth missing after recovery"); + const auto genome = with_birth.state->archive().find(life->identity.genome); + require(genome && genome->schema_version() == biology::genome_schema_v5 && + with_birth.state->snapshot() == born->snapshot(), + "bundle 13 birth is not founder 4 or recovery diverged"); + std::printf("photosynthesis bundle: head %llu at tick %llu\n", + static_cast(f.head.head.sequence), + static_cast(f.head.head.end_tick)); +} } // namespace void run_environment_publication_tests() { + { + Fixture producer; + producer.key = {30412, 1}; + producer.next_id = 4096; // Commit IDs are unique across every region. + funded_source(producer, 5); + photosynthesis_bundle(producer); + } Fixture fixture; funded_source(fixture); joint_profile(fixture); diff --git a/tests/network_control.cpp b/tests/network_control.cpp index 43d3779..d6fe123 100644 --- a/tests/network_control.cpp +++ b/tests/network_control.cpp @@ -371,7 +371,7 @@ void session_codec() { mutated.at(0) ^= 1; CHECK(refused(decode_session(mutated), SessionCodecError::bad_magic)); mutated = bytes; - mutated.at(4) = 12; // A future version; protocol versions through 11 are supported. + mutated.at(4) = 13; // A future version; protocol versions through 12 are supported. CHECK(refused(decode_session(mutated), SessionCodecError::unsupported_version)); mutated = bytes; mutated.at(7) = 1; diff --git a/tests/region_migration_tests.cpp b/tests/region_migration_tests.cpp index ebd27b3..e25eb5b 100644 --- a/tests/region_migration_tests.cpp +++ b/tests/region_migration_tests.cpp @@ -222,6 +222,7 @@ void upgrade_across_migration_and_barrier() { " -v migration_sha_54=$(s 0054_maturing_cellular_migration.sql)" " -v migration_sha_55=$(s 0055_retained_cellular_plans.sql)" " -v migration_sha_56=$(s 0056_cellular_environment_publication.sql)" + " -v migration_sha_57=$(s 0057_photosynthesis_bundle.sql)" " -v runtime_role=evo_runtime_test -f migrations/apply.sql" " > /dev/null 2>&1") != 0); CHECK(history(*owner_db) == "1,2,3,4,5,6,7"); @@ -239,7 +240,7 @@ void upgrade_across_migration_and_barrier() { "tools/migrate-postgres.sh\" > /dev/null") == 0); CHECK(history(*owner_db) == "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24," "25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46," - "47,48,49,50,51,52,53,54,55,56"); + "47,48,49,50,51,52,53,54,55,56,57"); CHECK(scalar(*owner_db, "SELECT (c.condeferrable AND c.condeferred AND " "c.confrelid = 'evolution.region_commits'::regclass)::text " "FROM pg_catalog.pg_constraint c WHERE c.conrelid = " diff --git a/tests/region_store_tests.cpp b/tests/region_store_tests.cpp index ed13819..15072c4 100644 --- a/tests/region_store_tests.cpp +++ b/tests/region_store_tests.cpp @@ -435,59 +435,62 @@ void provisioning_creates_the_life_allocator_once() { std::vector provision_cellular(const ServerRegion& r, const std::string& world, const std::string& opening, const std::string& build, const std::string& commit, const std::string& patch, - int& code, const std::string& food = "--patch") { + int& code, const std::string& food = "--patch", + const std::vector& extra = {}) { const auto endowed = evo::biology::primitive_endowment(); CHECK(endowed); evo::accounting::Inventory funding = endowed->body; funding.energy.value += endowed->reserve.energy.value + endowed->construction.value; - Child tool{{env("EVO_WORLD_CLONE_BIN"), - "provision", - "--world", - world, - "--region", - "1", - "--opening", - opening, - "--pg-host", - env("PGHOST"), - "--pg-port", - env("PGPORT"), - "--pg-database", - env("PGDATABASE"), - "--pg-user", - env("PGUSER"), - "--objects", - r.root.string(), - "--build", - build, - "--retain-build", - "true", - "--commit", - commit, - "--frame", - "9", - "--source-id", - "1", - "--funding-energy-pj", - std::to_string(funding.energy.value), - "--funding-carbon-fg", - std::to_string(funding.matter[0].value), - "--funding-nitrogen-fg", - std::to_string(funding.matter[1].value), - "--funding-phosphorus-fg", - std::to_string(funding.matter[2].value), - "--funding-other-fg", - std::to_string(funding.matter[3].value), - "--site", - "2500,2500", - "--width-um", - "10000", - "--height-um", - "10000", - "--ambient-temperature-mk", - "293150", - food, - patch}}; + std::vector arguments{env("EVO_WORLD_CLONE_BIN"), + "provision", + "--world", + world, + "--region", + "1", + "--opening", + opening, + "--pg-host", + env("PGHOST"), + "--pg-port", + env("PGPORT"), + "--pg-database", + env("PGDATABASE"), + "--pg-user", + env("PGUSER"), + "--objects", + r.root.string(), + "--build", + build, + "--retain-build", + "true", + "--commit", + commit, + "--frame", + "9", + "--source-id", + "1", + "--funding-energy-pj", + std::to_string(funding.energy.value), + "--funding-carbon-fg", + std::to_string(funding.matter[0].value), + "--funding-nitrogen-fg", + std::to_string(funding.matter[1].value), + "--funding-phosphorus-fg", + std::to_string(funding.matter[2].value), + "--funding-other-fg", + std::to_string(funding.matter[3].value), + "--site", + "2500,2500", + "--width-um", + "10000", + "--height-um", + "10000", + "--ambient-temperature-mk", + "293150", + food, + patch}; + arguments.insert(arguments.end(), extra.begin(), extra.end()); + Child tool{arguments}; code = tool.wait_exit(30s); return tool.lines(); } @@ -624,6 +627,32 @@ void cellular_v7_provisioning_scatters_bubbles() { manifest->history_profile == cellular_revision_history_profile); } +// ADR-0176: cellular-v8 is the cellular-v7 opening taken through one empty tick and the +// durable upgrades to bundle 13 with declared light; it is resumable and idempotent. +void cellular_v8_provisioning_declares_light() { + const ServerRegion r{{9775, 1}, fresh("cellular-v8-provision-9775")}; + const std::string build(64, 'e'); + const std::string commit = "b0b81e5c0f7e1d2ba1a0ce5c0f7e1d2d"; // Unique to this test. + int code = -1; + const auto dark = provision_cellular(r, "9775", "cellular-v8", build, commit, + "40,1,2000000,50000,20000,0,0", code, "--motes"); + CHECK(code != 0); // cellular-v8 requires --light-pj. + const auto first = + provision_cellular(r, "9775", "cellular-v8", build, commit, "40,1,2000000,50000,20000,0,0", + code, "--motes", {"--light-pj", "40"}); + CHECK(code == 0 && has(first, "provisioned world=9775 region=1 sequence=5 tick=1")); + const auto again = + provision_cellular(r, "9775", "cellular-v8", build, commit, "40,1,2000000,50000,20000,0,0", + code, "--motes", {"--light-pj", "40"}); + CHECK(code == 0 && has(again, "already-provisioned world=9775 region=1 sequence=5 tick=1")); + auto db = owner(); + const auto head = load_region_checkpoint(*db, r.key, 5s); + CHECK(head); + const auto manifest = decode_manifest(head->manifest); + CHECK(manifest && manifest->cellular_versions == cellular_v13_versions && + manifest->history_profile == cellular_revision_history_profile); +} + void cellular_provisioning_survives_a_build_promotion() { const ServerRegion r{{9761, 1}, fresh("cellular-provision-9761")}; const auto run = [&](const std::string& build, const std::string& commit, @@ -660,6 +689,7 @@ void run_region_store_tests() { cellular_v5_provisioning_uses_the_balance_bundle(); cellular_v6_provisioning_uses_the_reproduction_bundle(); cellular_v7_provisioning_scatters_bubbles(); + cellular_v8_provisioning_declares_light(); full_volumes_publish_nothing(); failing_writes_leave_nothing(); check_store_qualifies_the_stores(); diff --git a/tools/ci/history-domain-check.sh b/tools/ci/history-domain-check.sh index 4d263e5..33a731d 100644 --- a/tools/ci/history-domain-check.sh +++ b/tools/ci/history-domain-check.sh @@ -58,7 +58,7 @@ for invalid in NULL "'00000000-0000-0000-0000-000000000000'"; do done # Reconstruct the exact pre-context metadata schema in this disposable database. # Restore the resulting real legacy backup through both supported workflows. -# Undo schema 56's joint profile, schema 55's plan validators, schema 54's three +# Undo schema 57's bundle-13 wrappers, schema 56's joint profile, schema 55's plan validators, schema 54's three # replacements and schema 53; the backup must contain the actual pre-context # function contracts and privileges. awk '/^CREATE FUNCTION evolution\.admit_population_interval\(/ {capture=1; sub(/^CREATE FUNCTION/,"CREATE OR REPLACE FUNCTION")} capture {print} capture && /^END \$\$;/ {capture=0}' \ @@ -69,6 +69,12 @@ awk '/^CREATE FUNCTION evolution\.(check_cellular_migration_trace|prepare_cellul awk '/^CREATE OR REPLACE FUNCTION evolution\.(cellular_mutation_selections|check_cellular_mutation_block)\(/ {capture=1} capture {print} capture && /^END \$\$;/ {capture=0}' \ "$root/migrations/0040_cellular_mutation_decline.sql" | sql > /dev/null sql -v runtime_role="$EVO_PG_RUNTIME_ROLE" > /dev/null <<'SQL' +DROP FUNCTION evolution.publish_cellular_profile_migration(bytea); +ALTER FUNCTION evolution.publish_cellular_profile_migration_v56(bytea) RENAME TO publish_cellular_profile_migration; +DROP FUNCTION evolution.cellular_births(bytea,bytea); +ALTER FUNCTION evolution.cellular_births_v56(bytea,bytea) RENAME TO cellular_births; +DROP FUNCTION evolution.parse_checkpoint_manifest(bytea); +ALTER FUNCTION evolution.parse_checkpoint_manifest_v56(bytea) RENAME TO parse_checkpoint_manifest; DROP TRIGGER region_environment_evidence ON evolution.region_commits; DROP FUNCTION evolution.refuse_unpublished_environment(); DROP FUNCTION evolution.load_environment_evidence(evolution.u64,evolution.u64,uuid,evolution.u64,uuid); diff --git a/tools/ci/postgres-check.sh b/tools/ci/postgres-check.sh index 945a944..faa783f 100644 --- a/tools/ci/postgres-check.sh +++ b/tools/ci/postgres-check.sh @@ -161,7 +161,7 @@ PGDATABASE=upgrade_path psql -X -v ON_ERROR_STOP=1 -1 -v "migration_sha=$v1_sha" -f "$root/migrations/0001_region_bootstrap.sql" > /dev/null test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',') FROM evolution.schema_migrations")" = 1 PGDATABASE=upgrade_path bash "$root/tools/migrate-postgres.sh" -test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56 +test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57 # v2 heads have no payload binding: v2->v3 fails closed and leaves history at v2. v2_sha="$(sha256sum "$root/migrations/0002_region_fencing.sql")" v2_sha="${v2_sha%% *}" @@ -182,7 +182,7 @@ PGDATABASE=v3_commits psql -X -v ON_ERROR_STOP=1 \ -c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \ -c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '01000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32), 'hex'))" > /dev/null PGDATABASE=v3_commits bash "$root/tools/migrate-postgres.sh" -test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 56:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56 +test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 57:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57 test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) FROM evolution.region_commits")" = 1 # Review P1: a v4 database holding a published (possibly terminal) checkpoint has # no durable decisions for it. The v5 upgrade must refuse before changing anything. @@ -236,7 +236,7 @@ PGDATABASE=v6_populated psql -X -v ON_ERROR_STOP=1 \ -c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \ -c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '02000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32) || repeat('00', 80), 'hex'))" > /dev/null PGDATABASE=v6_populated bash "$root/tools/migrate-postgres.sh" -test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56 +test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57 test "$(PGDATABASE=v6_populated psql -XAtc "SELECT count(*) FROM evolution.region_commits c, LATERAL evolution.parse_checkpoint_manifest(c.manifest) m WHERE m.commit_sequence = 0 AND m.predecessor_commit IS NULL")" = 1 test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(conname, ',') FROM pg_constraint WHERE conrelid = 'evolution.region_heads'::regclass AND contype = 'c' AND pg_get_constraintdef(oid) LIKE '%end_tick%'")" = region_heads_published_tick phase permission-audit @@ -294,9 +294,9 @@ expect_audit_failure 'REVOKE EXECUTE ON FUNCTION evolution.load_world_cellular_m expect_audit_failure 'GRANT EXECUTE ON FUNCTION evolution.fork_restored_history_v1(uuid) TO evo_runtime_test' 'REVOKE EXECUTE ON FUNCTION evolution.fork_restored_history_v1(uuid) FROM evo_runtime_test' phase checksum-drift # Unknown future versions and checksum drift must not be repaired silently. -psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=57 WHERE version=56' +psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=58 WHERE version=57' if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi -psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=56 WHERE version=57" +psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=57 WHERE version=58" psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=14" if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=13" diff --git a/tools/migrate-postgres.sh b/tools/migrate-postgres.sh index 079930a..c6b08ca 100644 --- a/tools/migrate-postgres.sh +++ b/tools/migrate-postgres.sh @@ -124,6 +124,8 @@ digest_55="$(sha256sum "$root/migrations/0055_retained_cellular_plans.sql")" digest_55="${digest_55%% *}" digest_56="$(sha256sum "$root/migrations/0056_cellular_environment_publication.sql")" digest_56="${digest_56%% *}" +digest_57="$(sha256sum "$root/migrations/0057_photosynthesis_bundle.sql")" +digest_57="${digest_57%% *}" psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \ --set="migration_sha_2=$digest_2" --set="migration_sha_3=$digest_3" \ --set="migration_sha_4=$digest_4" --set="migration_sha_5=$digest_5" \ @@ -171,5 +173,6 @@ psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \ --set="migration_sha_52=$digest_52" \ --set="migration_sha_53=$digest_53" --set="migration_sha_54=$digest_54" \ --set="migration_sha_55=$digest_55" --set="migration_sha_56=$digest_56" \ + --set="migration_sha_57=$digest_57" \ --set="runtime_role=$runtime_role" \ --file="$root/migrations/apply.sql"