Skip to content

cvc::world: water_bodies, the sea, lakes and ponds and the shore grid (O1) - #1109

Merged
transfix merged 2 commits into
masterfrom
feat/water-bodies
Nov 10, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/water-bodies

Conversation

@transfix

@transfix transfix commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

O1 of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (Phase 0, W0.1–W0.2). Each later phase reads this to know which body of water a point is in and what its level is: depth damping, the shore layer, fetch, wake masks and the physics fields. It applies to the sea and also to lakes and ponds.

What it adds

cvc/world/water_bodies.h (standard library only, deterministic):

  • Labelling: build_water_bodies(ground, grid, params) labels the 8-connected runs of samples whose ground is below the water level.
    • Every run that reaches the grid's edge is part of the one sea. Those inlets meet past the world; a standard terrain_lab world has about ten of them.
    • Each enclosed run is a lake, or a pond under pond_max_area_m2 (1 ha, decision D7).
    • stream is reserved until hydrology (W1) gives each depression its own level.
  • Per-sample planes: body, level, depth, and the shore grid:
    • shore_m: the signed distance to the shore, + offshore. It is an exact Euclidean distance transform, so it is within half a sample of the waterline.
    • normal_x / normal_y: the unit shore normal, pointing offshore. It can be smoothed over normal_smooth_m so crests don't twist on the medial axis.
    • slope: tan β, for the Iribarren number later.
  • Per-body statistics: level, area, bounds, deepest point, and fetch_m, the major axis of the body's second-moment ellipse, for the fetch-limited wind sea on lakes.
  • Helpers: queries (body_at, bilinear sample), water_bodies_summary and water_bodies_debug_rgb.

The distance transform is shared now, in a new module, cvc::algo. cvc::world may not include cvc::nav (a configure-time rule), so the transform moved out of nav into cvc/algo/distance_transform.h, where both can use it:

  • nav's binary EDT moved unchanged from grid_nav.cpp. It is still Felzenszwalb–Huttenlocher, bit-identical to GRL-SNAM's sdf_nav._edt2, with its exact integer-sweep fast path.
  • It offers edt2_squared, edt2_squared_both (a mask and its complement in one pass) and edt2_squared_rows (a row at a time, for build_sdf).
  • cvc::algo depends on the standard library only. A configure-time check fails the build if an algo source includes another libcvc library.
  • nav::edt2_squared and nav::build_sdf call it, and build_sdf keeps its own per-thread rows.
  • water_bodies uses edt2_squared_both. The transform works in cells, so build_water_bodies now requires a square grid and throws on any other; every caller's grid is square.

generated_world::water is built in a new world_builder stage, shore, after water and before lod:

  • It reads the terrain mesh's own samples with the roads graded in, so its shore is the one the mesh draws.
  • It takes every water_bodies_stride(n)-th sample to stay at most 1025 a side.
  • It is one step, like the other single-call stages. The progress weights are rebalanced (mesh 0.24 → 0.22, water 0.08 → 0.07, shore 0.03).

terrain_lab.ari debug view:

  • The world panel's Colour by gains Water bodies: the sea blue, lakes teal, ponds green with a shade per body, dry land grey, and a contour every 25 m of shore distance.
  • In that mode the water surfaces' texture (surface_painter::take_water) takes the same colours, so the bodies show where the water covers the ground.
  • The realizer's first paint now goes through surface_painter too, so a document opened in this mode starts right.
  • The panel shows a water line (world.stats.water, e.g. "1 sea, 36 lakes, 203 ponds").
  • color: water works in a document. Both the cvcGL realizer and the headless host accept it.
  • Checked with arigl snapshot --set world.color=4 on terrain_lab.ari:
    • the standard 1.2 km world shows its edge inlets as one blue sea, the large central lake teal, and the ponds green;
    • the island preset shows the sea's contours following the coast.

Measured (native, Windows Release, default params)

world mesh water grid shore stage whole build bodies
1.2 km 241² 241² 4 ms 0.87 s 1 sea, 1 lake, 78 ponds
5 km 1001² 1001² 79 ms 6.2 s 1 sea, 21 lakes, 219 ponds
10 km 2001² 1001² 67–105 ms 11.9–12.9 s 1 sea, 36 lakes, 203 ponds

Not yet measured in wasm. The stage is a single step there too, so expect a hitch of a few hundred ms on the large worlds, in line with the other single-call stages. A 1001² grid holds eight float/int planes, about 32 MB.

Tests

world_water_bodies_test has 22 tests:

  • the roadmap's four labelling cases: an island is one sea; a hollow is one lake; two hollows are two lakes; a channel joins a hollow to the sea;
  • inlets at opposite edges are one sea;
  • 8-connectivity;
  • the pond / lake threshold;
  • dry and flooded grids;
  • a straight shore: exact distance, normal, slope and depth;
  • the shore distance against brute force on a random wet/dry pattern;
  • smoothing: it keeps a straight shore's normal and turns the medial-axis snap from 90° into a gentle turn;
  • fetch on a rectangle, either way round;
  • the water level;
  • missing ground (NaN counts as dry);
  • determinism;
  • bad grids;
  • off-grid queries;
  • generated worlds: the water sits on the mesh's samples; an island world is ringed by sea; the stride keeps large worlds to 1025;
  • the Water bodies colour mode, on the ground's texture and on the water's.

ariadne_scene_world_test now also checks that the headless host publishes world.stats.water.

algo_distance_transform_test has 5 tests:

  • distances against brute force;
  • an empty grid;
  • edt2_squared_both, and the rows form, against two plain calls, to the bit;
  • nav::edt2_squared is the same function.

Run locally (Windows Release, GL build, full tree built) and passing:

  • world_water_bodies_test (22), world_generated_test (29), algo_distance_transform_test (5);
  • ariadne_scene_world_test (9), ariadne_loader_test (223);
  • all 40 nav_* suites, including nav_test's NavEdtExact bit-for-bit checks against the reference kernel.

git clang-format 18.1.8 is clean on the changed lines.

The O1–O22 order of work is unchanged. Next is O2: the CPU h0 with per-cascade seeds and the swell term, with OceanFFT's h0 pass retired.

… (O1)

Phase 0 of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (W0.1-W0.2). build_water_bodies labels the
8-connected runs of ground below the water level: every run reaching the grid's edge is the one
sea, an enclosed run a lake, or a pond under 1 ha. Per sample: the body, level, depth, the signed
shore distance (an exact Euclidean distance transform; cvc::world may not include cvc::nav, so it
carries its own copy of edt2_squared's), the offshore unit normal (optionally smoothed over the
medial axis) and the ground's slope. Per body: level, area, bounds, deepest point and fetch.

generated_world::water is built in a new world_builder stage (shore) from the terrain mesh's
samples, roads graded in, at most 1025 a side: 4 ms on the 1.2 km world, 70-105 ms on 5 and 10 km
(native). terrain_lab's world panel gains Colour by > Water bodies (ground and water surfaces) and
a water line (world.stats.water); color: water works in a document.
…world

nav's binary EDT (Felzenszwalb-Huttenlocher, bit-identical to GRL-SNAM's sdf_nav._edt2, with
its exact integer-sweep fast path) moves unchanged from grid_nav.cpp to cvc/algo/
distance_transform.h: edt2_squared, edt2_squared_both (a mask and its complement in one pass)
and edt2_squared_rows (row at a time, for build_sdf). cvc::algo depends on the standard library
only, and a configure-time check keeps it so. nav::edt2_squared and build_sdf call it; water_bodies
drops its own copy and uses edt2_squared_both, so its grid's cells must now be square.

nav_test's NavEdtExact bit-for-bit checks pass, as do every nav suite, the water bodies tests and
algo_distance_transform_test (brute force; both and rows agree with two plain calls to the bit).
@transfix
transfix enabled auto-merge (squash) November 10, 2026 01:38
@transfix
transfix merged commit 21f4795 into master Nov 10, 2026
13 of 31 checks passed
@transfix
transfix deleted the feat/water-bodies branch November 10, 2026 02:20
transfix added a commit that referenced this pull request Nov 10, 2026
…arsed bodies

The writable-data scan failed on package-linux / libcvc-release-grpc:
- #1109 moved nav's per-thread EDT scratch into cvc::algo (edt_scratch) and
  left grid_nav its own sdf_scratch; both are thread_local scratch buffers,
  the same objects as the two stale grid_nav edt_scratch lines they replace.
- script_engine.cpp's SlicedCall constructor and locked_call each hold a
  static const parsed program (`body`), built once and never written.

The new list is the one the scan emitted for this build.
transfix added a commit that referenced this pull request Nov 10, 2026
…owlist caught up

The writable-data scan (#1107) failed on package-linux / libcvc-release-grpc
at 17916c7: 13 objects off the allowlist, 3 lines the build no longer has.

Moved instead of listed:
- AppRuntime's verb-table mutex was one process-wide static (verbs_mutex())
  for every AppRuntime's table. It is now Verbs::mutex. The providers' bodies
  hold the table by its shared_ptr, so the mutex lives as long as anything
  that locks it, after the AppRuntime too.

Listed, with the reason each can't live under the app:
- async_host.cpp t_starting, http_client.cpp t_cancel_scope and
  GraphicsNode.cpp t_writingPose: this thread's innermost scope (the host
  starting an async_work, the request's cancel scope, the node writing its
  own pose), set and restored by an object on the stack. They say what this
  thread is doing now, as t_running_top and t_poolDropReason do.
- net_intrinsics.cpp: open-url's one-a-second limit (last_ms) is the same
  object, now in register_open_url; the register_net_verbs line goes.
- Master's own, which master's scan has not run on (its CI runs were
  cancelled by newer pushes): #1105's and #1126's parsed programs in
  script_engine.cpp (SlicedCall's and locked_call's `body`, immutable once
  parsed), and #1109's thread-local scratch, edt_scratch moved to
  algo/distance_transform.cpp and grid_nav.cpp's renamed sdf_scratch.

The allowlist is CI's singleton-scan-libcvc artifact from that run, less
the verbs_mutex line.
transfix added a commit that referenced this pull request Nov 10, 2026
Two conflicts, both resolved to keep both sides:

- script_engine.cpp, ScriptLane::take_queue: master made the same fix as
  afcfc49 (the delivery's options' on_done emptied after it is taken, as
  libc++ leaves a moved-from std::function set). Master's form is kept.
- tools/singleton_scan/allowlist.txt: only the cvc header's count. The
  merged list is base plus both sides' changes, 805 lines: master drops the
  handler tables' statics, and both sides list #1105/#1126's parsed
  programs and #1109's EDT/SDF scratch the same way. cvc is 457; the list
  parses and is in scan.py's own order.

No line this branch adds uses an API #1119 changed. Rebuilt cvc, pycvc and
the Ariadne, state_exec, exec_pool, net, stream and lifetime suites; all
pass, and ariadne_runtime_test (291) and ariadne_host_test (48) pass with
CVC_EXEC_THREADS=auto.
transfix added a commit that referenced this pull request Nov 10, 2026
Picks up #1119's refresh of the writable-data scan's allowlist (the
objects from #1109 and #1126), which package-linux / libcvc-release-grpc
failed on.
transfix added a commit that referenced this pull request Nov 17, 2026
…all's legs (#1262)

* ariadne: Stage 1b interfaces

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.

* ariadne: providers and posts on the caller's group, and the init lane'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.

* ariadne: providers and posts on the caller's group: streams

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).

* ariadne: providers and posts on the caller's group: net

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).

* ariadne: providers and posts on the caller's group: room, oidc, nav_compute

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: uri_state's pins release the leaf first (S1.11)

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.

* state: the subscriber audit (S1.11)

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).

* gl: AriRuntime declares its scene prefix thread-affine

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.

* tests: uri_state's and stream descriptors' pins release the leaf first

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.

* ariadne: the net providers' and AriRuntime::wait_idle's header comments

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).

* state: a scheduler's ingress post count, for tests

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).

* ariadne: one pump per frame, isolated documents, and teardown

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).

* tests: Stage 1b Ariadne frames, isolated documents and providers

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).

* bench: mt.ariadne_docs

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.

* tests: AR-3b reads group 0's ingress count

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.

* ci: Stage 1b in the sanitizer jobs

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 7a09366f, and the clang leg took 23 minutes on 08fd204d before these two
binaries.

* ariadne: AppRuntime's providers keep the old order of their names

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 1407da0b, 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 1407da0b'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.

* ariadne: the isolation rules read the document's init: and tests:

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).

* core: a force-moved pump_all ends at its deadline

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.

* tests: AR-3b's providers on workers, EL-1's static / and log, AR-3's 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.

* state: a started call finishes through its host's finisher, safe after 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.

* net: a WebSocket frame is sent whole, one at a time (R1b-mid c-m6)

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).

* ariadne: a thread-affine prefix above the document makes its group host

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.

* ariadne: a resident a reload stops is reaped

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).

* ariadne: teardown and moves refuse to run inside a pump

R1b-mid c-m4. ~Impl and a placement change kill and reap on a scheduler a worker of the same
pump_all may be pumping, and destroy its group, which ~exec_group then aborts. Called inside a
pump_all of the app's pool (a host verb that closes a document, run in group 0 while
exec_pump_frame pumps it), they are now refused in every build: logged, then aborted before
anything is touched (refuse_inside_pump, through exec_pool_probe()). run_program asserts in debug
builds that it is outside a pump. ariadne.h and app_runtime.h say "host thread, outside a pump" on
the destructors, set_root, load and run_program.

Test: AriadneIsolatedDocsDeathTest.ATeardownInsideAPumpIsRefused: a group-0 native destroys
another Runtime while exec_pump_frame pumps group 0 beside an isolated document's group; the
process dies. Without the fix it exits normally (the victim's teardown runs inside the pump).

* ariadne: a moved document takes its streams, and its old group goes at once

R1b-mid s-m3 and c-m1. A placement change left the document's open streams posting to the old
scheduler, so after the move its restarted programs never heard them, not even their close, and it
kept the old group alive, registered and pumped for the Runtime's life, one more for each change.
Now a move re-points the document's open streams at the new scheduler and destroys the old group
at once:

- stream::retarget(app, scope, from, to) (stream.h, new): every live stream of the app opened at or
  under `scope` that posts to `from` posts to `to`. Every post holds the stream's new sched_mu_,
  which retarget takes too, so no post to `from` is in flight once it returns. stream.cpp keeps a
  list of the live streams for it.
- ensure_placement: kill and reap where the processes ran (move_out), unregister the old group,
  make the new one, retarget the streams under the document's prefix, then destroy the old group.
  RetiredGroup and the retired pumps are gone; the dropped contexts are still kept to ~Impl.
- ariadne.h: what a move does, that the placement is decided again after each set_root, and that
  drain() pumps the document's group through the app's pool.

Tests:
- AriadneIsolatedDocs.AMovedDocumentsStreamPostsWhereItNowRuns (probe PE): a stream opened in the
  group, a move to group 0, a resident there; the document's stream-close reaches the resident
  ("closed") and no group is alive after the move. Without the fix: the resident hears nothing.
- AriadneIsolatedDocs.AnEligibilityThatFlipsKeepsOneGroupAtMost (EachPlacementChange... probe):
  8 set_roots alternating eligible and not; live groups stay 1 or 0 and a frame pumps at most one.
  Without the fix: live groups and pumps grow by one per round trip.
- ALaterDocumentThatIsNotEligibleMovesToGroupZero now expects no group alive after the move.

* ariadne: the placement is decided again after a program, policy or host verb changes; idle decides nothing

R1b-mid s-m2, s-m4 and c-m2.
- s-m2: set_*_program, set_channel_policy and set_key_bindings clear the placement decision, as
  set_root and set_document_programs do, so a program or policy set after the placement is read by
  the isolation rules before the next program starts. The set_*_program calls also assert in debug
  builds that they run outside a pump (c-m4).
- s-m4: refresh_program_names, which AppRuntime calls for every registration, clears it too, so a
  host verb or function registered after load() is bound in an isolated document as in group 0 (a
  host_only one makes the group host). declare_thread_affine_prefix clears it as well.
- c-m2: Runtime::current_group() (new) returns the group as last decided, deciding and moving
  nothing; AppRuntime::idle() and wait_idle() use it instead of isolated_group().

Tests:
- AriadneIsolatedDocs.AProgramSetAfterThePlacementIsScanned (probe PD): an on_tick: on oidc's
  channel set after the placement moves the document to group 0 with the oidc reason. Without the
  fix: it stays isolated.
- AriadneIsolatedDocs.AHostVerbRegisteredAfterLoadIsBound (probe PF): a verb registered after load
  is called once, and the group is host. Without the fix: NameError, the group any.
- AriadneIsolatedDocs.IdleAndWaitIdleDecideNothing: after a set_root that would move the document,
  idle() and wait_idle() leave its group in place; the next drain moves it. Without the fix: idle()
  moves it.

* ariadne: AppRuntime's verb table is read and written under a mutex

R1b-mid c-m5. AppRuntime's provider bodies read its verb table (sync and async verbs, quit, the data
store, prefix and directory, functions, async functions), and a spawned child in an `any` group
runs them on the pumping worker, while a registration or a load writes the table. Both now hold one
mutex: a body copies what it binds under it and binds unlocked, and nothing a host gave (a callable,
whose destructor may take a lock such as the GIL) is destroyed under it. app_runtime.h says
registrations are made on the host thread, outside a frame, and before load() (or the placement is
decided again).

No deterministic test: the race needs a registration during a worker's env build, which fork-join
rules out for a host that keeps the rule; the clang TSan leg is where a regression would show.

* ariadne: header comments for providers and done channels

R1b-mid s-m8 and c-m7. The two-argument register_action_intrinsics says a host_proxied provider
binds synchronous natives only, and that what a provider binds that is not a native is made fresh
for each env or is immutable; intrinsics.h's provider_affinity and the registry comment in
ariadne.cpp say the same. app_runtime.h: register_async_verb's done channel goes to the calling
program's group (group 0 from init:).

* tests: EL-1's thread-affine prefix above the document (R1b-mid S-M2)

EL-1 gains an eligible document whose host declared a thread-affine prefix above its prefix
(docs.el.stage for docs.el.stage.doc): a subscriber there is called for every write the document
makes, so its group must be affinity::host. It fails until A's S-M2 fix (the rule matching an
ancestor of the document's prefix too) merges: today the group is `any`.

* ci: Stage 1b's implementer cases in the sanitizer jobs

SAN_REQUIRED_S1B gains the implementers' and the review round's new cases in ariadne_runtime_test
(the drain split's single pump, the init lane's registry, a reload's reaped resident, providers by
kind, idle and wait_idle, isolated documents' placement and moves, the teardown refused inside a
pump, net and stream posts on the caller's group) and state_exec_async_calls_test (a started call's
finisher). SAN_REQUIRED_S1A gains exec_pool_test's ExecPool.AForceMovedCallEndsAtItsDeadline, as
its rule asks. Every line names a binary each leg runs.

* docs: Stage 1b

Threaded execution's Stage 1b (Ariadne's half), as built.

- STATE_EXEC_THREADED.md: the status line; 4.6's Stage 1 (no router);
  4.8's subscriber audit table, declarations, debug home-thread asserts,
  GraphicsNode's verdict and follow-ups; 4.9's Ariadne contexts and hosts,
  posts on the caller's group, providers by kind, provider rules, a started
  call's finisher and whole WebSocket frames; 4.11 item 7; 4.12's drain
  split, host-thread calls, isolated documents (eligibility, affinity,
  placement and moves); 4.15's spawn_child; 4.17's Runtime teardown and
  the force-move deadline; 5 items 10 and 11 and Stage 1b's always-on
  changes; 7's Stage 1b entry and follow-ups; 8's Stage 1b cases.
- ARIADNE.md: documents in groups of their own (2.5), one pump a frame,
  the host-thread calls, thread-affine declarations and adding verbs by
  kind (9.1); stale file:line citations replaced by function names.
- STATE_EXEC_DEVELOPER_GUIDE.md: Ariadne providers (kinds, registration,
  rules, posting to the caller's group, the finisher).
- APP_API.md: Ariadne hosts and the frame pump.
- pycvc README: AriApp and the GIL.

* tests: the force-moved call's deadline is timed in its caller

AForceMovedCallEndsAtItsDeadline took its time after the busy worker's
thread joined, so it passed with only the worker's skip-notify: the
call then ended when the worker came, not at its deadline. The call is
now timed in its own thread and must end within half the worker's nap
(1 s). With only the worker half of the fix it fails (0.99 s); with
both it ends after about 0.06 s.

* ariadne: a move re-points the document's own streams and retires its old group; a held group refuses

R1b skeptic M1, m1, m2, m4 and m5.

- M1: a move re-points the streams the document owns, by owner, not every live stream under its
  prefix. stream gains a member retarget(from, to), which swaps its scheduler under sched_mu_ and
  returns with no post to `from` in flight, and scheduler_for_test(); the static
  stream::retarget(app, scope, ...) and the live-streams list are gone. stream_intrinsics gains
  retarget_document_streams(doc, from, to) and close_document_streams(doc) over the document's
  table, under its lock. ensure_placement re-points with &doc_scope_; if that throws it closes the
  document's streams (and, failing that, clears its scope), so none is left naming the old place.
  Every opener that names a document's scheduler (stream-open, room-subscribe's proxy through
  own_document_stream) is owned through the document's table; the others (stream_bridge,
  stream_relay, arigl's video proxy, the examples) open on group 0.
- m1, m5: the moved-out group is retired, not destroyed: unregistered and unpumped, with the
  contexts taken from it, and destroyed at a later drain_begin once its host has no kernel in
  flight; ~Impl destroys any left (it may wait, as teardown does). Only its own kernels'
  completions can post to it then: its processes are gone, no stream names it, the Runtime posts
  to the new place, and its host-call queue is empty outside a pump. retired_contexts_ keeps only
  the contexts taken from group 0.
- m2: refuse_if_held refuses a teardown or a move out of a group while a pump_all holds it
  (pool_link().call, set from the call's entry until it returns), from any thread, and prints
  "refused" on stderr before it aborts. A group-0 document's teardown or move is not refused.
- m4: run_program, which only queues, drops its pump assert.

Tests:
- AriadneIsolatedDocs.AMoveLeavesANestedDocumentsStreamAlone (probe P1): a group-0 document
  nested under a moving document keeps its stream on group 0, its producer's seq does not land in
  the mover's group, and after the mover's teardown the stream still names group 0. (It failed at
  fbe62b23 in the skeptic's run: taken 1, landed 1, dangling 1.)
- AriadneIsolatedDocs.AStreamTheDocumentOwnsFollowsItsMoveWhateverItsScope (probe P1b): a
  document-owned proxy with its publisher's scope names group 0 after a move there. Fails with the
  document's streams not re-pointed.
- AriadneIsolatedDocs.AMoveDoesNotWaitForTheOldGroupsCalls (probe P2): the move returns while the
  old group's 1.5 s kernel runs, the action is told it moved, and the retired group goes at a drain
  once the kernel has ended. Fails with the old group destroyed at the move (1.5 s).
- AriadneIsolatedDocsDeathTest.ATeardownInsideAPumpIsRefused, reworked: the victim is an isolated
  document whose group the same exec_pump_frame holds; the death must print "refused".
- AriadneIsolatedDocsDeathTest.ATeardownFromAnotherThreadWhileAPumpHoldsItsGroupIsRefused: a
  teardown on another thread while the frame thread's pump holds the group is refused. Fails with
  the refusal by thread (no "refused": ~exec_group aborts instead).
- AriadneIsolatedDocsDeathTest.TearingDownAnUnpumpedDocumentInsideAPumpIsAllowed (probe P3): a
  host group's native tearing down a never-run group-0 document inside the pump exits cleanly.
  Fails with the refusal by thread.
- AMovedDocumentsStreamPostsWhereItNowRuns and ALaterDocumentThatIsNotEligibleMovesToGroupZero
  check the old group gone after the next drain.

* ariadne: a late registration re-decides the placement only while nothing of the document runs

R1b skeptic m3, the lead's rule. Both registration paths make the placement stale: AppRuntime's
register_* (through refresh_program_names) and register_action_intrinsics (the providers'
registry moving past the generation the placement read). A stale placement is decided again at the
next decision point only when a move would kill nothing (no live action, started resident or mount
tick, nor spawned child where the document runs), which covers a registration between load() and
the first frame, init: included. Otherwise it waits for the document's next restart (a load,
set_root, set_*_program, which kill and restart anyway); until then a host_only name registered
late is a NameError in an isolated `any` group, logged once per placement. set_channel_policy,
set_key_bindings and declare_thread_affine_prefix still have it decided again at once.

ariadne.h (isolated_group, refresh_program_names) and app_runtime.h (the registration rule) say what
is now true: the streams the document owns follow a move, the old group goes once its calls end,
the refusal is by a held group, and the late-registration rule.

Tests:
- AriadneIsolatedDocs.AHostVerbRegisteredWhileItRunsBindsAtTheNextLoad (probe P4): with a tick
  resident running, a verb registered after load does not move the document: a parked action
  finishes, the verb is a NameError in the `any` group, and the next load binds it (group host).
  Fails when the registration moves the document at once (the parked action is killed).
- AriadneIsolatedDocs.AHostVerbRegisteredBeforeTheFirstFrameIsBound (renamed from
  AHostVerbRegisteredAfterLoadIsBound): a registration before the first frame still moves the
  document to a host group and binds the verb.
- AriadneIsolatedDocs.ProvidersAreInstalledByTheirKind registers its late host_only provider after
  a frame, while the tick resident runs, and says which case that is. Fails when a late
  registration moves the document regardless (the provider binds, the group turns host).

* state: a host's shutdown runs its calls' cancel hooks outside its lock (R1b skeptic m6)

async_host::shutdown cancelled each call, running its on_cancel hook, while it held the state
mutex a finisher takes. A hook that waits for its work's own thread (an abort that joins)
deadlocked when that thread was in finisher::finish, waiting for the mutex.

Now shutdown sets `stopped` and takes the live calls under the mutex, releases it, cancels them
(their hooks run unlocked), then waits for `running == 0` under the mutex again. A finisher that
comes after `stopped` still posts nothing. The header's rules say what is now allowed: a hook may
wait for a thread that finishes the call through a finisher.

Test: AsyncCalls.AShutdownsCancelHookMayWaitForAThreadInTheFinisher. A started call's hook starts
a thread that settles and finishes the call through the finisher, and waits up to 5 s for it: the
wait ends in time, the finisher posts nothing, and the scheduler's ingress count does not move.
With the old shutdown it fails (the hook waits out its 5 s guard).

* net: a cancelled request stops its transfer, and net's kernels pass their call's cancel (R1b skeptic m1)

A kill or a host's shutdown cancels an http-get's call, but the kernel's transfer ran on to the
server's reply or its timeout (30 s by default): perform() never looked at the call. An isolated
document's teardown waits for its group's kernels, so one slow request held it that long.

- HttpRequest gains `cancelled`, a predicate asked before the request is made and about once a
  second while it is in flight (the curl backend's CURLOPT_XFERINFOFUNCTION). Once it returns true
  the transfer is aborted and the reply is a transport failure, "cvc::net: cancelled". The
  browser's fetch ignores it.
- HttpCancelScope sets the same predicate for every request a thread sends while it lives, for
  requests built by code that takes no request options (Ariadne's (fetch), through its URI
  handlers, and a credential's renewal).
- http_kernel and uri_fetch_kernel hold one over their call's cancel_requested(). A kill
  (cancel_async_calls) and a host's shutdown both cancel the call, so either now ends the transfer
  in about a second.

Tests:
- NetCurlBackend.ACancelledRequestStopsItsTransfer: against a server that never answers, a request
  whose predicate (then a thread's HttpCancelScope) turns true ends about 1 s later with
  "cvc::net: cancelled", not at its 8 s timeout; one cancelled before it goes is never made.
- AriadneNetHost.ACancelledRequestStopsItsTransfer: an http-get to a server that stalls 12 s; the
  context host's shutdown returns in about 1 s, and after a kill the app host's kernel ends as
  soon. Without the progress callback both fail (8 s; 12 s and 10 s); without the kernels' scope
  the second fails alone.

* ci: the skeptic round's cases in the sanitizer jobs

SAN_REQUIRED_S1B gains A's move, retired-group, held-group and late-registration cases, I's cancelled-transfer and shutdown-hook cases, and AHostVerbRegisteredAfterLoadIsBound's new name.

* docs: Stage 1b, the review's fixes

The R1b skeptic round's fixes, as built.

- A move re-points the streams the document owns (retarget_document_streams,
  the member stream::retarget(from, to)), closing them if that fails; the
  old group is retired, unpumped, and destroyed at a later drain_begin once
  its host is idle (~Impl destroys any left); retired_contexts_ keeps only
  group 0's. The "retarget by scope" follow-up is resolved.
- refuse_if_held refuses a teardown or a move out of a group a pump_all
  holds, from any thread; group-0 documents are not refused.
- Late registrations, by either path, re-decide the placement only while
  nothing of the document runs; else they wait for its next restart, a late
  host_only name a NameError in its any group (logged once).
- run_program only queues and no longer asserts.
- async_host::shutdown runs cancel hooks outside its lock;
  STATE_EXEC_EXCEPTIONS.md 3.12 names the finisher.
- A cancelled http request stops its transfer (HttpRequest::cancelled,
  HttpCancelScope) in td 4.9, 4.17 and 5, and the developer guide.
- Section 8's new and renamed cases.
- ARIADNE.md 5 and 6: loader.cpp citations by function name.

* tests: three timing cases hold on a loaded machine

On a machine running four times slower than usual:

- AForceMovedCallEndsAtItsDeadline's caller thread started after the
  busy worker's nap, so the worker took the call at once. The case now
  records when the nap ends and the call begins, judges the deadline
  only when the worker stayed busy for over half its nap after the
  call began, and tries again (five times at most) when it did not.
- NetCurlBackend.ACancelledRequestStopsItsTransfer's 8 s timeout ran
  out 3.7 s after the cancel, before libcurl's once-a-second check got
  a turn. The timeout is 30 s, the stall 40 s, the ceiling 10 s.
- AriadneNetHost.ACancelledRequestStopsItsTransfer gets the same
  room: a 20 s stall, 8 s ceilings.

* ariadne: idle and wait_idle count the groups a move retired

A move retires the old group until its kernels end, but
AppRuntime::idle() and wait_idle() looked only at the current group:
a host waiting before it lets go of what an async function uses could
go on while that function still ran in a retired group. Runtime gains
retired_calls_in_flight() and wait_retired_calls(), which neither
decide nor destroy anything; idle() counts them and wait_idle() waits
for them (AriRuntime::wait_idle goes through it).

AriadneIsolatedDocs.IdleAndWaitIdleCountARetiredGroupsCalls fails
without it (idle while the kernel runs, wait_idle returns early) and
is required in the sanitizer jobs.

* docs: idle and wait_idle count retired groups; the hardened tests' timings

APP_API, the threading doc (4.12, section 8) and the pycvc README say AppRuntime::idle() and wait_idle() count a retired group's kernels (a9b3642b), and section 8 gives f4f474d6's new stalls, timeouts and the force-move case's retry.

* Stage 1b: the bench/CI/docs review's lead items

- clang-format (changed lines): two comment alignments that CI's
  git-clang-format against the base would reject (ariadne.cpp's
  thread_affine_, two include comments in ariadne_runtime_test.cpp).
- The AR-3b ingress counter is a relaxed load and store under the
  ingress lock, which already serializes the posts: no locked
  read-modify-write on post_message or post_async_completion.
- AForceMovedCallEndsAtItsDeadline passes with a note, rather than
  skipping, when no try had the worker busy: a skip prints no "OK ]"
  and would fail the sanitizer jobs' required list. Its hang check
  still runs on every try.
- A late registration binds the first time nothing of the document
  runs, at the latest at its next restart: the header comments and
  the log line now say so (they said "at the next load").

* docs: Stage 1b, the last review's wording

The R1b bench, CI and docs review's m8 and m9.

- m8: a late registration is decided again the first time nothing of the
  document runs, at the latest at its next restart (td 4.9, 4.12 and 5
  item 11; ARIADNE.md 2.5 and 9.1; the developer guide; APP_API), quoting
  the new log text.
- m9: AppRuntime::load also builds the scheduler (APP_API, ARIADNE.md
  2.2); idle() and wait_idle() never build, move or destroy the document's
  group; an `any` group runs on a worker or the calling thread.

* docs: Stage 1b, the last review's wording (a line rewrapped)

* bench: mt.ariadne_docs' gate judges only points that can wake a helper

The R1b bench review's m1, m2 and m3.

- mt.ariadne_docs reads each rep's placement after it, through Runtime::current_group() (a rep in
  which a document moved fails), and reports extra.any_groups, the documents in an `any` group of
  their own, and extra.wakeable, the most helpers a frame could wake as exec_pool's adaptive wake
  counts them: min(any_groups - caller_takes, effective workers), caller_takes 1 unless a
  host-affinity group or group 0 with a live process joins exec_pump_frame's pump_all. Also
  extra.wakes_per_frame.
- GATE_GUARDS, for mt.ariadne_docs' helper_wakes, wakes_per_frame and worker_pumps gates: a point
  with extra.isolated or extra.any_groups below docs fails as vacuous; a point with
  extra.wakeable 0 (t=0, or docs=1, whose lone group the caller takes) prints n/a, neither PASS
  nor FAIL, and a gate of nothing but n/a fails; and the same run's heavy points that can wake a
  helper are a control, each needing extra.worker_pumps at least 1 in the median rep. Self-tests
  for each.
- STATE_EXEC_BENCH.md: the gate is the median of a --reps 5 run in the quiet window, never the
  smoke; the small frames' measured margin to inline_below (about 2x at docs=8) instead of "well
  under"; --stat max marked load-sensitive; the wake rate recorded, not gated; S1b's A/B scope
  (the regression family with msg.* and async.*, the small-frames gate on the candidate alone,
  heavy recorded, the pump-scope and scaling gates optional); the S1b.0 stub passages gone.

* ci: stream_test and net_ws_client_test in every sanitizer leg, ariadne_host_test in the gcc legs

The R1b bench review's m6 and m7.

- stream_test and net_ws_client_test join SAN_CXX_TESTS and the clang leg's cxx_tests, and their
  Stage 1b cases join SAN_REQUIRED_S1B: Stream.EventsGoToTheSchedulerItWasOpenedWith (a producer
  thread's post under the stream's scheduler lock) and
  NetWsClient.TwoThreadsSendingOnOneConnectionSendWholeMessages (the send lock against the reader
  thread). libcurl's own threads are no known source of false reports here: both suppression files
  are empty, and at S1a's head (run 42482487375) both gcc legs ran curl's HTTP and WebSocket
  client, its reader thread included, through ariadne_runtime_test without a report.
- ariadne_host_test joins SAN_CXX_TESTS (the gcc legs) for ASan, with no required line: its Stage
  1b cases are single-threaded. net_http_client_test stays out (ariadne_runtime_test's cancel case
  covers its curl abort path in all three legs).
- The clang leg's Ariadne run is described as it is: CVC_EXEC_THREADS=4 sizes a pool built from
  the tree at up to four workers (three on the 4-vCPU runner), a case that sizes its own pool keeps
  it, and the lock manager's auto mode is shared.
- docs/TESTING.md: the legs' binaries, the Stage 1b row naming its 42 required lines by group
  ("every Stage 1b case of these binaries"), exec_pool_test's 34 cases, and Stage 1b's empty
  suppression files.

* ariadne: AR-3 allows a group the frame's deadline skipped one more frame

On the macOS Debug recipe leg (3 cores: 2 workers and the caller for
AR-3's 4 busy documents) each resident's pump outlasts the frame's 0.1 s
deadline, so the deadline skips the group that would start last (td
4.10). Its quick action then completes in the next frame, which starts
it first, and AR-3's "completes in its drain" check failed every retry.

AR-3 now reads pool_link().skipped after the frame: a group the frame
started must complete its action in that drain, a skipped one in the
next frame, and at least one group must start. td 4.11 item 7 and the
AR-3 row say the same.

Reproduced on Windows Release with 2 workers and a 120 ms sleep in the
probe native (the same failure, docs.d2); with the change it passes 5/5
under that load, taking the skip path each time.

* test(nav): compare the whole pos column in EachPolicyDrivesItsOwnAgents

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.

* script_engine: reflow SlicedCall's comment (clang-format)

* cvcGL: name CameraController's render-thread id renderThread

Master's #1124 gave CameraController::Impl a `double home[6]` (the Reset
view box), and this branch's 4.8 check had a `std::thread::id home` (the
thread that must get every state change). The 1516bb8a merge combined both
without a conflict, so cvcGL failed to compile. The thread id is now
renderThread.

* ariadne: the verb table's mutex is the table's; the writable-data allowlist caught up

The writable-data scan (#1107) failed on package-linux / libcvc-release-grpc
at 17916c78: 13 objects off the allowlist, 3 lines the build no longer has.

Moved instead of listed:
- AppRuntime's verb-table mutex was one process-wide static (verbs_mutex())
  for every AppRuntime's table. It is now Verbs::mutex. The providers' bodies
  hold the table by its shared_ptr, so the mutex lives as long as anything
  that locks it, after the AppRuntime too.

Listed, with the reason each can't live under the app:
- async_host.cpp t_starting, http_client.cpp t_cancel_scope and
  GraphicsNode.cpp t_writingPose: this thread's innermost scope (the host
  starting an async_work, the request's cancel scope, the node writing its
  own pose), set and restored by an object on the stack. They say what this
  thread is doing now, as t_running_top and t_poolDropReason do.
- net_intrinsics.cpp: open-url's one-a-second limit (last_ms) is the same
  object, now in register_open_url; the register_net_verbs line goes.
- Master's own, which master's scan has not run on (its CI runs were
  cancelled by newer pushes): #1105's and #1126's parsed programs in
  script_engine.cpp (SlicedCall's and locked_call's `body`, immutable once
  parsed), and #1109's thread-local scratch, edt_scratch moved to
  algo/distance_transform.cpp and grid_nav.cpp's renamed sdf_scratch.

The allowlist is CI's singleton-scan-libcvc artifact from that run, less
the verbs_mutex line.

* ariadne: a queued hook's on_done hears each event once on libc++ too

take_queue moved on_done out of the delivery's options, then started the
delivery with those options. libc++ leaves a moved-from std::function that
held a small callable still set (its move clones the small buffer), so
start() wrapped the user's on_done as the process's done as well, and the
delivery's own end came through as one more "ok" outcome. On macOS debug
AKeyHookTakesEveryKeyInOrder saw 4 outcomes for 3 keys and
AFailedEventLetsTheNextOneGo 3 for 2; libstdc++ and MSVC empty the source,
so Linux and Windows never showed it.

Take it out with std::exchange, which leaves the options' on_done empty
everywhere. This is #1129's code; master's macOS jobs for it were
cancelled before they ran, so this is the first macOS run of these tests.

* tests: the action-caps test's loop fits the default 0.1 s in a debug build

AriadneAsyncFn.ActionCapsAreTreeSettingsAndChargeAsyncCalls clicks a
200-round loop to show it fits the default 5000-step cap. On Linux debug
CI, in the threaded run of the whole binary (ariadne_runtime_test_threads_auto,
late in a loaded ctest), the loop ran out of the default 0.1 s instead:
time_limit_exceeded on all 3 tries at afcfc498 and the first of 2 at
0e3835e0. The per-test runs of the same build passed it.

Measured on Windows Release: the loop is 3,224 steps and about 0.4 ms of
CPU, the same plain and with CVC_EXEC_THREADS=auto, so the threaded mode
adds nothing per step; an unoptimized build on a busy runner is what puts
it near the time cap. 20 rounds are 344 steps: still over the test's
100-step cap, under a tenth of the CPU. The assertions are unchanged
apart from the value the loop writes.

* singleton scan: allowlist room_calls.cpp's message-id counter

Linux release-grpc's scan found one object from master's room-call (#1122)
that the merge's allowlist lines did not name: the atomic g_messages counter
that numbers room-call message ids. The other six predicted lines matched.

* clang-format the merged room_media and oidc registrations

The 600c1447 merge put master's app argument in front of this branch's provider-kind argument in room_media_intrinsics.cpp and oidc_host.cpp, and clang-format now wraps the app onto its own line. Whitespace only.

* No thread_locals of the branch's own: pass the context instead

libcvc keeps no process-wide state, and VOLROVER-LIBRARY-PORTS-ROADMAP.md 1.3
names "thread_local used to carry context past a function's arguments" among
what may not appear. This branch had added three, all on the allowlist; each
now travels as an argument or lives on the object it is about, and the
allowlist is back to master's counts (cvc 451, cvcGL 222).

- t_cancel_scope (net/http_client.cpp): HttpCancelScope set a cancel predicate
  for every request a thread sent, so net's kernels could stop requests built
  by code that took no request options. That code takes it now: resolve(uri,
  base, cancelled) hands a UriCancelled to the scheme's UriHandler, and the
  http(s) handlers, cached or not, set it on their request (a cache leader's
  fetch carries its caller's, as before). CredentialRenewer::renew(rejected,
  cancelled) sets it on the refresh; renew(rejected) still reads as before.
  http_kernel and uri_fetch_kernel pass their call's cancel_requested(). A
  handler that sends no request registers a UriLocalHandler, the old
  two-argument form, so the state, cvc and test schemes are unchanged.
  HttpCancelScope is gone.
- t_starting (state_exec/async_host.cpp): async_host::starting() named the host
  running a work's start. The call names it instead,
  async_call::starting_host(), set by async_host::call around the start and
  cleared after it; the script lane's exported calls read it there.
  async_start's signature is unchanged.
- t_writingPose (cvcGL/GraphicsNode.cpp): a scene-less node's own pose write
  is now marked on the node, an atomic thread id claimed by compare-exchange
  around the write. The handler drops the echo only on that thread, so another
  thread's matrix meanwhile is still not taken for the echo. A second thread
  writing the same node at once does not claim it and redraws the same pose.

Docs: STATE_EXEC_THREADED.md and STATE_EXEC_DEVELOPER_GUIDE.md describe the
arguments. The curl test keeps its HttpRequest::cancelled case.

* docs: a host posts to the scheduler the program parks on, not exec_scheduler()

app.h's compute_async comment, resolve_channel_key's doc comment and CVCGL-UI-DSL-ROADMAP.md still named exec_scheduler().post_message as the way a host wakes a parked (msg-recv). For a program of an isolated document (S1b) that post stays in group 0's queue and never wakes it. They now name ictx.host->parking_scheduler() (exec_scheduler() only when it is null), as AppRuntime's done channels and STATE_EXEC_DEVELOPER_GUIDE.md already do, and point at an async function on *ictx.host as the simpler route (nav_compute's).

The guide and resolve_channel_key's comment also state the lifetime: a move or teardown destroys an isolated document's group once its host's own calls have ended, which do not include an untracked compute_async job, so such a job must end before the document moves or goes. Comments and docs only.

* clang-format the sync adapter's merged comment

9b43e8a4's edit to connect_node's comment left one line over the column limit. Comment reflow only.

* open-url: the one-a-second clock is the app's, not a static

register_net_intrinsics makes the clock and its host_proxied provider hands it to each program's (open-url), so every program the app builds shares the limit and no process-wide object holds it. The allowlist drops the static's line.

* state_exec_bench: pool_aging records where its kernels ran

async.pool_aging's time per call is mostly the OS waking the floating kernel thread, so the core
it lands on sets that time more than either executor does. Its records now carry the share of
calls whose kernel ended on a CPU of the fastest efficiency class (P-cores on a hybrid part),
over the first and last 10 % of calls and over all of them: extra.first_fast_cpu_share,
last_fast_cpu_share and fast_cpu_share (-1 off Windows or on a uniform part).

On a Core Ultra 9 185H, over 184 stretches of 10 % of calls, those with at least 99 % of kernels on
P-cores took a median 9.1 us a call and those with under half 22.5 us (Pearson r -0.55). This is
what made the threaded Stage 1b A/B's pool_aging points 45-55 % noisy: with the same frozen
binaries interleaved every few seconds, base 8cba3b18 and candidate b4af08cc differ by -6.4 % to
+3.4 % per round, and by -2.2 % to +2.2 % with the kernels kept on one P-core.

* state_exec_bench: fastest_cpu_efficiency reads the CPU sets each time

It runs three times per pool_aging record, after the run, so it needs no function-local cache.

* state_exec_bench: pool_aging splits each call into its legs

async.pool_aging's time per call moves far more than the driver's cost does. A call is the
driver's turnaround (the previous kernel's end to this call being made), which is the handoff
(to the first step slice after that end: the completion posted, seen, drained and woken) plus the
driver's work (the steps up to the call), then the kernel thread's wake (the call being made to
its kernel starting).

The kernel thread spins a few us in its wait before it blocks. On a Core Ultra 9 185H with the
kernels on one P-core, a call made within about 5.2 us of the previous kernel's end waits about
1 us for its kernel, one made later about 7 us, and the driver's turnaround is about 5.1-5.3 us,
right at that edge. The two feed each other: with 25 ns more driver work per call (a calibrated
busy loop before the call, interleaved, quiet, kernels on CPU 12), driver work rose about 250 ns,
the share of slow wakes 0.1-0.2 and the time per call 11-26 %; with 100 ns, about 400 ns, 0.1-0.4
and 15-31 %. Over a run, driver work grows 13-19 % and slow wakes go from…
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