Repository navigation
ariadne: guests' ari_init at load, and guest calls from init: (G1, second part) - #1094
Merged
Merged
Conversation
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.
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
enabled auto-merge (squash)
November 9, 2026 18:03
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_initat load, and guest calls frominit:. Before this, a call frominit:raisedRuntimeError, becauseinit: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.Runtime::pump(), the drain's pump and sweep and nothing more.RuntimeErrorfrom inside a step of the app's scheduler, which it would have to re-enter.ProgramLane::initgives work done at loadrun_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'sinit:. It may call the host as an export may. A failure fails the load.init:.AppRuntime::register_async_work_functiontakes a blocking form. The provider binds that form where the lane's scheduler isn't the app's (theinit:lane), and the async function, which parks the program, everywhere else.ScriptLane::export_activationgivesScriptLane::runas the blocking form. Two routes that don't work:Tests
Local runs, Windows, MSVC 14.44, static Release core tree plus
arix:ariadne_wasm_test12/12 ×3, with the newAriInitAndInitCallsRunAtLoad:ari_initran beforeinit:, andinit:called the guest.ariadne_script_engine_test20/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.init:case ofAnExportedCallParksOnItsActivationnow runs the activation and gets its value.ariadne_runtime_test262/262,ariadne_requires_test20/20,ariadne_host_test57/57.arix_wasm_block(its newsetupcase checksari_initand theinit:call) andari_wasm_needs_arix.Docs
init:, andari_init.