Skip to content

arisrvx: clients' WebAssembly guests, (room-run module ...), run as their client's program (G4) - #1283

Merged
transfix merged 1 commit into
masterfrom
feat/arisrv-client-guests
Nov 16, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/arisrv-client-guests

Conversation

@transfix

Copy link
Copy Markdown
Owner

G4, first part of the scripting-hosts roadmap (§6.3 and §8.6): a client can send arisrvx a WebAssembly module to run there as the client's own. It runs as that client's S3 program does, so it has the same chroot, environment, write gate and caps, and nothing more.

# the relay's --doc (arisrvx built with wasmtime)
server:
  client_guests: { steps: 2000, time: 0.05, memory_mb: 8 }   # or `on`
; a client that joined the relay
(room-run (guest-bytes) 41 "score")                         ; the module's export `run`, with (41 "score")
(room-run-opts (dict "export" "score") (guest-bytes) 41)    ; another export

The call

  • room-run takes the module's bytes in place of the DSL source: a b"\0asm..." literal, or bytes the client read. room-run-async and room-run-opts work the same way, and room-run-opts' "export" names the function to call (run by default).
  • On room-call's path the request carries "guest" (bytes) and "export" in place of "fn" or "program". The value comes back as typed CBOR.

How the relay runs it

  • As its client's program. ServerDocument::run_client_guest starts S3's client process (factored out as start_client). That gives it:
    • the participant's chroot, conf.rooms.<room>.participants.<pid>;
    • the default-deny environment: the read lane's builtins, plus the five writers held to room_write_gate::may_write;
    • the caps from client_guests:, which only lower ariadne.limits.action_max_*;
    • one program or guest per client at a time.
  • The guest is that program's one call.
    • ScriptEngine::client_activation is new. It is an engine's way to run a client's code, and is null by default.
    • It makes the activation. run_as_program_work, factored out of export_activation's sliced path, runs it as the program's own sliced work.
    • So the guest's call, state imports and data reads reach only that environment.
    • Its gas is charged as the program's steps, so steps caps it. It can't call the two natives that run it.
  • A fix this needed in the sliced call. A sliced call's call() ran through a small DSL closure that took apply from the process's environment. A client's narrowed environment doesn't hold apply, so every such call was a NameError. The closure now has apply in a scope of its own (SlicedCall). What the activation calls is still only what the process holds.
  • In the wasm engine (ClientGuest):
    • Compiled off the loop. The module compiles on the app's pool (submitPooled), off the relay's loop.
      • The relay holds the guest until it has compiled (ScriptActivation::ready, new), and starts its program at the next step after that. So the wait costs none of its caps.
      • Meanwhile the client counts as running. A compile that takes over 10 s ends resource_exhausted.
      • The last 16 modules stay compiled, keyed by their bytes.
    • No start function. A module with one is refused (has_start, new in wasm_binary), because a start would run to its end on 100M gas as the instance is made.
    • Setup gas. _initialize and each ari_alloc get 1M gas, a thousand steps, charged to the program.
    • Its own instance. Each run gets a fresh instance, gone when the run ends.
    • Memory. Its linear memory is capped at memory_mb (16 MiB by default), and never above ariadne.limits.wasm_max_memory.
    • What it can't do. data.write is refused (a client's program makes no host object). It gets WASI's stubs alone, no ari_init and no hooks.
  • Hosts.
    • arisrvx links the engine where wasmtime's C API is found. -DARISRV_WITH_WASM=ON makes a missing wasmtime a configure error.
    • Stock arisrv refuses a document with client_guests:.
    • arisrvx refuses one under --bind-writes off.
  • Errors:
    • invalid: not a module, over 1 MiB, a start function, or no export named.
    • failed: it doesn't compile, doesn't export the function, traps, fail()s, or raises PermissionError or MemoryError.
    • unavailable: no client_guests:, a relay without WebAssembly, or the document not loaded.
    • rate_limited and resource_exhausted, as for programs.

Not in it (later parts of G4)

Tests

  • New gtests:
    • ServerBlockTest.ClientGuestsTakeOnOffOrCaps.
    • Four ServerDocumentTest cases with a fake engine, so they run without wasmtime:
      • the run, its value and the memory cap;
      • what its calls reach: no spawn, not the running natives, not the relay's keys, nothing outside its participant;
      • the refusals and caps;
      • the hold: a guest that isn't ready isn't started however many steps go by, counts as running, and starts once ready.
    • Three WasmClientGuestTest cases on wasmtime:
      • a guest's run, its writes, and a fresh instance each time;
      • what it may not do: pose, spawn, volume_new, memory past the cap, the step cap;
      • the engine's refusals: not a module, a start function, a module that doesn't validate, a missing export.
    • RoomCallsTest.ParseCall gains the guest field.
  • End to end: arisrvx_room_call_guest runs arisrvx with a --doc and an ari test client over gRPC, in seven cases. The guest is src/arisrv/tests/client_guest.wat, carried as bytes in the client. arisrv_doc_client_guests_need_arisrvx checks stock arisrv's refusal.
  • Locally on Windows (static Release with arisrv, arisrvx, ari and wasmtime 45):
    • the 29 targeted tests pass (ServerDocumentTest, ServerBlockTest, RoomCallsTest, WasmClientGuestTest, the two new ctests, and S3's arisrv_room_call_program and arisrv_room_call_unavailable);
    • 232 neighbouring tests pass: the room relay, room-call, every arisrv* test, the script lane and engine, and every Wasm* test;
    • the whole ^Ariadne suite passes, 825 of 825 (5 skipped as on master).
  • Lint: g++ 16 -fsyntax-only -Wall -Wextra finds nothing new in the five changed sources or the three changed tests (it caught a duplicate helper name, fixed). clang-format 18.1.8 is clean on the changed lines.

…heir client's program (G4)

A client can send arisrvx a WebAssembly module to run as its own
(ARIADNE_SCRIPTING_HOSTS.md §6.3 and §8.6, G4's first part). The server
document opts in with server: client_guests:, on or {steps, time,
memory_mb}, the same caps as client_programs:.

- The call. (room-run module arg ...) takes the module's bytes in place of
  the source, and calls its export run, or the one (room-run-opts (dict
  "export" E) ...) names, with the list of the arguments. The request
  carries "guest" and "export" on room-call's path.
- As its client's program. ServerDocument::run_client_guest starts S3's
  client process (now start_client): the participant's chroot, the
  default-deny environment with the five gated writers, the caps and one
  at a time. The guest is that program's one call: ScriptEngine's new
  client_activation makes it, and run_as_program_work (factored out of
  export_activation) runs it as the program's sliced work. So its call,
  state imports and data reads reach only that environment. data.write is
  refused, and memory_mb caps its linear memory (16 MiB by default).
- Its calls in a narrowed environment. A sliced call's call() ran through
  a closure that used apply from the process's environment, which a
  client's program doesn't hold. The closure now has apply in a scope of
  its own, so a call still reaches only what the process holds.
- In the wasm engine. The module compiles on the app's pool, off the
  relay's loop. The relay holds the guest until then (the new
  ScriptActivation::ready), so the wait costs none of its caps, for at
  most 10 s. The last 16 modules stay compiled. A start function is
  refused (has_start: it would run unsliced as the instance is made).
  _initialize and ari_alloc get 1M gas each, charged to the program. Each
  run has its own instance.
- Hosts. arisrvx links the engine where wasmtime is found
  (ARISRV_WITH_WASM makes it required). Stock arisrv refuses a document
  with client_guests:, and arisrvx refuses one under --bind-writes off.

Tests:
- ServerBlockTest.ClientGuestsTakeOnOffOrCaps.
- Four ServerDocumentTest cases with a fake engine: the run, what its
  calls reach, the refusals and caps, and the hold until it is ready.
- Three WasmClientGuestTest cases on wasmtime: the run, what a guest may
  not do, the engine's refusals.
- RoomCallsTest.ParseCall: the guest field.
- arisrvx_room_call_guest: arisrvx and ari over gRPC, with
  client_guest.wat as bytes.
- arisrv_doc_client_guests_need_arisrvx.

Docs: ARIADNE.md §9.7.2, and the roadmap's status, §6.3, §8.6 and the S3
and G4 rows.
@transfix
transfix enabled auto-merge (squash) November 16, 2026 00:26
@transfix
transfix merged commit 8b2d2ff into master Nov 16, 2026
29 checks passed
@transfix
transfix deleted the feat/arisrv-client-guests branch November 16, 2026 05:32
transfix added a commit that referenced this pull request Nov 16, 2026
- script_engine.cpp: #1283 factors the sliced form's process lookup into calling_process,
  which run_as_program_work (a client's WebAssembly guest, run as its client's program) shares.
  The lookup keeps this branch's group: the calling process is on the group whose pump runs the
  call (an isolated document's), else on group 0.
- STATE_EXEC_THREADED.md: notes that run_as_program_work shares the lookup.
transfix added a commit that referenced this pull request Nov 18, 2026
…, with hooks, leases and a gas ledger (#1290)

A plan, nothing built: docs/roadmap/ARIADNE_RESIDENT_GUESTS.md, from the
owner's ask after G4's first part (#1283).

- RG1: a client starts a resident guest that the relay keeps, one
  instance across firings, with hooks (on_tick, watch, msg, timer,
  owner, close). It writes its own conf.rooms.<room>.guests.<gid> under
  the participant rule and reads what its owner is sent.
- RG2: a gas ledger per principal, kept by salted hash: a grant at first
  sight, refill as a token bucket, a fee per firing, reserve then settle,
  starving at zero, a journal store behind an interface.
- RG3: leases past the connection (linger with a reset on reconnect,
  forever, ttl), reattaching by principal, closing reasons, and an admin
  role.
- RG4-RG7: DSL residents, hibernation, guests on clients (a Promise
  compile and the gas pass in the page), and the Worker backstop.

Twelve decisions (D1-D12) are open, each with a recommendation.
ARIADNE_SCRIPTING_HOSTS.md §8.7 points to it.
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