From 9a13e796f1fed393aef466370d48fdcb7cd1abdd Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 27 Sep 2026 18:51:09 -0400 Subject: [PATCH] Qualify M6.8 integrated environmental cycle and costs --- docs/ROADMAP.md | 9 + docs/STATUS.md | 9 +- .../ENVIRONMENTAL_QUALIFICATION.md | 4 + .../ENVIRONMENTAL_SLICE_QUALIFICATION.md | 105 ++++++++++ docs/engineering/VALIDATION.md | 21 ++ tests/environmental_qualification.cpp | 179 +++++++++++++++++- 6 files changed, 325 insertions(+), 2 deletions(-) create mode 100644 docs/engineering/ENVIRONMENTAL_SLICE_QUALIFICATION.md diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 5e197e6..d1a26e3 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -477,3 +477,12 @@ failure returns its committed prefix explicitly. Pause/resume needs no second clock or snapshot format. Tests compare 1/3/17/64-wide batches to direct execution for rules 1 and 2, restore between batches, partial failures and u64 boundaries. Next: M6.8 integrated multi-seed ecosystem qualification and cost evidence. + +M6.8 implemented and natively qualified: the integrated driver runs five regimes, +16 seeds and independent full-cycle episodes. Baseline demonstrates capture, +growth, feeding, consumer death, bounded nutrient return and two regrowth units; +negative regimes distinguish energy/nutrient/temperature/decay limitations. +Direct execution matches scheduled restore/retry continuation. Extended run: +5120 episodes, 655360 logical ticks, exact inventories and stable residency. +See engineering/ENVIRONMENTAL_SLICE_QUALIFICATION.md for costs and scope limits. +Next: M7.1 region durability contract; M6 does not claim durable worker recovery. diff --git a/docs/STATUS.md b/docs/STATUS.md index f15b89a..ee2269f 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -61,7 +61,7 @@ for the bounded proof; the general production ECS remains a later measured choic | Priority | Work | Completion evidence | |---|---|---| -| 1 | M6.8 validate the integrated environmental slice | Multi-seed full-cycle runs, per-channel conservation, restore/replay equivalence and cost report | +| 1 | M7.1 define region durability contract | Complete state inventory, commit/ACK semantics, bounded persistence batches and crash-point matrix | | Research | Improve aggregate fidelity and measure Linux/target-host costs | M4.6 found no qualifying width; see the aggregate budget report | | 2 | Revisit the ADR-0031/0032 reproduction cost model | Reproduction is affordable only at the genome schema's floor; decide whether that is intended before M4 builds cohorts on it | | Delivery gate | Add/update the dev workload when a deployable increment needs it; Argo is ready | Observe Job/pod completion separately from image publication; no World0 changes | @@ -733,3 +733,10 @@ M6.7 now schedules bounded explicit local intervals, checks stale/foreign bounda and reports committed prefixes on failed catch-up. Pause/restore/resume uses the existing process envelope; no wall-clock debt is inferred. M6.8 is next. See architecture/ENVIRONMENTAL_SCHEDULING.md for caller responsibilities. + +M6.8 completed the bounded environmental integration qualification. The extended +ensemble passed 5120 episodes across five regimes, including nutrient-fed regrowth, +conservation and direct-versus-restored equivalence. See +engineering/ENVIRONMENTAL_SLICE_QUALIFICATION.md for actual measurements and +limitations. M6 is natively qualified; Linux CI confirmation remains separate. +Next is M7.1: define complete region state, durable ACKs and the crash-point matrix. diff --git a/docs/engineering/ENVIRONMENTAL_QUALIFICATION.md b/docs/engineering/ENVIRONMENTAL_QUALIFICATION.md index 75ea727..f70d855 100644 --- a/docs/engineering/ENVIRONMENTAL_QUALIFICATION.md +++ b/docs/engineering/ENVIRONMENTAL_QUALIFICATION.md @@ -81,6 +81,10 @@ No optimization or performance SLA is justified by this measurement alone. ## Remaining scope +Historical scope below is superseded by M6.6/M6.7 and the +[M6.8 integrated qualification](ENVIRONMENTAL_SLICE_QUALIFICATION.md). The M6.5 +owner-size measurements above remain historical; M6.6 enlarged bounded receipts. + M6.6: terminal events with retained corpse resources and bounded decomposition. M6.7: scheduling intervals/catch-up. M6.8: the full death/nutrient/regrowth slice and longer ecological/cost analysis. This gate does not prove ecological stability, diff --git a/docs/engineering/ENVIRONMENTAL_SLICE_QUALIFICATION.md b/docs/engineering/ENVIRONMENTAL_SLICE_QUALIFICATION.md new file mode 100644 index 0000000..d1b13ea --- /dev/null +++ b/docs/engineering/ENVIRONMENTAL_SLICE_QUALIFICATION.md @@ -0,0 +1,105 @@ +# M6.8 integrated environmental qualification + +Scope: one closed synthetic habitat, two explicitly opened accounts, rules 2, +community envelope 2, coupled resources 1, fields 1, terrain's existing nested +codec and scheduling adapter 1 (ADRs 0054-0057). No version or biological rule +changes. This is an experiment, not live-world population initialization. + +## Acceptance protocol + +Extend the existing environmental qualification executable with independent +episodes. Each starts with empty actors and prepaid environmental resources. +Capture funds growth; finite N/P becomes limiting; a scheduled bite transfers +producer inventory into a consumer. A trusted terminal fact kills that consumer, +bounded decay returns N/P, and the surviving producer can grow again. Later a +terminal fact stops the producer. No episode resurrects an account or imports +resources into a running world. Opening a fresh episode is a new experiment. + +Run 16 explicit seeds in each of five regimes: baseline, source off, no nitrogen, +temperature blocked, and zero decay. Randomness varies openings, terminal timing, +later source/temperature inputs and scheduler batch widths. The initial cycle is +controlled so baseline nutrient-fed regrowth is testable, not merely probable. +Zero-decay must retain the corpse and prevent post-death regrowth; other failures +must remain distinct from resource-conservation success. + +Compare direct per-tick execution with bounded scheduled execution restored at +batch boundaries. Compare reports and complete canonical snapshots, audit checked +energy/C/N/P/other sums, and separately audit total water (not interchangeable with +organic other). Check source/growth/efficiency residual ranges. Capture snapshots +before/after terminal events and while decay is partial, including history eviction. +Retried committed inputs must not alter bytes. Aggregate hashes are diagnostics; +per-episode equality and biological-path assertions are the actual tests. + +CTest uses a short ensemble; --long uses more independent episodes. Cost samples +time only scheduled execution of prepared 128-tick full-cycle episodes, excluding +opening allocation, plus separate snapshot and restore timings. Report fixed owner, +resource and scheduler output sizes separately from RSS. No timing threshold or +R730xd capacity claim. Native and Linux evidence are recorded separately below. + +## Limits + +Finite incident energy eventually exhausts. Two actors with no reproduction cannot +sustain an ecosystem, and terminal facts are imposed rather than inferred mortality. +Carbon is prepaid organic carbon; waste is not mineralized by M6.6. Death, nutrient +return and regrowth demonstrate integration, not ecological stability, evolutionary +fitness, complete chemistry, offline fairness or durable crash recovery. M7 must +provide publication and ownership; these tests verify in-memory canonical restore. + +## Reproduce and observed results (2026-09-27) + +Run tools/windows-check.ps1 -Preset release -Action check, then +build/release/evo-environmental-qualification.exe --long. Linux uses the same +executable without .exe. No new dependencies or simulation rules were introduced. +Version bundle: rules/envelope 2, coupled resources 1, fields 1, terrain snapshot 1, +coordinate/generator/material versions 1, interval adapter 1. + +CTest includes 80 episodes (16 per regime), 10240 logical ticks plus comparison +execution. --long includes 5120 episodes, 655360 logical ticks and 1310720 +direct/scheduled advances. Each episode lasts 128 ticks: many independent full +cycles, not one long-lived ecosystem. Each seed index uses seed+16*episode, with +episode=0..63 in --long. Every batch restores and retries its last input without +changing bytes. Reports compare at every tick; inventory audits run at every +reference tick and scheduled batch boundary. Terminal cuts force partial-corpse +snapshots, including before and after deaths and after history eviction. + +| Regime (1024 episodes each) | Captured pJ | Growth | Assimilated N fg | Returned N fg | Regrowth | Hash fold | +|---|---:|---:|---:|---:|---:|---| +| Baseline | 308892 | 7672 | 2048 | 7672 | 2048 | 4c58e2ba79a59273 | +| Source off | 0 | 0 | 0 | 0 | 0 | bf6841cdf42d515d | +| No nitrogen | 308892 | 0 | 0 | 0 | 0 | 1d3c84ddeaeb67c8 | +| Temperature blocked | 0 | 0 | 0 | 0 | 0 | 89eda7740985eb00 | +| Zero decay | 308892 | 5624 | 2048 | 0 | 0 | 7d5a6f958dcf2018 | + +Returned N includes consumer and later producer decay. It counts transfers, so the +same conserved nitrogen can return more than once after regrowth. No-N captures +energy but cannot grow. Source-off/temperature-blocked actors stay empty until +trusted terminal events; no starvation death is inferred. Zero decay retains +biomass. Baseline asserts exactly two post-consumer-death growth units per episode. + +Integrated validation took 51.596947 seconds, including codec/replay and checks. +The existing v1 long qualification passed too: 2097152 advances and unchanged +93a9f9b296caac36 fingerprint. These diagnostics are not new frozen goldens. + +## Cost evidence + +Windows x64, MSVC 19.44 Release, Ryzen 7 9800X3D, 8 cores/16 logical CPUs. This is +the M6.5 developer host. Analysis/ASan jobs overlapped the run; timings are noisy +local observations, not isolated throughput or deployment sizing. Each sample +executes 100 prepared baseline episodes using two 64-tick calls each. Opening +allocation and codec measurements are outside the execution timer. + +| Sample | 12800 ticks (s) | Mean snapshot (ms) | Mean restore/replay (ms) | +|---|---:|---:|---:| +| 0 | 0.003182 | 0.088524 | 0.200919 | +| 1 | 0.003200 | 0.087795 | 0.199767 | +| 2 | 0.003212 | 0.087607 | 0.200362 | + +Final v2 envelope: 37367 bytes; accounted resources: 390216; owner: 20152; +reserved process/resource scratch: 131072; combined admitted budget: 541440. +Scheduler result: 14888 caller-owned bytes, separately charged. Resource residency +stays constant per episode. These are accounting/sizeof values, not RSS; allocator +overhead, caller input/results, OS and snapshot buffers are excluded. No performance +optimization or production capacity claim follows from these measurements. + +Native results are recorded in VALIDATION.md. Linux CI, R730xd execution and durable +worker recovery remain separate evidence. Next: M7.1 durability/state-closure design. diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index cb2b00c..fb55ba0 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -1975,3 +1975,24 @@ reran both environmental CTests: 2/2 passed. Analysis/ASan include that final gu Release format-check and git diff --check passed. Tests retain NDEBUG checks. Linux/UBSan/TSan CI confirmation remains pending; native validation does not claim a Linux or target-server run. Next is M6.8 integrated ecological qualification. + +## M6.8 integrated environmental qualification - 2026-09-27 + +Extended the existing qualification executable; no runtime, schema or golden +changed. Complete evidence and reproduction commands are in +[ENVIRONMENTAL_SLICE_QUALIFICATION.md](ENVIRONMENTAL_SLICE_QUALIFICATION.md). + +- tools/windows-check.ps1 -Preset release -Action check: 54/54 passed (4.06s). +- -Preset analysis -Action check: clang-tidy and 54/54 passed (18.57s). +- -Preset asan -Action check: 54/54 passed (60.83s); qualification itself 12.83s. +- -Preset release -Action format and git diff --check passed. +- Release evo-environmental-qualification.exe --long passed: existing v1 long + fingerprint unchanged, plus 5120 v2 episodes/655360 logical ticks/1310720 paired + advances. Full-cycle assertions, checked E/C/N/P/other totals, separate water, + residual ranges, stable resource residency and restored retry equality passed. +- Three integrated execution/snapshot/restore cost samples were collected on the + developer machine. Concurrent analysis/ASan work is disclosed in the report. + +M6 is natively qualified for the bounded synthetic scope. Linux CI/UBSan/TSan, +R730xd measurements and persistent server recovery are not claimed. The local +Linux toolchain/Docker engine remains unavailable. Next: M7.1 durability contract. diff --git a/tests/environmental_qualification.cpp b/tests/environmental_qualification.cpp index df3b686..d35eba4 100644 --- a/tests/environmental_qualification.cpp +++ b/tests/environmental_qualification.cpp @@ -401,6 +401,180 @@ void sequences(std::uint64_t ticks) { static_cast(bites), static_cast(fingerprint), elapsed); } +struct Slice { + EnvironmentalConfig parameters{config()}; + Opening opening{}; + std::array inputs{}; + std::uint64_t consumer_death{}, producer_death{}; +}; +Slice slice(std::uint64_t seed, unsigned regime) { + evo::Random rng{seed}; + Slice s; + s.parameters.rules = 2; + s.parameters.assimilation = 1000; + s.parameters.decay.fill(regime == 4 ? 0 : 1); + const auto nutrients = 4 + rng.next() % 4; + s.opening.environment = {200, regime == 2 ? 0 : nutrients, nutrients, 400, 0, 0, 200, 0, 2000, + 0}; + s.consumer_death = 32 + rng.next() % 5; + s.producer_death = 96 + rng.next() % 7; + for (std::size_t i = 0; i < s.inputs.size(); ++i) { + const auto tick = i + 1; + const auto draw = rng.next(); + auto& in = s.inputs[i]; + in.temperature_mK = regime == 3 || (tick > 40 && draw % 11 == 0) ? 260000 : 290000; + in.source_enabled = regime == 1 || (tick > 40 && draw % 5 == 0) ? 0 : 1; + if (tick == 16 && (regime == 0 || regime == 4)) + in.bite = {2, 2, 2, 2, 1}; + if (tick == s.consumer_death) + in.terminal[1] = 1; + if (tick == s.producer_death) + in.terminal[0] = 1; + } + return s; +} +void slice_audit(const EnvironmentalCommunity& o, const evo::accounting::Inventory& total, + const Slice& s) { + CHECK(audit(o) == total); + const auto water = o.resources().fields().read(0, Field::water); + if (!water) + throw std::runtime_error("missing water"); + CHECK(*water + o.resources().organisms()[0].balances[0] + + o.resources().organisms()[1].balances[0] == + s.opening.environment[0]); + const auto p = o.progress(); + CHECK(p.source_remainder < s.parameters.irradiance_denominator); + CHECK(p.growth_remainder < s.parameters.growth_denominator); + CHECK(p.efficiency_remainder < 1000 && p.last_funded <= p.tick); +} +void integrated(std::uint64_t episodes) { + const auto start = std::chrono::steady_clock::now(); + for (unsigned regime = 0; regime < 5; ++regime) { + std::uint64_t captured{}, grown{}, assimilated_n{}, returned_n{}, regrown{}, fingerprint{}; + for (std::uint64_t seed = 0; seed < 16; ++seed) + for (std::uint64_t episode = 0; episode < episodes; ++episode) { + const auto stream = seed + 16 * episode; + const auto s = slice(stream, regime); + auto reference = make(s.parameters, s.opening); + auto scheduled = make(s.parameters, s.opening); + const auto total = audit(*reference); + const auto resident = reference->resources().accounted_bytes(); + std::array reports{}; + std::uint64_t episode_growth{}, episode_regrowth{}, episode_capture{}; + for (std::size_t i = 0; i < s.inputs.size(); ++i) { + auto r = reference->advance(i + 1, s.inputs[i]); + CHECK(r); + reports[i] = *r; + slice_audit(*reference, total, s); + episode_growth += r->grown; + episode_capture += r->captured; + captured += r->captured; + grown += r->grown; + assimilated_n += r->assimilated[1]; + returned_n += r->decomposed[4]; + if (r->tick > s.consumer_death && r->tick < s.producer_death) + episode_regrowth += r->grown; + if (r->tick == s.consumer_death) { + CHECK(r->grown == 0 && r->consumer_transition == 1); + if (regime == 0) + CHECK(reference->resources().organisms()[1].balances[4] == 1); + } + if (r->tick >= s.producer_death) + CHECK(r->grown == 0 && r->captured == 0); + } + if (regime == 0) { + CHECK(episode_regrowth == 2 && reports[15].assimilated[1] == 2); + CHECK(episode_growth == s.opening.environment[1] + 2); + } else { + CHECK(episode_regrowth == 0); + if (regime == 4) + CHECK(episode_growth == s.opening.environment[1]); + else + CHECK(episode_growth == 0); + if (regime == 1 || regime == 3) + CHECK(episode_capture == 0); + } + regrown += episode_regrowth; + evo::Random batches{stream ^ 0xabcdefULL}; + for (std::size_t begin = 0; begin < s.inputs.size();) { + auto end = std::min(s.inputs.size(), + begin + 1 + static_cast(batches.next() % 16)); + // Force checkpoint boundaries around terminal events and history eviction. + for (auto cut : {s.consumer_death - 1, s.consumer_death, s.consumer_death + 1, + std::uint64_t{64}, s.producer_death - 1, s.producer_death}) + if (cut > begin && cut < end) + end = static_cast(cut); + auto r = schedule_environment( + *scheduled, {identity, begin, end, 50000, + std::span{s.inputs}.subspan(begin, end - begin)}); + CHECK(r && !r->failure && r->committed == end - begin); + for (std::size_t j = 0; j < r->committed; ++j) + CHECK(r->reports[j] == reports[begin + j]); + slice_audit(*scheduled, total, s); + CHECK(scheduled->resources().accounted_bytes() == resident); + auto b = bytes(*scheduled); + auto restored = EnvironmentalCommunity::restore(b, identity, 8000000); + CHECK(restored); + CHECK(bytes(**restored) == b); + CHECK((*restored)->advance(end, s.inputs[end - 1]) == reports[end - 1]); + CHECK(bytes(**restored) == b); + scheduled = std::move(*restored); + begin = end; + } + CHECK(bytes(*scheduled) == bytes(*reference)); + fingerprint = (fingerprint ^ hash(bytes(*reference))) * 1099511628211ULL; + } + std::printf( + "slice regime=%u episodes=%llu ticks=%llu capture=%llu growth=%llu " + "assimilated_N=%llu returned_N=%llu regrowth=%llu hash=%016llx\n", + regime, static_cast(16 * episodes), + static_cast(16 * episodes * 128), + static_cast(captured), static_cast(grown), + static_cast(assimilated_n), + static_cast(returned_n), static_cast(regrown), + static_cast(fingerprint)); + } + std::printf("slice_validation_seconds=%.6f\n", + std::chrono::duration(std::chrono::steady_clock::now() - start).count()); +} +void integrated_cost() { + for (unsigned sample = 0; sample < 3; ++sample) { + double steps{}, snapshot_ms{}, restore_ms{}; + std::size_t snapshot_bytes{}, resource_bytes{}; + for (std::uint64_t seed = 0; seed < 100; ++seed) { + const auto s = slice(seed, 0); + auto o = make(s.parameters, s.opening); + auto start = std::chrono::steady_clock::now(); + for (std::size_t begin = 0; begin < 128; begin += 64) { + auto r = schedule_environment(*o, {identity, begin, begin + 64, 50000, + std::span{s.inputs}.subspan(begin, 64)}); + CHECK(r && !r->failure && r->committed == 64); + } + steps += + std::chrono::duration(std::chrono::steady_clock::now() - start).count(); + start = std::chrono::steady_clock::now(); + auto b = bytes(*o); + snapshot_ms += + std::chrono::duration(std::chrono::steady_clock::now() - start) + .count(); + start = std::chrono::steady_clock::now(); + auto restored = EnvironmentalCommunity::restore(b, identity, 8000000); + CHECK(restored); + restore_ms += + std::chrono::duration(std::chrono::steady_clock::now() - start) + .count(); + CHECK(bytes(**restored) == b); + snapshot_bytes = b.size(); + resource_bytes = o->resources().accounted_bytes(); + } + std::printf("slice_cost sample=%u ticks=12800 seconds=%.6f snapshot_mean_ms=%.6f " + "restore_mean_ms=%.6f snapshot_bytes=%zu resource_bytes=%zu owner_bytes=%zu " + "interval_result_bytes=%zu\n", + sample, steps, snapshot_ms / 100, restore_ms / 100, snapshot_bytes, + resource_bytes, sizeof(EnvironmentalCommunity), + sizeof(EnvironmentalIntervalResult)); + } +} void cost() { std::array times{}; for (auto& seconds : times) { @@ -434,8 +608,11 @@ int main(int argc, char** argv) { malformed(); exhausted_tick(); sequences(argc == 2 ? 65536 : 4096); - if (argc == 2) + integrated(argc == 2 ? 64 : 1); + if (argc == 2) { cost(); + integrated_cost(); + } return 0; } catch (const std::exception& e) { std::fprintf(stderr, "%s\n", e.what());