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
+28 -3
View File
@@ -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<CellularOfferedCandidate> 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<std::uint64_t, 4> 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<CellularPerceivedPatch> patches; // strictly ordered by (x_um, y_um).
@@ -335,6 +358,8 @@ struct CellularPerception {
std::optional<CellularLifeDiagnostics> diagnostics;
// v11 only (then `patches` is empty): pools and bubbles in range, by ascending id.
std::vector<CellularPerceivedDeposit> deposits{};
// v12 only: visible producers by ascending organism.
std::vector<CellularPerceivedProducer> producers{};
friend bool operator==(const CellularPerception&, const CellularPerception&) = default;
};
struct IntentionReceipt {
@@ -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<CommittedCheckpoint, CellularProfileMigrationFailure>
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.
+19 -1
View File
@@ -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<std::vector<std::uint8_t>, CheckpointError>
cellular_inheritance_upgrade_payload(std::span<const std::uint8_t> 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<CheckpointManifest, CheckpointError>
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<std::vector<std::uint8_t>, CheckpointError>
cellular_photosynthesis_upgrade_payload(std::span<const std::uint8_t> 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<CheckpointManifest, CheckpointError>
@@ -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