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
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:
@@ -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<std::uint32_t> cellular_width_um, cellular_height_um, cellular_temperature_mk;
|
||||
std::vector<biology::CellularPatch> cellular_patches;
|
||||
std::vector<biology::CellularPatch> cellular_pools; // cellular-v7
|
||||
std::optional<biology::CellularMoteField> cellular_motes; // cellular-v7
|
||||
std::optional<biology::CellularMoteField> cellular_motes; // cellular-v7 and v8
|
||||
std::optional<std::uint64_t> light_pj; // cellular-v8: pJ per square um per tick
|
||||
std::optional<std::uint64_t> life_allocator_start;
|
||||
std::optional<persistence::Sha256Digest> build;
|
||||
bool retain_build{};
|
||||
@@ -333,8 +335,11 @@ std::optional<Options> 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<Options> 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<std::uint8_t> 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<ssize_t>(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<persistence::Sha256Digest, 1> 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<persistence::CommittedCheckpoint,
|
||||
persistence::CellularProfileMigrationFailure>
|
||||
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<std::uint64_t>::max() / 2}}, timeout);
|
||||
else
|
||||
return finish(4);
|
||||
if (!upgraded) {
|
||||
std::printf("photosynthesis opening upgrade refused %u\n",
|
||||
static_cast<unsigned>(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<unsigned>(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) {
|
||||
|
||||
Reference in New Issue
Block a user