Skip to content

state_exec: threaded execution Stage 1b (Ariadne: providers by kind, one pump a frame, isolated documents) - #1088

Merged
transfix merged 114 commits into
masterfrom
perf/threaded-s1b
Nov 17, 2026
Merged

transfix merged 114 commits into
masterfrom
perf/threaded-s1b

Conversation

@transfix

@transfix transfix commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Threaded execution Stage 1b: Ariadne's half of Stage 1. Providers post on their caller's host and group, there is one pump per frame, documents can run in groups of their own (opt-in), and the subscriber audit is done. The plan is state-exec-perf/threaded-impl/S1.md in the workstreams tracker (S1.9-S1.11, S1.14-S1.16; decisions S1-Q1..S1-Q12). Stage 1a (groups, the pool, pycvc's ExecPool) merged as 95b52d5.

The A/B ran in a quiet window on 2026-11-12, and Joe accepted it as recorded (see Gates). All three reviews are done (see Reviews).

What it adds

  • Providers on the caller's host (S1.9).
    • Every Ariadne lane has its own ictx.host: actions and spawned children, the init lane's inline host (charged to init's process, S1-Q2) and the probe's.
    • Posts go to the caller's group: done channels, streams (stream_params::scheduler), net completions.
    • Providers register by kind (provider_affinity: any, host_proxied, host_only):
      • AppRuntime's six, in the old binding order;
      • net's two;
      • streams, room, room-media, oidc and nav_compute;
      • the Runtime's own backend verbs from master (clipboard-set, fullscreen), as host_proxied.
    • A host_proxied provider's natives go through exec_group::install. A host_only name is a NameError in an any group.
  • One pump per frame (S1.10).
    • Runtime/AppRuntime::drain_begin() and drain_end() sit around app::exec_pump_frame(); drain() is both.
    • The host-thread calls (render, resident starts and kills, set_*_program, post_input, post_signal) are asserted outside a pump in debug builds.
  • Isolated documents (ariadne.exec.isolate_documents, off by default; S1-Q6).
    • Eligibility follows S1-Q6. The reason a document stays in group 0 is logged once and returned by isolation_reason().
    • A host_only native, or a thread-affine prefix at, above or under the document, makes its group's affinity host. Prefixes are declared through AppRuntime::declare_thread_affine_prefix; AriRuntime declares its scene prefix.
    • When the placement is decided:
      • at load;
      • again after set_root, a lane's program, the channel policy, the key bindings or a declaration;
      • for a late host verb or provider, the first time nothing of the document runs, at the latest at its next restart.
    • What a move does:
      • kills and reaps where they ran;
      • re-points the streams the document owns;
      • retires the old group until its calls end, so the frame never waits for them.
    • AppRuntime::idle() and wait_idle() count the document's group and any retired group, and decide nothing.
    • Teardown (S1-Q8):
      • kills and reaps every process the Runtime owns;
      • destroys its group before the channel policy and the document scope;
      • is refused while a pump holds the group, from any thread.
  • spawn_child from the parent's context.
  • The subscriber audit (S1.11): raw walks, uri_state and stream pin_vectors, debug home-thread asserts, and the declarations. The audit table is in STATE_EXEC_THREADED.md 4.8.
  • Async hosts and net:
    • A started call finishes through the host's finisher, which posts only while the host is up.
    • async_host::shutdown runs cancel hooks outside its lock.
    • A cancelled call aborts its curl transfer within about a second (HttpRequest::cancelled, cvc::net::HttpCancelScope).
    • WebSocket sends hold a send mutex for whole frames.
    • AppRuntime's verb table is locked.
  • exec_pool: under CVC_EXEC_FORCE_MOVE a caller waits no longer than its deadline. This was an S1a hang: a worker that skipped a call past its deadline told no one.
  • Bench: mt.ariadne_docs (docs 1/2/4/8 x t 0..8 x heavy/small frames). Its small-frames gate ("no helper wake") judges only points that can wake a helper, marks the others n/a, fails vacuous points, and gates a heavy-frame worker-pump control in the same run.
  • CI:
    • Stage 1b's cases are required lines in all three sanitizer legs, 42 in all.
    • The clang-tsan leg runs ariadne_runtime_test (CVC_EXEC_THREADS=4) and state_lifetime_stress_test.
    • stream_test and net_ws_client_test run in every leg, and ariadne_host_test in the gcc legs.
  • Docs:
    • STATE_EXEC_THREADED.md's Ariadne half: 4.6, 4.8, 4.9, 4.12, 4.17, 5, 7, 8, 9.2;
    • ARIADNE.md: documents in groups of their own, one pump per frame, adding verbs by kind; the stale line citations are now function names;
    • the developer guide's "Ariadne providers";
    • APP_API.md's "Ariadne hosts and the frame pump";
    • STATE_EXEC_EXCEPTIONS.md 3.12 (the finisher);
    • the bench and testing docs;
    • pycvc's README (AriApp and the GIL).

Behaviour changes with no host opting in

With the setting off and no host calling exec_pump_frame, every document runs in group 0 as before, apart from these:

  • The init lane charges its async calls to init's process (S1-Q2). No shipped document's init: calls an async verb; this was rechecked at this head.
  • A Runtime's teardown reaps every process of its owner, the actions' own processes included. A resident that a reload or a mount reconcile stops is reaped then (S1-Q8; HZ-8 reworked).
  • A spawned child takes its context from its parent's, so a child of a deleted chroot writes the detached node.
  • post_input and post_signal are host-thread calls (asserted in debug builds). Every shipped caller already calls them from its frame thread.
  • A killed program's http request aborts its transfer within about a second, instead of running on to its reply or its timeout.
  • Two threads sending on one WebSocket connection send whole messages.
  • Step counts are unchanged, except init: async calls, which are now charged.

Tests

Reviews

Every review fixed below has a test that fails without the fix.

Midpoint review (two lenses: semantics, and concurrency and memory). It found 3 major and 16 minor problems, among them:

  • AR-3b never ran its documents on workers;
  • a thread-affine prefix above a document did not make it host;
  • the CVC_EXEC_FORCE_MOVE hang above;
  • a started net call could post into a host that was gone;
  • WebSocket frames could interleave.

Skeptic pass over the fixes. It found 1 major and 7 minor:

  • A move re-pointed streams by scope rather than by owner. That could leave a stream naming a destroyed group, a use-after-free on its next post.
  • A move waited on the frame thread for the old group's calls.
  • The teardown refusal checked the thread rather than the held group.
  • Late registrations followed two different rules.

Bench, CI and docs review. It found 1 major and 9 minor:

  • a clang-format failure;
  • a gate that judged 1 of its 4 smoke points;
  • two binaries that ran under no sanitizer;
  • stale docs.

Gates

Section 6 of the plan, run in a quiet window on 2026-11-12 (Windows MSVC Release, two rounds). The base is 8cba3b1, master with S1a, as last merged here at 9b43e8a. The candidate is b4af08c. Verdicts are in comment 6837748380.

  • PASS: steps_total is unchanged on the deterministic families.
  • INCONCLUSIVE: the regression family, msg.* and async.* included, within 3%. All 396 points are noisier than 3%, though both rounds were quiet.
    • Repeated in both rounds: async.pool_aging at k=1000 and 3000 is +11% to +56%, and async.inflight_tax where=background at c=0 and 1 is +6% to +22%.
    • msg is +5% and sched.single is -2% and -9%.
    • Base and candidate were built in different worktrees, and native and eval move in opposite directions, so code layout may explain part of it.
  • PASS: mt.ariadne_docs small frames wake no helper: helper_wakes is 0 at all 16 wakeable points.
  • Heavy frames are recorded.

Joe accepted S1b as recorded on 2026-11-12 (comment 6838689168).

Open items

  • async.pool_aging and async.inflight_tax were slower in both S1b rounds, and slower in S1a's clean round too. They want a targeted look. This does not block the merge.
  • Every AppRuntime's verbs bind into every env, so affinity counts other hosts' verbs too (conservatively host).
  • There is no host API to declare a host verb's kind other than host_only.
  • The audit's follow-ups: volren and volslice settings, the two-scenes hazard, and state_sync_adapter's pinned walks.

The declarations threaded Stage 1b's implementers share (S1.md S1.9-S1.11, S1-Q12), with stubs that
keep today's behaviour:

- Runtime::drain_begin()/drain_end() and AppRuntime's pair: drain() in two halves around
  app.exec_pump_frame(). Stubs: drain_begin does nothing, drain_end is today's drain().
- register_action_intrinsics(provider, provider_affinity); the one-argument form is host_only.
  The stub ignores the kind.
- AppRuntime::declare_thread_affine_prefix (recorded) and AppRuntime::wait_idle (the app's host);
  pycvc's AriApp.wait_idle goes through it.
- Runtime::isolated_group() and isolation_reason(), for ariadne.exec.isolate_documents (S1-Q6).
- ictx.host in every Ariadne lane: an action and its spawned children get the app's async host
  (the one providers use today), the init lane its own inline host (S1-Q2), load_names' probe an
  inline host, so a provider can register on *ictx.host everywhere.
- CTest entries ariadne_runtime_test_threads_auto and ariadne_host_test_threads_auto (AR-1):
  both suites again with CVC_EXEC_THREADS=auto, AppLockManager.* left out.
…'s host

Threaded Stage 1b, S1.9's ariadne.cpp and app_runtime.cpp rows (S1.md; td 4.9; S1-Q2, S1-Q7):

- The provider registry keeps each provider's kind; the one-argument register_action_intrinsics
  is host_only. install_providers puts the providers into a program's env by kind: in group 0, a
  host-affinity group, the init lane and the name probes every provider runs as it is; in an
  `any` group an `any` provider runs as it is, a `host_only` one is not run (its names are
  NameErrors), and a `host_proxied` one runs into a scratch scope over the env, whose natives
  then go in through exec_group::install(..., host_proxied) and whose other bindings are copied.
  The design is documented beside the registry. (No group exists until S1.10, so every caller
  passes none here.)
- AppRuntime's one provider becomes four, registered with their kinds: the host's verbs and
  functions (host_only), quit and the data-* verbs (host_proxied), the async verbs (any) and the
  host's async functions (host_only). The async ones register on *ictx.host; their done channels
  post to ictx.host->parking_scheduler(), captured as the env is built, or to group 0 from an
  inline host (the init lane). The data-* provider's own-program probe walks the tree pinned,
  since a spawned child builds its env on its pumping thread.
- AppRuntime::idle() and wait_idle() also read the document's group (Runtime::isolated_group(),
  null until S1.10).
- The init lane's private scheduler gets its own cycle registry, declared before it and collected
  when the run ends.

Tests:
- AriadneInit.ItsCyclesAreItsOwnAndFreedWhenItEnds: fails without the init registry (65 objects
  left in the thread's own registry).
- AriadneHostVerbs.AnInitLanesAsyncVerbPostsItsDoneChannelToGroupZero: the inline host's done
  channel still reaches group 0.
S1.md S1.9's stream rows (td 4.9; S1-Q7):

- stream_params gains `scheduler` (appended; null keeps group 0, the app's exec scheduler). The
  stream takes it at open and posts its seq and lifecycle events there, from the producer thread
  too, instead of ctx_.exec_scheduler().
- (stream-open) passes the calling program's group, ictx.host->parking_scheduler(), or null (an
  inline host: group 0). The stream verbs' provider is `any`: mutex-guarded tables, descriptors
  written through pinned walks, posts to the opener's group; its body reads only the context.
- room-subscribe's proxy opens on the caller's group (an internal subscribe_on; the public
  room_subscribe keeps its signature and group 0, as stream_bridge and stream_relay do).
- descriptor_pins_ is a cvc::pin_vector, so the descriptor's chain is released leaf first (K's
  PIN-1, StreamDescriptorPinsReleaseTheLeafFirst).

Tests: Stream.EventsGoToTheSchedulerItWasOpenedWith (live, a seq posted from another thread and
closed reach the named scheduler, none the app's), AriadneStreamIntrinsics.AStreamPostsToItsOpenersGroup
(a stream opened from a context whose host parks on another scheduler posts there, not to group 0)
and AriadneStreamIntrinsics.AStreamOfAnInlineHostPostsToGroupZero (the fallback).
S1.md S1.9's net rows (td 4.9, B30; S1-Q7):

- The verbs register on the calling program's async host, *ictx.host (S1b.0 set it in every
  lane), not app.exec_async_host(): group 0's for a document in group 0, its group's for an
  isolated one, init's inline host on the init: lane. A started request (http_work,
  uri_fetch_work) keeps the host it started on and is finished there (settle_started); a host's
  shutdown, which a group's teardown makes after its kills, cancels each call it started, and a
  cancelled call is never finished on it, so nothing a started request needs dies before it.
- Two providers by kind: `any` (http-get, http-request, fetch, ws-*, net-allowed?, net-auth-*)
  and `host_proxied` (open-url). The credential store locks: every CredentialStore member that
  reads or writes its entries, bindings or renewers holds its mutex_, and the policy is immutable
  once the host made it, so net-allowed? and net-auth-* go with the requests. Both registration
  bodies read only the context and the atomic `live`, and bind natives into the new env.

Tests: AriadneNetIntrinsics.RequestsGoThroughTheContextsHost (a request is a kernel of the
context's host, and the app's host never sees it) and AriadneNetL4.AStartedRequestKeepsTheHostItStartedOn
(a started request is finished on its host, and that host's shutdown aborts it), both against a
context whose host is not the app's (use_host_in_contexts).
…ompute

S1.md S1.9's remaining provider rows (S1-Q7), each registered with the two-argument
register_action_intrinsics:

- room and room-media: host_proxied (raw walks and writes of the app-global room tree, a
  room_handle used outside room_table's lock, the bridge).
- oidc: host_proxied. Its completion still posts to group 0 (oidc#NAME): a document that uses
  oidc is never isolated (S1-Q6).
- nav_compute: (nav-step) on *ictx.host, `any`: its marshal touches nothing and its kernel runs on
  the background pool over the warmed compute pool, returning a fresh string. Its headless twin,
  AriadneAction.NavStepAsAnAsyncFunctionReturnsItsResult, registers the same way.

Every registration body reads only the context (and a weak host or an atomic) and binds natives
into the new env, so a spawned child may run it on a worker.
state_resolve and state_store pin the addressed node and its chain, and may run on a compute-pool
worker. The chain was a std::vector, released root first, declared after the node it held, and the
node itself was a copy that outlived the chain: once another thread unlinked the subtree, the pins
were its last owners and an ancestor died before its child (a destroyed() slot may walk _parent).

`chain` and `effective::pins` are cvc::pin_vectors (td 4.8). `pins` is declared before `node`, and
the node and its chain both move into `effective`, so the node goes first, then the chain leaf
first. For a followed transparent link the link node and its chain are let go of in that order
before the result is returned, since parameters go in no set order. K's PIN-1
(UriStateChainsReleaseTheLeafFirst) proves it.
The signals2 subscribers of S1-Q7's table, audited for writers on a worker (td 4.8, B15).

- The not-thread-safe cvcGL subscribers (CameraController, TouchGestures, StageLighting, FpsHud,
  ScreenTextHud, and Settings.cpp's ShadowSettings, UiSettings and ViewportLayout) record the
  thread that built them, so connected them, and assert in handleStateChanged that a state change
  reaches them there. Debug builds only; the member is unconditional, so a class's layout never
  depends on NDEBUG. A test that leaks one onto a worker fails in CI's Debug cvcGL jobs.
- GraphicsNode::handleStateChanged runs on the writing thread and checks for its echo before it
  marshals. The own-publisher check reads only thread-local state on a worker. The scene-less
  check read a plain member flag that the node's own thread sets around its direct pose write:
  another thread's matrix write meanwhile (a worker-pumped group's, or a publisher flushing a pose
  queued before the node lost its scene) raced it and, reading true, was dropped as the echo while
  the tree ended on it. The mark is now the writing thread's (a thread_local, as state_publisher's
  flushing() is), so only the inline echo is dropped and another thread's write is marshalled.
  cvcgl_unattached_node_thread's new case fails without it.
- state_sync_adapter stays not thread-safe (S1-Q7): its slots re-walk from the root with raw,
  creating lookups and read _attached unlocked. Comments say only host-thread writers reach the
  replicated subtree (conf.*) in Stage 1, and name the follow-up (pinned walks, an atomic flag).
In arigl the scene prefix is the document's, and the camera, touch, lighting, HUD and settings
subscribers under it assume the render thread. AriRuntime declares that prefix to its AppRuntime
before any load (AppRuntime::declare_thread_affine_prefix, S1.11), so an isolated document there is
pumped on the host thread (S1-Q6). AriRuntime::wait_idle goes through AppRuntime::wait_idle, which
also waits for the document's own group host once the document is isolated.
PIN-1 (S1.md section 4; S1.9, S1.11; td 4.8), at the end of state_lifetime_stress_test.cpp under
the Stage 1b banner, modelled on ContextRootPinsReleaseTheChrootFirst:

- StateLifetime.UriStateChainsReleaseTheLeafFirst: a state:// store whose write fires a slot that
  removes the node's parent is the last owner of both; the node dies with its parent alive, for the
  node itself and through a transparent link.
- StateLifetime.StreamDescriptorPinsReleaseTheLeafFirst: a stream whose document subtree was removed
  while it was open is the last owner of its descriptor chain when it closes; stats, the descriptor
  and streams each die before their parent.

Both fail on S1b.0 with MSVC (its std::vector releases front first, root first). libc++ destroys a
vector back to front, so the stream case may pass there before the fix; the uri_state case fails on
all three standard libraries, since the store's own node pin outlives its chain.
register_net_intrinsics no longer holds the app or its async host: each program calls through its
own context's host, and the verbs are two providers by kind. AriRuntime::wait_idle waits on the
document's group host too (AppRuntime::wait_idle).
async_scheduler::ingress_posts_for_test() counts the post_message() and post_async_completion()
calls a scheduler has taken, from any thread. AR-3b reads it to show an isolated document's
providers post to its own group and leave the app scheduler's ingress untouched (S1.md section 4).
Threaded Stage 1b, S1.10 (S1.md; td 4.12, 4.15; S1-Q6, S1-Q7, S1-Q8):

- The drain splits. Runtime::drain_begin() is the drain up to the pump (oidc, key bindings,
  images, the queued events and host handlers, ticks, input residents) plus has?'s snapshot for
  an `any` group; drain_end() is the pump, skipped when app.exec_pump_generation() moved since
  this Runtime's drain_begin(), then the sweep. drain() is both, and drain_end() alone runs
  drain_begin() first. AppRuntime's pair puts the scene work, warnings and frame hooks after
  drain_end(). starts_frame() and the pump clock stay on the drain() path.
- Host-thread calls: post_input, post_signal and render assert, in debug builds, that no pump_all
  of the app's pool is running on the calling thread (through exec_pool_probe(), which never
  builds the pool). ariadne.h's post_input and post_signal comments say "host thread, outside a
  pump" instead of thread-safe.
- Isolated documents (ariadne.exec.isolate_documents, "1" or "true"): the placement is decided at
  load (AppRuntime::load asks at its end; a bare Runtime decides at its first drain, render,
  submission or isolated_group() query after set_root), and again for each document set_root
  gives. S1-Q6's rules, in order: a non-empty prefix; an enforced (strict) channel policy with no
  global channel and no static '/' channel in any program; no oidc (an oidc-* call or the oidc#
  channel); no writable link: hole whose target leaves the prefix. An eligible document gets an
  exec_group (owner and name its owner tag, a frame group of the app), `host` when a host_only
  provider binds anything in its env or a declared thread-affine prefix is at or under its
  prefix, else `any`; an ineligible one stays in group 0 and logs why once. Actions, residents,
  ticks, input, signals, kills, the sweep and has? use its scheduler and host; providers install
  by kind; drain_end() pumps the group through the app's pool when no frame pump did. A document
  whose placement changes moves: its processes are killed and reaped where they ran, run_program
  callers are told, its residents start again in the new place, and the old group is kept (empty,
  still drained) until the Runtime goes, since a stream it left open posts to it.
  Runtime::declare_thread_affine_prefix (new) takes AppRuntime's declarations.
- spawn_child builds the child's context from its parent's (scheduler, host, root, root_pins,
  root_path, identity, channel policy, document scope, lock fields, spawn context), with no
  re-chroot by path, so a child of a deleted chroot writes its parent's detached node; nothing in
  it walks the tree, since it runs on the pumping thread.
- Teardown (~Impl), each step catching and logging what it throws: doc_scope_.clear(); kill_owner
  and the reap of every process the Runtime knows of, its actions' own included (S1-Q8); then
  the group (unregistered from the frames first) and any earlier group.

Tests:
- AriadneScheduler.DrainEndDoesNotPumpAgainAfterAFramePump: with drain_begin, exec_pump_frame,
  drain_end an await resumes once a frame (4 after 5 frames; 9 when drain_end pumps again).
- AriadneIsolatedDocs.ProvidersAreInstalledByTheirKind: in an `any` group at 2 threads with
  CVC_EXEC_FORCE_MOVE, a host_proxied native runs only on the frame thread and its constant is
  bound, an `any` native also runs on a worker, and a host_only provider registered after the
  group is made is a NameError that has? does not see (all three fail with every kind installed
  as it is).
- AriadneIsolatedDocs.IdleAndWaitIdleCountTheDocumentsGroup: idle() is false while the
  document's kernel runs on its group's host, and wait_idle() waits for it (both fail without
  S1.9's reads of the group).
- AriadneIsolatedDocs.TeardownReapsItsProcessesAndDestroysItsGroup: a parked action and its fork
  in a group; after the Runtime goes no group of the app is alive and a frame pump finds none.
- AriadneIsolatedDocs.ALaterDocumentThatIsNotEligibleMovesToGroupZero: a later tree with a
  writable hole out of the prefix moves the document to group 0; its resident is reaped in the
  group and starts again in group 0, and the hole is writable (fails when the placement is
  decided only once).
- AriadneHazards.HZ08_ForkedChildKeepsOwnerAndTeardownReapsIt, reworked (S1-Q8): after teardown
  the action's own process is gone too (fails without reaping it).
Threaded Stage 1b's Ariadne cases (S1.md section 4; td 8.5, 8.6), written from td and the plan
against S1b.0's interfaces, at the end of ariadne_runtime_test.cpp under the Stage 1b banner:

- IS-1b SpawnContext.IS01b_InAnIsolatedDocument: IS-1 in an isolated document's group, pumped by
  plain drain(); the child is in the group, not group 0, and the teardown destroys the group.
- AR-1 AriadneFrames.AR01_NoDocumentOptedInStaysOnTheFrameThread: at threads auto with no document
  opted in, init, ticks, actions, a spawned child and an await all run on the frame thread, and no
  worker pumps (exec_pool_worker_pumps_total).
- AR-2 AriadneFrames.AR02_ThreeDocumentsInGroupZeroPumpOnceAFrame: three Runtimes through
  drain_begin, exec_pump_frame, drain_end: group 0 is pumped once a frame, and an await whose call
  ends between two drain_end calls resumes at the next frame's pump.
- AR-3 AriadneFrames.AR03_IsolatedDocumentsRunOnWorkers: four isolated documents at 4 workers: the
  busy residents step on two threads or more, render never begins inside a pump_all, a quick action
  completes in its drain, and ps, inspect and kill see only the document's own group.
- AR-3b AriadneFrames.AR03b_ProvidersPostToTheirGroup: an isolated `any` document's AppRuntime async
  verb with a done channel, stream open and close and net request (the local HTTP server): each call
  is tracked by the document's group while in flight, the posts reach a resident in the group, and
  group 0 has no call, no process and no message.
- SP-1 SpawnContext.SP01_AChildOfADeletedChrootWritesTheDetachedNode: a resident's child, spawned
  after its chroot was deleted, writes the detached node; nothing is made at the old path.
- EL-1 AriadneFrames.EL01_IneligibleDocumentsStayInGroupZero: S1-Q6's rules, each ineligible
  document in group 0 with a reason; eligible ones isolated, affinity host for a declared
  thread-affine prefix or a host_only native, else any.
- FF-3's init half AriadneHazards.FF03_InitLaneRunsProviderCallsOnItsOwnHost: a provider on
  *ictx.host gives (21 21 6) from init, on an inline host that is not the app's, and init's process
  is charged both calls (budget-usage). HZ-13 is unchanged.

On S1b.0, AR-1 and FF-3 pass; the others fail where the behaviour is not built yet (no isolated
documents, the drain split's single pump, spawn_child's re-chroot by path).
Threaded Stage 1b's scenario (S1.md S1.14, td 6.3): `docs` (1, 2, 4, 8) AppRuntimes on one app,
each loading an eligible document (a prefix of its own, a strict channels: block; S1-Q6) with
ariadne.exec.isolate_documents on, driven a frame at a time by every document's drain_begin(),
app.exec_pump_frame(), every document's drain_end(). `t` (0, 1, 2, 4, 8) is the app's exec_pool
workers, built before anything builds group 0 or the lock manager (S1-Q1), under unpinned_scope,
with the pool scenarios' placement. frame=heavy gives each document's on_tick a 500-iteration
loop (about 8000 steps, well over the pool's 100 us inline_below), frame=small one state-incr.
No backend and no render: the region is the three calls, ns_per_iter the frame time. Extras:
helper_wakes (pool stats), worker_pumps (exec_pool_worker_pumps_total), isolated (documents in a
group of their own), pumps, skipped, effective_threads, ticks_per_frame. A point with fewer
documents isolated than it has prints a note and passes; a rep fails when a document did not
tick. Skipped without yaml-cpp. Smoke: t 0, 2, docs 1, 2, both frames, 4 frames.

The runner's gate fails a point that would pass vacuously (GATE_GUARDS): mt.ariadne_docs' rows
must have extra.isolated at their docs, since documents left in group 0 never wake a helper. On
S1b.0's stubs the gate therefore fails, as it should, until S1.10 isolates the documents.
AR-3b now asserts that group 0's ingress (async_scheduler::ingress_posts_for_test) takes no post
and no completion across the isolated document's action, as S1.md's AR-3b row asks, beside the
effects it already read. The include block's comments are aligned as clang-format wants.
S1.15's Ariadne lines (S1-Q9, S1.md section 5):

- The clang-tsan leg also builds and runs ariadne_runtime_test, with CVC_EXEC_THREADS=4 and
  --gtest_filter=-AppLockManager.* (the app's pool has workers and its lock manager is shared,
  which the AppLockManager cases assert is single), and state_lifetime_stress_test (PIN-1).
- A leg's matrix may give some of its C++ binaries their own variables and options: `cxx_runs`,
  one line a binary, `<name>: [VAR=VALUE ...] [--option ...]`, read by run.sh as SAN_CXX_RUNS. A
  --gtest_filter there gets *Stress* added to its negative patterns; a line naming a binary the leg
  does not run is an error. Every other binary, and every binary of the gcc legs, runs as before.
- SAN_REQUIRED_S1B, appended to every leg's required lines as SAN_REQUIRED_S1A is: the Ariadne
  cases of section 4 (IS-1b, AR-1, AR-2, AR-3, AR-3b, SP-1, EL-1, FF-3's init lane), HZ-8 (moved
  from the gcc legs' own lists, so each leg has one copy) and PIN-1's two. AR-3b is thus required
  in both TSan legs. The lead appends A's, I's and U's unit tests as they merge.
- The job's header comment, the matrix comment and docs/TESTING.md's sanitizer section say so.

The 180-minute job timeout is unchanged: the gcc tsan leg ran ariadne_runtime_test in 24 s of a
23-minute job on master 7a09366, and the clang leg took 23 minutes on 08fd204 before these two
binaries.
S1.9 split AppRuntime's one provider into four by kind, which changed which table wins when two
bind one name: a host function lost to (quit), a data-* verb and an async verb it used to override,
and an async verb overrode a data-* verb it used to lose to. The provider is now six, registered in
the order the one provider bound them at 1407da0, the later winning: the host's sync verbs
(host_only), (quit) (host_proxied), the async verbs (any), the data-* verbs (host_proxied), the
host's functions (host_only) and its async functions (host_only). So in group 0 every collision
resolves as it did; an `any` group installs them in the same order, by kind.

Test: AriadneHostVerbs.ANameTwoTablesBindResolvesInTheirOrder pins the winner of each of the 14
pairs of tables that can share a name. It passes with 1407da0's app_runtime.cpp (the one
provider) and with this commit; with S1.9's four providers it fails on quit/function, async
verb/data verb, async verb/function and data verb/function.
The eligibility scan (S1-Q6) read only the programs the Runtime holds, so a document whose init:
alone called oidc-* (or named a '/' channel) was isolated. AppRuntime::load runs init: itself and
keeps tests: for run_program; it now hands both to the Runtime with the new
Runtime::set_document_programs, before set_root, and the scan reads them with the document's own.

Test: AriadneIsolatedDocs.AnInitThatUsesOidcKeepsTheDocumentInGroupZero: a document whose init:
calls oidc-sign-in stays in group 0 with the oidc reason, beside the same document with a plain
init:, which is isolated. It fails without the hand-over (the document is isolated).
Under CVC_EXEC_FORCE_MOVE a pump_all's caller may not take a group it pumped last, so it hands the
call to the workers and waits on the call. A worker that reached the call past its deadline skipped
the groups in take_group and notified no one, and the caller waited for ever: exec_pump_frame and
an isolated Ariadne document's drain hung when a worker woke late (a loaded machine, TSan). R1b-mid
found it; it explains the hang seen once in AriadneIsolatedDocs.ProvidersAreInstalledByTheirKind,
and it reproduced under load in a repeat run of the isolation cases.

take_group now notifies the call when it skips its groups, and the caller waits no longer than the
deadline (in slices of at most a second, so a time_point::max() deadline never reaches wait_until)
and then skips them itself. ExecPool.AForceMovedCallEndsAtItsDeadline keeps the pool's one worker in
another caller's group past a 50 ms deadline: it failed (the caller still waiting after 10 s) and
passes.
…latch (R1b-mid)

R1b-mid's fixes for K's Stage 1b cases (S-M1, s-m6, s-m7), in ariadne_runtime_test.cpp's Stage 1b
section:

- S-M1: AR-3b runs with CVC_EXEC_FORCE_MOVE, so the document's one group, which plain drain()
  otherwise pumps on the caller every frame, is pumped on workers too. It asserts that workers
  pumped (exec_pool_worker_pumps_total moves) and that an `any` probe in the action ran on a thread
  other than the frame thread, which is what the TSan legs need of it. The action now parks with its
  stream open while a producer thread posts a seq on it (stream::post_seq, found with
  document_stream); the resident in the group receives it, beside the live and closed posts. IS-1b
  takes the same knob and asserts a worker pumped its group.
- s-m6: AR-3's comment says its render check cannot fail (the test calls render() between pumps)
  and that the latch is render's debug-build assertion, which Release builds compile out.
- s-m7: EL-1 gains a strict document with (msg-send "/x" ...) in a widget's on_click, which the
  load's lint does not read: it stays in group 0, its reason naming "/x". Each ineligible document's
  reason is read from the app's log (system.log_output) and must appear there once after three more
  frames; a log4cplus build skips that check.
…r the host (R1b-mid c-m3)

A started net request kept its host's raw address, and settle_started checked cancel_requested()
before host.finish(): a check, not a guard. A transport answering on a thread of its own just as an
isolated document's group goes (its host dies with the Runtime) could pass the check, then call
finish() on the freed host and post to the freed scheduler.

async_host::finisher (make_finisher()) holds the host's shared state. Its finish() posts a settled
call as finish() does, but under the state's lock and only while the host has not begun to shut
down: shutdown() sets `stopped` under that lock, so a post under way ends before the shutdown goes
on, and one that comes later touches neither the host nor its scheduler (the shutdown cancelled the
call). http_work and uri_fetch_work keep the finisher instead of the host. finish() is unchanged.

Test: AsyncCalls.AStartedCallsFinisherPostsOnlyWhileItsHostIsUp. Answered from another thread
while the host is up, the call resumes its process; settled and finished from another thread after
the host is destroyed, nothing is posted (the scheduler's ingress count does not move). The race
itself cannot be made to fail deterministically: the window lies between the transport's
cancel_requested() check and its finish, where no code the test controls runs, and the old
outcome is a use of a freed host, not an observable result.
CurlWsConnection::send_frame took the easy handle's lock per chunk and continued a partly sent
frame after releasing it. libcurl takes a large message in pieces and continues a partly sent frame
with the next send's bytes, so two threads sending on one connection (ws-send from two documents
pumped on two workers, or a close beside a send) interleaved their messages on the wire. A send
mutex is now held across the whole frame; the handle's lock is still taken per chunk, so the reader
goes on receiving between them.

Test: NetWsClient.TwoThreadsSendingOnOneConnectionSendWholeMessages sends two 4 MiB messages from
two threads on one connection while the local server holds off reading, and checks both sends
succeed and each message arrives whole. Without the mutex it fails every run (one send fails and
the server receives one message).
R1b-mid S-M2. A write under a document emits childChanged on every ancestor, so a render-thread
subscriber connected at an ancestor of the document's prefix runs on whichever thread writes. The
isolation rules matched a declared prefix only at or under the document's, leaving such a document
`any` and its subscriber on workers. A declared prefix at, above or under the document's prefix
(or the empty one, the root) now makes its group host. app_runtime.h's declaration comment says so.

Test: AriadneIsolatedDocs.AThreadAffinePrefixAboveTheDocumentMakesItHost (probe PC): scene.doc
isolated under CVC_EXEC_FORCE_MOVE at 2 workers, "scene" declared and a slot connected on its
childChanged; the group is host and the slot runs only on the frame thread. Without the fix: the
group is any and the slot runs off the frame thread.
R1b-mid s-m1 (S1-Q8). stop_resident killed the resident and forgot it, so a resident stopped by a
reload's set_*_program or by a mount reconcile stayed in group 0 as a killed record for the app's
life: neither the sweep nor teardown knew its pid. It is now killed and reaped at once (its forks
keep their own context). ariadne.h's set_tick_program comment says so.

Test: AriadneHazards.AResidentAReloadStopsIsReaped (probe PB): a tick resident, a second
set_tick_program, then teardown; group 0 holds only the new resident before teardown and nothing
after. Without the fix: the stopped resident's killed record is left (2 processes, then 1).
…erf/threaded-s1b

#925 starts ws-open's connect and ws-recv's wait where the transport does not block (the browser
without threads), and their callbacks settle the call. Its start paths kept the async_host by
reference and posted through it; here they take the host's finisher (host.make_finisher()) and
settle_started through it, as http_work and uri_fetch_work do: the callbacks answer later, and an
isolated document's group's host may be gone by then.

- net_intrinsics.cpp: the conflict kept this branch's providers by kind; have_ws takes master's
  NetAccess::ws. The any provider's comment says a host's own WebSocket transport must be as
  thread-safe as the compiled backend.
- ariadne_runtime_test: both sides' new L4 cases are kept, plus
  AStartedWebSocketCallKeepsTheHostItStartedOn, the WebSocket twin of
  AStartedRequestKeepsTheHostItStartedOn.
…#1177, #1167) into perf/threaded-s1b

The one conflict is the sanitizers' SAN_CXX_TESTS list in ci.yml: this branch added
stream_test, net_ws_client_test and ariadne_host_test, and #1167 added skeleton_test. The
list keeps all four.
The two conflicts were include lines. ariadne.cpp keeps this branch's requires.h and
stream_intrinsics.h and adds #1180's rich_text.h. ariadne_runtime_test.cpp keeps
stream/stream.h and adds rich_text.h. #1180's rich text reads its runs and fires on_link
through the Runtime's existing reactive evaluation and handler queue, so it follows this
branch's group routing as it is; its last-good runs are a per-Runtime map.
#1203 (no singletons) moved the URI registry, the HTTP client and options provider, the HTTP
cache's in-flight table, the net and OIDC hosts, the WebSocket table and open-url's clock onto
each app. This branch had changed the same code for threads. The merge keeps both:

- uri.h/uri.cpp: register_uri_handler and resolve take the app (#1203) and keep this branch's
  UriCancelled and UriLocalHandler; the http(s) handlers and the HTTP cache pass the request's
  cancel predicate through to the app's client.
- net_intrinsics.cpp: the providers stay by kind with each call on the calling program's host
  (ictx.host) and its finisher. The requests, fetch and WebSocket verbs take the app, the app's
  WsTable and its OpenUrlLimit (both app slots, got once at registration). open-url stays in its
  host_proxied provider, on the app's OpenUrlLimit instead of a clock of the provider's own.
- oidc_host.cpp: the refresh sends through the app's client with the asker's cancel predicate.
- ariadne.cpp: the Runtime's owner id is counted per app (#1203); has_snapshot asks the app's
  widget registry.
- allowlist.txt: master's (76 lines); the one line this branch removed is gone there too.

This branch's tests move onto the per-app APIs: the removed NetIntrinsicsGuard, L4Guard and
NetHostGuard go, set_http_client and send take the app, live_groups takes the app by reference,
and the worker pump counts come from the pool's stats (pool_stats::worker_pumps) where the
process-wide exec_pool_worker_pumps_total() was, in the tests, mt.ariadne_docs and the docs.
Also fixed: #1180's three rich-text tests called load_string without the app #1203 added.
The code merged without conflicts. Stage S's step_run, set_slice and process_table's
begin_run/preempted are as on master. This branch's one change on that path is the ingress post
counter (ingress_posts_for_test), taken in post_message and post_async_completion under the
ingress lock, beside the ingress_pending_ flag that ends a run. A post from another thread still
ends a run within one step.

Two doc conflicts. STATE_EXEC_THREADED.md takes master's Stage S section. STATE_EXEC_BENCH.md
takes master's Stage S gates, without its one-line placeholder for S1b, whose gates this branch
describes just above.
…#1222-#1225, #1229)

Master's #1190 (file-pick and http-upload) was written for a single async host; this branch runs
an isolated document's programs on its own group's host, on a pool worker in an `any` group.

- net_intrinsics.cpp: StartedRequest takes master's deliver()/on_outcome, settling through the
  host's finisher. http-upload is its own provider, `any` as the requests are: it parks on the
  calling program's host (ictx.host), takes its progress path from ictx.root_path (no tree walk
  on a worker), and a started upload (a browser page) keeps the host's finisher, not the host.
- ariadne.cpp: file-pick, file-info and file-forget bind into the program's env as they are, in
  every group (install_backend_verbs), not through the backend verbs' host_proxied wrapper, which
  cannot park an async verb. file-pick parks on the program's own host, claims the Runtime's
  picker hub under its lock where it is called, and opens the picker on the host thread
  (exec_pool::run_on_host; inline when called there). Its answer goes through the host's
  finisher, as the host may be gone by then.
- ci.yml: the sanitizer list keeps this branch's tests and master's point_classes_test.
- STATE_EXEC_THREADED.md: rows for http-upload, the file verbs, and the contours and
  point-classes providers. The last two are registered without a kind, so they are host_only, and
  an isolated document in an app that installs them goes to a host-affinity group.
- New test: AriadneIsolatedDocs.FilePickOpensItsPickerOnTheFramesThread.
Master's #1217 keeps nothing per thread in state_exec: a native's context (call_args::context())
carries its group, registry and stream, async_host::call and begin_external take it, and the pool
drops in_pump_all() and the one-argument run_on_host.

- async_host.h: begin_external takes the context, as on master, and keeps this branch's note that
  a call is finished through the host it was made on.
- script_engine.cpp: the sliced form finds the calling program's group from the call's context
  (exec_group::current(ctx)), else group 0, and reads its data step from the context.
- ariadne.cpp: file-pick opens its picker through run_on_host for the group its verbs were bound
  for (the env's, as its host is), and inline in group 0 and the init lane.
- exec_pool: in_pump_all() is back, for the host-thread calls' debug assertion and
  ScriptLane::run's refusal, read from the pool's calls (their callers' and pumpers' thread ids)
  under its mutex rather than from thread-locals.
- ariadne_runtime_test: the init lane's cycles test no longer compares against the calling
  thread's own registry, which master removed; it is AriadneInit.RunsAScriptThatLeavesCycles.
- ci.yml: the sanitizer's required list names the test by its new name.
- STATE_EXEC_THREADED.md: B29-B31 and the file-pick and sliced-call notes name the context-based
  calls.
- ci.yml: the sanitizer list keeps this branch's tests (stream_test, net_ws_client_test,
  ariadne_host_test) and master's planar_test.
- app_runtime.cpp: the constructor hands the scene its repeat: count function (#1230), then
  takes the verb table's lock as before.
- e2ee_intrinsics.cpp (#1191): the e2ee-* provider registers its async functions on the calling
  program's host (*ictx.host, else the app's), as every provider on this branch does (B30), so an
  isolated document's e2ee-backup and e2ee-restore park on its own group.
- STATE_EXEC_THREADED.md: the e2ee provider in the provider table and the file list.
No conflicts; #1245's ariglx-web WebAssembly guests touch no threading code.
- stream_intrinsics.cpp: the stream provider stays `any`, and #1236's raster verbs are a provider
  of their own, registered `host_proxied`: they are synchronous, raster-open and raster-publish
  write the raster's mirrors into the state tree raw (write_node), and one thread paints and
  publishes a raster, so in an `any` group they run on the host thread. Registered host_only (the
  default) they would have put every isolated document of an app with the stream verbs in a
  host-affinity group.
- STATE_EXEC_THREADED.md: the raster verbs and #1171's skeleton provider in the provider table,
  and the file list.
- ci.yml: the sanitizer list keeps this branch's tests (stream_test, net_ws_client_test,
  ariadne_host_test) and master's segmentation_test.
…#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.
- 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.
Conflicts (includes in ariadne.h, ariadne.cpp and ariadne_runtime_test.cpp; three hunks of
#1241's menubar tray in ariadne.cpp) keep both sides. #1241's code meets this branch's groups:

- An action's context keeps master's scope (a quit application's actions stop) and is built by
  this branch's finish_context.
- The notify verbs bind by kind with the backend's (install_backend_verbs is now
  install_host_verbs): host_proxied in an `any` group, as cvc::notify mirrors the feed into
  the app's notify.* subtree raw on the caller's thread.
- What they capture (scope, source, a copy of mount_names) is taken on the host thread when a
  context is made (NotifyScope); a spawned child, made on the thread that pumps its group, binds
  from its parent's copy through its spawn context instead of reading mount_names there.
- quit_app kills the application's actions on current_sched() (the document's group), not
  only on group 0 when this Runtime used it.
- drain_begin runs builtin_event before the handler seam, through this branch's `m`.

Tests: AriadneIsolatedDocs.TheNotifyVerbsRunOnTheFramesThread (the feed is written on the
frame's thread while a worker pumps the program; a spawned child posts as its parent's scope)
and AriadneIsolatedDocs.QuitKillsALoadedDocumentsActionsInItsGroup.
STATE_EXEC_THREADED.md: the notify verbs' row, Quit among the kills that go to the group, and
the spawned child's notify scope.
No conflicts; this branch touches none of its files (files.cpp, files.h, ImGuiBackend.cpp,
ARIADNE.md 10.8). ariadne_files_test passes locally.
…#1307)

One conflict, in ariadne_runtime_test.cpp's ActionCapsAreTreeSettingsAndChargeAsyncCalls: this
branch cut its loop to 20 rounds so it fit the 0.1 s time cap on Linux debug CI, and master
(#1282) rewrote the test, raising the time cap to 30 s wherever the loop must finish.
Master's fix covers the same flake, so the test is master's as it stands, 200 rounds again.

tools/singleton_scan is master's (#1276); the auto-merged net, CI, test and doc files keep both
sides.
…#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.
One conflict, in src/cvcGL/CameraController.cpp's includes: this branch's <cassert> and #1257's
<cctype> (sliceAxisOf), both kept.
One conflict, in ci.yml's SAN_CXX_TESTS: this branch added stream_test, net_ws_client_test and
ariadne_host_test to the sanitizer legs' list, and #1292 added gradient_vector_diffusion_test,
critical_points_test and seed_generators_test (reflowing the lines). Kept both.

ci.yml's line 1271 (the arigl-web path filter's files.h/files.cpp line) also goes back to master's
bytes: master stores ci.yml with CRLF but that one line LF-only, and an earlier merge here had
given it a CR, a whitespace-only change in this PR's diff.
No conflicts. #1328 fixes master's arisrvx build (the bridge ops pass self to server_link, after
#1276 and #1302 crossed), which failed this PR's pycvc-linux / cp312 job at c7735de.
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.
@transfix
transfix merged commit 2f113d7 into master Nov 17, 2026
31 checks passed
@transfix
transfix deleted the perf/threaded-s1b branch November 17, 2026 12:57
transfix added a commit that referenced this pull request Nov 17, 2026
Every file but the two bench files takes master's version: master holds
#1088's final head (which contains the perf/threaded-s1b 769b5a0 merged
here earlier) plus later work.
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