Add the immutable genome v1 record and its canonical encoding

Open M3 with the record that development and mutation will read, in a new
evo::biology library that nothing else links yet. A genome is validated
once at construction and exposes no mutator, so an invalid one cannot
exist at runtime and callers never revalidate. A draft carries
unvalidated input; create and decode apply identical semantic checks, so
a decoded record is never less validated than a constructed one.

Schema 1 fixes the seven v0.1 capability kinds. Each has a unit, an
inclusive range, whether every genome must carry it, and the capabilities
it mandates, all held as schema facts rather than record data, so no
record can contradict its own units. A capability adds one parameter and
a bitmask of declared developmental edges; the union of declared and
mandated edges must be acyclic, which seven nodes make exact and bounded.

Identity is a nonzero world-scoped genome ID distinct from every runtime
identity, a nonzero origin event, and zero or one parent. Zero parents
identifies a documented founder. The format reserves room for a second so
recombination needs a schema version rather than a layout change.

The encoding follows ADR-0008: explicit little endian, bounded before any
allocation, an exact length match so trailing bytes are rejected, records
strictly ascending by kind so the bytes are canonical and duplicates fall
out of the same comparison, a stored digest recomputed on decode, and a
trailing checksum. The digest covers identity and ancestry, so identical
capabilities from different origins never share one. Neither value is an
authenticity claim. Unknown schema versions fail closed.

Tests cover ancestry rules, every declared range boundary from both
sides, self, mutual and three-node cycles, a cycle closed by a mandated
edge, truncation at every length, trailing and oversized buffers, every
single-byte corruption, and three resealed edits that reach the digest,
version and ordering checks rather than stopping at the checksum. One
branch is recorded as uncovered rather than given a test that cannot
fail: in schema 1 every mandated capability is also required.

No genome affects any simulation. Native Release, clang-tidy analysis,
ASan and format checks pass 17/17; golden d61ad5bf0c928c76 and ecosystem
fingerprint 2cd4a15f9fbe9949 are unchanged. Linux CI has not run yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-22 20:53:23 -04:00
co-authored by Claude Opus 5
parent 22fb904c3e
commit 8584eb1f6f
12 changed files with 1017 additions and 5 deletions
+113
View File
@@ -0,0 +1,113 @@
# ADR-0030: Immutable genome v1 record and canonical encoding
## Status
Adopted for M3.1. Development, phenotype derivation, mutation candidates,
heredity operations and any coupling to the M2 process fixtures are out of scope
and remain M3.2 through M3.5. No gameplay balance is selected.
## Context
M2 closed with founder strategies duplicated verbatim from parent to child, so
nothing heritable exists and lineages differ only by their founder. Before
development or mutation can be written, the record they read must exist: a
versioned, validated, immutable description of developmental capability, with
ancestry that outlives its organisms and an encoding that is canonical enough to
compare across platforms and reject malformed input.
GENOME_MODEL fixes the shape of that record and the two failure modes to avoid:
literal DNA, and an Animal/Plant/Fungus style inheritance hierarchy. It also
leaves mutation, recombination, NPC divergence and multi-parent heredity open.
## Decision
Add an `evo::biology` library holding one value type, `Genome`, constructed only
through validation and exposing no mutator. A `GenomeDraft` carries unvalidated
input; `Genome::create` either returns a validated record or an error, and
`decode` applies the identical semantic checks to bytes. There is no way to hold
an invalid `Genome`, so callers never revalidate.
Genome v1 fixes seven capability kinds, matching the v0.1 list in GENOME_MODEL:
energy conversion, membrane, movement, ingestion, reproduction, target size and
thermal tolerance. These are capabilities, not genes, organs or species. A static
schema table gives each kind its unit, inclusive parameter range, whether every
genome must carry it, and the capabilities it mandates being present. The unit is
a schema fact and is never encoded, so no record can contradict its own units.
Energy conversion, membrane and target size are required in every v1 genome.
A capability record is a kind, one u32 parameter and a u32 bitmask of declared
prerequisites. Declared prerequisites are developmental ordering the genome
asserts; mandated prerequisites are schema facts. Validation rejects an unknown
capability bit or kind, a duplicate kind, a parameter outside its declared range,
a prerequisite naming a capability the genome does not carry, a missing required
or mandated capability, and any cycle in the union of declared and mandated
edges. Seven nodes make that closure exact and bounded.
Ancestry is immutable and separate from every runtime identity. A genome carries
a nonzero world-scoped ID distinct from the process and entity IDs of earlier
increments, a nonzero origin event explaining founder, mutation or reproduction
origin, and zero or one parent. The format reserves room for two so later
recombination needs a schema version rather than a layout change; v1 rejects more
than one. A parent may be neither zero, nor the genome itself, nor repeated.
The encoding follows ADR-0008: explicit little endian, an `AEVOGEN1` magic, fixed
u32 schema and development versions, the identity and ancestry fields, then
capability records sorted strictly ascending by kind, a content digest and a
trailing FNV-1a checksum. Strict ascending order makes the encoding canonical and
rejects duplicates in the same comparison. Sizes and counts are validated against
`max_genome_bytes` before any allocation, and an exact length match is required,
so trailing bytes are rejected rather than ignored.
The content digest covers the whole body, identity and ancestry included, so two
genomes with identical capabilities but different origins never share a digest.
It is an integrity and deduplication aid, never a content-identity key across
origins. It is stored and also recomputed on decode, and a mismatch is rejected:
the digest and the checksum answer different questions, record consistency and
accidental corruption, and neither is an authenticity claim.
Unknown schema versions fail closed. A genome is never migrated in place.
## Alternatives Considered
Literal nucleotide sequences would need an expression model no contract defines
and would make every range check meaningless. A capability class hierarchy would
bake the taxonomy GENOME_MODEL forbids into the type system. Deriving the digest
on demand instead of storing it would lose the record-consistency check that
catches a hand-edited or partially migrated record. Typed accounting units in the
parameters would couple the genome to the ledger before M3.3 has decided how
capability maps to energetic cost. A general graph with arbitrary node counts
would make cycle detection unbounded for no v1 benefit.
## Benefits
An invalid genome cannot exist at runtime. Capability, range and dependency
errors are caught once, at the boundary, with a named reason. Ancestry survives
encoding and is independent of every runtime identity. The bytes are canonical,
bounded and comparable across platforms, so later development and mutation work
starts from a record whose validity is already established.
## Costs
Seven fixed kinds and one u32 parameter each cannot express a capability with
several dimensions; that needs a schema version. The required set and the ranges
are chosen constants. Storing the digest costs eight bytes and one consistency
rule. Multi-parent heredity is reserved but not implemented.
## Risks
Do not read capability parameters as balance, stats or a power score: fitness is
an outcome. A parameter within range is not a viable organism, and validation
proves neither developmental feasibility nor biological plausibility. The schema
ranges must not become gameplay tuning by having been written down. Nothing here
decides mutation operators, inherited versus acquired expression, NPC divergence
or recombination, and no genome yet affects any simulation.
## Consequences
Test canonical round trips, byte-exact encoding stability, strict ordering,
truncation, trailing bytes, corrupted checksums, digest mismatch, unsupported and
zero versions, unknown capability kinds and prerequisite bits, duplicates,
every range boundary, missing required and mandated capabilities, self and mutual
and longer prerequisite cycles, and every ancestry rule. No snapshot format,
process fixture, database, renderer or deployment changes. The M1 particle codec
does not serialize genomes, and M3.2 development must not mutate this record.
+1
View File
@@ -22,6 +22,7 @@ Each record has the eight required sections.
0027 adds terminal inventory ownership and budgeted nutrient return for M2.4.
0028 adopts funded reproduction, bounded slot capacity and retained lineage IDs.
0029 scopes the deterministic ecosystem driver and bounded measured episodes.
0030 adopts the immutable genome v1 record, validation and canonical encoding.
Every dependency adoption records exact version/commit and integrity hash,
transitive license obligations, maintenance/security review, owner and removal