Skip to content

ariadne: --exec-policy, and pure exports on the read lane (G1, tenth part) - #1178

Merged
transfix merged 3 commits into
masterfrom
feat/wasm-policy-pure
Nov 13, 2026
Merged

transfix merged 3 commits into
masterfrom
feat/wasm-policy-pure

Conversation

@transfix

Copy link
Copy Markdown
Owner

G1, tenth and last part: a host option for the scheduler's policy, and pure exports on the read lane (roadmap §8.3, §8.5, §8.6). G1 is done.

The problem

  • Priorities changed nothing. The stock hosts build the app's scheduler while they set up, before any document loads, and had no option to set state_exec.policy. So the policy was always round_robin, and a guest's priority: was stored but never changed which process ran next (risk 15).
    • --set /state_exec.policy=... can't do it either: it's applied after the scheduler is built.
  • Reactive expressions couldn't call a guest. A visible_when or a computed bind: can't call a guest's export. Roadmap §8.6 planned pure: true exports for that.

The fix

--exec-policy round_robin|priority|priority_rr (host_cli.h):

  • It's one of the general flags, so ari, arigl, arix and ariglx all take it, validated at parse time.
  • apply_exec_policy writes it to the app tree's state_exec.policy. Each host calls it right after making its app, before the scene graph, enable_net or register_quit can build the scheduler: ari test, ari run/check/snapshot, and arigl's window and terminal paths.
  • Without the flag nothing changes: round_robin.

Runtime::register_read_function(name, fn):

  • It adds a function to the read lane's environment, beside its allowlist.
  • fn gets the call's arguments and the lane's environment, and runs inline in the expression's eval, under that eval's step and time caps.
  • Its state reads go through the lane's own wrapped readers. So the expression's result is kept, as the DSL's is, until a path it read is written.
  • A later registration replaces the function and drops the kept results.

ScriptLane::export_pure(name, make, options) makes an activation such a function:

  • Its slices run to the end inside the expression's eval. Each slice is charged to the eval's steps, and the eval's deadline (eval_deadline_check) is checked between slices.
  • Its call_now()s and call()s reach only the read lane's environment: the state readers, the allowlisted functions and other pure exports. A writer, a message or a host function is a PermissionError.
  • A yield goes straight on, and an await is a RuntimeError.
  • ScriptSlice::may_wait() is false there. So the wasm engine raises RuntimeError at once for an instance busy with another activation, rather than spinning until the 5 ms cap.

The wasm: block: export: takes {name:, as:, pure: true}. The export stays a function of the document's programs too.

Docs

  • ariadne.h, script_engine.h, host_cli.h and wasm_engine.h.
  • ARIADNE.md: §2.2 (the policy), the flags paragraph, and §9.6's "Pure exports".
  • The roadmap:
    • a "G1's tenth part, built" bullet in §8.3, which ends "Left for G1";
    • the notes in §8.5 and §8.6;
    • risk 15;
    • the G1 row, now Done.

Tests

New:

  • ariadne_host_test AriadneHostCli.ExecPolicyIsTheSchedulersPolicy: --exec-policy priority and =priority_rr reach app.exec_scheduler().policy(), no flag keeps round_robin, and fifo is a usage error.

  • ariadne_runtime_test AriadneReactive.AReadFunctionsReadsKeepItsResult:

    • a read function is called from a visible_when;
    • its result is kept while nothing it read changes;
    • it runs again after a write to what it read;
    • a re-registration replaces it.

    With the dropping of kept results taken out, this test fails.

  • ariadne_wasm_test WasmEngineTest.APureExportIsAFunctionOfTheReadLane: four guest exports marked pure, each a widget's visible_when:

    • get-x reads state through the lane;
    • set-y's write is refused as a PermissionError and reported, and the state is untouched;
    • nap's yields go straight on;
    • echo returns its arguments;
    • get-x's kept result is reused until x is written;
    • the export still works from a program.

Local, Windows static Release tree:

  • ariadne_wasm_test 28/28, ariadne_script_engine_test 30/30, ariadne_runtime_test 263/263 and ariadne_host_test 58/58, three runs each.
  • The arix_wasm_block and ari_wasm_needs_arix ctests.
  • arix test --exec-policy priority src/ariadne_wasm/tests/wasm_block.ari passes, --exec-policy fifo is refused with the usage, and --help lists it.
  • clang-format 18 on the changed lines, against the merge base: clean.

Not tested: the busy-instance RuntimeError, which takes an action parked mid-call while a frame renders. It's a plain throw where the wait would have been.

After G1

The roadmap's next phases are G2 (the install-time transform and the browser backend), G4 (client guests on arisrvx) and G6 (WASI on arisrvx).

…part)

G1's last part. A guest's priority: changed no pick under the stock
hosts, which build the app's scheduler round_robin before any document
loads and had no option to set state_exec.policy. And a reactive
expression (visible_when, a computed bind:) couldn't call a guest.

--exec-policy round_robin|priority|priority_rr is one of the general
flags, so ari, arigl and the x hosts take it. apply_exec_policy writes
state_exec.policy on the fresh app, before anything builds its scheduler.

Runtime::register_read_function adds a function to the read lane's
environment, beside its allowlist. It gets the lane's environment, so its
reads go through the lane's wrapped readers, and the expression's result
is kept until a path it read is written. A later registration replaces
it and drops the kept results.

ScriptLane::export_pure makes an activation such a function: its slices
run to the end inside the expression's eval, charged to the eval's steps,
with the eval's deadline checked between them. Its calls reach only the
read lane's environment (anything else is a PermissionError), a yield
goes straight on, and an await is a RuntimeError. ScriptSlice::may_wait()
is false there, so a wasm instance busy with another activation is a
RuntimeError at once rather than a wait. The wasm: block's export: takes
{name:, as:, pure: true}.

G1 is done.
@transfix
transfix enabled auto-merge (squash) November 12, 2026 09:57
@transfix
transfix disabled auto-merge November 12, 2026 09:59
#1159 (O7c) kept the last source sea_surface found in a thread_local, so
the velocity a fluid field reads after a cell's height at the same point
and time did not invert the sideways move again. A thread_local that
keeps state between calls is a static cache, which libcvc's no-singletons
rule forbids (VOLROVER-LIBRARY-PORTS-ROADMAP.md 1.3,
tools/singleton_scan). #1159's release-grpc job, where the scan runs, was
cancelled, so the scan never judged it; the next PR that merges master
would fail that lane on it.

The memo now belongs to the caller:

- sea_surface::source_memo, and height() / velocity() overloads that take
  one. The plain reads share nothing.
- fluid_surface::height_with / velocity_with and a surface_memo the
  caller owns; the defaults ignore it. ocean_surface passes it to the sea.
- field_set::apply keeps one memo per cell, for the cell's height and its
  velocity at the same clipped centre.

The memo is keyed on the point, the time and the digest as before, so
every value is unchanged.
@transfix
transfix enabled auto-merge (squash) November 13, 2026 03:54
@transfix
transfix merged commit 76cacaa into master Nov 13, 2026
29 of 33 checks passed
@transfix
transfix deleted the feat/wasm-policy-pure branch November 13, 2026 09:33
transfix added a commit that referenced this pull request Nov 13, 2026
# Conflicts:
#	docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md
#	src/cvc/tests/ariadne_wasm_test.cpp
transfix added a commit that referenced this pull request Nov 13, 2026
transfix added a commit that referenced this pull request Nov 13, 2026
Conflicts: ari's and arigl's main, where #1178 adds --exec-policy's
apply_exec_policy(app, o) and this branch adds setup_media(app, o), both
right after the app is made. Both stay, the policy first ("before anything
builds the scheduler").
transfix added a commit that referenced this pull request Nov 13, 2026
The one conflict was arigl_web_smoke.mjs. Both sides are kept:
- the /apps/up endpoint, with #1200's ISOLATION headers on its replies as on every response;
- the settle probe reads out and isolated/sab;
- each case runs its before/inject and #1200's isolation check.
The headless-Chrome smoke passes 6/6 here, the picked-file upload included.
Master since then: #1179, #1174, #1196, #1198, #1178, #1157, #1172, #1200.
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