Skip to content

Ariadne: a state: block, the document's starting values without init: calls - #1563

Merged
transfix merged 1 commit into
masterfrom
ariadne/state-block
Nov 27, 2026
Merged

transfix merged 1 commit into
masterfrom
ariadne/state-block

Conversation

@transfix

Copy link
Copy Markdown
Owner

A document can now give state keys their starting values in a state: block, instead of a run of (state-set ...) calls in init:.

state:
  run:
    world: data
    crop: 600
    paused: 0
  view.camera: follow        # a key may hold dots
  /app.theme: dark           # a leading / is the app root (§7.1)

Why

68 of the 202 shipped documents use init: to seed literal values: 231 state-set calls with a literal value. In 53 of them, init: does nothing else. cars.ari's was 24 lines of (state-set "run.crop" "600") and the like.

What it does

  • Where: each path resolves against the document's prefix with the same rule as every bind:. A top-level key starting with / is app-root-absolute.
  • When: the host writes the seeds (seed_state) on every load and reload, just before init: runs, after args:, data: and the keys: defaults. So init: reads them and may override them, and, like an init: seed, they win over a widget's def:.
  • Modules: a load:ed module's own state: is written at its mount's sub-prefix just before the module's init:, once, and again on a Restart, under the same once-only gate init: already has. A module with a state: and no init: is seeded too.
  • Values:
    • a map's keys are path segments joined by dots, and a key may hold dots itself;
    • a scalar is written as spelled (paused: 0 writes 0, ready: true writes true), so converting an init: keeps what it wrote;
    • a list of scalars is joined by commas, as position keys are;
    • a key with nothing after it writes "".
  • Refused with a warning, and left out:
    • a list or scalar for the block itself;
    • a key that is not a path (a..b, a trailing dot, a / below the top level);
    • a list holding a map.
      A key given twice warns, and the later value is used.

Changes

  • inc/cvc/ariadne/widget.h: StateSeeds, and Widget::state_seeds on a mount wrapper.
  • inc/cvc/ariadne/loader.h, src/cvc/ariadne/loader.cpp: LoadResult::state_seeds, parse_state (for the document and a load: fragment), and state among the loader's top-level blocks.
  • inc/cvc/ariadne/ariadne.h, src/cvc/ariadne/ariadne.cpp: seed_state. A mount writes its seeds just before its init:, and a restart clears that gate as before.
  • src/cvc/ariadne/app_runtime.cpp: AppRuntime::load seeds just before run_init. The relay's server document loads through it too.
  • Schema: top-level state, and a recursive $defs/state_tree (scalars, null, lists of scalars, maps). Its keys stay open because they are the document's own names.
  • ARIADNE.md:
    • §5.1 lists state (and prototypes, which was missing);
    • §5.3 describes the block, and its example document uses it;
    • §5.25 and §12 say a module's state: is written before its init:.
  • bindings/pycvc/pymod_gl/cars.ari: its init: becomes a state: block holding the same 24 keys and values in the same order (checked by script), with min_libcvc 4.0.9. The other shipped documents are left as they are, to stay out of other work's way.

Tests

  • ariadne_loader_test:
    • AriadneState.BlockFlattenedInOrder: nested and dotted keys, an app-root key, a list, an empty list, nothing, a quoted string, yes and 1.50 kept as spelled.
    • AriadneState.BadEntriesWarnAndAreLeftOut: a list for the block, an empty block (no warning), / below the top level, a..b, a trailing dot, a map in a list, a key given twice.
  • ariadne_host_test:
    • AriadneState.AppRuntimeWritesItBeforeInit: init: reads one seed and overrides another, an app-root key lands at the root, a list and an empty value, and a slider's def: does not replace a seed.
    • AriadneState.AReloadWritesItAgain.
    • AriadneState.AModulesStateIsWrittenAtItsMountBeforeItsInit: a module's init: reads its seed at the sub-prefix, a module with no init: is seeded, the parent's key of the same name is untouched, and a second frame does not seed again.
  • ariadne_schema_test: a valid state: document in kValid, and two mistakes: a list for the block, and a map inside a list.

Verified locally

Windows, MSVC, with the JSON-schema validator and FTXUI (no cvcGL, no pycvc), on master 633e605:

  • The whole tree builds (687 targets).
  • ariadne_loader_test: 274 pass.
  • ariadne_schema_test: 13 pass, plus 1 skip by design (the without-validator case). This includes EveryShippedDocumentIsValid, so cars.ari's state: validates.
  • ariadne_host_test: 69 pass.
  • ariadne_runtime_test: 368 pass.
  • ari validate: a nested, list and empty state: is valid. A map inside a list is reported at /state/a/1, at its line and column.
  • Every Ariadne ctest (-R [Aa]ri): 1,286 of 1,290 pass. The 4 that fail are AriMedia terminal-snapshot colour checks, and they fail the same way on an older build without this change, so the cause is something on this machine.

Not verified: cvcGL, pycvc, wasm, Linux and macOS (CI covers them). No code builds Widget positionally, so the new member shifts nothing.

… calls

A document's state: is a map of state paths to literal values, written under its prefix
(seed_state) on every load just before init: runs, so init: reads and may override them and,
like an init: seed, they win over a widget's def:. A load:ed module's state: is written at its
mount's sub-prefix just before its init:, once, and again on a Restart.

A map's keys are path segments (one may hold dots; a top-level one may start with / for the
app root); a scalar is written as spelled, a list of scalars joined by commas, nothing as "".
Anything else, and a key that is not a path, warns and is left out; a key given twice warns.

The schema gains top-level state and a recursive $defs/state_tree. ARIADNE.md 5.1, 5.3, 5.25
and 12 describe it, and cars.ari's 24-line init: becomes a state: block with the same keys and
values in the same order.
@transfix
transfix merged commit 93c9da4 into master Nov 27, 2026
30 checks passed
@transfix
transfix deleted the ariadne/state-block branch November 27, 2026 05:11
transfix added a commit that referenced this pull request Nov 27, 2026
#1563 added a document's state: block. A load:ed module's seeds are written at its sub-prefix
just before its init:, once, and again on a Restart. A mounts: entry's wrapper carries the same
seeds (load_mount goes through expand_load), but open_mount ran only its init:. That marked the
mount done in ran_inits, so the seeds were never written. open_mount now writes them just
before the init:, under the same once-only check. Reopening resumes without writing them, and a
Restart writes them again (emit_container, as for a load: module).

AriadneMounts.AMountsStateBlockIsWrittenAsItOpens checks that init: reads the seeds, a reopen
keeps a changed value, and a Restart writes the seeds again. It fails without the fix: the
mount opens but count is empty. ARIADNE.md 5.3 and 6.7 and the ARIADNE_SHELL.md 4.2 note say so.
transfix added a commit that referenced this pull request Nov 27, 2026
…ell.ari (#1566)

* Ariadne shell SH1: mounts:, app-open/app-close, budgets per mount, shell.ari

docs/roadmap/ARIADNE_SHELL.md 4.1, 4.2, 4.11 and the SH1 row; ARIADNE.md 6.7.

- mounts: <key>: one isolated mount per child of the key (uri, args), loaded through
  load_mount (expand_load in a fresh context, stateless) with the loader AppRuntime gives the
  Runtime (Runtime::set_mount_loader). Its init: runs and its on_tick: starts as it opens; it
  is an application (its bar one menu of the outer bar; one without a bar gets Restart, Quit,
  Close). Closing quits it, kills every process under its scope and frees its slot; its state
  stays, so reopening resumes it. Parsed again only when its uri, args or a file changes; hot
  reload keeps its resident when its program is the same. allow: (a list or { bind }) narrows
  what may be mounted, a refusal posted to the feed; catalog: names the documents that run as
  the local principal. The requires: check at mount refuses what the static scan would fail or
  warn on (a required entry, an unprovided call, gl.scene for a scene: on a host without one).
- (app-open URI [AS [ARGS]]) and (app-close AS) on the calling document's first slot; a mounted
  document gets a PermissionError.
- A budget per mount: cvc::state_exec::frame_account (execute_options::account, kept by spawn and
  fork). The async scheduler charges steps and seconds, ends a run at the limit, and parks a
  spent account's processes until the next frame (never killed); wake_awaiting starts each
  account's new frame. Memory is the processes' measured heap shares (process::measures_heap),
  summed by the Runtime. Defaults by principal (local 100000 steps, 0.025 s, 256 MB a frame;
  file: and remote: 20000, 0.005 s, 64 MB), settled against every shipped example (busiest:
  108 steps, under 0.4 ms a frame). Held for 3 s: a notice whose click offers Allow more, Quit
  and Restart. The apps mirror carries principal and budget.*; processes.ari shows each share.
- data: uri: { arg: NAME }; a menu_item: label that is an expression.
- components/shell.ari (--catalog in gallery.json format, --open), an Apps menu, a Launcher,
  processes.ari, a mounts: slot; examples/ariadne/documents/shell_apps.json (tray_demo,
  json_feed, apps/counter).
- The .ari schema learns mounts:, allow:, catalog: and uri: { arg }.

Tests: AriadneMounts.* (open, close with its memory freed, reopen with state kept, the verbs,
a refused URI, unmet requires:, hot reload, a busy mount held while another runs, a mount past
its memory, the shipped examples within the local budget), AriadneComponents.ShellOpensIts-
CatalogOnDemand, AriadneLoader.MountsSlotAndADataUriFromAnArgument and LoadMountParsesAn-
EntrysDocument, AsyncSchedulerTest.AFrameAccountHoldsItsProcessesToTheirFrame, and
ari_run_shell_{ftxui,tvision} (tmux, Linux).

* mounts: compare an allow: or catalog: path in the resolver's canonical form

On the Windows CI runner the temp directory is spelled with an 8.3
short name (C:\Users\RUNNER~1\...). The slot's base comes from the
resolver, which uses weakly_canonical, so it holds the long name. The
entry's path was only made lexically normal, so the two never matched,
and AriadneMounts.ARefusedUriIsPostedToTheFeed saw its allowed file
refused.

mount_norm now makes a local path canonical the way the resolver does
(links followed, short names spelled out), and keeps a trailing slash
so an allow: prefix still matches only under its directory.
Reproduced and verified locally by running ariadne_runtime_test with
TMP set to a short path: all 377 pass.

* mounts: no recursion on a deep document, and a mounts: slot drawn on a small stack

Rebased onto the iterative walk (#1577):
- emit_mounts pushes a frame per open mount (its id and emit_path entry, the wrapper on the
  walk, then a Then that pops them) instead of emitting each in a nested walk.
- plan_windows_menu's Mounts case pushes each open mount's tree, then a marker visit that makes
  it an application if it brought no bar (ARIADNE_SHELL.md 4.9), keeping tree order.
- app_menu ends every application's menu through app_commands (Restart, Quit, and Close for a
  mounts: entry's); one without a bar gets those alone.
- drop_mount_ticks seeds its loop with the slots' wrappers.

Runtime::set_root's search for the document's own first mounts: slot recursed once a level:
it overflowed ariadne_deep_nesting_test's 256 KiB stack on PlainGroups, MenusAndTrayMenus and
the FTXUI and tvision plain-group tests. It is a loop now.

AriadneDeepNesting.AMountsSlotsEntriesDraw: three entries opened and drawn on the small stack, a
window nesting 3000 groups, a bar whose menu nests 3000 submenus, and one without a bar, each
with its Close item, every begin_* and push_id balanced.

* mounts: a mounts: entry's state: block is written as it opens

#1563 added a document's state: block. A load:ed module's seeds are written at its sub-prefix
just before its init:, once, and again on a Restart. A mounts: entry's wrapper carries the same
seeds (load_mount goes through expand_load), but open_mount ran only its init:. That marked the
mount done in ran_inits, so the seeds were never written. open_mount now writes them just
before the init:, under the same once-only check. Reopening resumes without writing them, and a
Restart writes them again (emit_container, as for a load: module).

AriadneMounts.AMountsStateBlockIsWrittenAsItOpens checks that init: reads the seeds, a reopen
keeps a changed value, and a Restart writes the seeds again. It fails without the fix: the
mount opens but count is empty. ARIADNE.md 5.3 and 6.7 and the ARIADNE_SHELL.md 4.2 note say so.

* mounts: no function-local static for a slot without a spec

mount_principal and open_mount each kept a `static const MountsSpec kNoSpec` to stand for a slot
without a spec. A function-local static of a non-trivial type is a bss object and a guard
variable, so the writable-data scan on package-linux / libcvc-release-grpc failed on four
symbols that are not on the allowlist. Each is now a local MountsSpec: an empty one costs no
allocation, and nothing is left process-wide.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant