Complete M7.4b lineage checkpoint profile; M7.4 done
ADR-0062 adds a canonical LineageArchive codec (parents before children, organisms by id, FNV) that decodes by replaying admit/record_birth/ record_death and requires byte-identical re-encoding; it never overwrites an existing archive. LineageRegion binds the environmental producer and consumer accounts to archived organisms with identity high-waters, enforces closure (lifecycle vs deaths, exact living set, tick bounds) and records deaths in the tick that causes them. Checkpoint profile 2 (environmental-lineage-v1, history profile 1) publishes that container; schema v4 admits it with a 4,268,144-byte cap and requires each commit to keep its predecessor's profile, RNG, history and durability declarations. Linux adds provision/publish/recover for the profile on the shared publication path. Qualification found WSL2 stepping CLOCK_REALTIME back ~0.5 s every ~32 s, which made two 1 s-lease tests flaky under ASan. Tests now wait on database-time expiry; ADR-0060 records the slewed-clock requirement. Validated: Windows CTest 57/57; Linux GCC Debug/Release, clang-tidy and ASan/UBSan CTest 57/57 each; PostgreSQL suites 2x Release, 2x analysis, 5x ASan; SQL and C++ mutations each caught. No Docker/Gitea CI, remote store, process kill or deployment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <source_location>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -252,6 +254,149 @@ void capacity_refuses_loudly_rather_than_dropping() {
|
||||
CHECK(deep->front() == 1 && deep->back() == max_archived_genomes);
|
||||
CHECK(*archive.common_ancestor(max_archived_genomes, 1) == 1);
|
||||
}
|
||||
std::uint64_t field(const std::vector<std::uint8_t>& b, std::size_t at, unsigned width) {
|
||||
std::uint64_t value{};
|
||||
for (unsigned i = 0; i < width; ++i)
|
||||
value |= static_cast<std::uint64_t>(b[at + i]) << (8U * i);
|
||||
return value;
|
||||
}
|
||||
void set(std::vector<std::uint8_t>& b, std::size_t at, std::uint64_t value, unsigned width) {
|
||||
for (unsigned i = 0; i < width; ++i)
|
||||
b[at + i] = static_cast<std::uint8_t>((value >> (8U * i)) & 0xFFU);
|
||||
}
|
||||
// Recomputes the trailing FNV so a test reaches the check it is aimed at.
|
||||
void reseal(std::vector<std::uint8_t>& b) {
|
||||
std::uint64_t h = 14695981039346656037ULL;
|
||||
for (std::size_t i = 0; i + 8 < b.size(); ++i)
|
||||
h = (h ^ b[i]) * 1099511628211ULL;
|
||||
set(b, b.size() - 8, h, 8);
|
||||
}
|
||||
LineageArchive with_history() {
|
||||
auto archive = branching();
|
||||
CHECK(archive.record_birth(100, 4, evo::Tick{10}));
|
||||
CHECK(archive.record_birth(101, 5, evo::Tick{12}));
|
||||
CHECK(archive.record_birth(90, 1, evo::Tick{0}));
|
||||
CHECK(archive.record_death(90, evo::Tick{0}));
|
||||
CHECK(archive.record_death(100, evo::Tick{30}));
|
||||
return archive;
|
||||
}
|
||||
|
||||
void the_archive_round_trips_canonically() {
|
||||
const auto archive = with_history();
|
||||
const auto bytes = archive.encode();
|
||||
CHECK(field(bytes, 0, 8) == 0x3152414C4F564541ULL && field(bytes, 8, 4) == 1);
|
||||
CHECK(field(bytes, 16, 4) == 5 && field(bytes, 20, 4) == 3 &&
|
||||
field(bytes, 24, 8) == bytes.size());
|
||||
const auto decoded = LineageArchive::decode(bytes);
|
||||
CHECK(decoded && decoded->encode() == bytes);
|
||||
CHECK(decoded->archived() == 5 && decoded->recorded() == 3);
|
||||
CHECK(*decoded->find(4) == *archive.find(4));
|
||||
const auto dead = decoded->organism(100);
|
||||
CHECK(dead && !dead->alive && dead->died.value == 30 && dead->born.value == 10);
|
||||
CHECK(decoded->ancestry(4) == archive.ancestry(4));
|
||||
CHECK(decoded->living_organisms() == std::vector<std::uint64_t>{101});
|
||||
CHECK(decoded->highest_genome() == 5 && decoded->highest_organism() == 101);
|
||||
// A clone decodes into a new archive; the original is untouched.
|
||||
CHECK(archive.recorded() == 3 && archive.encode() == bytes);
|
||||
// Admission order does not change the bytes, only the content does.
|
||||
LineageArchive reordered;
|
||||
for (const auto& [id, parent, c] :
|
||||
{std::tuple{1, 0, 400U}, std::tuple{3, 1, 391U}, std::tuple{2, 1, 409U},
|
||||
std::tuple{5, 2, 400U}, std::tuple{4, 2, 418U}})
|
||||
CHECK(reordered.admit(
|
||||
descend(static_cast<std::uint64_t>(id), static_cast<std::uint64_t>(parent), c)));
|
||||
CHECK(reordered.record_birth(90, 1, evo::Tick{0}));
|
||||
CHECK(reordered.record_birth(101, 5, evo::Tick{12}));
|
||||
CHECK(reordered.record_birth(100, 4, evo::Tick{10}));
|
||||
CHECK(reordered.record_death(100, evo::Tick{30}));
|
||||
CHECK(reordered.record_death(90, evo::Tick{0}));
|
||||
CHECK(reordered.encode() == bytes);
|
||||
// A child with a smaller identity than its parent still follows its parent.
|
||||
LineageArchive inverted;
|
||||
CHECK(inverted.admit(descend(50, 0)) && inverted.admit(descend(7, 50)));
|
||||
const auto inverted_bytes = inverted.encode();
|
||||
CHECK(LineageArchive::decode(inverted_bytes));
|
||||
LineageArchive empty;
|
||||
CHECK(LineageArchive::decode(empty.encode()) && empty.encode().size() == 40);
|
||||
}
|
||||
|
||||
void the_archive_decoder_refuses_damage_and_disorder() {
|
||||
const auto bytes = with_history().encode();
|
||||
const auto refused = [&](auto change, ArchiveCodecError error, bool seal = true) {
|
||||
auto b = bytes;
|
||||
change(b);
|
||||
if (seal)
|
||||
reseal(b);
|
||||
const auto d = LineageArchive::decode(b);
|
||||
return !d && d.error() == error;
|
||||
};
|
||||
CHECK(refused([](auto& b) { b[40] ^= 1U; }, ArchiveCodecError::checksum, false));
|
||||
CHECK(refused([](auto& b) { b[0] ^= 1U; }, ArchiveCodecError::format));
|
||||
CHECK(refused([](auto& b) { b[8] = 2; }, ArchiveCodecError::version));
|
||||
CHECK(refused([](auto& b) { b[12] = 2; }, ArchiveCodecError::version));
|
||||
CHECK(refused([](auto& b) { set(b, 16, max_archived_genomes + 1, 4); },
|
||||
ArchiveCodecError::bounds));
|
||||
CHECK(refused([](auto& b) { set(b, 20, max_archived_organisms + 1, 4); },
|
||||
ArchiveCodecError::bounds));
|
||||
CHECK(refused([](auto& b) { set(b, 24, b.size() + 1, 8); }, ArchiveCodecError::format));
|
||||
CHECK(refused(
|
||||
[](auto& b) {
|
||||
b.insert(b.end() - 8, 0);
|
||||
set(b, 24, b.size(), 8);
|
||||
},
|
||||
ArchiveCodecError::format));
|
||||
CHECK(refused([](auto& b) { set(b, 20, 2, 4); }, ArchiveCodecError::format));
|
||||
// Genome body damage (its own digest), then an organism record naming no genome.
|
||||
CHECK(refused([](auto& b) { b[40] ^= 1U; }, ArchiveCodecError::genome));
|
||||
const auto organisms = bytes.size() - 8 - (3 * archived_organism_bytes);
|
||||
CHECK(refused([&](auto& b) { set(b, organisms + 8, 77, 8); }, ArchiveCodecError::history));
|
||||
CHECK(refused([&](auto& b) { b[organisms + 32] = 2; }, ArchiveCodecError::format));
|
||||
// Alive with a death tick; death before birth; organisms out of order.
|
||||
const auto alive = organisms + (2 * archived_organism_bytes); // Organism 101.
|
||||
CHECK(refused([&](auto& b) { set(b, alive + 24, 5, 8); }, ArchiveCodecError::format));
|
||||
const auto dead = organisms + archived_organism_bytes; // Organism 100.
|
||||
CHECK(refused([&](auto& b) { set(b, dead + 24, 9, 8); }, ArchiveCodecError::history));
|
||||
CHECK(refused(
|
||||
[&](auto& b) {
|
||||
std::swap_ranges(b.begin() + static_cast<std::ptrdiff_t>(organisms),
|
||||
b.begin() + static_cast<std::ptrdiff_t>(organisms + 33),
|
||||
b.begin() + static_cast<std::ptrdiff_t>(dead));
|
||||
},
|
||||
ArchiveCodecError::noncanonical));
|
||||
// A child encoded before its parent is refused by admission itself.
|
||||
LineageArchive pair;
|
||||
CHECK(pair.admit(descend(1, 0)) && pair.admit(descend(2, 1)));
|
||||
auto swapped = pair.encode();
|
||||
const auto first = field(swapped, 32, 2);
|
||||
std::vector<std::uint8_t> parent(swapped.begin() + 32,
|
||||
swapped.begin() + 34 + static_cast<std::ptrdiff_t>(first));
|
||||
std::vector<std::uint8_t> child(swapped.begin() + 34 + static_cast<std::ptrdiff_t>(first),
|
||||
swapped.end() - 8);
|
||||
std::ranges::copy(child, swapped.begin() + 32);
|
||||
std::ranges::copy(parent, swapped.begin() + 32 + static_cast<std::ptrdiff_t>(child.size()));
|
||||
reseal(swapped);
|
||||
const auto dangling = LineageArchive::decode(swapped);
|
||||
CHECK(!dangling && dangling.error() == ArchiveCodecError::history);
|
||||
CHECK(!LineageArchive::decode(std::span{bytes}.first(39)));
|
||||
}
|
||||
|
||||
void a_full_archive_round_trips() {
|
||||
LineageArchive archive;
|
||||
CHECK(archive.admit(descend(1, 0)));
|
||||
for (std::uint64_t id = 2; id <= max_archived_genomes; ++id)
|
||||
CHECK(archive.admit(descend(id, id - 1)));
|
||||
for (std::uint64_t o = 1; o <= max_archived_organisms; ++o) {
|
||||
CHECK(archive.record_birth(o, 1 + (o % max_archived_genomes), evo::Tick{o}));
|
||||
if (o % 3 == 0)
|
||||
CHECK(archive.record_death(o, evo::Tick{o + 1}));
|
||||
}
|
||||
const auto bytes = archive.encode();
|
||||
CHECK(bytes.size() <= max_archive_bytes);
|
||||
const auto decoded = LineageArchive::decode(bytes);
|
||||
CHECK(decoded && decoded->encode() == bytes && decoded->recorded() == max_archived_organisms);
|
||||
std::cout << "lineage_archive_full_bytes=" << bytes.size() << " max=" << max_archive_bytes
|
||||
<< '\n';
|
||||
}
|
||||
} // namespace
|
||||
int main() try {
|
||||
a_genome_outlives_every_organism_that_carried_it();
|
||||
@@ -263,6 +408,9 @@ int main() try {
|
||||
the_archive_cannot_be_replaced_or_rewound();
|
||||
the_archive_offers_no_way_to_forget();
|
||||
capacity_refuses_loudly_rather_than_dropping();
|
||||
the_archive_round_trips_canonically();
|
||||
the_archive_decoder_refuses_damage_and_disorder();
|
||||
a_full_archive_round_trips();
|
||||
std::cout << "PASS lineage retention, branching ancestry and provisional absence\n";
|
||||
return 0;
|
||||
} catch (...) {
|
||||
|
||||
Reference in New Issue
Block a user