Skip to content

arisrv: bound reads, a read scope per principal (S6) - #1147

Merged
transfix merged 2 commits into
masterfrom
feat/arisrvx-read-scope
Nov 12, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/arisrvx-read-scope

Conversation

@transfix

Copy link
Copy Markdown
Owner

S6 of the scripting-hosts roadmap (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md §6.5.6): bound reads. With S5's authenticate hook, a service can now say what each principal reads, and the relay sends each connection only that part of the tree.

@host.read_scope
def scope(principal):                 # sync and quick
    if "staff" in principal["roles"]:
        return ["cyprov"]
    return ["cyprov.public"] + [f"cyprov.projects.{p}" for p in projects_of(principal["id"])]

host.refresh_scope("bob")             # bob's connections get what they newly read, and lose the rest

What it adds

  • In the transports (state_transport::set_read_scope, refresh_read_scope, on gRPC and WS).
    • A scope is a state_delivery_filter for the connection admitted as a principal that identified (Hello) as a node id. A new state_prefix_filter covers the prefix case.
    • A scoped connection is held for its bootstrap until its Hello sets its scope, so it is never sent unscoped state. This holds whether or not the admission hold is on.
    • The scope joins the peer's registry rule (delivery_view::scope). The admit snapshot, snapshot replies and the WS broadcasts take it from there.
    • The live fan-out, the relay's forwards, the bridge, targeted pushes and messages check it under the connection's write lock.
    • A delete or reset above a readable path still reaches the connection (delivers_below), so a client never keeps data the relay removed.
  • A refresh. Under the connection's write lock, refresh_read_scope(principal) swaps the scope of each of that principal's connections, then sends it:
    • a delete of each subtree it can no longer read, at the subtree's root (a node above a path it can still read stays);
    • then one snapshot of what it can newly read.
    • Each delete comes from its own origin, <shard>#scope, with the shard clock's time as its sequence. So a client's seen-set never mistakes it for a journal entry, even after the relay restarts.
  • Deletes in state_sync_adapter.
    • The adapter applies a delete_subtree now. It used to ignore the op, which nothing sent. The relay's inbound gate still admits only set_value, touch and set_data from clients, so a delete only ever comes from a relay.
    • A bug fix along the way: the adapter's childChanged slot re-made a removed child that had no observer of its own (a node made on the way to another). So a deleted subtree came back empty, a local (state-delete …) included. A child that is gone is no longer re-made, and its observers are dropped, so a node made at that path later is observed afresh.
  • In the relay. room_read_scope(prefixes, room, pid) always adds the participant's own subtree, where its calls' replies land, and the room's nodes above it (a join waits for the room's node).
  • In arisrvx.
    • @host.read_scope and host.refresh_scope(principal_id).
    • The authenticate event hands the relay each principal's prefixes before its verdict (ServerLink::set_scope), so they are in place as it admits the connection.
    • A hook that raises, or answers anything but a list of str, refuses the connection.
    • A refresh is applied on the relay's next step, on both planes.
    • A later authentication that answers differently re-scopes the principal's other connections too.
    • A program with read_scope but no authenticate fails to start, and arisrvx check reports it.
  • Not scoped:
    • conference media and avatar poses, which are link-level, not tree state;
    • blob chunks fetched by digest (a client learns a digest only from an entry it may read).
  • relay_pair.py now checks --expect against the relay's output under --client-only too.

Tests

  • Unit:
    • StateSyncAdapterTest.ARemoteDeleteTakesTheSubtreeOut;
    • StatePrefixFilterTest.DeliversItsPrefixesAndExactPathsOnly;
    • StatePeerRegistryTest.AScopedViewDeniesWhatItsScopeDoes;
    • StateReadScopeTest.AChangeRetractsRootsKeepsAncestorsAndGrants and .ASubtreeOpAboveAReadablePathIsDelivered;
    • RoomCallsTest.AReadScopeKeepsTheParticipantsOwnSubtree.
  • Transports: StateTransportGrpcTest.AReadScopeBoundsWhatAPrincipalReads and StateTransportWsTest.AReadScopeBoundsWhatAPrincipalReads. Each checks that:
    • the bootstrap, the live stream and (WS) the broadcasts carry only the scope;
    • a refresh brings the newly readable subtree and deletes the other with one delete;
    • a later write under the retracted subtree stays away.
  • ctest: arisrvx_read_scope (gRPC) and arisrvx_read_scope_ws run tests/scope_service.py against tests/scope_user.ari. Bob reads svc.public and his project. Then:
    • joining another project brings its subtree;
    • leaving one deletes it;
    • a rename reaches him only for a project he reads.

Run locally on Windows (static Release, gRPC + WS, pycvc core, wasmtime from cvcpkg):

  • the suites this touches, whole:
    • state_sync_adapter_test: 11 passed, 2 skipped (the optional stress and perf cases);
    • state_peer_registry_test: 21;
    • state_transport_grpc_test: 54 passed, 3 skipped;
    • state_transport_ws_test: 44;
    • room_relay_integration_test: 22;
    • ariadne_host_test: 57.
  • The arisrv/arisrvx ctest set, with both new read-scope ctests: 53/53 with -j 3.
  • A browser build with CI's arigl-web flags (emscripten, no pthreads) compiles cvc, ari and arigl (the stacked PRs before this one showed why: that job runs only on PRs into master).

Not in this PR

  • ServerHarness and the end-to-end CI test (S7); the read-scope part of S7's test can now be written.
  • No release.

A service's read_scope hook (ARIADNE_SCRIPTING_HOSTS.md 6.5.6) names the path prefixes each
principal reads, and the relay sends each of that principal's connections only that part of the
tree: its bootstrap, its live stream, snapshot replies, the WS broadcasts, and the pushes and
messages it targets at it, on both planes. host.refresh_scope re-asks the hook, and each
connection is sent a delete of what it can no longer read and a snapshot of what it newly can.

- state_transport::set_read_scope and refresh_read_scope (gRPC, WS). A scoped connection is held
  for its bootstrap until its Hello sets its scope; the scope joins the peer's delivery_view and is
  checked under the connection's write lock on every tree write. A delete or reset above a
  readable path still reaches it (delivers_below). state_prefix_filter is the prefix scope.
- A retraction is a delete_subtree from the origin <shard>#scope, sequenced by the shard clock, so
  a client's seen-set never takes it for a journal entry.
- state_sync_adapter applies delete_subtree (it ignored the op, which nothing sent), and its
  childChanged slot no longer makes a removed child again: a node made on the way to another came
  back empty after a delete, a local (state-delete) included.
- room_read_scope: a participant always reads its own subtree, where its calls' replies land, and
  the room's nodes above it.
- arisrvx: @host.read_scope and host.refresh_scope. The authenticate event hands the relay the
  principal's prefixes before its verdict (ServerLink::set_scope); a refresh is applied on the
  relay's next step. read_scope without authenticate fails the start, and arisrvx check says so.
- relay_pair.py checks --expect under --client-only too.

Tests: StateSyncAdapterTest.ARemoteDeleteTakesTheSubtreeOut, StatePrefixFilterTest,
StatePeerRegistryTest.AScopedViewDeniesWhatItsScopeDoes, StateReadScopeTest.*,
StateTransportGrpcTest/StateTransportWsTest.AReadScopeBoundsWhatAPrincipalReads,
RoomCallsTest.AReadScopeKeepsTheParticipantsOwnSubtree, arisrvx_read_scope{,_ws}.
Picks up #1146, which builds ocean_sea_test without FMA contraction: OceanSea.IsTheSameOnEveryPlatform failed every macOS job here, as it did on master.
@transfix
transfix merged commit 8cba3b1 into master Nov 12, 2026
59 of 60 checks passed
@transfix
transfix deleted the feat/arisrvx-read-scope branch November 12, 2026 08:43
transfix added a commit that referenced this pull request Nov 12, 2026
Only state_sync_adapter.cpp conflicted, two places where both sides added next to each other. Master's #1147 added drop_subtree and apply_remote's delete_subtree branch; this branch had added comments on the adapter's raw, creating lookups. Both are kept, master's code first. The connect_node comment now also says the childChanged slot's new removal check is a findDescendant, which makes nothing but holds nothing either.

Master's #1159 adds a function-local thread_local memo in sea_surface::source (src/cvc/ocean/sea_surface.cpp). It is not on the allowlist, and #1159's release-grpc scan was cancelled, so the scan may flag it here. It is master's code, left unchanged; a fix on master is proposed separately.
transfix added a commit that referenced this pull request Nov 14, 2026
…t (S7) (#1177)

pycvc.ariadne.testing.ServerHarness (ARIADNE_SCRIPTING_HOSTS.md 6.5.8) plays arisrvx for a
service's tests under plain python, with no relay and no network. It drives arisrvx's own
dispatch, _Program, on host.loop with an in-process link in place of the relay, so the
authenticate hook, the read_scope hook, the role gates, ctx, the timeouts, CallError and the
per-principal limits are the same code a relay runs.

- connect(bearer) asks the authenticate hook (Refused when the relay would refuse), or
  client(principal). A client's call, call_with (room-call-opts), acall and acall_with return
  the value or raise CallError with the client's code; progress[name] holds the latest call's
  steps. Values cross through pycvc's capsules, as the wire carries them.
- get, get_tree and reads show what the relay would send the client: publish= namespaces,
  bounded by its principal's read scope, which host.refresh_scope updates. host.disconnect
  closes the principal's clients.
- pycvc.ariadne.testing is registered by the module itself (one file).
- The end-to-end ctest arisrvx_echo_service: tests/echo_service.py (an HTTP route and an export
  over one function, a fixed-token authenticate hook, the published echo subtree, a read scope
  of echo.public) against tests/echo_client.ari, which joins, calls the export, checks its reply
  and progress, reads what it wrote, is not sent echo.private, and fetches the route.
  relay_pair.py --client-net-asgi allows the origin the program serves on.
- Roadmap: S6 is done (#1147), S7 built; ARIADNE.md 9.8.6.

Tests: pycvc_ariadne_harness, arisrvx_echo_service.

Also in this PR:
- test_pycvc_ariadne_harness: skip the HTTP half when starlette's TestClient cannot load
- arisrvx harness test: skip the HTTP half without httpx; CI installs 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