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
+40 -13
View File
@@ -5,6 +5,7 @@
#include <algorithm>
#include <array>
#include <functional>
#include <string>
#include <string_view>
#include <utility>
@@ -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<CommittedCheckpoint, CellularProfileMigrationFailure>
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<CommittedCheckpoint, CellularProfileMigrationFailure> 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<std::expected<std::vector<std::uint8_t>, CheckpointError>(
std::span<const std::uint8_t>, 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<CommittedCheckpoint, CellularProfileMigrationFailure>
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<const std::uint8_t> payload, const CheckpointManifest& previous) {
return cellular_photosynthesis_upgrade_payload(payload, previous, light);
},
cellular_photosynthesis_upgrade_manifest);
}
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
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);
+27
View File
@@ -197,4 +197,31 @@ cellular_inheritance_upgrade_payload(std::span<const std::uint8_t> payload,
return std::unexpected(CheckpointError::payload);
return (*upgraded)->snapshot();
}
std::expected<CheckpointManifest, CheckpointError>
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<std::vector<std::uint8_t>, CheckpointError>
cellular_photosynthesis_upgrade_payload(std::span<const std::uint8_t> 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
+5 -5
View File
@@ -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;
}