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:
@@ -145,11 +145,11 @@ function signOut() {
|
||||
class ApiError extends Error {
|
||||
constructor(status, code) { super(code || `HTTP ${status}`); this.status = status; this.code = code; }
|
||||
}
|
||||
async function api(path, retry = true) {
|
||||
async function api(path, retry = true, method = 'GET') {
|
||||
const t = await token();
|
||||
if (!t) throw new ApiError(401, 'signed_out');
|
||||
const res = await fetch(path, { headers: { Authorization: `Bearer ${t}` }, cache: 'no-store' });
|
||||
if (res.status === 401 && retry) { access = null; return api(path, false); }
|
||||
const res = await fetch(path, { method, headers: { Authorization: `Bearer ${t}` }, cache: 'no-store' });
|
||||
if (res.status === 401 && retry) { access = null; return api(path, false, method); }
|
||||
if (!res.ok) {
|
||||
let code = null;
|
||||
try { code = (await res.json()).error; } catch { /* plain text */ }
|
||||
@@ -285,10 +285,70 @@ async function regionsPage() {
|
||||
{ key: 'sequence', label: 'Commits', num: true, render: (r) => fmtInt(r.sequence), sort: (r) => Number(r.sequence ?? -1) },
|
||||
{ key: 'committed_at', label: 'Last commit', render: (r) => fmtAgo(r.committed_at), sort: (r) => r.committed_at ?? 0 },
|
||||
{ key: 'build', label: 'Build', render: (r) => h('span', { class: 'mono', title: r.build || '' }, r.build ? r.build.slice(0, 12) : '—') },
|
||||
{ key: 'window_open', label: 'Sessions', render: windowBadge, sort: (r) => (r.window_open ? r.window_expires : 0) },
|
||||
{ key: 'viewable', label: '', render: (r) => (r.viewable ? h('a', { href: `#/regions/${r.region}` }, 'Open view →') : h('span', { class: 'muted' }, 'no view')) },
|
||||
], data.regions, { sortKey: 'region' }));
|
||||
}
|
||||
|
||||
function windowBadge(r) {
|
||||
return r.window_open ? h('span', { class: 'badge online', title: fmtTime(r.window_expires) }, `open · closes ${fmtAgo(r.window_expires)}`)
|
||||
: h('span', { class: 'muted' }, 'closed');
|
||||
}
|
||||
|
||||
// The region's session window (ADR-0087): who may connect, until when. Writes go through the
|
||||
// admin API as the signed-in admin; the region applies a change within about 5 seconds.
|
||||
function sessionWindowCard(region) {
|
||||
const card = h('div', { class: 'card' });
|
||||
const minutes = h('select', {}, [[30, '30 minutes'], [60, '1 hour'], [120, '2 hours'], [240, '4 hours']]
|
||||
.map(([m, label]) => h('option', { value: m, selected: m === 240 }, label)));
|
||||
const reason = h('input', { type: 'text', maxlength: 200, placeholder: 'Reason (optional)' });
|
||||
const note = h('div', { class: 'muted small' });
|
||||
let busy = false;
|
||||
const send = async (m) => {
|
||||
if (busy) return;
|
||||
if (m === 0 && !confirm(`Close sessions in region ${region}? Connected players are disconnected.`)) return;
|
||||
busy = true;
|
||||
try {
|
||||
const q = new URLSearchParams({ minutes: String(m) });
|
||||
if (reason.value.trim()) q.set('reason', reason.value.trim());
|
||||
await api(`/api/regions/${region}/session-window?${q}`, true, 'POST');
|
||||
reason.value = '';
|
||||
note.textContent = 'Saved. The region applies it within about 5 seconds.';
|
||||
} catch (e) {
|
||||
note.textContent = `Could not change the window: ${e.message}`;
|
||||
} finally {
|
||||
busy = false;
|
||||
load();
|
||||
}
|
||||
};
|
||||
const openButton = h('button', { class: 'primary', onclick: () => send(Number(minutes.value)) }, 'Open');
|
||||
const closeButton = h('button', { onclick: () => send(0) }, 'Close sessions');
|
||||
const status = h('div');
|
||||
const history = h('div');
|
||||
async function load() {
|
||||
try {
|
||||
const w = await api(`/api/regions/${region}/session-window`);
|
||||
const current = w.history[0];
|
||||
openButton.textContent = w.open ? 'Extend' : 'Open';
|
||||
closeButton.disabled = !w.open;
|
||||
status.replaceChildren(w.open
|
||||
? h('div', {}, h('span', { class: 'badge online' }, 'open'), ` until ${fmtTime(current.expires_at)} (closes ${fmtAgo(current.expires_at)})`)
|
||||
: h('div', {}, h('span', { class: 'badge' }, 'closed'), current && current.expires_at ? ` expired ${fmtAgo(current.expires_at)}` : ''));
|
||||
history.replaceChildren(w.history.length ? h('table', { class: 'compact' }, h('tbody', {}, w.history.slice(0, 8).map((x) =>
|
||||
h('tr', {}, h('td', {}, fmtAgo(x.created_at)),
|
||||
h('td', {}, x.expires_at ? `opened until ${new Date(x.expires_at * 1000).toLocaleTimeString()}` : 'closed'),
|
||||
h('td', { class: 'muted', title: x.author || '' }, (x.author || '').split(' (')[0]),
|
||||
h('td', { class: 'muted' }, x.reason || ''))))) : h('p', { class: 'muted' }, 'No window has been opened yet.'));
|
||||
} catch (e) {
|
||||
status.textContent = `Unavailable: ${e.message}`;
|
||||
}
|
||||
}
|
||||
card.replaceChildren(h('h2', {}, 'Session window'), status,
|
||||
h('div', { class: 'window-controls' }, minutes, openButton, closeButton), reason, note, history);
|
||||
load();
|
||||
return { card, load };
|
||||
}
|
||||
|
||||
// ---------- Region view ----------
|
||||
const channelNames = ['energy', 'carbon', 'nitrogen', 'phosphorus', 'other'];
|
||||
const css = (name) => getComputedStyle(document.documentElement).getPropertyValue(`--${name}`).trim();
|
||||
@@ -304,7 +364,8 @@ async function regionPage(region, params) {
|
||||
const show_ = { players: true, wildlife: true, pools: true, bubbles: true };
|
||||
const toggle = (k, label) => h('label', {}, h('input', { type: 'checkbox', checked: true, onchange: (e) => { show_[k] = e.target.checked; paint(); } }), label);
|
||||
const live = h('input', { type: 'checkbox', checked: true });
|
||||
let view = null, selected = null, timer = null;
|
||||
const sessions = sessionWindowCard(region);
|
||||
let view = null, selected = null, timer = null, beats = 0;
|
||||
let zoom = 1, panX = 0, panY = 0, drag = null;
|
||||
|
||||
show(
|
||||
@@ -314,6 +375,7 @@ async function regionPage(region, params) {
|
||||
h('div', { class: 'region-layout' },
|
||||
h('div', { class: 'canvas-wrap' }, canvas, tip, note),
|
||||
h('div', { class: 'side' },
|
||||
sessions.card,
|
||||
detail,
|
||||
h('div', { class: 'card' }, h('h2', {}, 'Show'), h('div', { class: 'toggles' },
|
||||
toggle('players', 'Player cells'), toggle('wildlife', 'Wildlife'), toggle('pools', 'Pools'), toggle('bubbles', 'Bubbles'))),
|
||||
@@ -495,7 +557,15 @@ async function regionPage(region, params) {
|
||||
status.className = 'error';
|
||||
}
|
||||
}
|
||||
const tick = () => { timer = setTimeout(async () => { if (live.checked && !document.hidden) await load(); tick(); }, 1000); };
|
||||
const tick = () => {
|
||||
timer = setTimeout(async () => {
|
||||
if (live.checked && !document.hidden) {
|
||||
await load();
|
||||
if (++beats % 10 === 0) sessions.load();
|
||||
}
|
||||
tick();
|
||||
}, 1000);
|
||||
};
|
||||
await load();
|
||||
tick();
|
||||
stopPage = () => { clearTimeout(timer); window.removeEventListener('resize', onResize); };
|
||||
|
||||
@@ -58,7 +58,7 @@ button {
|
||||
button:hover { border-color: var(--accent); }
|
||||
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
button.ghost { background: transparent; }
|
||||
input[type="search"] {
|
||||
input[type="search"], input[type="text"], select {
|
||||
font: inherit;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
@@ -182,3 +182,9 @@ dl.facts dd { margin: 0; }
|
||||
.toggles label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
|
||||
.error { color: var(--bad); }
|
||||
.center { display: grid; place-items: center; min-height: 50vh; text-align: center; }
|
||||
.window-controls { display: flex; gap: 8px; margin: 10px 0 8px; flex-wrap: wrap; }
|
||||
.side input[type="text"] { width: 100%; min-width: 0; }
|
||||
.small { font-size: 12px; margin-top: 6px; }
|
||||
table.compact { margin-top: 10px; font-size: 12.5px; background: transparent; }
|
||||
table.compact td { padding: 4px 6px; white-space: normal; }
|
||||
button:disabled { opacity: 0.5; cursor: default; }
|
||||
|
||||
Reference in New Issue
Block a user