Cellular balance rules 6 (ADR-0132, schema v41)
Foundation / checks (checks) (push) Successful in 42m33s
Foundation / checks (deploy) (push) Successful in 4m11s
Foundation / checks (ecs) (push) Successful in 2m27s
Foundation / checks (network) (push) Successful in 19m23s
Foundation / checks (postgres) (push) Successful in 44m44s
Foundation / checks (tsan) (push) Successful in 9m53s
Foundation / checks (client) (push) Successful in 16m19s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 3m14s
Foundation / image (push) Successful in 3m16s
Foundation / checks (checks) (push) Successful in 42m33s
Foundation / checks (deploy) (push) Successful in 4m11s
Foundation / checks (ecs) (push) Successful in 2m27s
Foundation / checks (network) (push) Successful in 19m23s
Foundation / checks (postgres) (push) Successful in 44m44s
Foundation / checks (tsan) (push) Successful in 9m53s
Foundation / checks (client) (push) Successful in 16m19s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 3m14s
Foundation / image (push) Successful in 3m16s
The playtest found mutation offers the arena could never pay for. A mutation's matter cost is the real body difference (ADR-0118), so it cannot be discounted. Rules 6 cut it honestly: - genome schema 3 steps a third as far (1/300 of the range); - development version 3 charges a third of the construction energy (13 instead of 40 pJ per 1000 fg). Founder 2 uses both. The cellular-v5 opening creates rules-6 regions on bundle v7, which schema v41 admits. Existing lineages, regions and committed history are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,15 +10,16 @@
|
||||
// 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|cellular-v2|cellular-v3|cellular-v4
|
||||
// development-v1|primitive-v1|cellular-v1|cellular-v2|cellular-v3|cellular-v4|cellular-v5
|
||||
// --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.
|
||||
// cellular-v1 to cellular-v4 also require --width-um N --height-um N
|
||||
// cellular-v1 to cellular-v5 also require --width-um N --height-um N
|
||||
// --ambient-temperature-mk N and one or more ordered --patch X,Y,SOURCE,ENERGY,C,N,P,O values
|
||||
// plus a stable --commit HEX32. cellular-v2 is the same opening on rules 3 (ADR-0124:
|
||||
// engulfment, detritus); cellular-v3 is it on rules 4 (ADR-0125: budding wildlife);
|
||||
// cellular-v4 on rules 5 (ADR-0128: offline freeze and resume).
|
||||
// cellular-v5 on rules 6 (2026-10-15 balance: finer mutations, cheaper construction).
|
||||
// primitive-v1 and cellular-v1/v2/v3 accept --life-allocator-start N
|
||||
// (ADR-0123): the world's life-identity allocator is created once at the operator-audited
|
||||
// start N; a later run leaves it untouched and refuses one that is below N.
|
||||
@@ -275,7 +276,8 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
o.reserve_mib = *n;
|
||||
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-v2" || value == "cellular-v3" || value == "cellular-v4" ||
|
||||
value == "cellular-v5"))
|
||||
o.opening = value;
|
||||
else if (o.command == "provision" && flag == "--frame" && n)
|
||||
o.primitive_frame = n;
|
||||
@@ -350,7 +352,8 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
if (cellular_options)
|
||||
return std::nullopt;
|
||||
} else if (o.opening == "cellular-v1" || o.opening == "cellular-v2" ||
|
||||
o.opening == "cellular-v3" || o.opening == "cellular-v4") {
|
||||
o.opening == "cellular-v3" || o.opening == "cellular-v4" ||
|
||||
o.opening == "cellular-v5") {
|
||||
const bool has_stock = std::ranges::any_of(o.cellular_patches, [](const auto& patch) {
|
||||
return patch.stock.energy.value != 0 ||
|
||||
std::ranges::any_of(patch.stock.matter,
|
||||
@@ -460,7 +463,8 @@ std::vector<std::uint8_t> probe_bytes() {
|
||||
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-v3" || o.opening == "cellular-v4" ||
|
||||
o.opening == "cellular-v5";
|
||||
const auto primitive_frame = o.primitive_frame.value_or(0);
|
||||
if ((primitive || cellular) && primitive_frame == 0)
|
||||
return 2;
|
||||
@@ -563,7 +567,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-v4" ? server::CellularLivesProfile::presence
|
||||
o.opening == "cellular-v5" ? server::CellularLivesProfile::balance
|
||||
: o.opening == "cellular-v4" ? server::CellularLivesProfile::presence
|
||||
: o.opening == "cellular-v3" ? server::CellularLivesProfile::budding
|
||||
: o.opening == "cellular-v2" ? server::CellularLivesProfile::engulf
|
||||
: server::CellularLivesProfile::offers);
|
||||
|
||||
@@ -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-20261015T234335-16592:1792118615"}
|
||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261016T005331-55669:1792122811"}
|
||||
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
||||
ports:
|
||||
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
# ADR-0132: Cellular balance, rules 6
|
||||
|
||||
## Status
|
||||
|
||||
Accepted (2026-10-15). Tunable trial values for DEV playtesting, not final balance.
|
||||
|
||||
## Context
|
||||
|
||||
The first sign-in playtest (DEV region 100/5) showed mutation offers the arena could
|
||||
never pay for. "Increase Membrane" asked a founder for about 200 million fg of carbon,
|
||||
4.4 times all the food carbon in the 10 × 10 mm arena, and raised upkeep 48-fold. Under
|
||||
ADR-0118 a mutation's matter cost is the physical difference between the current and
|
||||
successor bodies, so it cannot be discounted without creating matter. Only construction
|
||||
energy is overhead, paid into heat.
|
||||
|
||||
Two things set that cost: the mutation step, one hundredth of each capability's
|
||||
declared range (ADR-0099), and the construction energy rate of the genome's development
|
||||
version.
|
||||
|
||||
## Decision
|
||||
|
||||
The maintainer asked for costs cut by about two thirds. Rules 6 do that without
|
||||
breaking conservation:
|
||||
|
||||
- **Genome schema 3:** schema 2's capability table and units, with mutation steps a
|
||||
third as large (1/300 of the range). Successor bodies differ a third as much, so the
|
||||
matter a mutation needs, and its upkeep change, fall with them.
|
||||
- **Development version 3:** version 2 with construction energy 13 pJ per 1000 fg built
|
||||
instead of 40. This lowers the energy of every construction (mutations, buds, founder
|
||||
bodies). Matter, metabolism and rates are unchanged.
|
||||
- **Founder 2:** schema 3 and development 3. Its body, upkeep and reserve equal founder
|
||||
1's; only the construction energy paid from the nursery is lower.
|
||||
- **Rules 6** are rules 5 with founder 2. They add no state, so they keep owner format
|
||||
6. The `cellular-v5` opening creates them, with version bundle v7
|
||||
`{6, 6, 1, 1, 1, 3, 2, 2, 1}` (development 3, founder 2). Schema v41 normalizes v7 like
|
||||
v6 and binds its births.
|
||||
- A lineage keeps its schema and development version (ADR-0099): existing regions and
|
||||
genomes never change, and replay of committed history is unaffected. Only rules-6
|
||||
regions found the new versions; their descendants inherit them.
|
||||
|
||||
The DEV world moves to a new rules-6 region with more food (see the M11.9 plan).
|
||||
|
||||
## Alternatives
|
||||
|
||||
- **Discount the matter cost:** rejected. The successor body really holds that matter,
|
||||
so a discount would create it.
|
||||
- **Scale constants in place:** rejected. It would reinterpret existing genomes and
|
||||
change the replay of committed history.
|
||||
- **Only cut construction energy:** rejected by the maintainer. Matter costs would stay
|
||||
unaffordable.
|
||||
|
||||
## Consequences
|
||||
|
||||
Mutations change traits more gradually, so a player needs more mutations for the same
|
||||
change, each about a third of the cost. Buds and founders cost less energy. Old regions
|
||||
keep their balance until retired.
|
||||
@@ -32,6 +32,7 @@
|
||||
- [ADR-0129: Cellular readable play signals](0129-cellular-readable-play-signals.md) - M11.8 server half: v10 diagnostics report engulf and bud results in two reserved bytes, and v10 type 27 tells the owner its life ended and why (starved or engulfed); presentation stays with the maintainer.
|
||||
- [ADR-0130: Cellular playtest telemetry boundary](0130-cellular-playtest-telemetry-boundary.md) - M11.9: playtest telemetry is an offline, read-only `evo-world-clone summary` of a region head with account-free aggregates only (population, death causes, lifespans, buds, mutations, variety); per-player questions stay in consented notes.
|
||||
- [ADR-0131: Keycloak login and the grant broker](0131-keycloak-login-and-grant-broker.md) - players sign in to Keycloak realm `aeternalis` (PKCE, public client `aevolution-game`); `evo-grant-broker` verifies the RS256 access token, maps it to a game account (schema v39), issues 10-minute grants with increasing serials, and revokes on logout by raising the accepted serial and expiring control.
|
||||
- [ADR-0132: Cellular balance, rules 6](0132-cellular-balance-rules-6.md) - genome schema 3 (a third of the mutation step) and development version 3 (a third of the construction energy) for founders of rules-6 regions; opening `cellular-v5`, bundle v7, schema v41; existing lineages and history unchanged.
|
||||
|
||||
- [ADR-0058: Region durability contract](0058-region-durability-contract.md) - accepted M7.1 full checkpoint batches and explicit state closure; storage implementation follows.
|
||||
|
||||
|
||||
@@ -7721,3 +7721,29 @@ Executed locally:
|
||||
- WSL client 14/14 with clang-tidy, plus the Xvfb check;
|
||||
- MSVC `client-package` 18/18;
|
||||
- clang-format 19.
|
||||
|
||||
## 2026-10-15 — ADR-0132 rules 6, schema v41 (CI pending)
|
||||
|
||||
Genome schema 3 has a third of the mutation step; development version 3 has a third of
|
||||
the construction energy (13 instead of 40 pJ per 1000 fg). Founder 2 combines them.
|
||||
Rules 6 (`cellular-v5`, bundle v7, owner format 6) found founder 2. Existing schemas,
|
||||
development versions, rules and committed history are unchanged.
|
||||
|
||||
Tests:
|
||||
- `mutation_tests`: schema 3 steps 1/300 of the range;
|
||||
- `development_tests` and `metabolism_tests`: version 3 equals version 2 except
|
||||
construction 13, and version 4 is unknown;
|
||||
- founder 2 builds the same body, upkeep and reserve for less construction energy,
|
||||
and the default stays founder 1;
|
||||
- `genome_tests`: schema 3 ranges, and 4 is unknown;
|
||||
- `cellular_lives_tests`: a balance opening is format 6 / rules 6, founds a
|
||||
schema-3 / development-3 cell charging the nursery the founder-2 endowment, and
|
||||
restores as rules 6;
|
||||
- PostgreSQL: `evo-world-clone provision --opening cellular-v5` writes a v7 genesis,
|
||||
resolves it again and refuses another opening; a rules-6 host publishes a
|
||||
founder-2 birth on the v7 bundle and a restarted host recovers it.
|
||||
|
||||
Executed locally: WSL `m97-postgres` 79/79 CTests; `postgres-check.sh --full`,
|
||||
including the v41 upgrade and drift drills; clang-tidy-19 on the changed sources; WSL
|
||||
client 14/14 with clang-tidy plus the Xvfb check; MSVC `client-package` 18/18;
|
||||
clang-format 19.
|
||||
|
||||
@@ -31,9 +31,10 @@ inline constexpr std::uint64_t development_v2_rate_microseconds = 1'000'000;
|
||||
// of them: it follows from the genome's development version.
|
||||
[[nodiscard]] constexpr std::uint64_t
|
||||
development_rate_microseconds(std::uint32_t development_version) noexcept {
|
||||
return development_version == 1 ? development_v1_tick_microseconds
|
||||
: development_version == 2 ? development_v2_rate_microseconds
|
||||
: 0;
|
||||
return development_version == 1 ? development_v1_tick_microseconds
|
||||
: development_version == 2 || development_version == 3
|
||||
? development_v2_rate_microseconds // Version 3 keeps version 2's rates.
|
||||
: 0;
|
||||
}
|
||||
// Chosen constants, reviewable as a unit and selected by the genome's
|
||||
// development version. Declared model parameters, not balance.
|
||||
|
||||
@@ -23,11 +23,22 @@ struct FounderParameters {
|
||||
};
|
||||
inline constexpr FounderParameters primitive_founder_parameters{400, 1, 8'000'000,
|
||||
200, 574'000, 500};
|
||||
inline constexpr std::uint32_t primitive_founder_development_version = 2;
|
||||
// The genome schema and development version a founder is created with (the version
|
||||
// bundle's `founder`). Founder 1 serves rules 1-5; founder 2 serves rules 6 (2026-10-15
|
||||
// balance: a third of the mutation step and a third of the construction energy).
|
||||
struct FounderVersion {
|
||||
std::uint32_t genome_schema, development_version;
|
||||
auto operator<=>(const FounderVersion&) const = default;
|
||||
};
|
||||
inline constexpr FounderVersion primitive_founder_v1{genome_schema_v2, 2};
|
||||
inline constexpr FounderVersion primitive_founder_v2{genome_schema_v3, 3};
|
||||
inline constexpr std::uint32_t primitive_founder_development_version =
|
||||
primitive_founder_v1.development_version;
|
||||
// The founder genome under a world-scoped identity and its origin event. Fails only on
|
||||
// an invalid identity (zero).
|
||||
[[nodiscard]] std::expected<Genome, GenomeError> primitive_founder(std::uint64_t id,
|
||||
std::uint64_t origin_event);
|
||||
[[nodiscard]] std::expected<Genome, GenomeError>
|
||||
primitive_founder(std::uint64_t id, std::uint64_t origin_event,
|
||||
FounderVersion version = primitive_founder_v1);
|
||||
|
||||
// M11.2 founder rules 1 (ADR-0100): fully grown, no damage or spare matter;
|
||||
// 30 seconds of full-speed demand as usable energy. Construction energy is paid
|
||||
@@ -41,5 +52,6 @@ struct FounderEndowment {
|
||||
accounting::Picojoules construction{};
|
||||
auto operator<=>(const FounderEndowment&) const = default;
|
||||
};
|
||||
[[nodiscard]] std::expected<FounderEndowment, DevelopmentError> primitive_endowment();
|
||||
[[nodiscard]] std::expected<FounderEndowment, DevelopmentError>
|
||||
primitive_endowment(FounderVersion version = primitive_founder_v1);
|
||||
} // namespace evo::biology
|
||||
|
||||
@@ -106,15 +106,19 @@ enum class GenomeError : std::uint8_t {
|
||||
digest_mismatch,
|
||||
invalid_encoding
|
||||
};
|
||||
// The current schema. Schema 1 records stay valid and are never rewritten (ADR-0099).
|
||||
inline constexpr std::uint32_t genome_schema_version = 2;
|
||||
inline constexpr std::uint32_t genome_schema_v1 = 1;
|
||||
// The capability table of a supported schema (1 or 2); nullptr otherwise.
|
||||
inline constexpr std::uint32_t genome_schema_v2 = 2;
|
||||
// Schema 3 (rules 6, 2026-10-15 balance): schema 2's capability table and units, with
|
||||
// mutation steps a third as large (mutation.cpp). Founded only by rules-6 regions.
|
||||
inline constexpr std::uint32_t genome_schema_v3 = 3;
|
||||
// The newest schema. Older records stay valid and are never rewritten (ADR-0099).
|
||||
inline constexpr std::uint32_t genome_schema_version = genome_schema_v3;
|
||||
// The capability table of a supported schema (1, 2 or 3); nullptr otherwise.
|
||||
[[nodiscard]] constexpr const std::array<CapabilitySpec, capability_count>*
|
||||
capability_schema_for(std::uint32_t schema) noexcept {
|
||||
return schema == genome_schema_v1 ? &capability_schema_v1
|
||||
: schema == genome_schema_version ? &capability_schema_v2
|
||||
: nullptr;
|
||||
return schema == genome_schema_v1 ? &capability_schema_v1
|
||||
: schema == genome_schema_v2 || schema == genome_schema_v3 ? &capability_schema_v2
|
||||
: nullptr;
|
||||
}
|
||||
inline constexpr std::size_t max_parents = 2;
|
||||
inline constexpr std::size_t max_genome_bytes = 256;
|
||||
|
||||
@@ -59,10 +59,12 @@ inline constexpr CellularVersionBundle cellular_v4_versions{3, 4, 1, 1, 1, 2, 1,
|
||||
inline constexpr CellularVersionBundle cellular_v5_versions{4, 5, 1, 1, 1, 2, 1, 2, 1};
|
||||
// ADR-0128: rules 5 (offline freeze and resume) and owner envelope 6 (presence).
|
||||
inline constexpr CellularVersionBundle cellular_v6_versions{5, 6, 1, 1, 1, 2, 1, 2, 1};
|
||||
// 2026-10-15 balance: rules 6 on owner envelope 6, with development 3 and founder 2.
|
||||
inline constexpr CellularVersionBundle cellular_v7_versions{6, 6, 1, 1, 1, 3, 2, 2, 1};
|
||||
// Bundles with genome revisions: the revision history profile and format-3 traces.
|
||||
[[nodiscard]] constexpr bool cellular_revision_bundle(const CellularVersionBundle& b) noexcept {
|
||||
return b == cellular_v3_versions || b == cellular_v4_versions || b == cellular_v5_versions ||
|
||||
b == cellular_v6_versions;
|
||||
b == cellular_v6_versions || b == cellular_v7_versions;
|
||||
}
|
||||
|
||||
// Batch evidence bound by manifest v2 (ADR-0063); all zero at genesis.
|
||||
|
||||
@@ -30,6 +30,16 @@ inline constexpr std::uint32_t cellular_lives_bud_rules = 4;
|
||||
// the offline freeze, linger, suspension and resume.
|
||||
inline constexpr std::uint32_t cellular_lives_presence_format = 6;
|
||||
inline constexpr std::uint32_t cellular_lives_presence_rules = 5;
|
||||
// 2026-10-15 balance (ADR-0132): rules 6 are rules 5 with founders of genome schema
|
||||
// 3 and development version 3 (founder 2): a third of the mutation step and a third of the
|
||||
// construction energy. No new state, so they keep owner format 6.
|
||||
inline constexpr std::uint32_t cellular_lives_balance_rules = 6;
|
||||
// The founder a region of these rules creates.
|
||||
[[nodiscard]] constexpr biology::FounderVersion
|
||||
cellular_founder_version(std::uint32_t rules) noexcept {
|
||||
return rules >= cellular_lives_balance_rules ? biology::primitive_founder_v2
|
||||
: biology::primitive_founder_v1;
|
||||
}
|
||||
// Trial values (ADR-0128): ticks a frozen life lingers in the world (10 s at 50 ms), and
|
||||
// how many of its own extents away a resume may look for a clear spot.
|
||||
inline constexpr std::uint64_t cellular_linger_ticks = 200;
|
||||
@@ -148,7 +158,7 @@ struct CellularLifeTickFeedback {
|
||||
// Which owner version a new region starts on. Offers: format 2, rules 2 (the M11.3/11.4
|
||||
// trial, upgraded by the no-tick migrations). Engulf: format 4, rules 3 (ADR-0124).
|
||||
// Budding: format 5, rules 4 (ADR-0125). Presence: format 6, rules 5 (ADR-0128).
|
||||
enum class CellularLivesProfile : std::uint8_t { offers, engulf, budding, presence };
|
||||
enum class CellularLivesProfile : std::uint8_t { offers, engulf, budding, presence, balance };
|
||||
struct CellularLivesConfig {
|
||||
biology::CellularArea area{};
|
||||
std::uint64_t tick{};
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
-- 2026-10-15 balance (ADR-0132): admit the cellular-v7 bundle (rules 6 on owner
|
||||
-- envelope 6, development 3, founder 2: a third of the mutation step and of the
|
||||
-- construction energy). It has no new trace or state layout; earlier bundles and committed
|
||||
-- rows keep their meaning.
|
||||
|
||||
-- The v7 bundle shares v3's revision history profile and format-3 traces. Normalize it
|
||||
-- to v3 for the existing parser chain, then report the real bundle.
|
||||
ALTER FUNCTION evolution.parse_checkpoint_manifest(bytea)
|
||||
RENAME TO parse_checkpoint_manifest_v40;
|
||||
|
||||
CREATE FUNCTION evolution.parse_checkpoint_manifest(m bytea)
|
||||
RETURNS evolution.checkpoint_manifest LANGUAGE plpgsql IMMUTABLE
|
||||
SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE
|
||||
r evolution.checkpoint_manifest;
|
||||
v3_bundle constant bytea := '\x020000000300000001000000010000000100000002000000010000000200000001000000';
|
||||
v7_bundle constant bytea := '\x060000000600000001000000010000000100000003000000020000000200000001000000';
|
||||
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) = v7_bundle
|
||||
AND evolution.manifest_uint(m, 228, 4) = 0
|
||||
AND evolution.manifest_uint(m, 232, 4) = 4
|
||||
AND evolution.manifest_uint(m, 236, 4) = 1 THEN
|
||||
r := evolution.parse_checkpoint_manifest_v40(overlay(m PLACING v3_bundle FROM 161 FOR 36));
|
||||
r.versions := v7_bundle;
|
||||
RETURN r;
|
||||
END IF;
|
||||
RETURN evolution.parse_checkpoint_manifest_v40(m);
|
||||
END $$;
|
||||
REVOKE ALL ON FUNCTION evolution.parse_checkpoint_manifest(bytea) FROM PUBLIC;
|
||||
|
||||
-- Birth binding: v3 to v7 publications carry format-3 traces. Otherwise unchanged from
|
||||
-- schema v38.
|
||||
CREATE OR REPLACE FUNCTION evolution.cellular_births(p_trace bytea, p_manifest bytea)
|
||||
RETURNS TABLE(account_id uuid, request_id evolution.u64, generation evolution.u64,
|
||||
identity evolution.u64, born evolution.u64)
|
||||
LANGUAGE plpgsql IMMUTABLE SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE
|
||||
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
|
||||
revision boolean;
|
||||
ticks numeric;
|
||||
tick_index integer;
|
||||
trace_format numeric;
|
||||
tick_header_size integer;
|
||||
intent_count numeric;
|
||||
birth_count numeric;
|
||||
mutation_count numeric;
|
||||
off integer := 112;
|
||||
account bytea;
|
||||
previous_account bytea;
|
||||
previous_request numeric;
|
||||
BEGIN
|
||||
revision := c.versions IN (
|
||||
'\x020000000300000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x030000000400000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x040000000500000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x050000000600000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x060000000600000001000000010000000100000003000000020000000200000001000000'::bytea);
|
||||
trace_format := evolution.manifest_uint(p_trace, 8, 4);
|
||||
tick_header_size := CASE trace_format WHEN 2 THEN 8 WHEN 3 THEN 16 ELSE 0 END;
|
||||
IF c.profile <> 4 OR c.commit_sequence = 0 OR p_trace IS NULL
|
||||
OR octet_length(p_trace) <> c.trace_bytes OR sha256(p_trace) <> c.trace_sha256
|
||||
OR substring(p_trace FROM 1 FOR 8) <> '\x45564c4342543031'
|
||||
OR tick_header_size = 0
|
||||
OR (revision AND trace_format <> 3)
|
||||
OR (NOT revision AND trace_format <> 2)
|
||||
OR evolution.manifest_uint(p_trace, 12, 4) <> 4
|
||||
OR evolution.manifest_uint(p_trace, 16, 8) <> c.world_id
|
||||
OR evolution.manifest_uint(p_trace, 24, 8) <> c.region_id
|
||||
OR evolution.manifest_uint(p_trace, 32, 8) <> c.frame_id
|
||||
OR encode(substring(p_trace FROM 41 FOR 16), 'hex')::uuid <> c.predecessor_commit
|
||||
OR substring(p_trace FROM 57 FOR 32) <> c.predecessor_digest
|
||||
OR evolution.manifest_uint(p_trace, 88, 8) <> c.begin_tick
|
||||
OR evolution.manifest_uint(p_trace, 96, 8) <> c.end_tick THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace binding' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
ticks := c.end_tick - c.begin_tick;
|
||||
IF ticks < 1 OR ticks > 64 OR evolution.manifest_uint(p_trace, 104, 4) <> ticks
|
||||
OR evolution.manifest_uint(p_trace, 108, 4) <> 0 THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace range' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
FOR tick_index IN 0 .. ticks::integer - 1 LOOP
|
||||
IF off + tick_header_size > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'truncated cellular tick header' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
intent_count := evolution.manifest_uint(p_trace, off, 4);
|
||||
birth_count := evolution.manifest_uint(p_trace, off + 4, 4);
|
||||
mutation_count := 0;
|
||||
IF trace_format = 3 THEN
|
||||
mutation_count := evolution.manifest_uint(p_trace, off + 8, 4);
|
||||
IF evolution.manifest_uint(p_trace, off + 12, 4) <> 0 THEN
|
||||
RAISE EXCEPTION 'invalid cellular tick reserved word' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
END IF;
|
||||
IF intent_count > 256 OR birth_count > 256 OR mutation_count > 256
|
||||
OR off + tick_header_size + intent_count * 24 + birth_count * 40
|
||||
+ mutation_count * 40 > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'invalid cellular tick counts' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
off := off + tick_header_size + intent_count::integer * 24;
|
||||
previous_account := ''::bytea;
|
||||
previous_request := -1;
|
||||
FOR birth_index IN 0 .. birth_count::integer - 1 LOOP
|
||||
account := substring(p_trace FROM off + 1 FOR 16);
|
||||
account_id := encode(account, 'hex')::uuid;
|
||||
request_id := evolution.manifest_uint(p_trace, off + 16, 8);
|
||||
generation := evolution.manifest_uint(p_trace, off + 24, 8);
|
||||
identity := evolution.manifest_uint(p_trace, off + 32, 8);
|
||||
born := c.begin_tick + tick_index + 1;
|
||||
IF account_id = '00000000-0000-0000-0000-000000000000' OR request_id = 0
|
||||
OR generation = 0 OR identity = 0
|
||||
OR (account, request_id) <= (previous_account, previous_request) THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth record' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
previous_account := account;
|
||||
previous_request := request_id;
|
||||
off := off + 40;
|
||||
RETURN NEXT;
|
||||
END LOOP;
|
||||
off := off + mutation_count::integer * 40;
|
||||
END LOOP;
|
||||
IF off <> octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'trailing cellular trace bytes' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
INSERT INTO evolution.schema_migrations(version, sha256) VALUES (41, :'migration_sha_41');
|
||||
+26
-4
@@ -116,6 +116,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
SELECT :'history_v37' || ',38:' || :'migration_sha_38' AS history_v38 \gset
|
||||
SELECT :'history_v38' || ',39:' || :'migration_sha_39' AS history_v39 \gset
|
||||
SELECT :'history_v39' || ',40:' || :'migration_sha_40' AS history_v40 \gset
|
||||
SELECT :'history_v40' || ',41:' || :'migration_sha_41' AS history_v41 \gset
|
||||
SELECT :'history' = :'history_v22' AS at_v22,
|
||||
:'history' = :'history_v23' AS at_v23,
|
||||
:'history' = :'history_v24' AS at_v24,
|
||||
@@ -134,8 +135,10 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
:'history' = :'history_v37' AS at_v37,
|
||||
:'history' = :'history_v38' AS at_v38,
|
||||
:'history' = :'history_v39' AS at_v39,
|
||||
:'history' = :'history_v40' AS at_v40 \gset
|
||||
\if :at_v40
|
||||
:'history' = :'history_v40' AS at_v40,
|
||||
:'history' = :'history_v41' AS at_v41 \gset
|
||||
\if :at_v41
|
||||
\elif :at_v40
|
||||
\elif :at_v39
|
||||
\elif :at_v38
|
||||
\elif :at_v37
|
||||
@@ -509,7 +512,8 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
coalesce(max(version), 0) = 37 AS at_v37,
|
||||
coalesce(max(version), 0) = 38 AS at_v38,
|
||||
coalesce(max(version), 0) = 39 AS at_v39,
|
||||
coalesce(max(version), 0) = 40 AS at_v40
|
||||
coalesce(max(version), 0) = 40 AS at_v40,
|
||||
coalesce(max(version), 0) = 41 AS at_v41
|
||||
FROM evolution.schema_migrations \gset
|
||||
\if :at_v24
|
||||
\ir 0025_cellular_v2_bundle.sql
|
||||
@@ -528,6 +532,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v25
|
||||
\ir 0026_cellular_profile_migration.sql
|
||||
\ir 0027_cellular_v3_migration.sql
|
||||
@@ -544,6 +549,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v26
|
||||
\ir 0027_cellular_v3_migration.sql
|
||||
\ir 0028_cellular_v3_trace_bounds.sql
|
||||
@@ -559,6 +565,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v27
|
||||
\ir 0028_cellular_v3_trace_bounds.sql
|
||||
\ir 0029_cellular_mutation_reservations.sql
|
||||
@@ -573,6 +580,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v28
|
||||
\ir 0029_cellular_mutation_reservations.sql
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
@@ -586,6 +594,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v29
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
@@ -598,6 +607,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v30
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
@@ -609,6 +619,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v31
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
@@ -619,6 +630,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v32
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
@@ -628,6 +640,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v33
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
@@ -636,6 +649,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v34
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
@@ -643,29 +657,37 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v35
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\ir 0037_cellular_life_endings.sql
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v36
|
||||
\ir 0037_cellular_life_endings.sql
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v37
|
||||
\ir 0038_cellular_v6_presence_bundle.sql
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v38
|
||||
\ir 0039_account_identities.sql
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v39
|
||||
\ir 0040_cellular_mutation_decline.sql
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v40
|
||||
\ir 0041_cellular_v7_balance_bundle.sql
|
||||
\elif :at_v41
|
||||
\else
|
||||
\echo 'Unknown or changed migration history after v40'
|
||||
\echo 'Unknown or changed migration history after v41'
|
||||
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
|
||||
\endif
|
||||
-- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes
|
||||
|
||||
@@ -109,3 +109,10 @@ has freeze tick 0; a lingering one a freeze tick at most the checkpoint tick and
|
||||
less than 200 ticks before it; a suspended one a non-zero freeze tick at most the
|
||||
checkpoint tick. Wildlife is always active. Suspended lives keep their inventory
|
||||
in the region's conserved totals.
|
||||
|
||||
### Format 6, rules 6 (ADR-0132)
|
||||
|
||||
Format 6 also carries rules 6, byte for byte the same layout. Rules 6 differ only in
|
||||
what they found: new lives are founder 2 (genome schema 3, development version 3).
|
||||
Restore accepts format 6 with rules 5 or 6, and the version bundle (v6 or v7) must
|
||||
name the same rules.
|
||||
|
||||
@@ -64,6 +64,12 @@ std::expected<DevelopmentRules, DevelopmentError> rules_for(std::uint32_t develo
|
||||
if (development_version == 2) {
|
||||
return DevelopmentRules{1000, 1200, 10, 15, 40, 60'000, 293'150, 50};
|
||||
}
|
||||
// Version 3 (rules 6, 2026-10-15 balance): version 2 with a third of the construction
|
||||
// energy (13 pJ per 1000 fg built instead of 40). Construction is overhead paid into
|
||||
// heat, so this changes no matter balance.
|
||||
if (development_version == 3) {
|
||||
return DevelopmentRules{1000, 1200, 10, 15, 13, 60'000, 293'150, 50};
|
||||
}
|
||||
return std::unexpected{DevelopmentError::unsupported_rules};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
#include <limits>
|
||||
|
||||
namespace evo::biology {
|
||||
std::expected<Genome, GenomeError> primitive_founder(std::uint64_t id, std::uint64_t origin_event) {
|
||||
std::expected<Genome, GenomeError> primitive_founder(std::uint64_t id, std::uint64_t origin_event,
|
||||
FounderVersion version) {
|
||||
const auto& p = primitive_founder_parameters;
|
||||
GenomeDraft draft;
|
||||
draft.schema_version = genome_schema_version;
|
||||
draft.schema_version = version.genome_schema;
|
||||
draft.id = id;
|
||||
draft.origin_event = origin_event;
|
||||
draft.development_version = primitive_founder_development_version;
|
||||
draft.development_version = version.development_version;
|
||||
draft.capabilities = {{Capability::energy_conversion, p.energy_conversion, 0},
|
||||
{Capability::membrane, p.membrane, 0},
|
||||
{Capability::movement, p.movement, 0},
|
||||
@@ -19,11 +20,11 @@ std::expected<Genome, GenomeError> primitive_founder(std::uint64_t id, std::uint
|
||||
return Genome::create(draft);
|
||||
}
|
||||
|
||||
std::expected<FounderEndowment, DevelopmentError> primitive_endowment() {
|
||||
std::expected<FounderEndowment, DevelopmentError> primitive_endowment(FounderVersion version) {
|
||||
// Identity does not enter development; the published genome gets allocated
|
||||
// identities at creation, not these analysis-only values.
|
||||
const auto genome = primitive_founder(1, 1);
|
||||
const auto rules = rules_for(primitive_founder_development_version);
|
||||
const auto genome = primitive_founder(1, 1, version);
|
||||
const auto rules = rules_for(version.development_version);
|
||||
if (!genome || !rules)
|
||||
return std::unexpected{DevelopmentError::unsupported_rules};
|
||||
const auto budget = metabolic_budget(*genome, {1000, 0}, {rules->reference_temperature, {}});
|
||||
|
||||
@@ -108,7 +108,7 @@ metabolic_rules_for(std::uint32_t development_version) {
|
||||
return MetabolicRules{structure_shares, membrane_shares, 20, 50'000};
|
||||
}
|
||||
// Version 2: per second; movement at 1000 um/s costs 50 pJ/s per 1000 fg (tunable).
|
||||
if (development_version == 2) {
|
||||
if (development_version == 2 || development_version == 3) { // Version 3: same metabolism.
|
||||
return MetabolicRules{structure_shares, membrane_shares, 50, 50'000};
|
||||
}
|
||||
return std::unexpected{DevelopmentError::unsupported_rules};
|
||||
|
||||
@@ -28,12 +28,16 @@ constexpr std::array<MutationOperator, 4 * capability_count> catalog = [] {
|
||||
// One rule rather than a constant per capability: a hundredth of the declared
|
||||
// range, at least one. Granularity follows the range, which is a stated model
|
||||
// choice and not a claim about biology.
|
||||
// The step comes from the genome's own schema, so a schema 1 lineage keeps its steps.
|
||||
// The step comes from the genome's own schema, so a lineage keeps its steps. Schema 3
|
||||
// (rules 6, 2026-10-15 balance) takes a third of that step: successor bodies differ a
|
||||
// third as much, so the matter a mutation needs falls with them (ADR-0118: the cost is
|
||||
// the body difference, never a discount).
|
||||
constexpr std::uint32_t adjustment_step(const std::array<CapabilitySpec, capability_count>& table,
|
||||
Capability kind) noexcept {
|
||||
Capability kind, std::uint32_t schema) noexcept {
|
||||
const auto& limits = table[static_cast<std::size_t>(kind)];
|
||||
const auto span = limits.maximum - limits.minimum;
|
||||
return span / 100 == 0 ? 1 : span / 100;
|
||||
const std::uint32_t divisor = schema == genome_schema_v3 ? 300 : 100;
|
||||
return span / divisor == 0 ? 1 : span / divisor;
|
||||
}
|
||||
|
||||
std::uint64_t mix(std::uint64_t hash, std::uint64_t value) noexcept {
|
||||
@@ -92,7 +96,7 @@ std::optional<GenomeDraft> apply(const Genome& genome, const MutationOperator& e
|
||||
if (!present) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto step = adjustment_step(table, entry.target);
|
||||
const auto step = adjustment_step(table, entry.target, genome.schema_version());
|
||||
// Refused rather than clamped: a clamp would make two operators agree
|
||||
// and would offer a no-op as a real choice.
|
||||
if (carried->parameter > limits.maximum - step) {
|
||||
@@ -105,7 +109,7 @@ std::optional<GenomeDraft> apply(const Genome& genome, const MutationOperator& e
|
||||
if (!present) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto step = adjustment_step(table, entry.target);
|
||||
const auto step = adjustment_step(table, entry.target, genome.schema_version());
|
||||
if (carried->parameter < limits.minimum + step) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -168,6 +168,11 @@ provision_cellular_region(Postgres& owner, const FilesystemObjectStore& objects,
|
||||
// ADR-0128: a rules-5 region starts on the v6 bundle with genome revisions.
|
||||
manifest->cellular_versions = cellular_v6_versions;
|
||||
manifest->history_profile = cellular_revision_history_profile;
|
||||
} else if (manifest && opening.format_version() == server::cellular_lives_presence_format &&
|
||||
opening.rules_version() == server::cellular_lives_balance_rules) {
|
||||
// 2026-10-15 balance: a rules-6 region starts on the v7 bundle with genome revisions.
|
||||
manifest->cellular_versions = cellular_v7_versions;
|
||||
manifest->history_profile = cellular_revision_history_profile;
|
||||
} else if (manifest && (opening.format_version() != server::cellular_lives_legacy_format ||
|
||||
opening.rules_version() != 1))
|
||||
return std::unexpected{failure(PublicationError::candidate)};
|
||||
|
||||
@@ -72,7 +72,8 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
m.cellular_versions != cellular_v3_versions &&
|
||||
m.cellular_versions != cellular_v4_versions &&
|
||||
m.cellular_versions != cellular_v5_versions &&
|
||||
m.cellular_versions != cellular_v6_versions) ||
|
||||
m.cellular_versions != cellular_v6_versions &&
|
||||
m.cellular_versions != cellular_v7_versions) ||
|
||||
(cellular && m.versions != environmental_v1_versions))
|
||||
return false;
|
||||
if (primitive && (m.manifest_version != 2 || m.tick_microseconds != 50000 ||
|
||||
@@ -167,7 +168,8 @@ bool supported(const CheckpointManifest& m) noexcept {
|
||||
m.cellular_versions == cellular_v3_versions ||
|
||||
m.cellular_versions == cellular_v4_versions ||
|
||||
m.cellular_versions == cellular_v5_versions ||
|
||||
m.cellular_versions == cellular_v6_versions) &&
|
||||
m.cellular_versions == cellular_v6_versions ||
|
||||
m.cellular_versions == cellular_v7_versions) &&
|
||||
m.versions == environmental_v1_versions && m.tick_microseconds == 50000 &&
|
||||
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
|
||||
}
|
||||
|
||||
@@ -535,7 +535,8 @@ CellularLives::create(const PrimitiveLives& opening,
|
||||
const auto world = nursery_config.world;
|
||||
const auto region = nursery_config.region;
|
||||
const auto frame = nursery_config.frame;
|
||||
const bool presence = profile == CellularLivesProfile::presence;
|
||||
const bool balance = profile == CellularLivesProfile::balance; // Rules 6: presence plus.
|
||||
const bool presence = profile == CellularLivesProfile::presence || balance;
|
||||
const bool budding = profile == CellularLivesProfile::budding || presence;
|
||||
const bool engulf = profile == CellularLivesProfile::engulf || budding;
|
||||
if (engulf)
|
||||
@@ -548,10 +549,11 @@ CellularLives::create(const PrimitiveLives& opening,
|
||||
: budding ? cellular_lives_bud_format
|
||||
: engulf ? cellular_lives_engulf_format
|
||||
: cellular_lives_format,
|
||||
presence ? cellular_lives_presence_rules
|
||||
: budding ? cellular_lives_bud_rules
|
||||
: engulf ? cellular_lives_engulf_rules
|
||||
: cellular_lives_rules);
|
||||
balance ? cellular_lives_balance_rules
|
||||
: presence ? cellular_lives_presence_rules
|
||||
: budding ? cellular_lives_bud_rules
|
||||
: engulf ? cellular_lives_engulf_rules
|
||||
: cellular_lives_rules);
|
||||
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
|
||||
}
|
||||
|
||||
@@ -858,8 +860,11 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
|
||||
state_->archive.find(allocation.genome) || state_->archive.organism(allocation.organism))
|
||||
return std::unexpected{CellularLivesError::duplicate_life};
|
||||
|
||||
const auto endowed = biology::primitive_endowment();
|
||||
const auto genome = biology::primitive_founder(allocation.genome, allocation.event);
|
||||
// Rules 6 found version-2 founders: lower construction energy, finer mutations.
|
||||
const auto founder_version = cellular_founder_version(state_->rules_version);
|
||||
const auto endowed = biology::primitive_endowment(founder_version);
|
||||
const auto genome =
|
||||
biology::primitive_founder(allocation.genome, allocation.event, founder_version);
|
||||
if (!endowed || !genome)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
const auto budget = biology::metabolic_budget(
|
||||
@@ -964,9 +969,11 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
const bool offer_version = magic == cellular_lives_v2_magic &&
|
||||
format_version == cellular_lives_format &&
|
||||
rules_version == cellular_lives_rules;
|
||||
// Format 6 carries rules 5 or rules 6 (founder 2, no new state).
|
||||
const bool presence_version = magic == cellular_lives_v6_magic &&
|
||||
format_version == cellular_lives_presence_format &&
|
||||
rules_version == cellular_lives_presence_rules;
|
||||
(rules_version == cellular_lives_presence_rules ||
|
||||
rules_version == cellular_lives_balance_rules);
|
||||
// Formats 5 and 6 carry the bud sequence and parent lives (rules 4 and 5).
|
||||
const bool bud_version = presence_version || (magic == cellular_lives_v5_magic &&
|
||||
format_version == cellular_lives_bud_format &&
|
||||
|
||||
@@ -798,6 +798,48 @@ void rules_four_owner_buds_wildlife() {
|
||||
refresh_checksum(rewound);
|
||||
CHECK(!CellularLives::restore(rewound, 93, 1, 7, owner.tick()));
|
||||
}
|
||||
// 2026-10-15 balance: a rules-6 opening keeps owner format 6 and founds schema-3,
|
||||
// development-3 cells, whose birth costs the nursery less construction energy; the
|
||||
// snapshot restores as rules 6 and a rules-5 opening still founds founder-1 cells.
|
||||
void rules_six_found_cheaper_cells_with_finer_mutations() {
|
||||
auto primitive = PrimitiveLives::create({95, 1, 7, 17, founder_price(2), {{0, 0}, {1'500, 0}}});
|
||||
CHECK(primitive);
|
||||
auto habitat = evo::biology::CellularHabitat::create({95, 1, 7, 3'000, 2'000, {}});
|
||||
CHECK(habitat);
|
||||
auto created =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{3'000, 2'000}, 0, 293'150},
|
||||
CellularLivesProfile::balance);
|
||||
CHECK(created);
|
||||
auto owner = std::move(*created);
|
||||
CHECK(owner->format_version() == cellular_lives_presence_format &&
|
||||
owner->rules_version() == cellular_lives_balance_rules);
|
||||
const std::span<const CellularLifeIntent> no_lives{};
|
||||
CHECK(owner->advance_tick(no_lives));
|
||||
LifeRequest request{};
|
||||
request.account.back() = 7;
|
||||
request.action = 1;
|
||||
const LifeAllocation allocation{601, 601, 601, 601, {1}};
|
||||
const auto born = owner->birth_candidate(request, allocation);
|
||||
CHECK(born && (*born)->lives().size() == 1);
|
||||
const auto genome = (*born)->archive().find(allocation.genome);
|
||||
CHECK(genome && genome->schema_version() == evo::biology::genome_schema_v3 &&
|
||||
genome->development_version() == 3);
|
||||
const auto endowment = evo::biology::primitive_endowment(evo::biology::primitive_founder_v2);
|
||||
const auto classic = evo::biology::primitive_endowment();
|
||||
CHECK(endowment && classic && endowment->construction.value < classic->construction.value);
|
||||
CHECK((*born)->nursery().energy.value == owner->nursery().energy.value -
|
||||
endowment->reserve.energy.value -
|
||||
endowment->construction.value);
|
||||
CHECK((*born)->heat().energy.value == endowment->construction.value &&
|
||||
(*born)->current_total() == (*born)->opening_total());
|
||||
const auto recovered = CellularLives::restore((*born)->snapshot(), 95, 1, 7, (*born)->tick());
|
||||
CHECK(recovered && (*recovered)->rules_version() == cellular_lives_balance_rules &&
|
||||
(*recovered)->snapshot() == (*born)->snapshot());
|
||||
CHECK(cellular_founder_version(cellular_lives_presence_rules) ==
|
||||
evo::biology::primitive_founder_v1 &&
|
||||
cellular_founder_version(cellular_lives_balance_rules) ==
|
||||
evo::biology::primitive_founder_v2);
|
||||
}
|
||||
// ADR-0128: an offline owned life freezes, lingers 200 ticks, is suspended without aging,
|
||||
// survives restore, and resumes; a newborn on its spot makes it resume nearby.
|
||||
void rules_five_owner_freezes_lingers_suspends_and_resumes() {
|
||||
@@ -911,6 +953,7 @@ int main() {
|
||||
rules_three_owner_resolves_engulf_and_detritus();
|
||||
rules_four_owner_buds_wildlife();
|
||||
rules_five_owner_freezes_lingers_suspends_and_resumes();
|
||||
rules_six_found_cheaper_cells_with_finer_mutations();
|
||||
std::puts(
|
||||
"PASS cellular lives: feeding, tick ownership, terminal closure, rules 3, budding");
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -710,6 +710,99 @@ void cellular_host_admits_mutation_choices() {
|
||||
|
||||
// ADR-0125 (schema v36): a rules-4 region publishes a bud with its tick; the wildlife
|
||||
// descendant, its identity and the parent's debit recover after a restart.
|
||||
// 2026-10-15 balance (schema v41): a rules-6 region publishes a founder of genome schema 3
|
||||
// and development 3 on the v7 bundle, and a restarted host recovers it.
|
||||
void cellular_balance_region_founds_and_recovers() {
|
||||
using namespace evo::biology;
|
||||
constexpr RegionKey key{9771, 1};
|
||||
auto owner = connect_as(env("PGUSER"));
|
||||
auto runtime = connect_as(env("EVO_PG_RUNTIME_USER"));
|
||||
const auto build = filled<32>(0xDC);
|
||||
CHECK(owner->query("INSERT INTO evolution.retained_builds(build_identity) VALUES "
|
||||
"(decode(repeat('dc',32),'hex')) ON CONFLICT DO NOTHING",
|
||||
{}, 5s));
|
||||
auto endowed = primitive_endowment(primitive_founder_v2);
|
||||
CHECK(endowed);
|
||||
auto funding = endowed->body;
|
||||
funding.energy.value = endowed->reserve.energy.value + endowed->construction.value;
|
||||
auto primitive = PrimitiveLives::create({key.world, key.region, 1, 17, funding, {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
constexpr std::uint64_t stock = 10'000'000'000;
|
||||
auto habitat = CellularHabitat::create(
|
||||
{key.world,
|
||||
key.region,
|
||||
1,
|
||||
3'000,
|
||||
2'000,
|
||||
{{{0, 0}, 29, {{stock}, {{{stock}, {stock}, {stock}, {stock}}}}}}});
|
||||
CHECK(habitat);
|
||||
auto opening =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{3'000, 2'000}, 0, 293'150},
|
||||
CellularLivesProfile::balance);
|
||||
CHECK(opening);
|
||||
auto objects = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(objects);
|
||||
CHECK(provision_cellular_region(*owner, **objects, key, 1, **opening, distinct_commit(0xA7),
|
||||
build, 5s));
|
||||
CHECK(owner->query("INSERT INTO evolution.life_allocators VALUES(9771,1000) "
|
||||
"ON CONFLICT DO NOTHING",
|
||||
{}, 5s));
|
||||
const auto connect = [&]() -> std::expected<std::unique_ptr<Postgres>, PgFailure> {
|
||||
return Postgres::connect({env("PGHOST"),
|
||||
{},
|
||||
env("PGPORT"),
|
||||
env("PGDATABASE"),
|
||||
env("EVO_PG_RUNTIME_USER"),
|
||||
{},
|
||||
{}},
|
||||
5s);
|
||||
};
|
||||
// A fresh value per host: copying the config trips a GCC 14 -O3 array-bounds false positive.
|
||||
const auto config = [&] { return CellularHostConfig{key, 1, {}, build, {build}}; };
|
||||
auto made = CellularRegionHost::create(config(), connect, std::move(*objects));
|
||||
CHECK(made);
|
||||
auto host = std::move(*made);
|
||||
CHECK(host->step().ready && host->state()->rules_version() == cellular_lives_balance_rules);
|
||||
const auto account = filled<16>(0x85);
|
||||
const auto control = claim_account_control(*runtime, key, checked_value(host->authority()),
|
||||
account, 1, 1, 60'000ms, 5s);
|
||||
CHECK(control);
|
||||
CHECK(host->create_primitive_life(account, control->generation, 11).result ==
|
||||
evo::network::PrimitiveLifeResult::pending);
|
||||
const auto& committed = checked_value(host->committed());
|
||||
const auto digest = sha256(committed.manifest);
|
||||
CHECK(digest);
|
||||
CellularBatch birth;
|
||||
birth.header = {key.world,
|
||||
key.region,
|
||||
1,
|
||||
committed.head.commit,
|
||||
checked_value(digest),
|
||||
host->state()->tick(),
|
||||
host->state()->tick() + 1};
|
||||
birth.ticks.push_back({{}, {host->queued_births().front()}, {}});
|
||||
CHECK(host->publish(birth));
|
||||
const auto life = host->state()->lives().front();
|
||||
const auto genome = host->state()->archive().find(life.identity.genome);
|
||||
CHECK(genome && genome->schema_version() == genome_schema_v3 &&
|
||||
genome->development_version() == 3);
|
||||
const auto manifest = decode_manifest(checked_value(host->committed()).manifest);
|
||||
CHECK(manifest && manifest->cellular_versions == cellular_v7_versions);
|
||||
|
||||
// A restarted host recovers the rules-6 state from the v7 checkpoint.
|
||||
host->drain();
|
||||
host.reset();
|
||||
auto reopened = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(reopened);
|
||||
auto restarted = CellularRegionHost::create(config(), connect, std::move(*reopened));
|
||||
CHECK(restarted);
|
||||
host = std::move(*restarted);
|
||||
CHECK(host->step().ready && host->state()->rules_version() == cellular_lives_balance_rules &&
|
||||
host->state()->lives().size() == 1 &&
|
||||
host->state()->lives().front().identity == life.identity);
|
||||
host->drain();
|
||||
}
|
||||
|
||||
void cellular_bud_publishes_and_recovers() {
|
||||
using namespace evo::biology;
|
||||
constexpr RegionKey key{9767, 1};
|
||||
@@ -966,6 +1059,7 @@ void run_cellular_publication_tests() {
|
||||
cellular_mutation_publication_binds_results();
|
||||
cellular_host_admits_mutation_choices();
|
||||
cellular_bud_publishes_and_recovers();
|
||||
cellular_balance_region_founds_and_recovers();
|
||||
cellular_death_is_final_and_account_restarts();
|
||||
auto owner = connect_as(env("PGUSER"));
|
||||
const auto build = filled<32>(0xD9);
|
||||
|
||||
@@ -125,7 +125,7 @@ void schema_v2_rates_develop_identically() {
|
||||
old.capabilities.push_back({Capability::movement, 250, 0});
|
||||
old.capabilities.push_back({Capability::ingestion, 120'000, 0});
|
||||
auto now = old;
|
||||
now.schema_version = genome_schema_version;
|
||||
now.schema_version = genome_schema_v2;
|
||||
now.capabilities[3].parameter = 5'000; // 250 per tick, per second.
|
||||
now.capabilities[4].parameter = 2'400'000; // 120000 per tick, per second.
|
||||
for (const std::uint32_t realized : {250U, 500U, 1000U}) {
|
||||
@@ -167,12 +167,19 @@ void thermal_shortfall_is_reported_not_enforced() {
|
||||
|
||||
void rule_versions_and_invalid_growth() {
|
||||
CHECK(rules_for(1) && rules_for(2)); // Version 2: per second (ADR-0099).
|
||||
for (const auto version : {0U, 3U, 99U}) {
|
||||
// Version 3 (rules 6): version 2 with a third of the construction energy.
|
||||
const auto v2 = rules_for(2);
|
||||
const auto v3 = rules_for(3);
|
||||
CHECK(v2 && v3 && v3->construction_per_kilogram == 13 && v2->construction_per_kilogram == 40 &&
|
||||
v3->structure_density == v2->structure_density &&
|
||||
v3->maintenance_per_kilogram == v2->maintenance_per_kilogram &&
|
||||
development_rate_microseconds(3) == development_rate_microseconds(2));
|
||||
for (const auto version : {0U, 4U, 99U}) {
|
||||
const auto missing = rules_for(version);
|
||||
CHECK(!missing && missing.error() == DevelopmentError::unsupported_rules);
|
||||
}
|
||||
auto source = draft();
|
||||
source.development_version = 3;
|
||||
source.development_version = 4;
|
||||
const auto future = build(source);
|
||||
const auto derived = derive_phenotype(future, {1000, 0}, temperate);
|
||||
CHECK(!derived && derived.error() == DevelopmentError::unsupported_rules);
|
||||
|
||||
@@ -116,7 +116,7 @@ void capability_and_range_rules() {
|
||||
draft.capabilities.push_back({Capability::thermal_tolerance, 1, 1U << capability_count});
|
||||
reject(draft, GenomeError::unknown_capability);
|
||||
// Every boundary of every declared range, from both sides, in each schema's own table.
|
||||
for (const auto schema : {genome_schema_v1, genome_schema_version}) {
|
||||
for (const auto schema : {genome_schema_v1, genome_schema_v2, genome_schema_v3}) {
|
||||
const auto& table = *capability_schema_for(schema);
|
||||
const auto fresh = [&] {
|
||||
auto d = founder();
|
||||
@@ -334,7 +334,7 @@ void schema_v2_rates() {
|
||||
CHECK(old->per_second(Capability::target_size) == std::uint64_t{5'000}); // Not a rate.
|
||||
CHECK(!old->per_second(Capability::thermal_tolerance));
|
||||
auto v2 = v1;
|
||||
v2.schema_version = genome_schema_version;
|
||||
v2.schema_version = genome_schema_v2;
|
||||
v2.capabilities[3].parameter = 100'000; // Movement, per second.
|
||||
v2.capabilities[4].parameter = 20'000'000;
|
||||
const auto now = Genome::create(v2);
|
||||
@@ -351,10 +351,10 @@ void schema_v2_rates() {
|
||||
v1.capabilities[4].parameter = 1'000'001;
|
||||
reject(v1, GenomeError::parameter_out_of_range);
|
||||
auto unknown = founder();
|
||||
unknown.schema_version = 3;
|
||||
unknown.schema_version = 4; // Schema 3 exists since rules 6.
|
||||
reject(unknown, GenomeError::unsupported_version);
|
||||
auto bytes = Genome::create(founder())->encode();
|
||||
bytes[8] = 3; // Schema field; decode refuses before the checksum matters.
|
||||
bytes[8] = 4; // Schema field; decode refuses before the checksum matters.
|
||||
CHECK(!Genome::decode(bytes) &&
|
||||
Genome::decode(bytes).error() == GenomeError::unsupported_version);
|
||||
}
|
||||
@@ -399,6 +399,9 @@ int main() try {
|
||||
moves_preserve_validity();
|
||||
std::cout << "PASS genome schema, ancestry, development graph and canonical encoding\n";
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
} catch (...) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ void genome_revisions_preserve_birth_and_replay_current_genome() {
|
||||
CHECK(archive.admit(descend(10, 0)));
|
||||
CHECK(archive.record_birth(50, 10, evo::Tick{100}));
|
||||
CHECK(archive.current_genome(50) && *archive.current_genome(50) == 10);
|
||||
const auto successor = descend(11, 10, 420, genome_schema_version);
|
||||
const auto successor = descend(11, 10, 420, genome_schema_v2);
|
||||
CHECK(archive.record_mutation(50, successor, evo::Tick{101}));
|
||||
CHECK(archive.revisions().size() == 1);
|
||||
CHECK(archive.current_genome(50) && *archive.current_genome(50) == 11);
|
||||
@@ -447,9 +447,9 @@ void schemas_mix_without_rewriting() {
|
||||
const auto old = with_history().encode();
|
||||
CHECK(field(old, 12, 4) == genome_schema_v1);
|
||||
auto archive = branching();
|
||||
CHECK(archive.admit(descend(6, 4, 400, genome_schema_version)));
|
||||
CHECK(archive.admit(descend(6, 4, 400, genome_schema_v2)));
|
||||
const auto bytes = archive.encode();
|
||||
CHECK(field(bytes, 12, 4) == genome_schema_version);
|
||||
CHECK(field(bytes, 12, 4) == genome_schema_v2);
|
||||
const auto decoded = LineageArchive::decode(bytes);
|
||||
CHECK(decoded && decoded->encode() == bytes);
|
||||
CHECK(decoded->find(6)->schema_version() == 2 && decoded->find(4)->schema_version() == 1);
|
||||
|
||||
@@ -380,12 +380,17 @@ void absent_capabilities_cost_nothing() {
|
||||
|
||||
void rules_fail_closed() {
|
||||
CHECK(metabolic_rules_for(1));
|
||||
for (const auto version : {0U, 3U, 99U}) {
|
||||
// Version 3 (rules 6) keeps version 2's metabolism; 4 is unknown.
|
||||
const auto m2 = metabolic_rules_for(2);
|
||||
const auto m3 = metabolic_rules_for(3);
|
||||
CHECK(m2 && m3 && m3->movement_per_kilogram == m2->movement_per_kilogram &&
|
||||
m3->intake_energy_per_kilogram == m2->intake_energy_per_kilogram);
|
||||
for (const auto version : {0U, 4U, 99U}) {
|
||||
const auto missing = metabolic_rules_for(version);
|
||||
CHECK(!missing && missing.error() == DevelopmentError::unsupported_rules);
|
||||
}
|
||||
auto source = draft();
|
||||
source.development_version = 3;
|
||||
source.development_version = 4;
|
||||
const auto future = build(source);
|
||||
const auto refused = metabolic_budget(future, {1000, 0}, temperate);
|
||||
CHECK(!refused && refused.error() == DevelopmentError::unsupported_rules);
|
||||
@@ -508,6 +513,27 @@ void development_v2_and_the_first_bud() {
|
||||
CHECK(!bud_funding_seconds(*metabolic_budget(build(plain), {1000, 0}, temperate), 1000));
|
||||
}
|
||||
|
||||
// 2026-10-15 balance: founder 2 (rules 6) is schema 3 and development 3. Its body, upkeep
|
||||
// and reserve equal founder 1's; only construction energy falls, to 13/40 of it.
|
||||
void founder_v2_builds_the_same_cell_for_less_energy() {
|
||||
const auto v1 = primitive_founder(1, 1, primitive_founder_v1);
|
||||
const auto v2 = primitive_founder(1, 1, primitive_founder_v2);
|
||||
CHECK(v1 && v2 && v2->schema_version() == 3 && v2->development_version() == 3);
|
||||
const auto b1 = metabolic_budget(*v1, {1000, 0}, temperate);
|
||||
const auto b2 = metabolic_budget(*v2, {1000, 0}, temperate);
|
||||
CHECK(b1 && b2 && b1->body == b2->body &&
|
||||
b1->phenotype.maintenance == b2->phenotype.maintenance &&
|
||||
b1->phenotype.extent == b2->phenotype.extent);
|
||||
CHECK(b2->reproduction_investment.energy.value * 40 <=
|
||||
b1->reproduction_investment.energy.value * 13 + 40);
|
||||
const auto e1 = primitive_endowment(primitive_founder_v1);
|
||||
const auto e2 = primitive_endowment(primitive_founder_v2);
|
||||
CHECK(e1 && e2 && e1->body == e2->body && e1->reserve == e2->reserve &&
|
||||
e2->construction.value < e1->construction.value &&
|
||||
e2->construction.value * 40 <= e1->construction.value * 13 + 40);
|
||||
CHECK(*primitive_endowment() == *e1); // The default stays founder 1.
|
||||
}
|
||||
|
||||
int main() try {
|
||||
hand_calculated_budget();
|
||||
construction_composes_each_compartment();
|
||||
@@ -524,6 +550,7 @@ int main() try {
|
||||
splits_conserve_at_awkward_masses();
|
||||
a_genome_drives_a_feeding_tick();
|
||||
development_v2_and_the_first_bud();
|
||||
founder_v2_builds_the_same_cell_for_less_energy();
|
||||
std::cout << "PASS metabolic budgets, composition splits and genome-driven feeding\n";
|
||||
return 0;
|
||||
} catch (...) {
|
||||
|
||||
@@ -323,14 +323,18 @@ void invalid_contexts_are_refused() {
|
||||
} // namespace
|
||||
// ADR-0099: a successor keeps its parent's schema and that schema's adjustment step, so
|
||||
// a schema 1 lineage is never migrated by mutating, and a schema 2 one steps per second.
|
||||
// Schema 3 (rules 6) steps a third as far: 1/300 of the range.
|
||||
void successors_keep_their_parents_schema() {
|
||||
for (const auto schema : {genome_schema_v1, genome_schema_version}) {
|
||||
for (const auto schema : {genome_schema_v1, genome_schema_v2, genome_schema_v3}) {
|
||||
auto source = draft();
|
||||
source.schema_version = schema;
|
||||
source.capabilities.push_back(
|
||||
{Capability::movement, schema == genome_schema_v1 ? 50'000U : 1'000'000U, 0});
|
||||
const auto parent = build(source);
|
||||
const auto step = schema == genome_schema_v1 ? 1'000U : 20'000U; // 1/100 of the range.
|
||||
const auto step = schema == genome_schema_v1 ? 1'000U // 1/100 of the range.
|
||||
: schema == genome_schema_v2 ? 20'000U
|
||||
: 6'666U; // 2,000,000 / 300.
|
||||
|
||||
bool adjusted = false;
|
||||
// Offers are seeded; search seeds (deterministically) for the movement adjustment.
|
||||
for (std::uint64_t seed = 1; seed <= 200 && !adjusted; ++seed) {
|
||||
|
||||
@@ -212,7 +212,7 @@ void upgrade_across_migration_and_barrier() {
|
||||
" EVO_PG_RUNTIME_ROLE=evo_runtime_test bash \"$EVO_SOURCE_ROOT/"
|
||||
"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");
|
||||
"25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41");
|
||||
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 = "
|
||||
|
||||
@@ -564,6 +564,28 @@ void cellular_v4_provisioning_uses_the_presence_bundle() {
|
||||
has(lines, "evolution buds=0 mutations=0 living_genomes=0 deepest_lineage=0"));
|
||||
}
|
||||
|
||||
// 2026-10-15 balance: cellular-v5 is the rules-6 opening on the v7 bundle (schema v41).
|
||||
void cellular_v5_provisioning_uses_the_balance_bundle() {
|
||||
const ServerRegion r{{9770, 1}, fresh("cellular-v5-provision-9770")};
|
||||
const std::string build(64, 'e');
|
||||
const std::string commit = "ba1a0ce5c0f7e1d2ba1a0ce5c0f7e1d2"; // Unique to this test.
|
||||
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
||||
int code = -1;
|
||||
const auto first = provision_cellular(r, "9770", "cellular-v5", build, commit, patch, code);
|
||||
CHECK(code == 0 && has(first, "provisioned world=9770 region=1 sequence=0 tick=0"));
|
||||
// The same genesis resolves again; another opening for the region is refused.
|
||||
const auto again = provision_cellular(r, "9770", "cellular-v5", build, commit, patch, code);
|
||||
CHECK(code == 0);
|
||||
const auto older = provision_cellular(r, "9770", "cellular-v4", build, commit, patch, code);
|
||||
CHECK(code == 4);
|
||||
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_v7_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,
|
||||
@@ -597,6 +619,7 @@ void run_region_store_tests() {
|
||||
cellular_v2_provisioning_uses_the_engulf_bundle();
|
||||
cellular_v3_provisioning_uses_the_budding_bundle();
|
||||
cellular_v4_provisioning_uses_the_presence_bundle();
|
||||
cellular_v5_provisioning_uses_the_balance_bundle();
|
||||
full_volumes_publish_nothing();
|
||||
failing_writes_leave_nothing();
|
||||
check_store_qualifies_the_stores();
|
||||
|
||||
@@ -122,7 +122,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
|
||||
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
|
||||
# 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%% *}"
|
||||
@@ -143,7 +143,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")" = 40: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
|
||||
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 41: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
|
||||
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.
|
||||
@@ -197,7 +197,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
|
||||
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
|
||||
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
|
||||
@@ -250,9 +250,9 @@ expect_audit_failure 'REVOKE EXECUTE ON FUNCTION evolution.claim_account_control
|
||||
bash "$root/tools/migrate-postgres.sh" # Restored configuration passes the audit again.
|
||||
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=41 WHERE version=40'
|
||||
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=42 WHERE version=41'
|
||||
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=40 WHERE version=41"
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=41 WHERE version=42"
|
||||
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"
|
||||
|
||||
@@ -92,6 +92,8 @@ digest_39="$(sha256sum "$root/migrations/0039_account_identities.sql")"
|
||||
digest_39="${digest_39%% *}"
|
||||
digest_40="$(sha256sum "$root/migrations/0040_cellular_mutation_decline.sql")"
|
||||
digest_40="${digest_40%% *}"
|
||||
digest_41="$(sha256sum "$root/migrations/0041_cellular_v7_balance_bundle.sql")"
|
||||
digest_41="${digest_41%% *}"
|
||||
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" \
|
||||
@@ -125,5 +127,6 @@ psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
|
||||
--set="migration_sha_38=$digest_38" \
|
||||
--set="migration_sha_39=$digest_39" \
|
||||
--set="migration_sha_40=$digest_40" \
|
||||
--set="migration_sha_41=$digest_41" \
|
||||
--set="runtime_role=$runtime_role" \
|
||||
--file="$root/migrations/apply.sql"
|
||||
|
||||
Reference in New Issue
Block a user