From 9de55e352d6d8342da94dda8ee51757d24ab2c8a Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 29 Oct 2026 08:31:16 -0400 Subject: [PATCH] fix(cellular): one action per account a tick, never a refused tick Region 16 playtest: a bud showed and was then undone, and several buds were refused. The client scheduled a discrete action at server tick + lead, but movement runs ahead of that once the lead shrinks (each movement takes the tick after the last one sent), so a bud could name a tick a movement already had. A tick takes one action per account: the region refused the whole tick and dropped every player's actions on it ("tick stalled ... error=4"). - Server: keep_one_action_per_account keeps each account's discrete action (engulf, bud, become, emerge), else its newest, and refuses only the rest. - Client: a discrete action is scheduled after every tick already sent, and movement is held off the tick a queued discrete action owns. - Failed background commits now log their category, publication error, store error and SQLSTATE (never server text), to diagnose ok=0 commits. Co-Authored-By: Claude Opus 5.5 --- apps/evo-client/remote_session.hpp | 16 ++++++++--- apps/evo-server/main.cpp | 16 +++++++++++ docs/STATUS.md | 10 +++++++ include/evo/server/cellular_session_batch.hpp | 7 +++++ src/server/session/cellular_session_batch.cpp | 27 +++++++++++++++++++ tests/cellular_session_batch_tests.cpp | 18 +++++++++++++ 6 files changed, 90 insertions(+), 4 deletions(-) diff --git a/apps/evo-client/remote_session.hpp b/apps/evo-client/remote_session.hpp index 2ab8f5e..8c59fca 100644 --- a/apps/evo-client/remote_session.hpp +++ b/apps/evo-client/remote_session.hpp @@ -265,10 +265,13 @@ class RemoteSession { [[nodiscard]] bool request_cellular(CellAction kind, MutationChoice choice = {}, bool become = false) { const auto lead = cellular_lead_.lead(); - const auto tick = - kind == CellAction::mutation - ? server_tick_ - : server_tick_ + lead + (sent_tick_ && *sent_tick_ == server_tick_ ? 1 : 0); + // A tick takes one action per account: never one a movement already named (movement + // runs ahead of the lead after the lead shrinks). + const auto tick = kind == CellAction::mutation + ? server_tick_ + : std::max(server_tick_ + lead + + (sent_tick_ && *sent_tick_ == server_tick_ ? 1 : 0), + cellular_sent_tick_ + 1); if (!cellular_trial_ || !cellular_play_.queue(kind, tick, choice, become)) return false; action_check_at_ = {}; @@ -630,6 +633,11 @@ class RemoteSession { // trails it by the replication delay, so schedule by the adaptive lead. // Strictly increasing even when the lead shrinks: one movement per tick. const auto tick = std::max(server_tick_ + cellular_lead_.lead(), cellular_sent_tick_ + 1); + // A queued discrete action owns its tick; movement resumes after it is sent. + if (const auto& p = cellular_play_.pending(); p && p->state == CellActionState::queued && + p->kind != CellAction::mutation && + p->tick <= tick) + return; const auto steering = steer_cellular(cellular_controls_, intention, cellular_perception(), organisms_.current(), cellular_feed_target_); cellular_feed_target_ = steering.patch; diff --git a/apps/evo-server/main.cpp b/apps/evo-server/main.cpp index 309d615..a361fec 100644 --- a/apps/evo-server/main.cpp +++ b/apps/evo-server/main.cpp @@ -1038,6 +1038,18 @@ int serve_cellular(Options& o) { std::printf("cellular commit ticks=%zu ms=%lld handoff_ms=%lld ok=%d\n", flight_ticks, static_cast(commit_ms), flight_handoff_ms, *landed ? 1 : 0); + if (!*landed) { + // Categories and SQLSTATE only (never server text); -1 when not reported. + const auto& failure = landed->error(); + const auto store = failure.store.value_or(persistence::LeaseStoreFailure{}); + std::printf("cellular commit failed host=%u publication=%d store=%d " + "sqlstate=%.5s object=%d\n", + static_cast(failure.kind), + failure.publication ? static_cast(*failure.publication) : -1, + failure.store ? static_cast(store.kind) : -1, + failure.store ? store.cause.sqlstate.data() : "-", + failure.object ? static_cast(*failure.object) : -1); + } if (*landed) { host.refuse_births(flight_refusals); flight_actions.clear(); @@ -1325,6 +1337,10 @@ int serve_cellular(Options& o) { }); bridge->dropped(departed, true); } + // One action per account a tick; a second would refuse the whole tick. + if (const auto superseded = server::keep_one_action_per_account(actions); + !superseded.empty()) + bridge->dropped(superseded, true); if (!batch_builder) { auto created = server::CellularSessionBatchBuilder::create( *state, host.committed()->head); diff --git a/docs/STATUS.md b/docs/STATUS.md index 15e2e06..e166836 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -1,5 +1,15 @@ # Project status and next steps +## One action per account a tick - 2026-10-29 + +Region 16 playtest: a bud was shown, then undone, and several were "refused". The client +scheduled a bud at the server tick plus its lead, while movement had run ahead of that after the +lead shrank, so both named one tick. A tick takes one action per account, so the region refused +the whole tick and dropped every player's actions on it (`tick stalled ... error=4`). The region +now keeps each account's discrete action (else its newest) and refuses only the others; the client +schedules a discrete action after every tick it already sent and holds movement off that tick. +Failed commits now log their category and SQLSTATE. + ## Ending a stranded life - 2026-10-29 The portal's account page can end a published life whose reservation was never ended, which diff --git a/include/evo/server/cellular_session_batch.hpp b/include/evo/server/cellular_session_batch.hpp index cdc2289..d9ee8ff 100644 --- a/include/evo/server/cellular_session_batch.hpp +++ b/include/evo/server/cellular_session_batch.hpp @@ -47,6 +47,13 @@ prepare_cellular_session_tick( std::span actions, std::span mutations = {}); +// A tick takes one action per account. Keeps each account's discrete action (engulf, bud, +// become, emerge), else its newest (highest id), in `actions`, and returns the others, which +// the caller refuses. A client naming a tick it already sent a movement for then loses only +// that movement, not every player's actions on the tick. +[[nodiscard]] std::vector +keep_one_action_per_account(std::vector& actions); + // Builds one bounded publication from the last durable head. Its working copy is private; // only the host may publish, and callers must discard it after uncertainty until the host // resolves that exact prepared batch. diff --git a/src/server/session/cellular_session_batch.cpp b/src/server/session/cellular_session_batch.cpp index c9aed45..62288d6 100644 --- a/src/server/session/cellular_session_batch.cpp +++ b/src/server/session/cellular_session_batch.cpp @@ -170,6 +170,33 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick, return prepared; } +std::vector +keep_one_action_per_account(std::vector& actions) { + const auto discrete = [](const network::CarriedAction& action) { + if (!action.cellular_input) + return false; + const auto input = network::decode_cellular_action_input(*action.cellular_input); + return input && (input->engulf || input->bud || input->become || input->emerge); + }; + std::vector kept, superseded; + kept.reserve(actions.size()); + for (const auto& action : actions) { + const auto same = std::ranges::find_if(kept, [&](const network::CarriedAction& other) { + return other.account.bytes == action.account.bytes; + }); + if (same == kept.end()) { + kept.push_back(action); + continue; + } + const bool replaces = discrete(action) != discrete(*same) + ? discrete(action) + : action.action_id > same->action_id; + superseded.push_back(replaces ? std::exchange(*same, action) : action); + } + actions = std::move(kept); + return superseded; +} + std::expected CellularSessionBatchBuilder::create(const CellularLives& committed_state, const persistence::RegionHead& committed_head) { diff --git a/tests/cellular_session_batch_tests.cpp b/tests/cellular_session_batch_tests.cpp index 42fdcdf..dd45007 100644 --- a/tests/cellular_session_batch_tests.cpp +++ b/tests/cellular_session_batch_tests.cpp @@ -174,6 +174,24 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() { const std::array duplicate{action, action}; CHECK(prepare_cellular_session_tick(**state, 2, baseline, duplicate).error() == CellularSessionBatchError::duplicate_action); + // Two actions of one account on one tick: the discrete one is kept, even when older, + // so the tick is not refused for every player; between movements the newest is kept. + { + const network::CarriedAction bud{network::AccountId{controlled.account}, 80, 2, + network::ActionKind::cellular, bud_input}; + auto later = action; + later.action_id = 90; + std::vector both{bud, later}; + const auto superseded = keep_one_action_per_account(both); + CHECK(both.size() == 1 && both[0] == bud && superseded.size() == 1 && + superseded[0] == later); + CHECK(prepare_cellular_session_tick(**state, 2, baseline, both)); + std::vector moves{action, later}; + CHECK(keep_one_action_per_account(moves) == std::vector{action} && moves.size() == 1 && + moves[0] == later); + std::vector single{action}; + CHECK(keep_one_action_per_account(single).empty() && single.size() == 1); + } auto unknown = action; unknown.account.bytes.back() = 3; const std::array unknown_actions{unknown};