Skip to content

ariadne: the script_engine interface (P1b), with Python moved onto it - #1091

Merged
transfix merged 1 commit into
masterfrom
feat/script-engine
Nov 9, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/script-engine

Conversation

@transfix

@transfix transfix commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

The script_engine interface from the scripting-hosts roadmap's P1b row (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md §10). It is the one prerequisite of G1 (WebAssembly guests on wasmtime) and of L1 (Lua). Python now runs on it, and what a document sees is unchanged.

What's in core

inc/cvc/ariadne/script_engine.h + src/cvc/ariadne/script_engine.cpp, libpython-free:

  • ScriptEngine: language(), has_module() for the <language>.<module> tokens, load_block(ScriptBlock, ScriptLane &, warnings), and unload(ScriptLane &).
    • register_script_engine is process-wide. It makes the language a block key and makes its tokens hold. It replaces the token-only set_script_engine; has_script_engine and capability_holds now read the registry.
    • AppRuntime::use_script_engine is per runtime. Each load hands that engine's block to it after the parse, before the load hooks, requires: and init:, which is where Python's load hook ran. From the second load on, the engine is unloaded first and its lane's hooks are dropped.
  • ScriptBlock: what a block hands its engine. That is the language, the block as written, the document's path, directory and prefix, and the module ("" until module blocks run).
  • ScriptLane: one per runtime and engine. It is how the engine reaches the document, and it is the program lane's own surface (§8.6):
    • functions: export_function / export_async_function, the one registry (AppRuntime::register_function);
    • activations (§8.5): start, stop, running;
    • hooks (§8.7): on_event runs an action per on: event. on_frame runs a resident at the end of each drain, and on_watch a resident when a value under the prefix changed. Both keep one delivery in flight, so a slow one coalesces.
  • Activations are built like sliced_task.h. Each is a process of the document's program lane, started through the new Runtime::start_process(LaneProcess).
    • It runs in an environment made as an action's (make_action_context), with the document's owner tag, chroot, channel policy, lock manager and functions:.
    • It runs under ProgramLane::action or resident caps from ariadne.limits.*. Its own caps only lower them.
    • The process is a DSL loop around (script-step). Each step runs one ScriptActivation::step(ScriptSlice &) of ariadne.limits.<language>_slice_steps (64).
    • A slice ends one of five ways: more work, finish, yield_frame, await(future), or call(function, args).
    • charge(steps) adds DSL steps (data steps) to the process, so the lane's step cap is the gas cap.
    • The loop makes a call itself, as (apply f args) inside a try. So an engine reaches exactly what a DSL program there reaches (chroot, link: holes, locks), and a call that waits parks the process. ActivationOptions::may_call narrows the calls; a refused name comes back as a PermissionError.
    • A language's activations share ariadne.limits.<language>_frame_budget (0.008 s) of each frame. The frame comes from the new exec_frame(app), the pump clock the Runtimes share.
    • A throw from a step fails the activation with its class. An activation that never finished is cancelled when its process ends, its document's teardown included.
  • AppRuntime also gains app() and add_warning(), so a hook that fails to start becomes a runtime warning.

Python on it

src/ariadne_python/python_engine.cpp:

  • PythonScriptEngine answers the tokens and runs the python: block in load_block, with the same code that ran it as a load hook.
  • Engine registers it at boot and unregisters it before Py_FinalizeEx.
  • attach() calls use_script_engine instead of add_load_hook.
  • It starts no activations: calls stay inline natives (async ones on the pool), and Host's hooks stay add_frame_hook.

Not in this PR

  • The rest of P1b: run -m, load: module blocks, --python-allow, and GRL-SNAM's ports.
  • G1 itself. §8.3 now lists what G1 adds on top of this interface:
    • the wasm_runtime, the guest ABI and wasm:;
    • in-program sliced calls;
    • a pump budget that counts slice steps;
    • one activation per instance;
    • key, pointer, signal and message hooks;
    • WasmError, ari_init's lane, the policy option, and pure exports.

Tests

  • New ariadne_script_engine_test (18 cases), a stub engine through all of it:
    • registration, and the block reaching its engine with the lane;
    • a runtime that doesn't use the engine, a block that throws, and a reload that unloads first;
    • slices in one drain, an on_done that starts the next activation, step caps (lowered, never raised; a resident has no total), a yield, and the frame budget;
    • calls (state natives under the chroot, a host function, a document function, a raise, a NameError), and may_call;
    • an await, a throwing step, stop and teardown;
    • the event, frame and watch hooks.
  • AriadneRequires.ScriptLanguageTokensHoldOnlyWithItsEngine now registers a stub Python engine instead of calling set_script_engine.

Local runs on Windows, MSVC 14.44, RelWithDebInfo, shared (build-scriptengine):

  • ariadne_script_engine_test: 18/18, and 18/18 on each of 30 repeats (the frame-budget case busy-waits).
  • ariadne_requires_test: 20/20. ariadne_host_test: 57/57.
  • The scripting-host ctests: 7/7.
    • arix_python_block ran its 5 cases.
    • Also arix_python_program, arix_python_error, arix_python_interpreter, ari_python_needs_arix, ariglx_python_check and ariglx_python_program.
  • The ari_* and arigl_* ctests: 12/12.
  • clang-format 18.1.8 on the changed lines: clean.
  • ariadne_runtime_test: 262/262, from a static Release build of this branch (ariadne_script_engine_test 18/18 and requires 20/20 there too). Master's shared Windows builds no longer link this suite: gtest's death_test_style flag has been unresolved since 3320f18, which is unrelated to this PR.

Docs

docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md:

  • the status lines;
  • §3.1 (what the Python engine installs, and how);
  • §8.3 (the engine interface that landed, and what's left for G1);
  • the P1b, L1 and G1 rows.

Merge note

#1081 (S1, arisrvx) touches the same lines of python_engine.cpp (attach(), the constructor) and the hint string in requires.cpp and its test. Whichever lands second rebases. That PR's server branch keeps add_load_hook(refuse_python_block), which still works beside use_script_engine.

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.
@transfix
transfix enabled auto-merge (squash) November 9, 2026 07:23
@transfix
transfix merged commit 806c70a into master Nov 9, 2026
16 of 30 checks passed
@transfix
transfix deleted the feat/script-engine branch November 9, 2026 09:05
transfix added a commit that referenced this pull request Nov 9, 2026
Master's script_engine interface (#1091) runs a scripting engine's
activations as document processes (Runtime::start_process). Fitted to
Stage 1b:

- start_process submits to the document's scheduler (its isolated
  group's, else group 0), as submit_action does; master's executed on
  app.exec_scheduler() with a context made for the document's group.
  It is a host-thread call (assert_outside_pump).
- An activation's natives run its language inline, charge the slice to
  current_process(), look up the document's functions and share a
  per-language frame budget: they stay on the host thread. New
  Runtime::require_host_thread(why) gives an isolated document a host
  affinity group, decided again as a late registration is (m3).
  AppRuntime::use_script_engine declares it; start_process declares it
  for a process with natives of its own (LaneProcess::extend) and
  refuses one while the document still runs in an `any` group.
- ScriptLane::stop and running reach the document's group
  (current_group), not group 0.
- Conflicts: ariadne.h's includes and forward declarations (both kept);
  ~AppRuntime unloads the engines first, then swaps the verb table out
  under its lock. Master's engine frame hooks landed in drain_end and
  its sweep change in sweep_actions.

Tests: ScriptEngineTest.AnIsolatedDocumentThatUsesAnEngineRunsOnTheHostThread
(failed on the plain merge: an `any` group, the activation in group 0,
stop and running missing it) and AProcessWithNativesIsRefusedInAWorkersGroup.
Docs: STATE_EXEC_THREADED.md (affinity, scripting engines, late
registrations), ARIADNE.md, APP_API.md.
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