partly implementedProfilenative CQualifiedcpu

54. Publish a realm

Status: partly implemented. Visitors of a made realm see the revision its owner published, played by the engine build and assets it was published with: the publish record pins the document's hash and the engine's manifest (host script, wasm, shaders, voice engine, render package and asset packs, each named by its content, and each served file's own SHA-256) and its hash (GitHub #12629). The whole route (edit, publish, reload from the record, a later release, fork, edits kept apart, refusals) is one checked walkthrough below, and the manifest and record are worked by hand and run in metaverse-engine/examples/publish-a-realm.coax. Not built yet: the release gates per version (golden, 60 FPS) and the page text's hash in the record. Hand-built realms are published from one table (apps/openagents-web/realms.json) and are not pinned this way.

Publishing turns a realm someone is working on into one other people visit. That needs three promises: what visitors get is a fixed version (a document, a module build and its assets, each by hash); the version passed the same checks every realm passes (it draws, it holds 60 FPS, it matches its golden); and a release of the engine never overwrites what someone made.

What this chapter teaches

  • A realm as four things: its world on the galaxy, its module, its assets, its save slot.
  • A publish record: document hash, module build identity, asset hashes, golden and page text.
  • Release gates per realm, compared against production first, so a release is stopped only by a regression it causes.
  • Makers: who a realm belongs to and where its tips go.

The method

A publish record is the unit a release reasons about. This is its design; the record the server keeps today (a revision, the document's hash, the engine manifest and its hash) is in The engine a made realm is published with:

jai
Published :: struct {    slug: Slug; version: u32;    doc_sha256: Hash;            // chapter 51's document (made realms)    module: BuildId;             // the module's wasm, by hash    assets: [MAX_ASSETS] Hash;   // chapter 53's packs and files    golden: GoldenRule;          // lit share, settle time, blocks allowed to differ    page_md_sha256: Hash;        // the page as text, for agents and readers}

Hand-built realms are published by a reviewed change to the table and their module; made realms and forks by their owner, with no deploy. Both end as the same record. A new version is checked before it replaces the old: the page draws (enough lit pixels after it settles), its shot matches its golden within the allowed blocks, and its frame times hold the 60 FPS rule. A made realm lives only in the bucket, so the release copies engine code, never another environment's realms.

What exists today

  • docs/metaverse/realm-host.md: the table entry (id, kind, orbit, realm.slug, module, slot, assets, golden, style, clock), the required hand-written index.md, bun coax/web/realms.ts --check and coax/web/realms.test.ts.
  • coax/web/realms.ts writes apps/openagents-web/realms.coax (the galaxy's table), realms/<slug>/index.html and /realms' list.
  • Made realms: POST /api/playtest/realms writes realms/<slug>, index.html, index.md and realms/made-slugs.txt into the bucket (drops_site_write); upload.py never removes a listed one (realm-builder.md, "Releases").
  • A made realm's owner publishes a revision: POST /api/playtest/realms/<slug>/publish {"rev": N, "listed": true|false}. The server refuses a revision that is not the current one with 409 and the current revision, records published_rev, published_sha256 and the time, and keeps the revision in verse.realm_revisions (0093_realm_documents.sql). listed: false keeps the page noindex and off /og's rows. In the realm, PUBLISH is shown to the owner only when the saved revision is not yet the published one.
  • Visitors get the revision published (0094_realm_live_and_undo.sql). Making or forking a realm publishes its first revision. The spec, /doc and a fork by anyone but the owner are of the published revision; the owner and site admins get the latest. Under the realm's name the owner reads "LIVE: VERSION 3", "LIVE: VERSION 3. NOT PUBLISHED: 5" (saved, not published) or "LIVE: VERSION 3. NOT SAVED".
  • Realms made or forked by a tool (the verse-automation cookie or the X-Verse-Automation header) are unlisted from the start.
  • Forks stay noindex until their owner publishes (realm-fork.md).
  • Goldens in coax/web/goldens/, golden-check.sh naming the commit that changed a page, and perf.ts for frame times.
  • Makers and tips (makers.md): a one-time claim code, a Lightning address, "MADE BY NAME · TIP" drawn in Coax.
  • An agent publishes a hand-built realm by pull request (metaverse/SKILL.md); the template is metaverse/realm-template/.
  • GameBuilder & gamebuilder.org worlds (#13986, #13988, #14045, #14057): GameBuilder worlds publish as static web bundles on gamebuilder.org—five live worlds ship on the unified pipeline (Fated Dragon /fated-dragon, SPLICEBOTS /packs/splicebots, Ice Cream Man, Scrappers Arena, and The Whispering Spring /whispering-spring)—and can also be published from OpenAgents Desktop's embedded GameBuilder Studio drawer (Publish & Nostr Lobby, #14045) or packaged into Desktop releases via the OA_PACK_METAVERSE pack gate (#14057).

The made-realm write and the hand-built table are separate code paths with separate checks.

The engine a made realm is published with

A made realm's page used to fetch /realms/built on every visit and copy its app script, so a release changed every published realm the moment it landed. That script is the engine: every file it names is named by its content (coax/web/deploy.sh) and never deleted from the site's bucket. So publishing keeps the script itself, as an engine manifest, one attribute a line in the page's order:

jai
ENGINE_HEADER :: "aethyr-engine 1\n";ENGINE_TEXT :: 4096;      // a manifest's bytes at most (the server's limit too)ENGINE_ATTRS :: 24;       // attributes at mostENGINE_NAME :: 32;        // an attribute name's letters at mostENGINE_PATH :: 200;       // a path's characters at mostENGINE_HASH :: 12;        // hex digits in a content name: deploy.sh's sha256 prefixENGINE_APP :: "myrealm";  // the made-realm engine; nothing else is pinned hereENGINE_OPEN :: "<script type=\"module\" src=\"";// A manifest being written into a caller's buffer, and what it has seen.EngineAcc :: struct {  n: int; bad: bool;  names: [ENGINE_ATTRS] string; count: int;  src: bool; app: bool; wasm: bool; wgsl: bool;}

A value may name only paths named by their content: NAME.<12 hex>.EXT somewhere along it, or a 64-hex directory (a render package's):

jai
// A path the manifest may name: from the site's root, plain characters, no empty or dot-dot// segments, and named by its content somewhere along it.engine_path_ok :: (p: string) -> bool #effects(all) {  return p.count <= ENGINE_PATH && engine_at(p, 0, "/") && engine_segments(p[1..<p.count], false);}// The segments after a slash: none empty, "." or "..", plain characters, one of them (or one// before, `named`) a content name.engine_segments :: (rest: string, named: bool) -> bool #effects(all) {  cut := engine_upto(rest, '/');  seg := rest[0..<cut];  if seg.count == 0 || seg == "." || seg == ".." || !engine_all(seg, ENGINE_PATH_CHARS) { return false; }  now := named || engine_named_segment(seg);  return ifx cut == rest.count then now else engine_segments(rest[cut + 1..<rest.count], now);}

Each attribute goes through one rule, which both reads a page and checks a manifest read back:

jai
// One attribute into the manifest: its name, then its value with every run of white space one// space and none at either end, checked once written. A name seen before, more than// ENGINE_ATTRS, or a value naming anything not named by its content spoils the manifest.engine_add :: (buf: [] u8, a: [] EngineAcc, name: string, raw: string) #effects(all) {  if !engine_name_ok(name) || a[0].count == ENGINE_ATTRS { a[0].bad = true; return; }  for k: 0..<a[0].count { if a[0].names[k] == name { a[0].bad = true; } }  a[0].names[a[0].count] = name; a[0].count += 1;  engine_put(buf, a, name); engine_put(buf, a, " ");  start := a[0].n; gap := false;  for c: raw {    if engine_in(c, ENGINE_SPACE) { gap = a[0].n > start; continue; }    if gap { engine_put(buf, a, " "); gap = false; }    one := [1] u8.[c]; engine_put(buf, a, cast(string) one[..]);  }  if a[0].bad { return; }  value := cast(string) buf[start..<a[0].n];  if !engine_value_ok(value) || (name == "data-app" && value != ENGINE_APP) { a[0].bad = true; return; }  if name == "src" { a[0].src = engine_host_ok(value); }  if name == "data-app" { a[0].app = true; }  if name == "data-wasm" { a[0].wasm = engine_path_ok(value); }  if name == "data-wgsl" { a[0].wgsl = engine_path_ok(value); }  engine_put(buf, a, "\n");}// The manifest, or "" when anything spoiled it, it is over ENGINE_TEXT bytes, or the host script,// engine, wasm or shaders are missing.engine_finish :: (buf: [] u8, a: [] EngineAcc) -> string #effects(all) {  if a[0].bad || a[0].n > ENGINE_TEXT || !a[0].src || !a[0].app || !a[0].wasm || !a[0].wgsl { return ""; }  return cast(string) buf[0..<a[0].n];}
jai
// The made-realm engine's script in a page: what follows "<script " in the one tag that opens like// the engine's and names data-app="myrealm", to before its ">". "" when there is none, two, or one// that doesn't end.engine_tag :: (t: string) -> string #effects(all) {  found := ""; seen := false;  for i: 0..<t.count {    if !engine_at(t, i, ENGINE_OPEN) { continue; }    end := i + engine_upto(t[i..<t.count], '>');    if end == t.count { return ""; }    if engine_has(t[i..<end], " data-app=\"myrealm\"") {      if seen { return ""; }      found = t[i + 8..<end]; seen = true;    }  }  return found;}// The made-realm engine's manifest from a page (the template /realms/built): every attribute of its// script in the page's order, NAME="VALUE" each. "" when the page is refused: no such script, an// attribute malformed or repeated, a value naming anything not named by its content, no host// script, wasm or shaders, or more than the buffer or ENGINE_TEXT holds.engine_manifest :: (template: string, buf: [] u8) -> string #effects(all) {  out := buf;  a: [1] EngineAcc;  engine_put(out, a[..], ENGINE_HEADER);  rest := engine_tag(template);  while rest.count > 0 {    if engine_in(rest[0], ENGINE_SPACE) { rest = rest[1..<rest.count]; continue; }    eq := engine_upto(rest, '=');    if !engine_at(rest, eq, "=\"") { return ""; }    value := rest[eq + 2..<rest.count];    close := engine_upto(value, '"');    if close == value.count { return ""; }    engine_add(out, a[..], rest[0..<eq], value[0..<close]);    rest = value[close + 1..<value.count];  }  return engine_finish(out, a[..]);}
jai
// A manifest read back (from the server's publish record) holds when it is exactly what// engine_manifest writes: written again line by line through the same rule, the same bytes.engine_check :: (m: string) -> bool #effects(all) {  if !engine_at(m, 0, ENGINE_HEADER) { return false; }  buf: [ENGINE_TEXT] u8; a: [1] EngineAcc;  engine_put(buf[..], a[..], ENGINE_HEADER);  at := ENGINE_HEADER.count;  for i: ENGINE_HEADER.count..<m.count {   // each line; text after the last newline is never written again    if m[i] != '\n' { continue; }    line := m[at..<i]; at = i + 1;    sp := engine_upto(line, ' ');    if sp == line.count { return false; }    engine_add(buf[..], a[..], line[0..<sp], line[sp + 1..<line.count]);  }  return engine_finish(buf[..], a[..]) == m;}

The server keeps the same rule in SQL (0107_realm_engine_pins.sql): POST .../<slug>/publish reads realms/built/index.html from the bucket, and in one transaction publishes the revision and pins the manifest, or, when the page can't be read or names anything not by content, publishes nothing and answers 503. Every publish is a row of verse.realm_publications (revision, document hash, manifest, engine hash, why), and GET .../<slug>/published answers the latest. The spec gains engine SHA256. The realm's page carries the manifest (data-engine) and builds the engine's script from it, so a later release can't change it; ?engine=current tries today's engine. A fork starts on its parent's engine and its own publishes leave its parent's record alone. A realm's first revision, and every realm published before pins, is pinned to the engine served when its page is next written.

jai
// A publish record (GET .../<slug>/published) holds together: a revision, the document's 64-hex// hash, a manifest this rule writes, and the engine hash is that manifest's.engine_record_ok :: (rev: int, doc_sha: string, engine: string, want: string) -> bool #effects(all) {  if rev < 1 || doc_sha.count != 64 || !engine_all(doc_sha, ENGINE_HEXES) || !engine_check(engine) { return false; }  h: [64] u8;  return engine_sha(engine, h[..]) && cast(string) h[..] == want;}

A file's name is the hash of its bytes before deploy.sh strips the comments from scripts and shaders, so the bytes served for host.*.js and *.wgsl hash to something else (the wasm and packs match their names). After the strip, coax/web/tool.sh engine-served write SITE (engine-served.coax) adds the served bytes' own hashes to the engine's script, data-served="SHA256=PATH ...", so the manifest a publish pins carries them and its hash covers them. engine-served check MANIFEST SITE holds a pinned record to a site's files: every path the script names listed once, each file's bytes hashing to what the record says.

Worked by hand

The engine page served on 2026-11-02 (ENGINE_FIXTURE in publish.coax) has one script that opens like the engine's and names data-app="myrealm". Its attributes, in the page's order, are type, src, data-app, data-realm, data-slot, data-voice, data-style, data-clock, data-assets, data-voice-wasm, data-wasm and data-wgsl. Each becomes one line, NAME VALUE, after the header line aethyr-engine 1, 13 lines in all. data-assets starts with a newline and two spaces in the page; the leading white space is dropped, so its line is data-assets pack:/build/realms/fixture/assets/fixture.df9c027378c8.pack. Every path is named by its content: host.9ca333f3d8b0.js, myrealm.0e7b9526d8a2.wasm, myrealm.224131021ece.wgsl, voice.71d76f28966b.wasm and fixture.df9c027378c8.pack (df9c027378c8 is the first 12 hex digits of `sha256sum apps/openagents-web/realms/fixture/assets/fixture.pack`). The host script, engine, wasm and shaders are all there, so the manifest holds. The engine hash is the SHA-256 of those bytes. sha256sum agrees, computed apart from the Coax:

shell
printf 'aethyr-engine 1\ntype module\nsrc /coaxial/host.9ca333f3d8b0.js\ndata-app myrealm\ndata-realm built\ndata-slot built\ndata-voice made-realm\ndata-style lowpoly\ndata-clock fixed:0.5\ndata-assets pack:/build/realms/fixture/assets/fixture.df9c027378c8.pack\ndata-voice-wasm /build/voice.71d76f28966b.wasm\ndata-wasm /build/myrealm.0e7b9526d8a2.wasm\ndata-wgsl /build/myrealm.224131021ece.wgsl\n' | sha256sum
text
1592e30f8f480ae5f99954d1733f6f57cb1b139b6d0d449ad6098e5e2336b006  -

A later release changes the host script's name to host.5b0c2e81d4f7.js. One line of the manifest changes, so its hash does too (sha256sum gives 077452…ab781 for those bytes). The record still names the first manifest, which still holds. A page whose wasm is /build/myrealm.wasm names a file not by its content, so it has no manifest and nothing is published. A record whose manifest has one digit of the host's name changed still follows the rule line by line, but no longer hashes to the engine hash the record states, so the record is refused. So is a record at revision 0.

Publish Lamp Cove

The program is metaverse-engine/examples/publish-a-realm.coax. The document hash here is the SHA-256 of the fixture's document text (EDITOR_DOC_V1); the server hashes its own canonical document the same way:

jai
#load "../editor/publish.coax";#load "../editor/doc.coax";#import "Basic";// The hex SHA-256 of some bytes, as the record writes it.hex :: (t: string, out: [] u8) -> string { return ifx engine_sha(t, out) then cast(string) out[0..<64] else ""; }// Lamp Cove's revision 4 published: the engine page served today becomes a manifest, the record// pins it with the document's hash, and the record is read back and held to the rule. Then a later// release, a page that names a file not by its content, and a record changed by one byte.main :: () {  m: [ENGINE_TEXT] u8;  manifest := engine_manifest(ENGINE_FIXTURE, m[..]);  print("%", manifest);  e: [64] u8; engine := hex(manifest, e[..]);  print("engine: %\n", engine);  d: [64] u8; doc := hex(EDITOR_DOC_V1, d[..]);  print("record: rev 4, document %, engine %\n", doc, engine);  print("the record holds: %\n", engine_record_ok(4, doc, manifest, engine));  // A later release: a new host script. Its manifest and hash differ; the record still names the first.  t: [4096] u8; later := engine_swap(ENGINE_FIXTURE, "host.9ca333f3d8b0.js", "host.5b0c2e81d4f7.js", t[..]);  m2: [ENGINE_TEXT] u8; next := engine_manifest(later, m2[..]);  e2: [64] u8;  print("a later release's engine: %\n", hex(next, e2[..]));  print("the record still holds, naming the first: %\n", engine_record_ok(4, doc, manifest, engine));  // Refusals: a page naming its wasm without a content name pins nothing.  u: [4096] u8; plain := engine_swap(ENGINE_FIXTURE, "data-wasm=\"/build/myrealm.0e7b9526d8a2.wasm\"", "data-wasm=\"/build/myrealm.wasm\"", u[..]);  m3: [ENGINE_TEXT] u8;  print("a page with /build/myrealm.wasm -> manifest \"%\" (refused: nothing is published)\n", engine_manifest(plain, m3[..]));  // A record whose manifest says a different host script but keeps the old hash.  b: [ENGINE_TEXT] u8; bent := engine_swap(manifest, "host.9ca333f3d8b0", "host.9ca333f3d8b1", b[..]);  print("the manifest with one digit changed: holds by the rule %, record holds %\n", engine_check(bent), engine_record_ok(4, doc, bent, engine));  print("a record at revision 0: %\n", engine_record_ok(0, doc, manifest, engine));}
shell
coax/bin/coax run metaverse-engine/examples/publish-a-realm.coax
text
aethyr-engine 1
type module
src /coaxial/host.9ca333f3d8b0.js
data-app myrealm
data-realm built
data-slot built
data-voice made-realm
data-style lowpoly
data-clock fixed:0.5
data-assets pack:/build/realms/fixture/assets/fixture.df9c027378c8.pack
data-voice-wasm /build/voice.71d76f28966b.wasm
data-wasm /build/myrealm.0e7b9526d8a2.wasm
data-wgsl /build/myrealm.224131021ece.wgsl
engine: 1592e30f8f480ae5f99954d1733f6f57cb1b139b6d0d449ad6098e5e2336b006
record: rev 4, document 22445c951d53b25548aa0909254446198fcb3215ee5d84f4a745a5b3969c2517, engine 1592e30f8f480ae5f99954d1733f6f57cb1b139b6d0d449ad6098e5e2336b006
the record holds: true
a later release's engine: 077452077f674f61863d2ad089e79d66356abbb8bc1133b3823b052ffedab781
the record still holds, naming the first: true
a page with /build/myrealm.wasm -> manifest "" (refused: nothing is published)
the manifest with one digit changed: holds by the rule true, record holds false
a record at revision 0: false

The engine hash is the sha256sum one above, and so is the later release's. The last three lines are the broken cases, each refused.

The route, checked end to end

coax/web/tool.sh coax/web/api/tests/realm_walkthrough.coax (PGURL, PSQL, WORK) runs the OpenAgents Metaverse Engine's route against PostgreSQL with every migration applied, and works out again from the bytes every digest the server states:

  1. A release is staged (its five engine files, /realms/built), and engine-served writes the served hashes.
  2. The realm is read into the edit model; a move, a turn, a resize, a removal and an undone move are one save (revision 2).
  3. Publish pins revision 2 and the engine; the engine hash it states is the manifest's, computed here.
  4. Reload from the record: the manifest holds by the rule and hashes to the record's engine hash; every served file is the bytes the record says; a visitor's document hashes here to the record's document hash and reads back (doc.coax) as exactly the moves, turns, sizes and removals the edits made; the realm's page plays the pinned engine.
  5. A second release with a new engine: the record and the realm's page still name the first.
  6. The owner saves revision 3 unpublished: a visitor's document is revision 2's, byte for byte. A visitor's fork starts on the parent's engine and its published moves and shapes; the fork's edits leave the parent's published and current documents untouched.
  7. Refusals keep the last valid document: a stale save (409), a publish whose engine can't be pinned (503, revision 2 stays published), and a newer document version the reader doesn't know.

It ran on a fresh PostgreSQL 17 with this checkout's migrations: 24 checks.

What the pin does not cover yet: the API is shared, so a pinned page talks to today's server (as a pinned demo does, coax/web/pin.sh); a realm pinned before served hashes were written (an older /realms/built) has names only, and engine-served check says so; built-in realms' forks are not pinned; the walkthrough stages its own site instead of reading the production bucket.

Checks: coax/bin/coax run metaverse-engine/examples/publish-a-realm.coax (the worked example, in the book's --coax runs, debug and release), coax/bin/coax test metaverse-engine/editor/publish.coax --library (the rule, the live page's fixture and its hash, which sha256sum agrees with; `coax mutate with no survivors), coax/web/tool.sh coax/web/api/tests/realm_engine_pin.coax` (the same fixture through the SQL rule gives the same hash; first pin, publish, refused publishes keeping nothing, a fork on its parent's engine, a server without a bucket), coax/bin/coax test coax/web/engine-served.coax --library, the walkthrough above, test_realm_fork.py (a save leaves visitors on the revision published, their /doc is its document, a visitor's fork copies it) and coax/web/tool.sh editor-journey URL (after SAVE the owner reads "not published" and a visitor's spec has the published revision; after PUBLISH, "live", and the visitor gets it).

What it builds

  • metaverse-engine/editor/publish.coax: the engine manifest and the record's check exist; the checks a version must pass before it replaces the last (golden, frame times) and the page text's hash do not yet.
  • The realm table's rules (unique slots, required index.md, style and clock fields) as Coax checks shared by realms.ts and the made-realm path.

Acceptance checks and oracles

  • bun coax/web/realms.ts --check and realms.test.ts pass; a table entry without index.md, with a duplicate slot or an open world without a realm is refused.
  • Every published realm's golden passes on the release walk; a page whose look changed without its golden is named with the commit that changed it.
  • The 60 FPS rule (95th percentile frame at most 17.5 ms, none over 33 ms) holds for each realm's recorded walk.
  • A release run against a bucket with made realms leaves every made realm's files byte-identical.
  • A publish record's hashes match the served files; a mismatch refuses.

Dependencies

Chapter 16 (identities), chapter 37 (measurement), chapter 51 and chapter 53.

In the other books

A published realm has an owner and, when claimed, a maker who is paid.