feat(admin): session windows in SQL, opened from the admin portal (schema 62)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m33s
Foundation / postgres-tools (push) Successful in 2m14s
Foundation / server-image (push) Successful in 5m21s
Foundation / image (push) Successful in 6m18s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m33s
Foundation / postgres-tools (push) Successful in 2m14s
Foundation / server-image (push) Successful in 5m21s
Foundation / image (push) Successful in 6m18s
The dev session window moves from Git to SQL (ADR-0087 amendment): the admin portal opens, extends (30 min to 4 h from now) and closes it, and the cellular region re-reads it every 5 s with --session-window-source db. No push, sync or restart per window; a closed window keeps the region running instead of crash-looping. - Schema 62: append-only session_windows (4 h cap, no rewrites), load_session_window_v1 for the runtime group, admin_set_session_window_v1 and admin_session_windows_v1 for a dedicated admin group role, granted and audited each migration run when EVO_PG_ADMIN_ROLE is set (aevolution_admin in DEV). Schema 61's views are revoked from the runtime group. - RegionSessions admission switch: while closed every Hello is refused before signature work and closing closes open sessions (new sessions were still admitted after expiry before). - Admin API: GET/POST /api/regions/<n>/session-window, window state in the regions list; the portal's session-window card with history. - Git: REGION_SESSION_WINDOW and the pre-push refresh rule are removed; the policy check requires the database source and refuses a committed window. Needs the new image and the aevolution_admin role (with the portal's login in aevolution-admin-pg) before a sync. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,11 @@
|
||||
// GET /api/accounts/<uuid> one account and its life requests
|
||||
// GET /api/regions the world's regions, leases and heads
|
||||
// GET /api/regions/<n>/view the region's live view (render_cellular_admin_view)
|
||||
// GET /api/regions/<n>/session-window the current session window and its last changes
|
||||
// POST /api/regions/<n>/session-window?minutes=M[&reason=R]
|
||||
// opens or extends the window for M (1..240) minutes
|
||||
// from now, or closes it (M = 0), as the signed-in admin
|
||||
// (ADR-0087 amendment). No request body.
|
||||
namespace evo::server::admin {
|
||||
struct AdminAsset {
|
||||
std::string path; // "/index.html", ...; "/" serves "/index.html".
|
||||
@@ -52,11 +57,15 @@ class AdminApi {
|
||||
std::chrono::steady_clock::time_point now);
|
||||
|
||||
private:
|
||||
[[nodiscard]] OpsResponse api(std::string_view path, const broker::AccessTokenClaims& admin,
|
||||
[[nodiscard]] OpsResponse api(std::string_view method, std::string_view path,
|
||||
std::string_view query, const broker::AccessTokenClaims& admin,
|
||||
std::chrono::steady_clock::time_point now);
|
||||
[[nodiscard]] OpsResponse accounts(std::optional<std::string_view> account);
|
||||
[[nodiscard]] OpsResponse regions();
|
||||
[[nodiscard]] OpsResponse view(std::uint64_t region, std::chrono::steady_clock::time_point now);
|
||||
[[nodiscard]] OpsResponse window(std::uint64_t region);
|
||||
[[nodiscard]] OpsResponse set_window(std::uint64_t region, std::string_view query,
|
||||
const broker::AccessTokenClaims& admin);
|
||||
[[nodiscard]] std::optional<persistence::PgRows> query(const std::string& sql,
|
||||
std::vector<std::string> parameters);
|
||||
|
||||
@@ -80,4 +89,8 @@ class AdminApi {
|
||||
std::size_t limit);
|
||||
// JSON string literal (quotes included) with control characters escaped.
|
||||
[[nodiscard]] std::string json_string(std::string_view text);
|
||||
// The decoded value of `name` in a URL query ("a=1&b=x%20y"), or nullopt when absent or
|
||||
// malformed (bad escape, a decoded control character, over `limit` bytes).
|
||||
[[nodiscard]] std::optional<std::string> query_value(std::string_view query, std::string_view name,
|
||||
std::size_t limit = 200);
|
||||
} // namespace evo::server::admin
|
||||
|
||||
@@ -207,6 +207,11 @@ class RegionSessions {
|
||||
[[nodiscard]] const network::motion::ProbeMarkers& markers() const noexcept;
|
||||
// Closes every connection with `shutdown` (flushed by later polls).
|
||||
void shutdown(std::chrono::steady_clock::time_point now);
|
||||
// ADR-0087 session window: while closed, every Hello (grant or handoff ticket) is closed
|
||||
// with `shutdown` before signature work. Open by default; closing does not close the
|
||||
// connections already open (call shutdown for that).
|
||||
void set_admission(bool open) noexcept;
|
||||
[[nodiscard]] bool admitting() const noexcept;
|
||||
[[nodiscard]] std::vector<RegionSessionEvent> take_events();
|
||||
[[nodiscard]] std::optional<std::uint64_t> holder(const network::AccountId& account) const;
|
||||
[[nodiscard]] std::size_t sessions() const noexcept;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
@@ -67,4 +68,52 @@ class SessionWindow {
|
||||
bool closed_{};
|
||||
};
|
||||
|
||||
// ADR-0087 amendment (2026-10-27): the window as the database records it, re-read every few
|
||||
// seconds. A newer activation replaces the current window (sessions continue); a closed,
|
||||
// expired, over-long or absent record closes it. Each admitted window keeps its own absolute
|
||||
// deadline, and a window once closed never reopens: only a newer activation opens sessions
|
||||
// again. While the database cannot be read the caller does not observe, so the current
|
||||
// window keeps running to its deadline.
|
||||
class SessionWindowFeed {
|
||||
public:
|
||||
struct Record {
|
||||
std::string activation_id;
|
||||
std::optional<std::uint64_t> expires_at; // nullopt: the record closes the window.
|
||||
};
|
||||
enum class Change : std::uint8_t { none, opened, closed, refused };
|
||||
|
||||
// `record` is the region's newest row, or nullopt when it has none.
|
||||
Change observe(const std::optional<Record>& record, std::uint64_t now_seconds) {
|
||||
if (!record) {
|
||||
const bool had = window_.has_value();
|
||||
window_.reset();
|
||||
seen_.clear();
|
||||
return had ? Change::closed : Change::none;
|
||||
}
|
||||
if (record->activation_id == seen_)
|
||||
return Change::none;
|
||||
seen_ = record->activation_id;
|
||||
const bool had = window_.has_value();
|
||||
window_.reset();
|
||||
if (!record->expires_at)
|
||||
return had ? Change::closed : Change::none;
|
||||
auto opened = SessionWindow::open(
|
||||
record->activation_id + ":" + std::to_string(*record->expires_at), now_seconds);
|
||||
if (!opened)
|
||||
return Change::refused;
|
||||
window_ = std::move(*opened);
|
||||
return Change::opened;
|
||||
}
|
||||
[[nodiscard]] bool accepting(std::uint64_t now_seconds) noexcept {
|
||||
return window_ && window_->accepting(now_seconds);
|
||||
}
|
||||
[[nodiscard]] const std::optional<SessionWindow>& window() const noexcept {
|
||||
return window_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<SessionWindow> window_;
|
||||
std::string seen_; // The newest activation observed, admitted or not.
|
||||
};
|
||||
|
||||
} // namespace evo::server
|
||||
|
||||
Reference in New Issue
Block a user