Skip to content

Ariadne: each document's host functions are its own when two runtimes share an app - #1305

Merged
transfix merged 1 commit into
masterfrom
fix/cross-doc-exports
Nov 16, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/cross-doc-exports

Conversation

@transfix

@transfix transfix commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Two AppRuntimes on one cvc::app, both documents loaded before either runs: the first document's export call reached the second document's guest. G6's work on ProcExitEndsTheGuestNotTheHost (#1199) found it: document art's (args) returned document plain's argc.

Cause

Each AppRuntime bound its verbs and host functions through one register_action_intrinsics provider on the app. Every program env on that app ran every runtime's provider, in the order they were registered, so the last runtime's who overwrote the first's in the first document's own env.

A scripting engine's exports are host functions (ScriptLane::export_function / export_activation → AppRuntime::register_function / register_async_work_function), so every language had the flaw:

  • wasm guests;
  • Python: the console natives, and a python: block's export: through pycvc.host_function;
  • the verbs (register_verb, quit) and the (data-*) verbs, which bound under the other document's prefix.

The same leak made a third document's (has? "who") and its requires: see the other documents' exports.

The existing tests didn't catch it because they only start a second AppRuntime after the first one is done.

Fix

The provider is now the document's own, not the app's:

  • Runtime::add_program_intrinsics(provider). The provider runs in every program env that Runtime builds, after the app's providers, and in no other Runtime's. That covers make_action_context (actions, residents, children, start_process), the names probe (has?, requires:), and a mounted module's init:.
  • Runtime::program_intrinsics() plus a new trailing own parameter on run_init. The document's own init:, and the children it spawns, get them too.
  • AppRuntime::ensure_intrinsics registers on rt_ instead of the app.

The list lives on Runtime::Impl, so there are no new mutable statics and nothing goes onto the allowlist. The app's action_intrinsics_table is untouched. A gone runtime's provider now goes with it, instead of staying in the app's list with emptied verbs.

ActionIntrinsicProvider's alias moves up in ariadne.h so Runtime can name it. run_init's new parameter is defaulted, so existing callers compile unchanged.

Tests (failing first)

Each new test loads two documents on one app that export the same name, and calls each one before the other runs. All three failed on master in this tree before the fix:

  • ScriptEngineTest.TwoDocumentsOnOneAppEachCallTheirOwnExports (stub engine): a function, an activation, its -async form, init: on a reload, and a bare third document's has?. On master the first document got ui.s2 for each, and the third document's has? answered yes.
  • WasmEngineTest.TwoDocumentsOnOneAppEachCallTheirOwnGuest: two guests whose (who) answer 1 and 2, called from an action, as a future, and from init:. On master the first document got 2.
  • ArixEngine.TwoDocumentsOnOneAppEachRunTheirOwnPython: the console natives on master ran the first document's cell in the second document's namespace (2). Its export: half needs pycvc, so the test now gets the build's pycvc paths, and it skips that half where pycvc can't be imported. It is a ctest entry of its own (arix_engine_two_documents, through --gtest_filter), because each case boots an interpreter and a process boots one only once.

To check that the fix is that one line: with only ensure_intrinsics' registration put back on the app, all three fail again, the Python export: half included ((which) answered 2).

Local results

Windows, MSVC Release, static. The tree has arix with Python (cvcpkg python312), wasmtime, and pycvc core. All of it ran on this change over master 591b8f4. The rebase onto 3976ae2 adds only #1304, which is cvcGL and not in this tree. Head is 98ff1cc.

  • ctest -R "Wasm|wasm|wasi|Wasi|ScriptEngine|arix|AriadneRequires|ari_python|ari_wasm": 134/134 passed. arix_matplotlib_backend skipped, since this Python has no matplotlib. That run covers:
    • ariadne_wasm_test (48 cases, among them WasmEngineTest 16)
    • ariadne_script_engine_test 32
    • ariadne_requires_test 20
    • every arix ctest, among them arix_engine_test and arix_engine_two_documents (its export: half ran, not skipped)
  • ariadne_runtime_test 300/300, whole suite, one process.
  • ariadne_host_test 59/59.
  • clang-format 18.1.8 on the changed lines: clean.

Overlap

#1088 (threaded Stage 1b) rewrites AppRuntime::ensure_intrinsics into providers by kind, still registered on the app, and drops action_intrinsics_snapshot. Whichever of the two lands second has to carry the other over: here, that means the per-runtime registration and run_init's own. #1276 adds tests beside the ones src/ari/CMakeLists.txt changes here.

… share an app

Two AppRuntimes on one cvc::app, both documents loaded before either runs:
the first document's export call reached the second document's guest. Each
AppRuntime bound its verbs and host functions through a provider on the app
(register_action_intrinsics), and every program env on the app ran all of
them, the last registered winning. A scripting engine's exports are host
functions, so wasm guests, Python's console natives and a python: block's
export: all crossed; so did the verbs, quit and the (data-*) verbs, and a
third document's has? and requires: saw the others' names.

Runtime::add_program_intrinsics: a provider of the Runtime's own, run after
the app's in every program env that Runtime builds (an action, a resident,
a child, start_process, a module's init:, the has?/requires: probe) and in
no other's. Runtime::program_intrinsics() hands them to run_init (a new
defaulted `own` parameter) for the document's init: and its children.
AppRuntime registers its provider there instead of on the app. The list
lives on Runtime::Impl: no new mutable state outside it.

Tests, failing first on master:
- ScriptEngineTest.TwoDocumentsOnOneAppEachCallTheirOwnExports
- WasmEngineTest.TwoDocumentsOnOneAppEachCallTheirOwnGuest
- ArixEngine.TwoDocumentsOnOneAppEachRunTheirOwnPython, a ctest entry of its
  own (arix_engine_two_documents): each case boots an interpreter.
@transfix
transfix merged commit 7705635 into master Nov 16, 2026
29 of 30 checks passed
@transfix
transfix deleted the fix/cross-doc-exports branch November 16, 2026 20:33
transfix added a commit that referenced this pull request Nov 16, 2026
transfix added a commit that referenced this pull request Nov 16, 2026
…#1305, #1310, #1311)

#1305 gives each Runtime program-lane providers of its own (add_program_intrinsics), so two
documents on one app no longer reach each other's verbs and host functions, and moves
AppRuntime's provider there from the app's list. This branch had split that provider in seven,
each registered on the app with its kind (S1-Q7). Conflicts in ariadne.h, app_runtime.cpp and
ariadne.cpp keep both:

- Runtime::add_program_intrinsics takes a kind too (the form without one is host_only, as
  register_action_intrinsics's), and the Runtime's own list keeps it. AppRuntime adds its seven
  providers there, each with the kind it had, in the same order.
- install_providers runs any list by kind; the Runtime's own run after the app's, by the same
  rules, wherever an env is built: an action, a resident, a spawned child (finish_context), the
  names probe, and init: and a module's init: (every kind as it is, on their own thread).
- host_only_bindings counts the Runtime's own host_only providers, so one that binds anything
  pumps the document's group on the host thread, as an app provider does.
- add_program_intrinsics marks the placement stale, as a late host verb does.
- The own list is read where an env is built, a spawned child's on its pumping worker, so it is
  under a mutex of its own (own_mutex), copied, and run unlocked; names_mutex no longer guards it.

STATE_EXEC_THREADED.md: the Runtime's own providers, AppRuntime's seven among them, and the
fourth late-registration path. Built locally (MSVC Release; AB.lock held the box, so the suites
were not run here); a test of the own providers by kind follows.
transfix added a commit that referenced this pull request Nov 17, 2026
AriadneIsolatedDocs.ARuntimesOwnProvidersInstallByKind covers what the #1305 merge (dc4f36d)
gave Runtime::add_program_intrinsics: a kind, run by the same rules as the app's providers.

In an isolated document's group, forced to move between threads (CVC_EXEC_FORCE_MOVE), an own
`any` provider binds on the worker and an own host_proxied one runs only on the frame's thread;
the group stays `any`. On a second Runtime of the same app, an own provider with no kind
(host_only) that binds a function gives that document's group `host`. Each Runtime's
has_function sees only its own providers' names.
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