ADR 0127
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m23s
Foundation / checks (tsan) (push) Successful in 10m11s
Foundation / checks (client) (push) Failing after 14m26s
Foundation / checks (network) (push) Successful in 18m54s
Foundation / checks (checks) (push) Successful in 42m9s
Foundation / checks (postgres) (push) Successful in 43m51s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-15 09:32:51 -04:00
parent 0a0f6c3bb1
commit 817a830a8a
20 changed files with 474 additions and 28 deletions
+35 -1
View File
@@ -33,6 +33,10 @@ struct CellActionRecord {
MutationChoice choice{};
network::AdmitStatus refusal{network::AdmitStatus::admitted};
};
struct CellEnergyChange {
std::uint64_t from_tick{}, to_tick{}, amount{};
bool falling{};
};
class CellularPlay {
public:
@@ -54,6 +58,8 @@ class CellularPlay {
void disconnected() {
connected_ = false;
fresh_ = false;
energy_sample_.reset();
energy_change_.reset();
offer_.reset();
if (pending_) {
if (pending_->state == CellActionState::queued) {
@@ -71,6 +77,20 @@ class CellularPlay {
fresh_ = true;
if (ended_ && view.life_identity == ended_->life_identity)
return; // A retained pre-death view must never revive this identity.
if (view.life_identity != 0 && view.diagnostics) {
const auto energy = view.diagnostics->reserve_energy_pj;
if (energy_sample_ && energy_sample_->life == view.life_identity) {
if (view.tick > energy_sample_->tick)
energy_change_ = CellEnergyChange{energy_sample_->tick, view.tick,
energy < energy_sample_->energy
? energy_sample_->energy - energy
: energy - energy_sample_->energy,
energy < energy_sample_->energy};
} else {
energy_change_.reset();
}
energy_sample_ = EnergySample{view.life_identity, view.tick, energy};
}
// Never replay an intention onto a later life. Keep its uncertain result visible.
if (life_ != view.life_identity) {
offer_.reset();
@@ -95,6 +115,7 @@ class CellularPlay {
}
if (life_ != 0) {
birth_pending_ = false;
birth_result_ = network::PrimitiveLifeResult::born;
if (ended_ && ended_->life_identity != life_)
ended_.reset();
}
@@ -201,7 +222,11 @@ class CellularPlay {
finish();
}
[[nodiscard]] bool can_restart() const {
return connected_ && fresh_ && life_ == 0 && !birth_pending_;
const bool refused = birth_result_ == network::PrimitiveLifeResult::insufficient_funding ||
birth_result_ == network::PrimitiveLifeResult::no_placement ||
birth_result_ == network::PrimitiveLifeResult::cancelled;
return connected_ && (fresh_ || refused) && life_ == 0 && !birth_pending_ &&
(birth_result_ != network::PrimitiveLifeResult::existing_life || ended_);
}
[[nodiscard]] bool restart() {
if (!can_restart())
@@ -211,6 +236,7 @@ class CellularPlay {
return false;
birth_request_ = id;
birth_pending_ = true;
birth_result_ = network::PrimitiveLifeResult::pending;
return true;
}
void birth(const network::PrimitiveLifeOutcome& result) {
@@ -258,6 +284,9 @@ class CellularPlay {
[[nodiscard]] const auto& bud_feedback() const {
return bud_feedback_;
}
[[nodiscard]] const auto& energy_change() const {
return energy_change_;
}
private:
void finish() {
@@ -277,5 +306,10 @@ class CellularPlay {
std::deque<CellActionRecord> history_;
std::optional<std::pair<std::uint64_t, network::CellularEngulfResult>> engulf_feedback_;
std::optional<std::pair<std::uint64_t, network::CellularBudOutcome>> bud_feedback_;
struct EnergySample {
std::uint64_t life{}, tick{}, energy{};
};
std::optional<EnergySample> energy_sample_;
std::optional<CellEnergyChange> energy_change_;
};
} // namespace evo::client_app