Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m40s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m46s
Foundation / image (push) Successful in 5m34s
The region view adds the rules-13 drip and complete counts and totals over every life and deposit. The region page is rebuilt around the map: a KPI strip (tick pace, population, deposit capacity, region energy and matter, spent pool, next drip), layer toggles that double as the legend, zoom and a scale, and tabs for inspecting cells and deposits, resources (where each channel sits, the spent pool and each channel's next drip), actions, the running tuning and session access. The admin API serves the region tuning file read only (--region-tuning). Light and dark themes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
323 lines
20 KiB
Markdown
323 lines
20 KiB
Markdown
# ADR-0182: Admin portal, world tuning in SQL and per-tick amendments
|
|
|
|
## Status and scope
|
|
|
|
Accepted direction, 2026-10-27, from the maintainer's decisions in chat; delivered in parts
|
|
(sections 8-13). DEV (world 100) only; stage and World0 need their own review. Supersedes, for
|
|
rules-13 regions, ADR-0181's "Git tuning affects future openings only. No live retune": since
|
|
schema 66 (section 13) a running rules-13 region adopts tuning revisions at recorded ticks.
|
|
Regions on older rules keep their recorded rules.
|
|
|
|
## Context
|
|
|
|
Every balance change so far has meant a Git tuning edit, a new image or ConfigMap and a new
|
|
DEV region (regions 14, 15 and 16 in a week). The maintainer wants an admin portal to review
|
|
accounts, act on regions and tune the cellular game while it runs. This is a game, not a
|
|
pure simulation: designer-controlled resource sources are acceptable when they are named and
|
|
counted.
|
|
|
|
The constraint is determinism. A region's history must replay to the same state, so nothing
|
|
may change a running region except an event recorded at a tick.
|
|
|
|
## Decision
|
|
|
|
### 1. World tuning lives in SQL
|
|
|
|
- Schema 63 adds append-only `world_tuning_revisions(world, revision, parent_revision,
|
|
format, canonical_text, digest, author_subject, reason, created_at)`. A revision is the
|
|
complete canonical tuning text (`encode_cellular_revamp_tuning`), never a diff, so the
|
|
existing parser and validator are the only interpretation.
|
|
- All regions of a world share its tuning and mutation definitions (maintainer decision).
|
|
Per-region values are not offered.
|
|
- Revisions are immutable. Undo is a new revision whose text equals an earlier one.
|
|
- Git keeps the seed file for creating a world and the test fixtures. It is not consulted
|
|
by a running region, and Argo no longer carries tuning for regions on the new format.
|
|
|
|
### 2. Amendments are recorded per tick
|
|
|
|
- A region polls for a newer world revision on its existing database connection, bounded
|
|
and off the tick path (at most once a second).
|
|
- It validates the revision with its own parser. If it can parse it, it adopts it at its next
|
|
tick boundary and records `tuning_adopted(revision, digest)` at that tick in its own
|
|
history, published with that tick. If it cannot, for example because the revision uses
|
|
keys its image does not know, it keeps its current revision and reports `tuning_refused`
|
|
with the revision number. The portal shows each region's adopted revision.
|
|
- Replay and recovery read the recorded revision by number and digest, never "the latest".
|
|
- Amendments change future calculations only. Heritable values already in a genome are not
|
|
rewritten (for example, a new `mutation.min_points` does not change existing traits).
|
|
- Every tuning key is classified **live** or **opening-only**. Opening-only keys (geometry
|
|
and size, tick rate, world/frame, liquid profile structure) can be revised, but a running
|
|
region ignores them and the portal labels them "next opening".
|
|
|
|
### 3. Admin commands
|
|
|
|
- Schema 63 adds `admin_commands(world, region, command_id, kind, payload, author_subject,
|
|
reason, created_at, applied_tick, outcome)`. The admin API inserts and the region host
|
|
drains them at tick boundaries in id order, publishing each with that tick. This is the
|
|
same pattern as the durable mutation queue (schema 59).
|
|
- Kinds:
|
|
- `kill_cell(life)`: the cell dies with an "admin" outcome. Its body and reserve go to
|
|
the spent pool and drip back.
|
|
- `grant_reserve(life, inventory)`: a **game-source import** into that cell's reserve.
|
|
- `add_region_bubbles(inventory, count)`: a game-source import as bubbles at random
|
|
spots, at most the region's bubble limit per tick; the rest follows on later ticks.
|
|
- `add_pool(inventory)`: a game-source import into the spent pool.
|
|
- `release_pool(inventory)`: moves pool matter into the region through the drip settings
|
|
below, so a large release is spread over drips, never one tick.
|
|
- **Game source** is a named import in the region's accounting, like emergence is a named
|
|
export. Conservation still holds: every unit is either from the starting stock, imported
|
|
by a recorded source or exported by a recorded sink.
|
|
|
|
### 4. Drip and source settings
|
|
|
|
The spent-pool drip (today: interval, largest energy bubble, largest matter bubble per
|
|
channel) becomes one settings group used by both the pool drip and the game-source spawn:
|
|
|
|
| Setting | Meaning |
|
|
|---|---|
|
|
| `drip.interval_ticks` | how often a drip happens (0: never) |
|
|
| `drip.bubbles_per_drip` | the most bubbles one drip creates |
|
|
| `drip.bubble_max.<channel>` | the most of that channel one bubble may carry (energy pj; carbon, nitrogen, phosphorus, other fg) |
|
|
| `drip.scale_percent.<channel>` | per channel, how much faster or slower that channel is released |
|
|
| `source.per_drip.<channel>` | game-source import per drip and channel (0: none) |
|
|
|
|
For the pool, scale changes how quickly the pool drains; it never releases more than the
|
|
pool holds. For the source, scale multiplies the import.
|
|
|
|
### 5. Data-defined mutations
|
|
|
|
- Mutation definitions move from the compiled catalog into the world revision:
|
|
`mutation.<key>.*` gains the definition itself (name, description, effect, primary and
|
|
paired traits, steps, costs, triggers and requirements), not only overrides.
|
|
- A definition may use only effects, traits, triggers and requirement predicates the image
|
|
implements. Requirements come from a fixed predicate set (carbon burned, buds made, a
|
|
trait at or above a value, a mutation held). New behaviour needs code and a new image;
|
|
the region then refuses revisions using it until promoted.
|
|
- The per-cell affinity scores become a vector keyed by mutation id. New entries start at
|
|
zero. This is part of the new owner format.
|
|
- Mutations are never deleted from a running world. `enabled = 0` stops new offers;
|
|
applied mutations stay applied because their effect already changed the genome.
|
|
Replacement is disable plus a new definition.
|
|
- Session protocol: the client receives definitions (name, description, costs) instead of
|
|
using compiled names.
|
|
|
|
### 6. Accounts
|
|
|
|
- **Status**: logged in (an open session interval), banned, alive or dead, the region of
|
|
the active life, and current mutations (applied mutation results along the life's line).
|
|
- **Ban**: `account_bans(account, author_subject, reason, created_at, lifted_at)`. The grant
|
|
broker refuses a banned account (`403 account_banned`) and the ban runs the existing
|
|
logout (`revoke_account_grants`), so a live session closes within 5 s.
|
|
- **Log out**: the existing `revoke_account_grants`.
|
|
- **Grant resource**: `grant_reserve` against the account's active life.
|
|
- **Death count**: the account's lives with a death outcome.
|
|
- **Reset count**: the account's founder births after its first (a new life after death).
|
|
- **Living offspring**: living wildlife descended from any of the account's lives, using
|
|
the parent links kept since format 5.
|
|
- **Time played**: `session_intervals(account, region, started_at, ended_at)` written by the
|
|
region host on session open and close. Intervals still open at a region start are closed
|
|
at that start. History begins with this schema; earlier play is not recoverable.
|
|
|
|
### 7. Admin API and portal
|
|
|
|
- `evo-admin-api`: a C++ service built like the grant broker. It verifies Keycloak access
|
|
tokens against the realm keys pinned in Git, requires audience `aevolution-admin`,
|
|
authorized party `aevolution-admin-portal` and realm role `aevolution-admin`, and serves
|
|
one configured world. Its component exists only in the evolution-dev overlay; World0 and
|
|
stage have no admin portal (World0 has no fixed world id to refuse in code).
|
|
- Every write records the token subject and a reason.
|
|
- The region view: the region host's internal ops port gains a bounded snapshot route (cell
|
|
id, position, extent, wildlife/player and account, bubbles), reachable only from the admin
|
|
API by NetworkPolicy. The admin API serves it to the portal at up to 1 Hz.
|
|
- The portal is a static browser application at `https://srs.aeternalisgames.com`
|
|
(section **Cellular** now, **3D** later) using authorization code with PKCE. It is plain
|
|
HTML, CSS and JavaScript with no third-party code, so no dependency evaluation is needed.
|
|
- Keycloak (maintainer setup): realm role `aevolution-admin`; public client
|
|
`aevolution-admin-portal` with standard flow and PKCE S256, redirect URI
|
|
`https://srs.aeternalisgames.com/*`, web origin `https://srs.aeternalisgames.com` and
|
|
post-logout redirect `https://srs.aeternalisgames.com/`; an audience mapper adding
|
|
`aevolution-admin`; MFA required for the role.
|
|
|
|
### 8. Read-only portal (delivered first, schema 61)
|
|
|
|
- **Schema 61** adds three bounded, read-only SECURITY DEFINER functions, executable by the
|
|
runtime group and listed in the privilege audit: `admin_accounts_v1(world)` (every account
|
|
with its identity, session control, lives, deaths, active life and mutation-choice count),
|
|
`admin_account_lives_v1(world, account)` (its life requests and endings) and
|
|
`admin_regions_v1(world)` (leases and heads). No table or existing function changes. The
|
|
runtime group still has no table privilege. DEV's admin API logs in with its own login in
|
|
that group, as the grant broker does; a dedicated read role is a later least-privilege step.
|
|
- **Derived values.** A life is a published, unrefused reservation; a death is an ended one;
|
|
resets are lives after the first; logged in means the session control has not expired.
|
|
- **Region view.** `GET /admin/view` on the cellular region's ops port renders the committed
|
|
in-memory owner (`render_cellular_admin_view`): every cell (life and organism ids as
|
|
strings, account, footprint, extent, wildlife/connected/lingering/suspended flags,
|
|
members, reserve, body mass) and every pool and bubble, bounded to 4,096 cells and 16,384
|
|
deposits with totals. It reads without changing anything; the ops server's response
|
|
bound becomes configurable (4 MiB for this port), default 16 KiB elsewhere.
|
|
- **Portal files and headers.** The image ships the portal under
|
|
`/usr/local/share/evo-admin-portal`. Files go out with a strict Content-Security-Policy
|
|
(`'self'` scripts and styles, connections only to this origin and the realm), `nosniff`,
|
|
`no-referrer` and `DENY` framing; every answer is `no-store`. The access token stays in
|
|
page memory and the rotating refresh token in the tab's sessionStorage.
|
|
- **Not yet available** (they need the schema-63 records): time played, bans, current
|
|
mutations and living offspring.
|
|
|
|
### 9. Session windows and the admin role (schema 62)
|
|
|
|
The dev session window moves from Git to SQL and is opened, extended and closed from the
|
|
portal; see the [ADR-0087 amendment](0087-dev-session-route.md). Schema 62 also moves the
|
|
admin functions to a dedicated, operator-created NOLOGIN group role (`aevolution_admin` in
|
|
DEV, `EVO_PG_ADMIN_ROLE` for the migration): every migration run grants it exactly the admin
|
|
functions and audits it like the runtime group (no table privilege, no privileged
|
|
attribute, no membership outside it, not the runtime role). Schema 61's read views are
|
|
revoked from the runtime group. The admin API logs in with its own login in that group.
|
|
Writes go through POST without a body (`?minutes=M&reason=R`); the bearer token in the
|
|
`Authorization` header, never a cookie, is the only credential.
|
|
|
|
### 10. Admin commands (delivered, schema 63, trace 5)
|
|
|
|
The commands of section 3 are delivered without a new owner format or region opening:
|
|
|
|
- **Trace 5.** A rules-13 batch may record operator commands: trace 4 plus 64-byte records
|
|
(id, kind, count, target, energy and four matter amounts) counted in the tick header's last
|
|
word, which trace 4 keeps zero. A batch without commands stays trace 4, so builds before
|
|
this one still replay it; only commits that carry commands need this build or later.
|
|
Bundle 15 admits trace 5 (`cellular_checkpoint_trace_admits`); the manifest is unchanged.
|
|
- **Application.** `CellularLives::admin_candidate` applies a tick's commands after its
|
|
births, by ascending id, each on a copy kept only if it applies and still closes:
|
|
`remove_cell` (body and reserve to the spent pool, a corpse with the new `removed` cause;
|
|
a player's life then ends as any death does), `grant_reserve`, `add_bubbles` and
|
|
`add_pool` (imports in the boundary ledger), `release_pool` (moves at most what the pool
|
|
holds into bubbles) and `spawn_wildlife` (1-64 randomized founder roots, the ADR-0180 seed
|
|
with an exact import for their reserve, body and construction). A command whose target is
|
|
gone, or that does not fit (region cap, deposit limit, a taken identity), is refused and
|
|
changes nothing.
|
|
- **Queue and binding.** `admin_enqueue_command_v1` (admin role) stores the exact command;
|
|
spawning reserves its identities from the world's life allocator. The region reads
|
|
`load_pending_admin_commands_v1` every 2 s and appends up to 16 per tick. Both cellular
|
|
publishers bind every recorded command to its queue row exactly once, in the publishing
|
|
transaction; a differing or already-applied command refuses the publication. The SQL trace
|
|
parsers read a trace 5 through its trace-4 normal form, after binding the real trace to
|
|
the manifest.
|
|
- **Portal.** Region actions (spawn wildlife, add bubbles, add to or release the spent pool),
|
|
per-cell Remove and Grant reserve, and the command history with the tick each applied at.
|
|
Amounts are entered in µJ and ng.
|
|
|
|
### 11. Account administration (delivered, schema 64)
|
|
|
|
- **Bans.** Append-only `account_bans` rows; the newest per account decides. A banned
|
|
account's grant request fails with SQLSTATE EVL20 (the broker answers 403
|
|
`account_banned`), and banning also revokes its grants, so a live session closes at its
|
|
next control renewal. Lifting a ban is another row.
|
|
- **Logout.** `admin_logout_account_v1` revokes by account id, as the player's own logout
|
|
does by Keycloak identity.
|
|
- **Time played.** The session-control functions keep their signatures and also record
|
|
`session_intervals`: a claim opens one, a renewal moves its last-seen time, a release ends
|
|
it; an unreleased session ends at its last renewal. History starts with schema 64.
|
|
- **Living offspring.** The region view adds each cell's lineage root; the portal counts
|
|
living wildlife whose root is one of the account's lives.
|
|
|
|
### 12. Resource schedules (delivered, schema 65)
|
|
|
|
The game source of section 4 without a new owner format: a schedule repeats an
|
|
`add_bubbles`, `release_pool` or `spawn_wildlife` command (count, amounts per resource)
|
|
every 1 s to 24 h while enabled. When the region reads its pending commands, each due
|
|
schedule queues its next command as an operator would, so it is recorded in the trace and
|
|
bound once; a schedule never has two commands waiting, so an idle region (no living cells,
|
|
no ticks) accumulates nothing. Versions are append-only; the newest decides.
|
|
|
|
The spent pool's own drip (interval, bubble caps, bubbles per drip, per-channel scale) is a
|
|
rules setting and stays with the tuning amendments.
|
|
|
|
### 13. Tuning amendments (delivered, schema 66)
|
|
|
|
Sections 1-2 are delivered without a new owner format or opening, so running rules-13 regions
|
|
(region 16 included) can be retuned:
|
|
|
|
- **Revisions.** Append-only `tuning_revisions(revision, world, text, rules_sha256, author,
|
|
reason, created_at)`. The text is the Git revamp tuning file format, kept as the admin wrote
|
|
it (comments included); `rules_sha256` is the SHA-256 of `encode_cellular_revamp_rules` for
|
|
the rules it produces, the same canonical bytes the owner snapshot stores. The admin API
|
|
parses and validates the text (`parse_cellular_revamp_tuning`, `cellular_revamp_rules`,
|
|
`cellular_revamp_valid`) before storing it, and `admin_set_tuning_v1` queues the adoption
|
|
in every region of the world in the same transaction.
|
|
- **Adoption is an admin command.** Kind 7 `adopt_tuning` carries the revision as its target
|
|
and the rules digest in its four amount words (little-endian; `other` zero). It is queued
|
|
only through a revision, never by kind. The region fetches the revision's text
|
|
(`load_tuning_revision_v1`), rebuilds the rules with its own parser and appends the command
|
|
only when the digest matches; a text it cannot parse or a mismatch is logged and the command
|
|
stays pending (section 2's `tuning_refused`). Applied at a tick after births, the command
|
|
replaces the region's rules; it is recorded in trace 5 and bound once like any command.
|
|
- **Replay and recovery.** Applying or replaying an adoption needs whoever does it to name
|
|
the rules for that revision and digest (`CellularTuningResolver`): the host from its
|
|
verified revisions, the publisher and recovery from the successor state, checked against
|
|
the recorded digest. A batch carries at most one adoption, so its successor names exactly
|
|
one set of rules. Nothing reads "the latest" revision.
|
|
- **What cannot change live.** `reproduction.safety_version` is a law of the opening
|
|
(ADR-0181): the admin API refuses a text that changes it, and a region would refuse the
|
|
command. `playtest.*` only matters when a region opens. Heritable values already in genomes
|
|
are not rewritten.
|
|
- **Portal.** A Tuning page: the editor starts from the newest revision or the baseline file
|
|
the regions opened with (`--baseline-tuning`, the mounted Git revamp file), Check reports
|
|
the line, key and kind of a problem, Adopt stores the revision with a reason, the revision
|
|
list shows how many regions adopted each, and each region shows which revision its live
|
|
rules match (`rules_sha256` in the region view).
|
|
- **Region page (2026-10-28).** The region view also carries the rules-13 drip
|
|
(`drip`: interval, energy and matter bubble caps) and, over every life and deposit whatever
|
|
the listing limits, `counts` (players, wildlife, patches, pools, bubbles) and `totals`
|
|
(reserve, body, patch, pool and bubble stock). The region page shows where the region's
|
|
stock sits, the spent pool with each channel's next drip and time to empty, a countdown to
|
|
the next drip at the measured tick pace, the deposit capacity (8,192) and whether the tick
|
|
is advancing. Its Tuning tab lists the settings the region runs (the matching revision or
|
|
baseline text) and the region tuning file (`--region-tuning`, the mounted `cellular.tuning`,
|
|
read only). The portal has light and dark themes.
|
|
|
|
Live today: everything the revamp file holds, including the drip (`spent.drip_interval_ticks`,
|
|
`spent.drip_bubble_pj`, `spent.drip_bubble_fg`). Section 4's new drip settings (bubbles per
|
|
drip, per-channel scale) are new rules fields, so they need a rules format change; the
|
|
resource schedules of section 12 cover the game source meanwhile.
|
|
|
|
Still pending from this ADR: section 4's new drip settings,
|
|
data-defined mutations (section 5) and the account's current mutations; opening new regions
|
|
or worlds from the portal (a later gate: Git-generated manifests through the Gitea API and an
|
|
Argo sync for one more region in the world; several concurrent regions or worlds need
|
|
per-region Deployments, volumes and routes).
|
|
|
|
## Delivery order
|
|
|
|
1. Read-only portal: login, accounts (from existing data), regions, region view (schema 61,
|
|
section 8).
|
|
2. Schema 63 and the new owner format: world revisions, adoption records, admin commands,
|
|
game source, drip settings, the score vector, session intervals and bans. One new
|
|
opening on that format.
|
|
3. Admin commands and account actions in the portal.
|
|
4. Live tuning in the portal.
|
|
5. Data-defined mutations in the portal.
|
|
|
|
## Deferred
|
|
|
|
- **Cell migration between regions.** With world-shared tuning and mutations it no longer
|
|
meets per-region mismatches, but still needs the paired transfer extended to the new
|
|
format and to player lives, and a client handoff.
|
|
- **New matter types.** `accounting::Element` has four channels throughout accounting,
|
|
traits, bubbles, the protocol and the client. A later decision; a fixed number of matter
|
|
slots is the expected approach.
|
|
|
|
## Alternatives
|
|
|
|
- **Export portal changes to Git and reopen regions.** Rejected: more steps for the same
|
|
result, and not live.
|
|
- **Change values in a running region's memory.** Rejected: replay and recovery would diverge.
|
|
- **Per-region tuning.** Rejected: all regions of a world share rules.
|
|
- **Database push instead of polling.** Not needed at one adoption check per second.
|
|
|
|
## Consequences
|
|
|
|
- Balance changes become data: no image, ConfigMap or region per change.
|
|
- Balance history moves from Git review to the revision table (author, reason, full text).
|
|
It is covered by database backups and history domains (ADR-0155).
|
|
- Argo no longer shows tuning drift for new-format regions; the portal shows each region's
|
|
adopted revision instead.
|
|
- One more opening is required, for the new owner format.
|