Skip to content

arisrv: clients' DSL programs, (room-run ...), on a relay whose document opts in (S3) - #1273

Merged
transfix merged 1 commit into
masterfrom
feat/arisrv-client-programs
Nov 15, 2026
Merged

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

Conversation

@transfix

Copy link
Copy Markdown
Owner

S3 of the scripting-hosts roadmap (§6.3, tier 2): a client can send its relay a DSL program to run there as the client's own. It runs in stock arisrv, and in arisrvx the same way, never in Python.

# the relay's --doc
server:
  client_programs: { steps: 2000, time: 0.02 }   # or `on`: the action lane's caps
; a client that joined the relay
(room-run "(state-set (nth args 1) (+ (car args) 1)) (+ (car args) 1)" 41 "score")   ; 42

The call

  • (room-run "source" arg ...) parks the program until the value of the source's last form comes back. It also has room-run-async and (room-run-opts (dict "timeout" S) ...).
  • It rides room-call's path (room_calls.h): the request carries "program" in place of "fn", and the reply comes back the same way, as typed CBOR.
  • In the program, args is the list of the arguments.

How the relay runs it (ServerDocument::run_client_program)

  • Opt-in. The server document needs server: client_programs:: either on, or caps (steps, time, memory_mb) that only lower ariadne.limits.action_max_*. arisrv refuses a document with it under --bind-writes off.
  • As an action of the document (Runtime::start_process), on the relay's loop. run_program didn't fit: it has no chroot, no narrowed environment and no result value.
  • Chrooted to the sender's own participant, conf.rooms.<room>.participants.<pid>. The program reads and writes only there. It gets no room view, no published namespaces, and none of the document's state or functions.
  • Only writes the client could make itself. The environment has five writers: state-set, state-data-set, state-incr, state-cas and state-swap. Each checks its path with room_write_gate::may_write, the rule the transport applies to the client's own writes. So the relay's keys inside the participant (pose, device, net.relay, a stream's ready) stay the relay's, and so does a padded path the tree would trim onto one. Any other write raises PermissionError.
  • A default-deny environment.
    • It is made with the new LaneProcess::allow: a scope with no parent, as the read lane's evaluator is made.
    • It holds the read lane's builtins, the five writers and args. The read lane's list moved unchanged from ReactiveEngine to read_lane_builtins(), so both share it.
    • So nothing spawns, messages, watches, locks, sleeps, opens a file or the network, or calls (quit).
    • The special forms that remain (eval, root ...) can't reach past the environment.
  • One program per client at a time.
  • Errors:
    • unavailable: no client_programs:, or the document hasn't loaded.
    • invalid: the source doesn't parse on its own (so it can't close the wrapper), or is over 64 KiB.
    • rate_limited.
    • failed: it raised; the message is its report.
    • resource_exhausted: a cap stopped it.
    • too_large and internal, from the reply as for room-call.

Not in it (design choices to revisit)

  • Reads beyond its own participant. A natural widening is "what its client is sent", under the connection's read scope (S6). It's left out because that read scope lives in the transport.
  • Quoted forms as the program. to_string isn't a printer that reads back, so the program is its source text.
  • Calling the document's functions:.

Tests

  • New gtests:
    • ServerBlockTest.ClientProgramsTakeOnOffOrCaps.
    • Four ServerDocumentTest cases: the chroot and the value; the relay's keys, including a trimmed path; no way out (spawn, quit, msg-send, state-watch, state-delete, sleep); and the refusals and caps (opt-out, not loaded, unparseable, a source that tries to close the wrapper, over 64 KiB, rate_limited, the step cap).
    • RoomCallsTest.ParseCall gains the program field.
  • End to end: arisrv_room_call_program runs stock arisrv with a --doc and an ari test client over gRPC, in six cases. arisrv_room_call_unavailable now also checks that a relay with no --doc refuses a program.
  • Locally on Windows (static Release with arisrv, arisrvx and ari):
    • those 19 tests pass;
    • 163 neighbouring tests pass (the room relay, room-call, every arisrv* test, the script lane);
    • the whole ^Ariadne suite passes, 814 of 814. It covers the read lane, whose list moved.
  • Lint: g++ 16 -fsyntax-only finds nothing in the two changed sources. clang-format 18.1.8 is clean on the changed lines.

…ent opts in (S3)

A client can send its relay a DSL program to run there as its own
(ARIADNE_SCRIPTING_HOSTS.md §6.3, tier 2). The server document opts in
with server: client_programs:, either on or {steps, time, memory_mb} caps,
which only lower the action lane's.

- The call. (room-run "source" arg ...), room-run-async and room-run-opts
  ride room-call's path. The request carries "program" in place of "fn",
  and the reply comes back the same way, as typed CBOR.
- Where it runs. ServerDocument::run_client_program runs it as one of the
  document's actions (Runtime::start_process), chrooted to the sender's
  participant, conf.rooms.<room>.participants.<pid>. It runs in stock
  arisrv as in arisrvx, never in Python.
- What it may do. Its environment is default-deny (the new
  LaneProcess::allow). It holds the read lane's builtins (now
  read_lane_builtins()) and five writers: state-set, state-data-set,
  state-incr, state-cas and state-swap. room_write_gate::may_write checks
  each write, so the relay's keys there (pose, device, ...) stay the
  relay's. args is the list of the arguments. It has no spawn, messages,
  watches, locks, sleep, files, network or quit.
- One program per client at a time. The error codes are unavailable,
  invalid, rate_limited, failed and resource_exhausted.
- arisrv refuses a document with client_programs: under --bind-writes off.

Tests:
- ServerBlockTest.ClientProgramsTakeOnOffOrCaps.
- Four ServerDocumentTest cases: the chroot and the value, the relay's
  keys, no way out, refusals and caps.
- RoomCallsTest.ParseCall.
- arisrv_room_call_program: stock arisrv and ari over gRPC.
- arisrv_room_call_unavailable now also checks that a relay with no --doc
  refuses a program.

Docs: ARIADNE.md §9.7.1, and the roadmap's §6.3 and S3 row.
@transfix
transfix enabled auto-merge (squash) November 15, 2026 08:31
@transfix
transfix merged commit 6cab8d4 into master Nov 15, 2026
28 checks passed
@transfix
transfix deleted the feat/arisrv-client-programs branch November 15, 2026 16:44
transfix added a commit that referenced this pull request Nov 16, 2026
…#1253, #1255, #1256, #1264, #1268, #1271, #1273, #1277)

- ci.yml: the sanitizer list keeps this branch's tests (stream_test, net_ws_client_test,
  ariadne_host_test) and master's segmentation_intrinsics_test.
- STATE_EXEC_THREADED.md: the room-call verbs (room-run is #1273's) and #1252's segment.seeded
  provider in the provider table, both registered without a kind. room-call's async functions
  stay on the app's host: a reply settles on the relay client's reader thread through
  host.finish, so moving them to *ictx.host needs a finisher first.
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