Add channel-limited cellular uptake proposal
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 3m14s
Foundation / checks (checks) (push) Canceled after 3m19s
Foundation / checks (network) (push) Canceled after 1m19s

This commit is contained in:
dingo
2026-10-10 21:11:00 -04:00
parent a97c5f3204
commit c552eb3250
7 changed files with 178 additions and 3 deletions
+6 -1
View File
@@ -69,7 +69,7 @@ evo_owned_target(evo_accounting)
add_library(evo_biology STATIC add_library(evo_biology STATIC
src/biology/genome.cpp src/biology/development.cpp src/biology/metabolism.cpp src/biology/genome.cpp src/biology/development.cpp src/biology/metabolism.cpp
src/biology/mutation.cpp src/biology/lineage.cpp src/biology/founder.cpp src/biology/mutation.cpp src/biology/lineage.cpp src/biology/founder.cpp
src/biology/cellular_motion.cpp) src/biology/cellular_motion.cpp src/biology/cellular_uptake.cpp)
add_library(evo::biology ALIAS evo_biology) add_library(evo::biology ALIAS evo_biology)
target_include_directories(evo_biology PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_include_directories(evo_biology PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(evo_biology PUBLIC evo::accounting) target_link_libraries(evo_biology PUBLIC evo::accounting)
@@ -429,6 +429,11 @@ if(BUILD_TESTING)
evo_owned_target(evo-cellular-motion-tests) evo_owned_target(evo-cellular-motion-tests)
add_test(NAME cellular-motion-contracts COMMAND evo-cellular-motion-tests) add_test(NAME cellular-motion-contracts COMMAND evo-cellular-motion-tests)
set_tests_properties(cellular-motion-contracts PROPERTIES TIMEOUT 60) set_tests_properties(cellular-motion-contracts PROPERTIES TIMEOUT 60)
add_executable(evo-cellular-uptake-tests tests/cellular_uptake_tests.cpp)
target_link_libraries(evo-cellular-uptake-tests PRIVATE evo::biology)
evo_owned_target(evo-cellular-uptake-tests)
add_test(NAME cellular-uptake-contracts COMMAND evo-cellular-uptake-tests)
set_tests_properties(cellular-uptake-contracts PROPERTIES TIMEOUT 60)
add_executable(evo-primitive-lives-tests tests/primitive_lives_tests.cpp) add_executable(evo-primitive-lives-tests tests/primitive_lives_tests.cpp)
target_link_libraries(evo-primitive-lives-tests PRIVATE evo::lifecycle) target_link_libraries(evo-primitive-lives-tests PRIVATE evo::lifecycle)
evo_owned_target(evo-primitive-lives-tests) evo_owned_target(evo-primitive-lives-tests)
@@ -38,6 +38,10 @@ not depend on graphics, networking or database code.
server-owned atomic operation. C, N, P, other and energy remain separate server-owned atomic operation. C, N, P, other and energy remain separate
conserved channels. Any conversion between tags needs an explicit biological conserved channels. Any conversion between tags needs an explicit biological
rule; water, incident energy and heat are not edible reserve by relabeling. rule; water, incident energy and heat are not edible reserve by relabeling.
- An absorption proposal moves each acquired channel into the living cell's
reserve, not directly into its fully formed body or growth state. Food matter
remains there for later funded development/reproduction; usable energy is
available for movement and maintenance. Absorption alone builds no tissue.
- The habitat opening, depletion, organism balances and transfer/retry state - The habitat opening, depletion, organism balances and transfer/retry state
belong to the cellular checkpoint closure. A crash cannot publish only one belong to the cellular checkpoint closure. A crash cannot publish only one
side of a transfer. Profile-3 creation checkpoints and M6 field snapshots side of a transfer. Profile-3 creation checkpoints and M6 field snapshots
+3 -2
View File
@@ -43,8 +43,9 @@ patches without client authority over speed or position.
Checked quotient/remainder arithmetic is required; overflow refuses the whole step. Checked quotient/remainder arithmetic is required; overflow refuses the whole step.
A zero per-tick speed or zero displacement costs zero. The movement resolver A zero per-tick speed or zero displacement costs zero. The movement resolver
reports a proposed cost; the state owner applies the move only if the reserve reports a proposed cost; the state owner applies the move only if the reserve
can fund that cost. This resolver does not also spend maintenance, which can fund that cost, then transfers the spent energy to the heat sink in the
remains a separate tick-ordered biological cost. same candidate state. This resolver does not also spend maintenance, which
remains a separate tick-ordered cost from reserve to heat.
- The body footprint determines which patch squares it overlaps. Contact - The body footprint determines which patch squares it overlaps. Contact
candidates are returned in canonical patch-address order; an exact boundary candidates are returned in canonical patch-address order; an exact boundary
touch counts as contact. Feeding limits, simultaneous claims, predation touch counts as contact. Feeding limits, simultaneous claims, predation
+16
View File
@@ -5838,3 +5838,19 @@ build target idled at 0 CPU and was stopped; the test executable was compiled
directly and then run by CTest. Linux GCC, ASan+UBSan and server/PostgreSQL process directly and then run by CTest. Linux GCC, ASan+UBSan and server/PostgreSQL process
qualification remain pending CI. This small resolver does not make 11.3 or a qualification remain pending CI. This small resolver does not make 11.3 or a
playtest-ready cellular stage complete. playtest-ready cellular stage complete.
## 2026-10-10 — M11.3c-1 channel-limited uptake proposal (CI pending)
Added a pure uptake proposal that computes each 50 ms intake capacity from the
development-v2 per-second budget, then independently bounds energy and C/N/P/other
by patch stock and reserve headroom. It returns both post-transfer inventories and
the exact amount acquired; it does not mutate either side, so the cellular host can
publish them as one candidate. ADR-0101 now states that absorbed material accumulates
in reserve without changing the fully formed body.
Executed locally: MSVC 19.44 warning-as-error Debug compile/link and focused CTest
(1/1 passed); direct Release/NDEBUG compile/run (passed); clang-format 19.1.5
dry-run; clang-tidy 19.1.5 against the generated compile database; and
`git diff --check`. Linux GCC and sanitizer runs are unavailable locally; the full
cellular-owner conservation, contention, durable publication and PostgreSQL process
checks remain pending CI. This helper does not yet close the server-side transfer.
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include "evo/biology/metabolism.hpp"
#include <compare>
#include <expected>
namespace evo::biology {
struct CellularUptakeProposal {
accounting::Inventory patch_after;
accounting::Inventory reserve_after;
accounting::Inventory acquired;
auto operator<=>(const CellularUptakeProposal&) const = default;
};
enum class CellularUptakeError : std::uint8_t { unsupported_rate_period, overflow };
// Pure, channel-by-channel uptake proposal for one 50 ms tick from a patch
// already confirmed in contact. The caller commits patch and reserve together.
[[nodiscard]] std::expected<CellularUptakeProposal, CellularUptakeError>
propose_cellular_uptake(accounting::Inventory patch, accounting::Inventory reserve,
const MetabolicBudget& budget) noexcept;
} // namespace evo::biology
+50
View File
@@ -0,0 +1,50 @@
#include "evo/biology/cellular_uptake.hpp"
#include "evo/accounting/rates.hpp"
#include "evo/biology/cellular_motion.hpp"
#include <algorithm>
#include <limits>
namespace evo::biology {
namespace {
constexpr std::uint64_t rate_period_microseconds = 1'000'000;
std::uint64_t take(std::uint64_t stock, std::uint64_t reserve, std::uint64_t rate_limit) noexcept {
const auto room = std::numeric_limits<std::uint64_t>::max() - reserve;
return std::min({stock, rate_limit, room});
}
} // namespace
std::expected<CellularUptakeProposal, CellularUptakeError>
propose_cellular_uptake(accounting::Inventory patch, accounting::Inventory reserve,
const MetabolicBudget& budget) noexcept {
if (budget.rate_microseconds != rate_period_microseconds)
return std::unexpected{CellularUptakeError::unsupported_rate_period};
const auto energy_limit =
accounting::per_tick(budget.intake_limit.energy.value, cellular_motion_tick_microseconds,
accounting::Rounding::down);
if (!energy_limit)
return std::unexpected{CellularUptakeError::overflow};
CellularUptakeProposal proposal{patch, reserve, {}};
const auto energy = take(patch.energy.value, reserve.energy.value, *energy_limit);
proposal.acquired.energy.value = energy;
proposal.patch_after.energy.value -= energy;
proposal.reserve_after.energy.value += energy;
for (std::size_t channel = 0; channel < proposal.acquired.matter.size(); ++channel) {
const auto limit =
accounting::per_tick(budget.intake_limit.matter[channel].value,
cellular_motion_tick_microseconds, accounting::Rounding::down);
if (!limit)
return std::unexpected{CellularUptakeError::overflow};
const auto amount =
take(patch.matter[channel].value, reserve.matter[channel].value, *limit);
proposal.acquired.matter[channel].value = amount;
proposal.patch_after.matter[channel].value -= amount;
proposal.reserve_after.matter[channel].value += amount;
}
return proposal;
}
} // namespace evo::biology
+77
View File
@@ -0,0 +1,77 @@
#include "evo/biology/cellular_uptake.hpp"
#include <cstdio>
#include <limits>
#include <source_location>
#include <stdexcept>
#include <string>
namespace {
using namespace evo::biology;
using evo::accounting::Inventory;
void check(bool value, std::source_location at = std::source_location::current()) {
if (!value)
throw std::runtime_error("cellular uptake line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
MetabolicBudget budget() {
MetabolicBudget result{};
result.rate_microseconds = 1'000'000;
result.intake_limit = {{1'001}, {{{101}, {53}, {31}, {17}}}};
return result;
}
void channel_limited_atomic_proposal() {
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
const Inventory patch{{101}, {{{100}, {1}, {100}, {50}}}};
const Inventory reserve{{49}, {{{maximum - 3}, {0}, {0}, {0}}}};
const auto result = propose_cellular_uptake(patch, reserve, budget());
CHECK(result);
CHECK(result->acquired == Inventory{{50}, {{{3}, {1}, {1}, {0}}}});
CHECK(result->patch_after == Inventory{{51}, {{{97}, {0}, {99}, {50}}}});
CHECK(result->reserve_after == Inventory{{99}, {{{maximum}, {1}, {1}, {0}}}});
CHECK(result->patch_after.energy.value + result->reserve_after.energy.value ==
patch.energy.value + reserve.energy.value);
for (std::size_t channel = 0; channel < patch.matter.size(); ++channel) {
CHECK(patch.matter[channel].value - result->patch_after.matter[channel].value ==
result->acquired.matter[channel].value);
CHECK(result->reserve_after.matter[channel].value - reserve.matter[channel].value ==
result->acquired.matter[channel].value);
}
}
void empty_and_full_channels() {
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
const auto no_stock = propose_cellular_uptake({}, {}, budget());
CHECK(no_stock && no_stock->acquired == Inventory{} && no_stock->patch_after == Inventory{});
Inventory patch{};
patch.energy.value = maximum;
patch.matter.fill({maximum});
Inventory reserve{};
reserve.energy.value = maximum;
reserve.matter.fill({maximum});
const auto full = propose_cellular_uptake(patch, reserve, budget());
CHECK(full && full->acquired == Inventory{});
CHECK(full->patch_after == patch && full->reserve_after == reserve);
}
void unsupported_rate_period() {
auto invalid = budget();
invalid.rate_microseconds = 50'000;
CHECK(!propose_cellular_uptake({}, {}, invalid));
}
} // namespace
int main() {
try {
channel_limited_atomic_proposal();
empty_and_full_channels();
unsupported_rate_period();
std::puts("PASS cellular uptake: finite channel limits and atomic proposal");
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}
}