Propose mutations without proposing a best build

M3.4 adds the candidate-generation experiment GENOME_MODEL describes: a
static catalog of four effects over the seven capabilities, drawn from a
recorded context with an explicit stream.

The named risk is a hidden best build or offerings biased toward what
would help, so the defence is structural rather than asserted. Nothing is
ranked: candidates are drawn without replacement by rejection sampling,
making every eligible operator exactly as likely as any other, and the
result is returned sorted by operator ID. No score exists in the record,
position carries no meaning, and nothing about an organism's situation
makes a helpful mutation more likely to be offered.

Eligibility is not a second rulebook. An operator is eligible when the
genome it would produce passes the M3.1 validation unchanged, so
prerequisites, required capabilities, ranges and the acyclic development
graph are enforced once, where they were defined. Shedding a capability
another declares as a prerequisite fails that check with no rule written
here to catch it. Range boundaries are refused rather than clamped, since
a clamp would make two operators agree and offer a no-op as a choice.

The draw reads the parent digest and the context and nothing else, so the
same context always returns the same candidates and a retry cannot
reroll; a new event index is what earns a new draw. select_mutation
regenerates the offer and refuses unless it still matches, so a changed
context is rejected rather than answered with a different mutation.

Cost is not invented: a candidate reports the successor's own maintenance
and mass under ADR-0032, and reserves nothing.

The eligible set is pinned by hand from the schema rather than observed,
and the uniformity check is confirmed to fail against a draw that takes
the first eligible operators. The rejection sampling that removes modulo
bias is correct by construction, not test-verified: at this scale the
bias is one part in 10^18. That is recorded rather than claimed.

No organism mutates and no fixture calls any of this. Candidate count,
mutation cost as a game rule, inherited versus acquired expression, NPC
mutation and recombination all remain open, as GENOME_MODEL requires.

Native Release, clang-tidy analysis, ASan and format checks pass 20/20.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-23 15:27:21 -04:00
co-authored by Claude Opus 5
parent fd6faeb7f8
commit 5497f4d74c
11 changed files with 788 additions and 6 deletions
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include "evo/biology/metabolism.hpp"
namespace evo::biology {
enum class MutationEffect : std::uint8_t { adjust_up, adjust_down, acquire, shed };
// One entry of the static catalog. The ID is stable: it orders candidates and
// names them across calls, and it carries no ranking.
struct MutationOperator {
std::uint16_t id;
Capability target;
MutationEffect effect;
auto operator<=>(const MutationOperator&) const = default;
};
// What the recorded context is. The draw reads this and the parent genome and
// nothing else, so events elsewhere in a world cannot move a candidate set.
struct MutationContext {
std::uint64_t seed;
std::uint32_t stream; // explicit stream identity, never a shared global
std::uint64_t event_index; // a new event earns a new draw; a retry does not
std::uint16_t candidate_count;
GrowthState growth;
EnvironmentState environment;
auto operator<=>(const MutationContext&) const = default;
};
// A proposal. It reserves nothing. Maintenance and mass are what ADR-0032 would
// charge for the successor, not a price invented here and not a score.
struct MutationCandidate {
std::uint16_t operator_id;
Capability target;
MutationEffect effect;
std::uint32_t parameter; // the successor's value; zero when shed
std::uint64_t maintenance;
std::uint64_t total_mass;
auto operator<=>(const MutationCandidate&) const = default;
};
enum class MutationError : std::uint8_t {
invalid_context,
no_candidates,
unknown_candidate,
context_changed,
invalid_successor
};
inline constexpr std::size_t max_candidates = 8;
[[nodiscard]] std::span<const MutationOperator> mutation_catalog() noexcept;
// Identical inputs always yield identical candidates, sorted by operator ID.
// The order is canonical and means nothing: nothing here is ranked.
[[nodiscard]] std::expected<std::vector<MutationCandidate>, MutationError>
mutation_candidates(const Genome& genome, const MutationContext& context);
// Regenerates the offer and refuses unless it still matches exactly, so a changed
// context is rejected rather than answered with a different mutation.
[[nodiscard]] std::expected<Genome, MutationError>
select_mutation(const Genome& genome, const MutationContext& context,
std::span<const MutationCandidate> offered, std::uint16_t chosen,
std::uint64_t successor_id, std::uint64_t origin_event);
} // namespace evo::biology