Skip to content

arisrvx: Python services beside the relay (S1) - #1081

Merged
transfix merged 6 commits into
masterfrom
feat/arisrvx
Nov 9, 2026
Merged

transfix merged 6 commits into
masterfrom
feat/arisrvx

Conversation

@transfix

@transfix transfix commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

S1 of the scripting-hosts application-services cut (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md §6.5 and the S1 row in §10). It builds on S0 (#1046) and P1's engine (#985, #1000).

arisrvx is arisrv with an embedded CPython 3.12. arisrvx --python main.py [relay flags] runs the operator's program beside the relay, on a script thread of its own with one asyncio loop. That loop serves the program's ASGI apps (FastAPI on uvicorn). The relay never runs Python, never takes the GIL, and never waits on the program. The reference is the new ARIADNE.md §9.8.

from pycvc.ariadne import Host, serve_asgi
host = Host()
serve_asgi(app, host="127.0.0.1", port=8780)
host.run()      # until SIGTERM; the app's shutdown, then the relay

Risk 16, tested first

Tested on cvcpkg's python312 3.12.10 with uvicorn 0.53.0, FastAPI 0.141.1 and Starlette 1.7.0. Windows was tested here; Linux runs in this PR's CI.

  • Off the main thread, Server.serve() installs no signal handlers: SIGINT, SIGTERM, SIGBREAK and the wakeup fd are untouched.
  • The lifespan and the requests run on the script thread. A graceful stop with a request in flight takes about 0.2 s.
  • Finding: uvicorn ends a failed startup (a lifespan that raises, a port that is taken) with sys.exit(3). When serve() is a task of its own, asyncio re-raises that SystemExit out of the loop, and every other task on it dies too. serve_asgi catches it inside the task's own coroutine. Recorded under risk 16 in §9.

What's in it

  • ServerLink (src/ariadne_python/server_link.h) sits between the script thread and the relay. The program's writes queue there, coalesced per path in the order of each path's last write (a section's fields, then its rev). The relay applies them at the top of each room step, ahead of the server document, within --script-write-budget bytes (65536 by default). set_tree writes the way (state-set-tree) does. The relay's events reach the loop through a Python waker thread that blocks without the GIL.
  • pycvc.ariadne (src/ariadne_python/ariadne_server.py) holds Host (set, set_tree, set_series, get*, get_tree, run, stop, loop), serve_asgi and current_host.
    • arisrvx builds it in and imports it at boot, so arisrvx needs no pycvc.
    • pycvc also installs it, as _pycvc_ariadne.py, and pycvc's import registers it as pycvc.ariadne. Under plain python the same program runs, with Host keeping its own tree.
  • Startup. The relay binds nothing until every ASGI app has started. A failed startup stops arisrvx with 1 and the traceback, before it listens. A stop that arrives before the program serves stops it there too.
  • Stopping. On SIGTERM or SIGINT the relay keeps stepping while the program shuts down: each server drains within --shutdown-timeout (10 s) and runs its app's shutdown. The program's last writes go out, and then the relay stops. host.stop(code) stops the relay with that status.
  • --http-listen ADDR:PORT serves the program's app for a program that doesn't call serve_asgi.
  • arisrvx check main.py [relay flags] loads the --doc (its requires:) and runs the program without serving. It reports missing modules, an --http-listen with no app, and ports that are taken.
  • arisrvx python is the embedded interpreter as a plain python3.
  • cvcpkg/recipes/arisrvx (Linux). Its publish step sits beside arix's in publish-cvcpkg.yml and runs tests/program.py beside a relay before it packs.
  • CI: the pycvc-linux job now provisions gRPC (as package-linux's gRPC lanes do) and turns on the gRPC and WebSocket transports, which arisrv needs. It also installs fastapi-cp312 and uvicorn-cp312, and runs the arisrvx tests with the scripting-host ones.

Flagged for review

  • A server document's python: block is refused in arisrvx, not run. Its functions would be called from the document's programs on the relay's loop (§6.2). I moved it to S2, where exports run on the script thread.
  • --script-slow-ms moved to S2. The warning names a sync export, and exports are S2's.
  • Two copies of one file. pycvc.ariadne is built into arisrvx and also ships with pycvc. In arisrvx the built-in copy always wins: pycvc's import leaves an existing pycvc.ariadne alone.
  • Publishing from Python alone. Clients still receive only what the server document publishes (server: publish:), so a Python-only service runs with a --doc that publishes its namespace. S7's end-to-end test may want a way to publish from Python.
  • The message for requires: [python] on a stock host now names arix, ariglx or arisrvx.

Tests

Local, on Windows (static Release, gRPC + WebSocket):

  • ServerLinkTest (11 cases);
  • the arisrvx_* ctests: serve, program, http_listen, startup_fails, check, check_missing_module, doc_python_refused, python_interpreter;
  • arisrv_python_needs_arisrvx;
  • the existing arisrv_*, ari_server_* and AriadneRequires tests.

That is 52/52. test_pycvc_ariadne_server.py passed against a stand-in pycvc; with the real pycvc it runs in CI's pycvc-linux job.

arisrvx is arisrv with an embedded CPython 3.12 (src/ariadne_python with its new server part).
`arisrvx --python main.py [relay flags]` runs the operator's program on a script thread of its
own with one asyncio loop, which serves its ASGI apps (pycvc.ariadne.serve_asgi, uvicorn). The
relay never runs Python, never takes the GIL and never waits on the program
(ARIADNE_SCRIPTING_HOSTS.md S1, section 6.5; reference ARIADNE.md 9.8).

- ServerLink (server_link.h): the program's writes queue there, coalesced per path in the order
  of each path's last write, and the relay applies them at the top of each room step within
  --script-write-budget bytes (65536); the relay's events reach the loop through a waker thread
  that blocks without the GIL.
- pycvc.ariadne (ariadne_server.py): Host (set, set_tree, set_series, get, get_tree, run, stop),
  serve_asgi, current_host. Built into arisrvx and imported at boot, so it needs no pycvc; also
  installed with pycvc as _pycvc_ariadne.py for plain python, where Host keeps its own tree.
- Startup: the relay listens only once every ASGI app has started; a failed lifespan startup or
  bind stops arisrvx with 1 before it listens. uvicorn's sys.exit(3) on a failed startup is caught
  inside its task: raised from a task of its own it escapes the whole loop (risk 16's finding).
- Stopping: on SIGTERM/SIGINT the relay keeps stepping while the program drains its servers
  (--shutdown-timeout, 10 s) and runs its apps' shutdown; its last writes go out, then the relay
  stops. host.stop(code) stops the relay with that status. uvicorn installs no signal handlers.
- --http-listen ADDR:PORT serves the program's `app`; `arisrvx check main.py` runs it without
  serving and checks the --doc, the modules and the ports; `arisrvx python` is the interpreter.
- A server document's python: block is refused in arisrvx (its functions would run on the relay's
  loop); stock arisrv refuses the Python flags and names arisrvx; the python token's message
  names arisrvx too.
- cvcpkg/recipes/arisrvx (Linux), its publish step beside arix's, and the pycvc-linux CI job
  builds and runs it (WebSocket transport on, the cp312 FastAPI stack installed).

Tests: ServerLinkTest; arisrvx_serve, _program, _http_listen, _startup_fails, _check,
_check_missing_module, _doc_python_refused, _python_interpreter; arisrv_python_needs_arisrvx;
pycvc_ariadne_server.
…s' shutdown; 3.7.13

ServerLink::wait_finished replaces end_script's wait_start loop, which returned at once once the program was past startup. The ASGI servers get 2 s past --shutdown-timeout for their apps' shutdown, inside the 5 s grace before arisrvx gives up on the program. The recipe and the test documents follow master's 3.7.13 bump.
arisrv's main.cpp uses the gRPC state and media transports whatever else is on, so a WebSocket-only libcvc configured arisrv but could not link it (undefined state_transport_grpc, stream_transport_grpc, stream_relay). The job now installs grpc and protobuf in a prefix of its own, as package-linux's enable_grpc lanes do, and turns CVC_ENABLE_GRPC on beside CVC_ENABLE_WS.
Conflicts kept both sides: the python token names arix, ariglx or arisrvx and the new wasm one arix or ariglx (arisrvx gets no wasm engine); the roadmap's status lists S1 with P1b and G1; the engine's header comment says both. The server part is unchanged on Python's ScriptEngine: a server host's attach still gives its document's runtime no Python engine, only the hook that refuses a python: block, and it includes loader.h itself now that the engine no longer does.
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
transfix merged commit daba736 into master Nov 9, 2026
21 of 30 checks passed
@transfix
transfix deleted the feat/arisrvx branch November 9, 2026 20:24
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