diff --git a/AGENTS.md b/AGENTS.md index cc0920f..973f29e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -25,3 +25,7 @@ limits in docs/engineering/VALIDATION.md. Preserve uncommitted work by others. After each completed and validated gate segment, commit its scoped changes and push to the configured Git remote. Preserve unrelated untracked work; never stage secrets. +Immediately before each push, refresh REGION_SESSION_WINDOW in +deploy/kubernetes/region/dev-session-route/listener.yaml with a unique activation +and absolute UTC expiry four hours ahead (ADR-0087). Include it in that push; +do not deploy or claim live reachability from a Git update alone. diff --git a/README.md b/README.md index 2f6db46..c6a0b95 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,9 @@ juveniles through adulthood and budding in the same raw/cohort kernel. retains both representations and their full recovery evidence. [Rules-9 census](docs/adr/0159-maturing-cellular-census.md) observes exact growing stock through verified history and registered snapshots; mixed rule cuts fail. -Rules-9 migration and autonomous ecological qualification remain separate gates. +[Portable rules-9 transfers](schemas/cellular-migration-trace-v2.md) retain exact +growing bodies under a distinct replay version. Durable rules-9 migration and +autonomous ecological qualification remain separate gates. The microscope client is the M11 playtest path. `evo::simulation` remains graphics-, network- and database-independent. diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index b36c859..9cec590 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -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-20261017T183218-47482:1792272738"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261019T130838-2a437d9d:1792429718"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/docs/STATUS.md b/docs/STATUS.md index 70f712e..d551267 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -1,5 +1,21 @@ # Project status and next steps +## Portable transfer of maturing wildlife - 2026-10-19 + +[ADR-0160](adr/0160-portable-maturing-wildlife-transfer.md) qualifies exact +portable rules-9 transfer and distinct trace 2 for raw/cohort owners. Real +juveniles grow before and after transfer while life fields remain exact at the +no-tick boundary. Mixed rules and cross-rule replay fail. Trace 1 retains rules 8; +durable adapters and SQL continue to refuse trace 2/bundle 11. + +Native Release passes **81/81**, GCC transfer/restart **2/2**, ASan/UBSan **2/2**, +private Release/ASan matrices (**22/63 s**), analysis and formatting. Seven old +trace/result/continuation artifacts retain exact bytes. The DEV session window +is refreshed in the same commit and future pushes must refresh it; offline +rendered policy and all 46 policy self-tests pass. See +[validation](engineering/VALIDATION.md). Durable rules-9 migration and remaining +ecology/soak/product gates remain open. + ## Census of funded maturing owners - 2026-10-19 [ADR-0159](adr/0159-maturing-cellular-census.md) admits rules-9/owner-7 retained diff --git a/docs/adr/0160-portable-maturing-wildlife-transfer.md b/docs/adr/0160-portable-maturing-wildlife-transfer.md new file mode 100644 index 0000000..d1e4180 --- /dev/null +++ b/docs/adr/0160-portable-maturing-wildlife-transfer.md @@ -0,0 +1,54 @@ +# ADR-0160: Portable transfer of funded maturing wildlife + +## Status and scope + +Accepted for the scoped M12 portable maturation-transfer prerequisite, 2026-10-19. +Extends ADR-0144/0157/0159. No new biological rule, SQL schema, durable migration +admission, automatic route, live upgrade or production enablement. + +## Decision + +Allow exact no-tick transfer candidates between owner-7 cuts with equal rules 9, +using the same complete group, eligibility, placement, history, identity, stock +and boundary-flow checks as rules 8. Raw and population envelope 2 use the same +biological operation. Preserve realized growth, body, reserve, damage, mutation +state, coordinates and every other life field exactly. Neither endpoint matures +at the transfer cut. Subsequent destination ticks apply their retained rules and +environment; source nonresident history never owns or grows a second copy. + +Reject mixed rules 8/9 before deriving either result, even at otherwise equal +cuts. The existing format-upgrade API remains rules 8 only; moving a rules-9 +owner does not repeat an upgrade or create another source of biological rules. + +Add portable migration trace 2, magic `AEVMIG02`, version 2. Keep the same bounded +layout, request/endpoint/member/inventory fields, reserved zero, checksum and size +limit as trace 1. Version 2 means equal rules-9/owner-7 inputs; version 1 retains +equal rules-8/owner-7 inputs and its exact bytes. Population inputs use envelope 2. +Record selects the version from the supported predecessor rule. Replay requires +that exact version/rule pair in addition to the trusted request and complete +rederived candidates. Unknown versions, mixed magic/version and cross-rule trace +replay fail. No checksum or embedded request grants authority. + +The durable adapter remains bundle 10/trace 1 only, including explicit portable +trace-version refusal. A later gate must admit bundle 11/trace 2 through source +freeze, destination staging, atomic paired publication and complete recovery, +including registered pending-handoff census evidence. Portable support alone +must not silently expand those SQL or activation contracts. + +## Alternatives, costs and qualification + +Reusing trace 1 would change a retained rule contract. Copying or re-deriving adult +bodies would change actual biomass. Treating transfer as a tick would progress +frozen life. A separate migration algorithm risks representation drift. Retain +one operation, require equal biological rules and distinguish replay evidence. +The additional version adds a small dispatch branch and a second qualification +matrix without increasing allocation bounds or dependencies. + +Require real player-origin buds, growth before/after transfer, exact life equality +at the cut, raw/cohort equivalence, source nonresident/census exclusion, combined +channel conservation, repeated return trips, collision/capacity/eligibility +refusal, canonical codec attacks, old bytes, cross-rule refusal and independent +process replay/continuation. Run Release, ASan/UBSan, analysis and affected private +durable regressions. This does not qualify sustainable generations, linked +geometry/environmental budgets, cross-host partitions, actual days or M12 product +readiness. diff --git a/docs/architecture/PERSISTENCE_ARCHITECTURE.md b/docs/architecture/PERSISTENCE_ARCHITECTURE.md index 0b90a84..2837e4b 100644 --- a/docs/architecture/PERSISTENCE_ARCHITECTURE.md +++ b/docs/architecture/PERSISTENCE_ARCHITECTURE.md @@ -4,8 +4,11 @@ ADR-0158/schema 53 admits the explicit same-profile bundle-10 -> 11 maturation upgrade through the existing immutable version journal and lease/head fence. Recovery rederives the complete retained transformation; raw trace 3 and population batch 2 keep their layouts. Profile changes preserve the tuple. No new genesis, -automatic upgrade or default change. Biological migration for rules 9 remains -unsupported. [ADR-0159](../adr/0159-maturing-cellular-census.md) admits its exact +automatic upgrade or default change. Durable biological migration for rules 9 +remains unsupported. [ADR-0160](../adr/0160-portable-maturing-wildlife-transfer.md) +adds portable equal-rules-9 transfer candidates and separately identified trace 2; +the durable adapter still admits only bundle 10/trace 1. +[ADR-0159](../adr/0159-maturing-cellular-census.md) admits its exact retained stocks to census projection 1 and the existing verified history and registered snapshot readers. Mixed rules-8/rules-9 regional cuts fail the complete query. Unavailable evidence cannot become zero life. See diff --git a/docs/engineering/M12_EXACT_BIOLOGICAL_TRANSFER.md b/docs/engineering/M12_EXACT_BIOLOGICAL_TRANSFER.md index 1ead355..16c1a90 100644 --- a/docs/engineering/M12_EXACT_BIOLOGICAL_TRANSFER.md +++ b/docs/engineering/M12_EXACT_BIOLOGICAL_TRANSFER.md @@ -42,7 +42,13 @@ need an explicit versioned maturation contract and ecological qualification. ADR-0157 subsequently supplies opt-in portable rules-9 maturation with a funded multi-generation family proof. These transfer contracts and durable bundle 10 -remain rules 8; they refuse rules-9 migration until separately qualified. +originally remained rules 8. ADR-0160 subsequently qualifies portable owner-7 +transfers between equal rules-9 cuts with distinct trace 2. It preserves every +realized growth/body/reserve field without a tick and rejects mixed rules. +Real juveniles grow before and after transfer with finite declared destination +food; raw/cohort biology and recorded continuation agree. Rules-8 trace 1 retains +its bytes and meaning. Durable bundle-11/trace-2 admission, pending freeze/staging, +atomic paired publication and complete recovery remain a separate gate. This is not the durable escrow gate. No prepared candidate may become an active destination owner before a future fenced transaction commits both heads and diff --git a/docs/engineering/M12_REMAINING_GATES.md b/docs/engineering/M12_REMAINING_GATES.md index e5c3239..797bb1d 100644 --- a/docs/engineering/M12_REMAINING_GATES.md +++ b/docs/engineering/M12_REMAINING_GATES.md @@ -124,6 +124,14 @@ checked. Mixed rules 8/9, unavailable objects/builds and stale grants refuse the complete query. No new SQL schema, redundant census journal or biological rule. This does not close viable-store reconciliation, extinction or M12 ecology gates. +ADR-0160 qualifies portable transfer between equal rules-9/owner-7 cuts and +separately identified migration trace 2. No transfer tick, growth reset or stock +re-derivation is introduced; real pre/post-transfer growth, exact raw/cohort +biology, replay/process continuation and refusal matrices are checked. Trace 1 +retains rules 8. The durable adapter still rejects trace 2/bundle 11: explicit +freeze/stage/paired publication/recovery and registered pending-handoff census +qualification are required before rules-9 durable migration is supported. + M12.6a's [regional census projection](../../schemas/ecology/regional-cellular-census-v1.md) independently implements local current-genome and descendant-closure queries. It keeps suspended stock and retained zero-carrier ancestry, separates exact cohort diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index c806622..57b5e91 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -1,5 +1,69 @@ # Validation report +## 2026-10-19 - Portable transfer of maturing wildlife + +[ADR-0160](../adr/0160-portable-maturing-wildlife-transfer.md) admits exact +portable transfer between equal rules-9/owner-7 cuts, raw or population envelope +2. Migration trace 2 has distinct magic/version and the existing bounded layout. +Trace 1 retains rules 8. Durable metadata/retry adapters explicitly refuse trace +2; SQL schema 53 and bundle-10 migration admission remain unchanged. + +Executed locally: + +- MSVC default Release full CTest **81/81 passed, 22.13 s**, with NDEBUG. +- GCC 14 Release migration contract/process restart **2/2 passed, 3.29 s**. +- Clang 19 ASan/UBSan migration contract/process restart **2/2 passed, 87.00 s**, + without sanitizer reports. +- The complete affected private PostgreSQL population/history/migration fault + matrix passed **exit 0, 22 s** (19 s population). The same ASan/UBSan matrix + passed **exit 0, 63 s** (60 s population), without reports. +- clang-tidy 19 passed on cellular lives, transfer, trace and durable migration + sources and both affected tests. Repository clang-format 19 and + `git diff --check` passed. +- Seven retained rules-8 restart artifacts from the preceding native run match + byte-for-byte: raw/cohort trace 1, both complete output pairs and the continued + population snapshot. No old golden or numbered SQL migration changed. + +Rules-9 repeats the raw transfer/census/conservation matrix, 100 return trips, +imported death/decay, body-overlap refusal, whole-group capacity refusal and the +complete raw/cohort codec/replay matrix. Every transferred life field remains +equal at the no-tick cut. Cross-rule replay, mixed magic/version, unknown version, +malformed bounds, altered members/material and incompatible trusted requests +fail. Fresh processes restore/replay both rule versions in both representations, +then reproduce the exact recorded 64-tick destination continuation. + +A separate real-bud fixture verifies funded growth before transfer, exact +raw/cohort candidate biology, and further funded growth after transfer. Finite +destination food is declared in its opening fixture; no reserve/body credit or +reusable boundary-flow stock is granted. Complete combined per-channel stock +closes and destination growth retains the unchanged transfer ledger. Mixed rules +in either raw direction and in cohorts fail; vulnerable controlled life remains +ineligible. Rules-9 cannot repeat the old format-upgrade API. + +Private raw/cohort durable tests additionally submit canonical trace 2 to retry +freeze/stage, direct staging and SQL source preparation. C++ refuses it before +publication; SQL independently returns 22023 before duplicate lookup. Existing +rules-8 freeze/stage/commit and rules-9 census regressions continue to pass. +The initial new codec-tampering fixture triggered GCC's optimized bounds warning; +using checked vector access resolved it before the complete qualification above. + +Per maintainer instruction, the DEV route's `REGION_SESSION_WINDOW` is refreshed +in this same scoped commit, with a unique UTC activation and a four-hour absolute +expiry. Rendered deployment policy passes **75 objects / 74 files, 138 rendered +objects / 17 overlays, 0 failures**. The working agreement now requires a refresh +before every push. Deployment-policy self-tests pass **46 cases, 0 failures**, +including rejection of overlong windows; the final fresh window also passes the +rendered policy check. This is desired Git configuration, not a live connectivity or +Argo application observation. + +The full backup/DR, TLS relay and SQL privilege/checksum suite was not repeated; +no SQL, durable publication layout or transport algorithm changed. Temporary +private Unix-socket databases were used; no live database, deployment or World0 +operation occurred. TSan was not rerun because shared-memory scheduling did not +change. Durable rules-9 migration, linked environmental resources/geometry, +autonomous generations, target-host costs, actual days and product gates remain +open; this portable prerequisite does not complete M12. + ## 2026-10-19 - Census of funded maturing owners [ADR-0159](../adr/0159-maturing-cellular-census.md) admits rules 9/owner 7, diff --git a/include/evo/persistence/cellular_migration_store.hpp b/include/evo/persistence/cellular_migration_store.hpp index 0d7ab74..6381e9a 100644 --- a/include/evo/persistence/cellular_migration_store.hpp +++ b/include/evo/persistence/cellular_migration_store.hpp @@ -25,6 +25,7 @@ struct CellularMigrationFailure { // Verify both complete cuts and the paired biology, retain a verified destination // replay capsule in the source namespace, then freeze the exact source head. // Neither candidate is published or activated by this operation. +// Durable migration remains bundle 10/trace 1; portable trace 2 is refused. [[nodiscard]] std::expected prepare_cellular_migration_freeze(Postgres&, const FilesystemObjectStore& source_objects, const FilesystemObjectStore& destination_objects, diff --git a/include/evo/server/lifecycle/cellular_migration.hpp b/include/evo/server/lifecycle/cellular_migration.hpp index f0631a4..3275f65 100644 --- a/include/evo/server/lifecycle/cellular_migration.hpp +++ b/include/evo/server/lifecycle/cellular_migration.hpp @@ -32,6 +32,7 @@ struct CellularPopulationMigrationExecution { // This chooses neither a route nor a movement. It preserves every coordinate and // biological field, imports the complete genome ancestry and moves actual stock. // Publication must commit the pair under both current fences before activation. +// ADR-0160: owner 7, equal rules 8 or equal rules 9; mixed rules fail. class CellularMigration { public: [[nodiscard]] static std::expected diff --git a/include/evo/server/lifecycle/cellular_migration_trace.hpp b/include/evo/server/lifecycle/cellular_migration_trace.hpp index 433dad6..d6111b7 100644 --- a/include/evo/server/lifecycle/cellular_migration_trace.hpp +++ b/include/evo/server/lifecycle/cellular_migration_trace.hpp @@ -24,6 +24,8 @@ struct CellularMigrationTrace { CellularMigrationRequest request; accounting::Inventory transferred; std::vector members; + // Trace 1 retains rules 8; trace 2 requires rules 9. Both require owner 7. + std::uint32_t format_version{1}; bool operator==(const CellularMigrationTrace&) const = default; }; inline constexpr std::size_t migration_trace_header_bytes = 256; @@ -40,6 +42,7 @@ struct RecordedPopulationMigration { // Portable recorded pair, not a receipt or ownership grant. The I/O adapter must // establish the trusted request against BOTH immutable predecessor manifests and // digest-checked payloads, then fence/commit both results before activation. +// Portable trace 2 does not extend the durable bundle-10/trace-1 allowlist. [[nodiscard]] std::expected prepare_migration_trace(const CellularLives&, const CellularLives&, const CellularMigrationRequest&); diff --git a/schemas/cellular-maturation-upgrade.md b/schemas/cellular-maturation-upgrade.md index 635e70f..99a585e 100644 --- a/schemas/cellular-maturation-upgrade.md +++ b/schemas/cellular-maturation-upgrade.md @@ -38,7 +38,8 @@ allows only the existing fenced entry points. Earlier migration bytes are intact No live/default auto-upgrade or new provisioning mode. An explicitly upgraded owner can recover and continue raw/cohort biology, including interval admission, settlement and materialization before returning-player operations. Biological -migration remains bundle 10 only. ADR-0159 subsequently admits rules-9 retained +durable migration remains bundle 10 only. ADR-0160 qualifies portable equal-rules-9 +candidates/trace 2 without extending that admission. ADR-0159 admits rules-9 retained body/reserve to census projection 1 and the verified history/registered snapshot readers. Mixed rule cuts or unavailable evidence prevent a complete result and cannot prove zero life or terminal extinction. Ecology/environment/actual-days/product diff --git a/schemas/cellular-migration-trace-v1.md b/schemas/cellular-migration-trace-v1.md index 81f29ae..bdce728 100644 --- a/schemas/cellular-migration-trace-v1.md +++ b/schemas/cellular-migration-trace-v1.md @@ -1,5 +1,8 @@ # Exact paired biological transfer trace 1 +Follow-on [trace 2](cellular-migration-trace-v2.md) supports portable rules-9 +transfers. Trace 1 remains rules 8 with the exact layout and bytes below. + Authority: ADR-0144. Portable replay evidence only; no durable manifest admission, ownership receipt or activation authority. This is separate from the M10 probe, normal cellular tick traces and population batch 1. It is not a migration route. diff --git a/schemas/cellular-migration-trace-v2.md b/schemas/cellular-migration-trace-v2.md new file mode 100644 index 0000000..fea9825 --- /dev/null +++ b/schemas/cellular-migration-trace-v2.md @@ -0,0 +1,38 @@ +# Exact paired biological transfer trace 2 + +Authority: [ADR-0160](../docs/adr/0160-portable-maturing-wildlife-transfer.md). +Portable replay only. Durable freeze/stage/paired publication remains bundle +10/trace 1 and explicitly refuses this version; no ownership grant is added. + +Use the exact bounded [trace-1 layout](cellular-migration-trace-v1.md), with these +two changes: + +| Offset | Bytes | Value | +|---:|---:|---| +| 0 | 8 | ASCII magic `AEVMIG02` | +| 8 | 4 | Version, exactly 2 | + +Version 2 requires equal rules-9/owner-7 predecessors in both regions. Raw +representation 1 uses those owners directly; population representation 2 uses +envelope 2. Trace 1 retains equal rules 8 and its exact old bytes. Never infer the +rule from a current head, accept mixed predecessor rules, or pair one version's +magic with another version number. Unknown versions fail before allocation. + +All other fields and bounds are unchanged: positive common completed cut, stable +trusted request, both endpoint predecessor digests/result identities, exact +whole-genome member set, transferred energy/C/N/P/other, zero reserved field, +canonical little-endian re-encoding and final FNV-1a64. Maximum size remains +2,312 bytes. The I/O layer still owes manifest/payload SHA-256 validation. + +Preparation/replay preserves every realized growth/body/reserve/damage/choice +field at the no-tick cut. It neither spends food nor runs maturation. Ordinary +destination intervals continue the retained rules-9 kernel and boundary ledger. +Source nonresident history owns no inventory and never grows another copy. +Newly spent construction energy becomes heat under ADR-0157, not migration flow. + +Qualification includes real growth before and after transfer, raw/cohort exact +biology, repeated returns, stock/census closure, placement/capacity/eligibility +refusals, codec tampering and independent-process raw/cohort pair and interval +continuation. A later durable gate must explicitly admit trace 2 with bundle 11, +source freeze, staged ghost, atomic paired receipt, recovery and pending-handoff +census evidence. Nothing here enables routing or claims sustainable ecology. diff --git a/src/persistence/cellular_migration_store.cpp b/src/persistence/cellular_migration_store.cpp index 9706370..5813434 100644 --- a/src/persistence/cellular_migration_store.cpp +++ b/src/persistence/cellular_migration_store.cpp @@ -86,8 +86,8 @@ bool cuts(const CheckpointManifest& s, const CheckpointManifest& d, const auto profile = t.representation == server::CellularMigrationRepresentation::individual ? CheckpointProfile::cellular_lives_v1 : CheckpointProfile::cellular_population_v1; - return supported(s) && supported(d) && encode_manifest(s) && encode_manifest(d) && - s.cellular_versions == cellular_v10_versions && + return t.format_version == 1 && supported(s) && supported(d) && encode_manifest(s) && + encode_manifest(d) && s.cellular_versions == cellular_v10_versions && d.cellular_versions == cellular_v10_versions && s.profile == profile && d.profile == profile && s.sequence > 0 && d.sequence > 0 && s.key == RegionKey{t.world, t.request.source.region} && @@ -145,7 +145,8 @@ std::expected retry_cellular_migration_freeze(Postgres& db, const LeaseGrant& lease, const CellularMigrationPrepared& prepared, milliseconds timeout) { const auto trace = server::decode_migration_trace(prepared.trace); - if (!trace || prepared.key != RegionKey{trace->world, trace->request.source.region} || + if (!trace || trace->format_version != 1 || + prepared.key != RegionKey{trace->world, trace->request.source.region} || lease.frame != trace->frame) return std::unexpected(failed(PublicationError::candidate)); const std::array args{std::to_string(prepared.key.world), @@ -340,7 +341,8 @@ retry_cellular_migration_stage(Postgres& db, const LeaseGrant& lease, const CellularMigrationStagePrepared& prepared, milliseconds timeout) { const auto trace = server::decode_migration_trace(prepared.trace); - if (!trace || prepared.key != RegionKey{trace->world, trace->request.destination.region} || + if (!trace || trace->format_version != 1 || + prepared.key != RegionKey{trace->world, trace->request.destination.region} || lease.frame != trace->frame || prepared.ghost.sha256 == Sha256Digest{} || prepared.ghost.bytes == 0) return std::unexpected(stage_failed(PublicationError::candidate)); diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index fc7ee5b..a3135f9 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -679,7 +679,9 @@ std::expected, CellularLivesError> CellularLives::migration_replacement(std::vector living, const biology::LineageArchive& archive, CellularBoundaryLedger boundary) const { - if (state_->rules_version != cellular_lives_foraging_rules || + if ((state_->rules_version != cellular_lives_foraging_rules && + !(state_->rules_version == cellular_lives_maturation_rules && + state_->format_version == cellular_lives_migration_format)) || (state_->format_version != cellular_lives_presence_format && state_->format_version != cellular_lives_migration_format)) return std::unexpected(CellularLivesError::version); @@ -709,6 +711,8 @@ CellularLives::migration_replacement(std::vector living, std::expected, CellularLivesError> CellularLives::migration_upgrade_candidate() const { + if (state_->rules_version != cellular_lives_foraging_rules) + return std::unexpected(CellularLivesError::version); return migration_replacement(state_->lives, state_->archive, state_->boundary); } std::expected, CellularLivesError> diff --git a/src/server/lifecycle/cellular_migration.cpp b/src/server/lifecycle/cellular_migration.cpp index e994738..b6fd8ce 100644 --- a/src/server/lifecycle/cellular_migration.cpp +++ b/src/server/lifecycle/cellular_migration.cpp @@ -44,8 +44,9 @@ CellularMigration::prepare(const CellularLives& source, const CellularLives& des std::uint64_t genome) { if (source.format_version() != cellular_lives_migration_format || destination.format_version() != cellular_lives_migration_format || - source.rules_version() != cellular_lives_foraging_rules || - destination.rules_version() != cellular_lives_foraging_rules) + (source.rules_version() != cellular_lives_foraging_rules && + source.rules_version() != cellular_lives_maturation_rules) || + destination.rules_version() != source.rules_version()) return std::unexpected(CellularMigrationError::version); if (genome == 0 || source.world() != destination.world() || source.region() > cellular_bud_max_region || diff --git a/src/server/lifecycle/cellular_migration_trace.cpp b/src/server/lifecycle/cellular_migration_trace.cpp index b16837f..ba1f0a9 100644 --- a/src/server/lifecycle/cellular_migration_trace.cpp +++ b/src/server/lifecycle/cellular_migration_trace.cpp @@ -6,6 +6,7 @@ namespace evo::server { namespace { constexpr std::array magic{'A', 'E', 'V', 'M', 'I', 'G', '0', '1'}; +constexpr std::array maturing_magic{'A', 'E', 'V', 'M', 'I', 'G', '0', '2'}; template bool zero(const T& bytes) { return std::ranges::all_of(bytes, [](auto byte) { return byte == 0; }); } @@ -23,7 +24,8 @@ bool valid_request(const CellularMigrationRequest& request) { return std::ranges::adjacent_find(ids) == ids.end(); } bool shape(const CellularMigrationTrace& trace) { - if ((trace.representation != CellularMigrationRepresentation::individual && + if ((trace.format_version != 1 && trace.format_version != 2) || + (trace.representation != CellularMigrationRepresentation::individual && trace.representation != CellularMigrationRepresentation::population) || trace.world == 0 || trace.frame == 0 || trace.tick == 0 || !valid_request(trace.request) || trace.transferred == accounting::Inventory{} || trace.members.empty() || @@ -55,6 +57,8 @@ record(const Owner& source, const Owner& destination, const CellularMigrationReq CellularMigrationTrace trace{ representation, state(source)->world(), state(source)->frame(), state(source)->tick(), request, execution->transferred, execution->members}; + trace.format_version = + state(source)->rules_version() == cellular_lives_maturation_rules ? 2 : 1; if (!shape(trace)) return std::unexpected(CellularMigrationError::format); return Recorded{std::move(trace), std::move(*execution)}; @@ -65,6 +69,10 @@ auto replay(const Owner& source, const Owner& destination, const CellularMigrati -> decltype(CellularMigration::prepare(source, destination, trusted.genome)) { if (!shape(trace)) return std::unexpected(CellularMigrationError::format); + const auto version = + state(source)->rules_version() == cellular_lives_maturation_rules ? 2U : 1U; + if (trace.format_version != version) + return std::unexpected(CellularMigrationError::version); if (trace.request != trusted || trace.representation != representation || trace.world != state(source)->world() || trace.frame != state(source)->frame() || trace.tick != state(source)->tick() || trusted.source.region != state(source)->region() || @@ -144,8 +152,8 @@ encode_migration_trace(const CellularMigrationTrace& trace) { return std::unexpected(CellularMigrationError::format); std::vector bytes; bytes.reserve(migration_trace_header_bytes + 8 * trace.members.size() + 8); - append(bytes, magic); - put(bytes, 1, 4); + append(bytes, trace.format_version == 1 ? magic : maturing_magic); + put(bytes, trace.format_version, 4); put(bytes, static_cast(trace.representation), 4); for (const auto value : {trace.world, trace.frame, trace.tick, trace.request.genome}) put(bytes, value); @@ -174,14 +182,17 @@ decode_migration_trace(std::span bytes) { if (end.get() != checksum(bytes.first(bytes.size() - 8))) return std::unexpected(CellularMigrationError::checksum); Reader in(bytes); - if (in.array<8>() != magic) + const auto tag = in.array<8>(); + if (tag != magic && tag != maturing_magic) return std::unexpected(CellularMigrationError::format); - if (in.get(4) != 1) + const auto version = in.get(4); + if ((version != 1 && version != 2) || (version == 1 ? tag != magic : tag != maturing_magic)) return std::unexpected(CellularMigrationError::version); const auto representation = in.get(4); if (representation != 1 && representation != 2) return std::unexpected(CellularMigrationError::version); CellularMigrationTrace trace; + trace.format_version = static_cast(version); trace.representation = static_cast(representation); trace.world = in.get(); trace.frame = in.get(); diff --git a/tests/cellular_migration_restart.cmake b/tests/cellular_migration_restart.cmake index 6967811..aa92847 100644 --- a/tests/cellular_migration_restart.cmake +++ b/tests/cellular_migration_restart.cmake @@ -12,19 +12,26 @@ execute_process(COMMAND "${MIGRATION_TEST}" --replay "${prefix}" RESULT_VARIABLE if(NOT replayed EQUAL 0) message(FATAL_ERROR "Fresh-process migration replay failed: ${replayed}") endif() -foreach(representation raw pop) - foreach(side source destination) - execute_process(COMMAND "${CMAKE_COMMAND}" -E compare_files - "${prefix}.${representation}.${side}.expected" - "${prefix}.${representation}.${side}.resumed" RESULT_VARIABLE compared) - if(NOT compared EQUAL 0) - message(FATAL_ERROR "Migration ${representation}/${side} diverged across process replay") - endif() +foreach(variant legacy maturing) + if(variant STREQUAL "legacy") + set(pair "${prefix}") + else() + set(pair "${prefix}.maturing") + endif() + foreach(representation raw pop) + foreach(side source destination) + execute_process(COMMAND "${CMAKE_COMMAND}" -E compare_files + "${pair}.${representation}.${side}.expected" + "${pair}.${representation}.${side}.resumed" RESULT_VARIABLE compared) + if(NOT compared EQUAL 0) + message(FATAL_ERROR "Migration ${variant}/${representation}/${side} diverged across process replay") + endif() + endforeach() endforeach() + execute_process(COMMAND "${CMAKE_COMMAND}" -E compare_files + "${pair}.pop.continuation.expected" "${pair}.pop.continuation.resumed" + RESULT_VARIABLE continued) + if(NOT continued EQUAL 0) + message(FATAL_ERROR "Transferred ${variant} population interval diverged across process replay") + endif() endforeach() -execute_process(COMMAND "${CMAKE_COMMAND}" -E compare_files - "${prefix}.pop.continuation.expected" "${prefix}.pop.continuation.resumed" - RESULT_VARIABLE continued) -if(NOT continued EQUAL 0) - message(FATAL_ERROR "Transferred population interval diverged across process replay") -endif() diff --git a/tests/cellular_migration_tests.cpp b/tests/cellular_migration_tests.cpp index dc26021..54482fd 100644 --- a/tests/cellular_migration_tests.cpp +++ b/tests/cellular_migration_tests.cpp @@ -162,9 +162,13 @@ CellularPopulationExecution continuation(const CellularPopulation& population) { auto inputs = checked(unattended_population_inputs(s, header), "transferred interval inputs"); return checked(prepare_population_batch(population, std::move(inputs)), "transferred interval"); } -void trace_contract() { +void trace_contract(bool maturing = false) { auto source = checked(funded()->migration_upgrade_candidate(), "trace source"); auto target = checked(destination(*source, 1)->migration_upgrade_candidate(), "trace target"); + if (maturing) { + source = checked(source->maturation_upgrade_candidate(), "trace maturing source"); + target = checked(target->maturation_upgrade_candidate(), "trace maturing target"); + } const auto before = source->snapshot(), peer_before = target->snapshot(); const auto request = request_for(*source, *target); auto recorded = checked(prepare_migration_trace(*source, *target, request), "record pair"); @@ -172,7 +176,20 @@ void trace_contract() { require(bytes.size() == migration_trace_header_bytes + 8 * recorded.trace.members.size() + 8, "trace length changed"); const auto trace = checked(decode_migration_trace(bytes), "decode pair"); - require(trace == recorded.trace, "trace canonical roundtrip"); + require(trace == recorded.trace && trace.format_version == (maturing ? 2U : 1U), + "trace canonical roundtrip or rule version"); + auto wrong_version = trace; + wrong_version.format_version = maturing ? 1 : 2; + require(!replay_migration_trace(*source, *target, request, wrong_version), + "transfer trace reinterpreted under different biological rules"); + wrong_version.format_version = 3; + require(!encode_migration_trace(wrong_version), "unknown transfer trace version"); + for (const auto offset : {std::size_t{7}, std::size_t{8}}) { + auto mixed = bytes; + mixed.at(offset) = offset == 7 ? (maturing ? '1' : '2') : (maturing ? 1 : 2); + checksum(mixed); + require(!decode_migration_trace(mixed), "mixed transfer magic/version"); + } auto replayed = checked(replay_migration_trace(*source, *target, request, trace), "replay pair"); require(replayed.source->snapshot() == recorded.execution.source->snapshot() && @@ -302,6 +319,85 @@ void trace_contract() { require(source->snapshot() == before && target->snapshot() == peer_before, "trace validation changed its input"); } +void maturing_growth_transfer() { + auto old = checked(funded()->migration_upgrade_candidate(), "growth migration source"); + auto old_peer = checked(destination(*old)->migration_upgrade_candidate(), "growth old peer"); + auto source = checked(old->maturation_upgrade_candidate(), "growth rules-9 source"); + auto peer = checked(old_peer->maturation_upgrade_candidate(), "growth rules-9 peer"); + const auto genome = wildlife_genome(*source); + const auto before = source->snapshot(), old_bytes = old->snapshot(); + for (const auto& result : {CellularMigration::prepare(*source, *old_peer, genome), + CellularMigration::prepare(*old, *peer, genome)}) + require(!result && result.error() == CellularMigrationError::version, + "mixed rules entered raw transfer"); + auto population = checked(CellularPopulation::create(restore(*source)), "growth population"); + auto old_population = + checked(CellularPopulation::create(restore(*old_peer)), "old population peer"); + const auto mixed = CellularMigration::prepare(*population, *old_population, genome); + require(!mixed && mixed.error() == CellularMigrationError::version && + source->snapshot() == before && old->snapshot() == old_bytes && + !source->migration_upgrade_candidate(), + "mixed cohort transfer changed input or rules-9 repeated the format upgrade"); + auto active = checked(funded(false)->migration_upgrade_candidate(), "active boundary owner"); + auto active_peer = checked(destination(*active)->migration_upgrade_candidate(), "active peer"); + active = checked(active->maturation_upgrade_candidate(), "active maturing owner"); + active_peer = checked(active_peer->maturation_upgrade_candidate(), "active maturing peer"); + const auto vulnerable = + CellularMigration::prepare(*active, *active_peer, wildlife_genome(*active)); + require(!vulnerable && vulnerable.error() == CellularMigrationError::ineligible, + "rules-9 transfer bypassed vulnerable controlled life"); + for (unsigned tick = 0; tick < 64; ++tick) + step(*source); + bool grew_before = false; + for (const auto& life : source->lives()) { + const auto prior = std::ranges::find(old->lives(), life.identity.life, + [](const auto& value) { return value.identity.life; }); + grew_before |= prior != old->lives().end() && + life.growth.realized_per_thousand > prior->growth.realized_per_thousand; + } + require(grew_before, "migration fixture never funded pre-transfer growth"); + // Finite destination food is declared in its opening fixture, not credited + // to a migrant's reserve or copied from the source's spending ledger. + peer = checked(checked(destination(*source, 0, 0, true)->migration_upgrade_candidate(), + "funded destination boundary") + ->maturation_upgrade_candidate(), + "funded destination maturation"); + const auto request = request_for(*source, *peer); + auto raw = checked(prepare_migration_trace(*source, *peer, request), "growing raw transfer"); + population = checked(CellularPopulation::create(restore(*source)), "growing source cohort"); + auto destination_population = + checked(CellularPopulation::create(restore(*peer)), "growing destination cohort"); + checked(population->collapse(genome), "growing cohort membership"); + auto recorded = checked(prepare_migration_trace(*population, *destination_population, request), + "growing cohort transfer"); + require(raw.execution.source->snapshot() == recorded.execution.source->state().snapshot() && + raw.execution.destination->snapshot() == + recorded.execution.destination->state().snapshot() && + recorded.trace.format_version == 2, + "growing transfer changed biology across representations"); + const auto total = plus(source->current_total(), peer->current_total()); + const auto arrival = recorded.execution.destination->state().snapshot(); + auto continued = continuation(*recorded.execution.destination); + bool grew_after = false; + for (const auto& life : continued.state->state().lives()) { + const auto prior = std::ranges::find(source->lives(), life.identity.life, + [](const auto& value) { return value.identity.life; }); + grew_after |= prior != source->lives().end() && + life.growth.realized_per_thousand > prior->growth.realized_per_thousand; + } + require(grew_after && + plus(recorded.execution.source->state().current_total(), + continued.state->state().current_total()) == total && + continued.state->state().boundary_ledger() == + recorded.execution.destination->state().boundary_ledger() && + recorded.execution.destination->state().snapshot() == arrival, + "imported juvenile failed funded growth or spent boundary flow as stock"); + const auto replay = + checked(replay_population_batch(*recorded.execution.destination, continued.batch), + "growing destination interval replay"); + require(replay->snapshot() == continued.state->snapshot(), + "post-transfer growth replay differs"); +} void write_bytes(const std::string& path, std::span bytes) { std::ofstream out(path, std::ios::binary | std::ios::trunc); out.write(reinterpret_cast(bytes.data()), @@ -320,9 +416,13 @@ std::vector read_bytes(const std::string& path) { require(in.good(), "restart fixture read"); return bytes; } -void record_restart(const std::string& prefix) { +void record_restart(const std::string& prefix, bool maturing = false) { auto source = checked(funded()->migration_upgrade_candidate(), "restart source"); auto target = checked(destination(*source, 1)->migration_upgrade_candidate(), "restart target"); + if (maturing) { + source = checked(source->maturation_upgrade_candidate(), "restart maturing source"); + target = checked(target->maturation_upgrade_candidate(), "restart maturing target"); + } const auto request = request_for(*source, *target); auto recorded = checked(prepare_migration_trace(*source, *target, request), "restart raw pair"); write_bytes(prefix + ".raw.source", source->snapshot()); @@ -381,7 +481,7 @@ void replay_restart(const std::string& prefix) { "fresh transferred continuation"); write_bytes(prefix + ".pop.continuation.resumed", continued->snapshot()); } -void upgrade_and_move() { +void upgrade_and_move(bool maturing = false) { auto original = funded(); auto other = destination(*original, 1); const auto original_bytes = original->snapshot(); @@ -397,6 +497,10 @@ void upgrade_and_move() { source->boundary_ledger() == CellularBoundaryLedger{} && original->snapshot() == original_bytes, "upgrade changed biology/funding"); + if (maturing) { + source = checked(source->maturation_upgrade_candidate(), "moving maturing source"); + target = checked(target->maturation_upgrade_candidate(), "moving maturing target"); + } const auto source_before = source->snapshot(), target_before = target->snapshot(); const auto total = plus(source->current_total(), target->current_total()); const auto genome = wildlife_genome(*source); @@ -597,7 +701,7 @@ void population_envelope() { } checked(next->advance_tick(controlled), "new envelope continued biology"); } -void overlap_refusal() { +void overlap_refusal(bool maturing = false) { auto raw = funded(false); for (unsigned i = 0; i < 128; ++i) step(*raw, false); @@ -605,6 +709,10 @@ void overlap_refusal() { step(*raw); auto source = checked(raw->migration_upgrade_candidate(), "overlap source upgrade"); auto target = checked(destination(*source)->migration_upgrade_candidate(), "overlap peer"); + if (maturing) { + source = checked(source->maturation_upgrade_candidate(), "overlap maturing source"); + target = checked(target->maturation_upgrade_candidate(), "overlap maturing target"); + } const auto first = wildlife_genome(*source); auto initial = checked(CellularMigration::prepare(*source, *target, first), "overlap first group"); @@ -710,11 +818,15 @@ void refusal_and_codec() { require(source->snapshot() == before && target->snapshot() == target_before, "rejection modified a peer"); } -void capacity() { +void capacity(bool maturing = false) { auto raw = funded(true, 1); auto crowded = destination(*raw, 256); auto source = checked(raw->migration_upgrade_candidate(), "capacity source upgrade"); auto target = checked(crowded->migration_upgrade_candidate(), "capacity target upgrade"); + if (maturing) { + source = checked(source->maturation_upgrade_candidate(), "capacity maturing source"); + target = checked(target->maturation_upgrade_candidate(), "capacity maturing target"); + } const auto before = source->snapshot(), other = target->snapshot(); const auto result = CellularMigration::prepare(*source, *target, wildlife_genome(*source)); require(!result && result.error() == CellularMigrationError::capacity && @@ -761,11 +873,13 @@ void local_budding_among_imports() { int main(int argc, char** argv) try { if (argc == 3) { const std::string_view mode{argv[1]}; - if (mode == "--record") + if (mode == "--record") { record_restart(argv[2]); - else if (mode == "--replay") + record_restart(std::string{argv[2]} + ".maturing", true); + } else if (mode == "--replay") { replay_restart(argv[2]); - else + replay_restart(std::string{argv[2]} + ".maturing"); + } else throw std::runtime_error("unknown migration fixture mode"); return 0; } @@ -777,6 +891,11 @@ int main(int argc, char** argv) try { overlap_refusal(); local_budding_among_imports(); trace_contract(); + upgrade_and_move(true); + capacity(true); + overlap_refusal(true); + trace_contract(true); + maturing_growth_transfer(); return 0; } catch (const std::exception& error) { std::cerr << error.what() << '\n'; diff --git a/tests/population_publication_tests.cpp b/tests/population_publication_tests.cpp index 1a46c03..e0ff77c 100644 --- a/tests/population_publication_tests.cpp +++ b/tests/population_publication_tests.cpp @@ -2688,6 +2688,29 @@ void migration_freezes(Fixture& f) { auto frozen = take(prepare(request), "durable source freeze"); const CellularMigrationPrepared prepared{ f.key, take(encode_migration_trace(frozen.trace), "frozen canonical trace")}; + auto unsupported = frozen.trace; + unsupported.format_version = 2; + const auto unsupported_bytes = + take(encode_migration_trace(unsupported), "portable rules-9 trace"); + const auto refused_freeze = + retry_cellular_migration_freeze(*f.db, f.lease, {f.key, unsupported_bytes}, 5s); + const auto refused_stage = retry_cellular_migration_stage( + *f.db, destination_lease, {destination_key, unsupported_bytes, {f.build, 1}}, 5s); + require(!refused_freeze && refused_freeze.error().kind == PublicationError::candidate && + !refused_stage && refused_stage.error().kind == PublicationError::candidate && + !stage_cellular_migration(*f.db, *f.objects, *destination_objects, + destination_lease, f.head, destination_head, + unsupported, 5s), + "portable rules-9 trace expanded durable migration admission"); + const std::array unsupported_args{hexadecimal(f.lease.holder, false), + std::to_string(f.lease.epoch), + hexadecimal(unsupported_bytes)}; + const auto refused_sql = + f.db->query("SELECT * FROM evolution.prepare_cellular_migration_freeze(30201," + "1,$1::uuid,$2::evolution.u64,$3::bytea)", + unsupported_args, 5s); + require(!refused_sql && std::string(refused_sql.error().sqlstate.data(), 5) == "22023", + "SQL admitted portable trace 2 before duplicate lookup"); auto malformed = prepared.trace; malformed.back() ^= 1; const std::array malformed_args{hexadecimal(f.lease.holder, false),