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

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:
dingo
2026-10-27 15:13:02 -04:00
co-authored by Claude Opus 5.5
parent 510ecaee80
commit 46c106409e
31 changed files with 807 additions and 93 deletions
+8 -18
View File
@@ -44,8 +44,9 @@ import re
# restart after expiry, delayed application, extend/close races, clock movement,
# synthetic inputs stopping while commits drain). The runtime contract and focused
# expiry tests are now implemented in the M10 QUIC
# bridge. The route remains constrained to the dev overlay and a committed absolute
# window; delayed application fails closed in the server.
# bridge. The route remains constrained to the dev overlay. Since the ADR-0087 amendment of
# 2026-10-27 the window lives in SQL (evolution.session_windows, set from the admin portal)
# and the region re-reads it; Git carries no window.
ROUTE_ENABLING_PERMITTED = True
# Addresses the route may use: RFC 1918 plus internal ranges the maintainer has
# explicitly approved in ADR-0087 (none yet; the cluster LAN 172.10.0.0/16 is not
@@ -703,22 +704,11 @@ for overlay, docs in renders.items():
check(env.get('REGION_SESSION_LISTEN') == listen,
f'{where}: REGION_SESSION_LISTEN must be {listen} (route {"on" if route_active else "off"})')
check(text.count('--m10-listen') == 1 and '--m10-listen "$REGION_SESSION_LISTEN"' in text
and '--session-window "$REGION_SESSION_WINDOW"' in text,
f'{where}: one M10 listener and absolute session window, addressed only by GitOps env')
# The server refuses a window ending more than 4 h after it starts
# (SessionWindow::max_duration_seconds) and exits in a loop. The id carries
# its UTC activation (dev-YYYYMMDDTHHMMSS-...); the expiry must fall within
# 4 h of it. Checked here because the server sees it only at startup.
window = env.get('REGION_SESSION_WINDOW') or ''
if route_active and window:
import calendar, re, time
m = re.fullmatch(r'[0-9A-Za-z._-]*?(\d{8}T\d{6})Z?[0-9A-Za-z._-]*:(\d+)', window)
ok = False
if m:
start = calendar.timegm(time.strptime(m.group(1), '%Y%m%dT%H%M%S'))
ok = start < int(m.group(2)) <= start + 4 * 60 * 60
check(ok, f'{where}: REGION_SESSION_WINDOW must name its UTC activation and end '
'within 4 h of it (the server maximum)')
and '--session-window-source db' in text and '--session-window ' not in text,
f'{where}: one M10 listener whose session window is read from SQL (ADR-0087)')
# The window lives in SQL; a Git-committed one would never be read.
check('REGION_SESSION_WINDOW' not in env,
f'{where}: the session window lives in SQL, not in REGION_SESSION_WINDOW')
else:
check('--m10-listen' not in text and '--synthetic-inputs' not in text,
f'{where}: only evo-server may listen for sessions')
+7 -7
View File
@@ -132,14 +132,14 @@ CASES = [
('non-RFC 1918 VIP without approval', lambda t: edit(t, ROUTE + 'service.yaml', '172.10.1.202',
'172.11.1.210'), 'internal address'),
# Review M9.8f P1: inline/JSON patches and namespace changes, seen only when rendered.
('session window longer than the server maximum', lambda t: inline_patch(
('session window committed to Git again', lambda t: inline_patch(
t, 'deploy/kubernetes/dev/kustomization.yaml',
env_patch('REGION_SESSION_WINDOW', 'dev-20261008T111342-32432:1791477222')),
'end within 4 h of it'),
('session window without an activation time', lambda t: inline_patch(
t, 'deploy/kubernetes/dev/kustomization.yaml',
env_patch('REGION_SESSION_WINDOW', 'dev-manual:1791477222')),
'end within 4 h of it'),
'the session window lives in SQL'),
('fixed session window argument', lambda t: edit(
t, 'deploy/kubernetes/region/base/deployment.yaml', '--session-window-source db',
'--session-window "$REGION_SESSION_LISTEN"'),
'session window is read from SQL'),
('inline patch: synthetic inputs on', lambda t: inline_patch(
t, 'deploy/kubernetes/dev/kustomization.yaml', env_patch('REGION_INPUTS', 'development-v1')),
'sessions must be dev only with the route'),
@@ -155,7 +155,7 @@ CASES = [
{'kind': 'Deployment', 'name': 'evo-region'}), 'container ports must be'),
('JSON patch: second listener argument', lambda t: inline_patch(
t, DEV, '- op: add\n path: /spec/template/spec/containers/0/args/-\n value: --m10-listen 0.0.0.0:7401\n',
{'kind': 'Deployment', 'name': 'evo-region'}), 'one M10 listener and absolute session window'),
{'kind': 'Deployment', 'name': 'evo-region'}), 'one M10 listener whose session window is read from SQL'),
('namespace transformation', lambda t: edit(t, DEV, 'namespace: evolution-dev', 'namespace: evolution-stage'),
'expected evolution-dev'),
('inline quota patch in stage', lambda t: inline_patch(
+4
View File
@@ -75,6 +75,10 @@ awk '/^CREATE FUNCTION evolution\.(publish_cellular_checkpoint|publish_cellular_
awk '/^CREATE OR REPLACE FUNCTION evolution\.valid_cellular_action_input\(/ {capture=1} capture {print} capture && /^END \$\$;/ {capture=0}' \
"$root/migrations/0036_cellular_v5_budding_bundle.sql" | sql > /dev/null
sql -v runtime_role="$EVO_PG_RUNTIME_ROLE" > /dev/null <<'SQL'
DROP FUNCTION evolution.admin_session_windows_v1(evolution.u64,evolution.u64);
DROP FUNCTION evolution.admin_set_session_window_v1(evolution.u64,evolution.u64,integer,text,text);
DROP FUNCTION evolution.load_session_window_v1(evolution.u64,evolution.u64);
DROP TABLE evolution.session_windows;
DROP FUNCTION evolution.admin_regions_v1(evolution.u64);
DROP FUNCTION evolution.admin_account_lives_v1(evolution.u64,uuid);
DROP FUNCTION evolution.admin_accounts_v1(evolution.u64);
+9 -5
View File
@@ -71,6 +71,10 @@ fi
psql -X -v ON_ERROR_STOP=1 -c 'CREATE ROLE evo_runtime_test NOLOGIN' \
-c 'CREATE ROLE evo_runtime_login LOGIN IN ROLE evo_runtime_test'
export EVO_PG_RUNTIME_ROLE=evo_runtime_test EVO_PG_RUNTIME_USER=evo_runtime_login
# ADR-0182: the admin API's own group role and login, outside the runtime group.
psql -X -v ON_ERROR_STOP=1 -c 'CREATE ROLE evo_admin_test NOLOGIN' \
-c 'CREATE ROLE evo_admin_login LOGIN IN ROLE evo_admin_test'
export EVO_PG_ADMIN_ROLE=evo_admin_test EVO_PG_ADMIN_USER=evo_admin_login
phase migrate
bash "$root/tools/migrate-postgres.sh"
bash "$root/tools/migrate-postgres.sh" # exact supported upgrade/restart is a no-op
@@ -168,7 +172,7 @@ PGDATABASE=upgrade_path psql -X -v ON_ERROR_STOP=1 -1 -v "migration_sha=$v1_sha"
-f "$root/migrations/0001_region_bootstrap.sql" > /dev/null
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',') FROM evolution.schema_migrations")" = 1
PGDATABASE=upgrade_path bash "$root/tools/migrate-postgres.sh"
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62
# v2 heads have no payload binding: v2->v3 fails closed and leaves history at v2.
v2_sha="$(sha256sum "$root/migrations/0002_region_fencing.sql")"
v2_sha="${v2_sha%% *}"
@@ -189,7 +193,7 @@ PGDATABASE=v3_commits psql -X -v ON_ERROR_STOP=1 \
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
-c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '01000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32), 'hex'))" > /dev/null
PGDATABASE=v3_commits bash "$root/tools/migrate-postgres.sh"
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 61:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 62:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) FROM evolution.region_commits")" = 1
# Review P1: a v4 database holding a published (possibly terminal) checkpoint has
# no durable decisions for it. The v5 upgrade must refuse before changing anything.
@@ -243,7 +247,7 @@ PGDATABASE=v6_populated psql -X -v ON_ERROR_STOP=1 \
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
-c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '02000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32) || repeat('00', 80), 'hex'))" > /dev/null
PGDATABASE=v6_populated bash "$root/tools/migrate-postgres.sh"
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT count(*) FROM evolution.region_commits c, LATERAL evolution.parse_checkpoint_manifest(c.manifest) m WHERE m.commit_sequence = 0 AND m.predecessor_commit IS NULL")" = 1
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(conname, ',') FROM pg_constraint WHERE conrelid = 'evolution.region_heads'::regclass AND contype = 'c' AND pg_get_constraintdef(oid) LIKE '%end_tick%'")" = region_heads_published_tick
phase permission-audit
@@ -301,9 +305,9 @@ expect_audit_failure 'REVOKE EXECUTE ON FUNCTION evolution.load_world_cellular_m
expect_audit_failure 'GRANT EXECUTE ON FUNCTION evolution.fork_restored_history_v1(uuid) TO evo_runtime_test' 'REVOKE EXECUTE ON FUNCTION evolution.fork_restored_history_v1(uuid) FROM evo_runtime_test'
phase checksum-drift
# Unknown future versions and checksum drift must not be repaired silently.
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=62 WHERE version=61'
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=63 WHERE version=62'
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=61 WHERE version=62"
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=62 WHERE version=63"
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=14"
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=13"