Skip to content

ariadne: guests' ari_init at load, and guest calls from init: (G1, second part) - #1094

Merged
transfix merged 7 commits into
masterfrom
feat/wasm-guests-2
Nov 9, 2026
Merged

transfix merged 7 commits into
masterfrom
feat/wasm-guests-2

Conversation

@transfix

@transfix transfix commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Stacked on #1093 (base feat/wasm-guests), which is stacked on #1091. It is rebased and retargeted to master as those land, and CI runs then; its recipe run is cancelled while it's stacked.

G1, second part: a guest's ari_init at load, and guest calls from init:. Before this, a call from init: raised RuntimeError, because init: runs on a scheduler of its own and its program can't park. This is the roadmap's own example: init: (state-set "score" (score_route (state-get "route"))).

What's in it

  • ScriptLane::run(activation, options, max_seconds) runs an activation to its end now.
    • It starts the activation, then pumps the app's scheduler a frame at a time until it ends. The pumping is done by Runtime::pump(), the drain's pump and sweep and nothing more.
    • It runs under the activation's lane caps, with a wall-clock backstop (30 s), past which it stops the activation.
    • It refuses with a RuntimeError from inside a step of the app's scheduler, which it would have to re-enter.
  • ProgramLane::init gives work done at load run_init's caps: 10 million steps and 5 s.
  • ari_init. A guest that exports it has it run that way at every load, after its exports and hooks are registered and before the document's init:. It may call the host as an export may. A failure fails the load.
  • Calls from init:. AppRuntime::register_async_work_function takes a blocking form. The provider binds that form where the lane's scheduler isn't the app's (the init: lane), and the async function, which parks the program, everywhere else. ScriptLane::export_activation gives ScriptLane::run as the blocking form. Two routes that don't work:
    • A kernel can't do it: state_exec forbids a kernel to run processes (STATE_EXEC_EXCEPTIONS.md §3.7).
    • A plain native wrapping the async one loses the program's place to park.
  • Provider fix. The provider now looks at the app only when its runtime has such functions. The provider of a runtime that has gone stays registered (with emptied verbs), and its app may be gone too. Reading it unconditionally hung whole-suite runs here.

Tests

Local runs, Windows, MSVC 14.44, static Release core tree plus arix:

  • ariadne_wasm_test 12/12 ×3, with the new AriInitAndInitCallsRunAtLoad: ari_init ran before init:, and init: called the guest.
  • ariadne_script_engine_test 20/20 ×3:
    • RunFinishesAnActivationNow: a yield passes; the init caps let through 20,000 steps that an action's cap stops; a call from inside a step is refused.
    • The init: case of AnExportedCallParksOnItsActivation now runs the activation and gets its value.
  • ariadne_runtime_test 262/262, ariadne_requires_test 20/20, ariadne_host_test 57/57.
  • ctests: arix_wasm_block (its new setup case checks ari_init and the init: call) and ari_wasm_needs_arix.
  • clang-format 18.1.8 is clean on the changed lines.

Docs

  • ARIADNE.md §9.6: calls from init:, and ari_init.
  • The roadmap: §8.3 adds "G1's second part" and trims "Left for G1"; the G1 row is updated.

The seam G1 (WebAssembly guests on wasmtime) and L1 (Lua) plug into beside
Python (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md 3.1, 8.3-8.7).

- inc/cvc/ariadne/script_engine.h: ScriptEngine (language, has_module,
  load_block, unload), registered once per process by language
  (register_script_engine), which makes its block a key the loader keeps
  and its tokens hold; set_script_engine goes. ScriptBlock is what a
  block hands its engine: the block, the document's path, dir and prefix.
- ScriptLane, one per runtime and engine (AppRuntime::use_script_engine):
  the document's function registry, activations, and hooks (an on: event
  as an action, every frame and a changed value as a resident, one in
  flight).
- Activations run like sliced tasks: a process of the document's program
  lane (Runtime::start_process: its owner tag, chroot, channel policy,
  lock manager, functions: and ariadne.limits.* caps, which an activation
  may lower and never raise), a DSL loop around (script-step) that steps
  a ScriptActivation one slice at a time. A slice charges DSL steps, so
  the step cap is the gas cap; it may finish, yield the frame, await a
  future, or call any function the lane holds, which the loop applies in
  the process (narrowed by may_call). A language's activations share
  ariadne.limits.<language>_frame_budget (0.008 s) of each frame
  (exec_frame).
- Python's engine is a ScriptEngine: it answers the tokens and runs the
  python: block in load_block, and attach() uses it instead of a load
  hook. What a document sees is unchanged.
- Tests: ariadne_script_engine_test (a stub engine through all of it);
  the AriadneRequires token test through a stub Python engine.
A document's wasm: block runs a compiled plugin in arix and ariglx, as a
ScriptEngine on P1b's interface (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md
8.2-8.7; ARIADNE.md 9.6).

- src/ariadne_wasm: the runtime interface (guest_runtime.h) and its
  wasmtime backend, where each slice is one wasmtime_call_future_poll
  under a fuel yield interval and an import that waits is an async host
  function; a CBOR codec for DSL values; and the engine: the wasm:
  block (module, export, hooks, imports, limits, priority), an instance
  per document, _initialize, and the guest ABI (values as CBOR in the
  guest's memory, ari_alloc, the call, reply, yield and fail imports).
- ScriptLane::export_activation: a function whose calls are activations
  the caller parks on (an async function whose work starts itself, so no
  pool thread, and the wait counts against the caller's caps), with
  -async futures. AppRuntime::register_async_work_function under it.
  ActivationOutcome keeps a failed step's exception, so it re-raises
  with its own class.
- Fuel is charged as DSL steps (ariadne.limits.wasm_gas_per_step), under
  the action caps and the wasm frame budget; one activation per
  instance; a guest calling its own export is refused; imports:
  narrows its calls (state.read, state.write, msg, net, call).
- WasmError joins the built-in classes (18), the wasm token and the
  loader's warning for a wasm: block on a host without guests.
- arix and ariglx carry the engine where wasmtime's C API is found
  (-DARI_WITH_WASM / -DARIGL_WITH_WASM require it); CI's package-linux
  installs the cvcpkg wasmtime package.
- Tests: ariadne_wasm_test (a WAT guest), the export_activation stub
  case, and the arix_wasm_block / ari_wasm_needs_arix ctests.
…cond part)

ScriptLane::run runs an activation to its end now: it starts it and
pumps the app's scheduler a frame at a time (the new Runtime::pump)
until it ends, under its lane's caps, with a wall-clock backstop. It
refuses from inside a step of the app's scheduler, which it would
re-enter. ProgramLane::init gives a load's work run_init's caps (10
million steps, 5 s).

- The wasm engine runs a guest's ari_init that way at every load,
  after its exports and hooks are registered and before the document's
  init:. A failure fails the load.
- An exported activation called from init: (whose scheduler is its own,
  so its program can't park) now runs to its end in the call:
  AppRuntime::register_async_work_function takes a blocking form, which
  the provider binds where the lane's scheduler isn't the app's. A
  kernel can't do this (state_exec forbids a kernel to run processes),
  and a wrapper around the async native loses its place to park.
- The provider computes that only when its runtime has such functions:
  a gone runtime's provider stays registered, and its app may be gone.

Tests: RunFinishesAnActivationNow and the init: case of
AnExportedCallParksOnItsActivation (stub engine);
AriInitAndInitCallsRunAtLoad (wasm); wasm_block.ari's setup case.
Base automatically changed from feat/wasm-guests to master November 9, 2026 10:14
master's tree is feat/wasm-guests' (ec7eef2), which this branch already holds.
Master's test (#1077) compared one agent's position. scatter_free's draw
differs between standard libraries, and on macOS that agent stays where
it began under both policies, so the macOS recipe and package legs fail
here. This is the same hunk as open #1095, so merging master once #1095
lands is clean.
@transfix
transfix enabled auto-merge (squash) November 9, 2026 18:03
@transfix
transfix merged commit ad8b075 into master Nov 9, 2026
11 of 30 checks passed
@transfix
transfix deleted the feat/wasm-guests-2 branch November 9, 2026 18:35
transfix added a commit that referenced this pull request Nov 9, 2026
The conflicts were #1094's own lines, squashed on master, against this
branch's edits of them (the ABI notes in wasm_engine.h, and roadmap 8.3's
G1 lists and the G1 row); this branch's side is kept. #1075's roadmap
changes (5.1, 5.5, 9, 10) come in untouched. The 8.4.1 note now gives
mesh_read's attribute as a pointer and a length, as the import takes it.
transfix added a commit that referenced this pull request Nov 9, 2026
)

Master adds a blocking form for async work functions, used where a
program can't park (init:), and ScriptLane::run / Runtime::pump to run
an activation to its end outside the frame loop (a guest's ari_init at
load, an exported call from init:).

Fitted to Stage 1b:
- The seventh provider binds the blocking form where the program's host
  can't park (host.parking_scheduler() is null: init:'s inline host,
  S1-Q2), not where ictx.sched isn't group 0's. An isolated document's
  actions park on their group's host and keep the async form.
- register_async_work_function swaps its (marshal, blocking) pair in
  under the verb tables' lock.
- Runtime::pump is drain_end's pump and sweep: group 0 as
  scheduler_to_pump says and the document's group through the app's
  pool, then the sweep where its processes run (sweep_document, shared
  with drain_end). It asserts it is outside a pump.
- ScriptLane::run refuses inside a step of the document's scheduler or
  group 0's, or inside a frame's pump_all, and waits on the document's
  scheduler. Exported calls keep finishing through the host they were
  made on.
- The group-0 reason is logged only once a document is set: a first
  load's ari_init or init: call places the document before its channels
  are known, and the load decides again after set_root.
- New ScriptEngineTest.AnIsolatedDocumentsInitCallRunsInItsGroup: an
  isolated document's init: calls an export at a first load (group 0)
  and at a reload (its group). It fails with a group-0-only pump (the
  reload's call runs past 30 s).
- STATE_EXEC_THREADED.md: the blocking form and run in the scripting
  engines bullet and the provider table.
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