feat(ecology): make photosynthesis regions playable on DEV
Foundation / checks (ecs) (push) Successful in 2m19s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 16m48s
Foundation / checks (network) (push) Canceled after 16m46s
Foundation / checks (postgres) (push) Canceled after 16m47s
Foundation / checks (client) (push) Canceled after 16m53s
Foundation / checks (tsan) (push) Canceled after 14m33s

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 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-19 23:04:34 -04:00
co-authored by Claude Opus 5.5
parent 108f29eda5
commit b73ccbae9a
38 changed files with 1106 additions and 140 deletions
+57
View File
@@ -486,6 +486,62 @@ void v11_perception_carries_deposits() {
std::get<CellularLifeEnded>(*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<CellularPerception>(*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<CellularPerception>(*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<CellularMutationOffer>(*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) {
+25
View File
@@ -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) {
+92 -2
View File
@@ -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<std::string, 1> 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<unsigned long long>(f.head.head.sequence),
static_cast<unsigned long long>(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);
+1 -1
View File
@@ -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;
+2 -1
View File
@@ -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 = "
+79 -49
View File
@@ -435,59 +435,62 @@ void provisioning_creates_the_life_allocator_once() {
std::vector<std::string> 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<std::string>& 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<std::string> 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();