Skip to content

P0a: the last process state we control goes onto the app; the allowlist ends at the settled list - #1276

Merged
transfix merged 8 commits into
masterfrom
p0a/last-globals
Nov 16, 2026
Merged

transfix merged 8 commits into
masterfrom
p0a/last-globals

Conversation

@transfix

Copy link
Copy Markdown
Owner

Removes the last process state we control: the CUDA device manager, raycast.cu's marching-cubes tables, the hosts' signal flags, curl's second init flag, and the globals in the Ariadne hosts and their embedded Python, which the scan never looked at. The scan now covers those hosts, arisrv and arisrvx among them. The allowlist drops from 22 to 10 lines, and ends there: what is left is the process's, as settled on 2026-11-14 (roadmap §9 item 5).

Follows #1203 and #1217, both merged; master (f36e986) is merged in, with no conflicts. Please merge with a merge commit.

What changed

  • CUDA device manager (2 lines): no instance and no cache. Each static call asks the CUDA runtime, which keeps the answer itself. instance() is gone; the CUDA-off stub never had it, so portable code could not call it.
  • raycast.cu (7 lines): the four marching-cubes tables are one const __constant__ object, filled at compile time from detail/mc_tables.h by a constexpr copy. It is part of the module image, so every device has it: no upload, no per-device flag, no mutex.
  • cvcGL's macOS clipboard: cvcgl_mac_clip_get() returns a std::string instead of a pointer into a thread_local buffer.
  • The embedded Python (src/ariadne_python): its state lives in an EngineState the Engine owns: what the host lent, _ariadne_python, _arihost and the ScriptEngine.
    • _arihost is made at boot and put in sys.modules. It is no longer an inittab entry, because an inittab's init function has nothing to reach its engine through.
    • Its functions reach their engine through the module's state.
    • <host> python still has _arihost, reporting that nothing is attached.
  • ari, arix, arigl and ariglx:
    • g_python and g_wasm are gone. main() hands a Scripting (the Python engine and the WebAssembly guests' engine) down to the runs that lend them.
    • arigl's walk keys are a constexpr table.
    • Its "no libopus" warning is said once per conference session, not once per process.
  • arisrv's load bench: the room step, the client frame and the tick clock belong to the bench's relay. now_s() keeps no epoch.
  • Signals (host_signals.h): each app keeps its own stop flag and trapped signals (signals_of(app), an app slot). A signal_route(app, mode) points the process's handlers at one app while it lives and puts the previous ones back when it goes, so routes nest.
    • The one process-wide object left is the pointer the handler follows. It keeps g_raised's name and allowlist line, because it is where a raised signal goes. The saved handlers live in the route, so g_previous goes.
    • arisrv, arisrvx and cvc serve route in stop mode (SIGINT and SIGTERM, on Windows too) and poll the app's flag: g_stop and g_serve_running are gone. ari and arigl route in trap mode, from on_start to on_stop.
  • curl: the WebSocket client calls the HTTP client's init (detail::curl_global_init_once), so libcvc has one once-flag for curl, not two.
  • The examples (not scanned): the demo menu's state is an app slot (demos_menu(app, slug), demo_switch_requested(app), in all ten demos); terrain_lab's extents, units, sun and building library are main's or the app's; the nav city demos' frame state is locals, so a second run after a demo switch starts clean.
  • The allowlist ends at the settled entries. Each group carries the reason it stays (scan.py's WHY_IT_STAYS, written by render_allowlist, so a regenerated list keeps them; a scan test fails a line with no reason). The header, the scan's README and roadmap §9 item 5 quote Joe's four answers. The ratchet stays.

The scan

  • package-linux / libcvc-release-grpc now also scans ari, arigl and arisrv_aoi_bench.
  • pycvc-linux now also scans arix and ariglx, which carry the embedded Python.
  • VTK's module autoinit objects (vtk*_AutoInit_Instance, which vtk_module_autoinit puts in each file) join VTK's other header objects on the third-party list.
  • package-linux / libcvc-release-grpc also scans arisrv, and pycvc-linux scans arisrvx: their stop flag is the app's now, so they have no writable object of their own.

Behaviour changes to review

  • CUDA:
    • The device manager no longer calls cudaDeviceReset() at exit; that reset every device for the whole process.
    • get_device_info() asks each device every call. That includes its free memory, which sets the device current for a moment, as get_free_memory() already did.
  • _arihost: no longer in sys.builtin_module_names. Every importer uses import _arihost, which still works.

Tests

  • New ctest arix_python_two_apps: arix test runs two documents, each in an app of its own, lent in turn to the one interpreter.
  • New MultiAppIntegration.SignalsGoToTheRoutedAppOnly: a signal reaches only the routed app, from another thread too; a nested route has the signals until it goes; the last route puts the process's handlers back; trap routes give each app only its own signals, each once. The workload of AppsNeverCollide checks each app's flags are its own (alone, at once on threads, reversed).
  • Existing: the arix and ariglx tests, including arix_python_interpreter (_arihost in arix python), and the scan's own tests, with a new autoinit case.

Testing

  • Windows (MSVC Release), on the merge with master f36e986: full build, then the affected tests (multi-app, ari, arix, arigl, ariglx, the Python host, the cvc CLI, the HTTP and WebSocket clients): 266 of 266 pass, 22 skipped because this build has no FTXUI or matplotlib. The ariglx tests, which drive the same engine as the skipped arix document tests (arix_python_two_apps among them), pass.
  • Before the merge, the full ctest -j 6 (bench, slow and soak left out): 7,323 of 7,323 pass.
  • The examples: they build (ImGui on), and terrain_lab renders offscreen (--capture orbit --frames 3).
  • Syntax checks (cl /Zs) of code this machine does not build as configured:
    • arix and ariglx with the WebAssembly guests on;
    • arigl with its conference code on (CVC_ENABLE_WS);
    • arisrv's load bench.
  • The constexpr table builder: compiled on the host compiler, with static_asserts that it copies mc_tables.h exactly.
  • clang-format: clean on changed lines.
  • ratchet.py against master's allowlist: OK (22 lines to 10). The scan's own tests: 18 of 18 (1 skipped without nm).
  • No new globals from master: a source search of the hosts and examples after the merge finds no writable global, function static or signal handler, and master did not touch the allowlist.
  • Not run locally: CUDA (no toolkit here), macOS (the clipboard), Linux and the scan itself, and arisrv (this build has no gRPC). CI covers them; the CUDA lane is package-linux / libcvc-release-grpc.

Still open

  • The CUDA volume cache is one per app (raycast_cuda_cache_of(app)), each block keyed by device, not one per device shared by the apps on it, as §9 item 5's option has it. Sharing it needs an object that owns the device and that the host hands to each app; not in this PR.

What is left (10 lines), as settled

  • Signal state (1): the route pointer.
  • The process's nice level (1).
  • Library setup (5): curl's and ImageMagick's once-flags, HDF5's library lock (with its guard), Jolt's reference-counted runtime.
  • state_exec (3): the built-in exception classes (read-only, with their guard) and the scope-serial ID source.

The CUDA device manager keeps no instance or cache: each static call asks
the CUDA runtime. raycast.cu's marching-cubes tables are one const
__constant__ object filled at compile time from detail/mc_tables.h, part
of the module image on every device, so nothing uploads them or tracks
which device has them. cvcGL's macOS clipboard returns a string instead
of a pointer into a thread_local buffer.

The embedded Python's state (what the host lent, _ariadne_python,
_arihost, the ScriptEngine) lives in an EngineState its Engine owns.
_arihost is made at boot and put in sys.modules; its functions reach
their engine through the module's state. ari, arix, arigl and ariglx hand
their Python and WebAssembly engines down instead of keeping g_python and
g_wasm; arigl's walk keys are a constexpr table and its "no libopus"
warning is the conference session's. arisrv's load bench keeps its room
step, client frame and tick clock on its relay.

The writable-data scan now covers ari, arigl and arisrv_aoi_bench
(package-linux) and arix and ariglx (pycvc-linux); VTK's module autoinit
objects join its other header objects as third-party. arisrv and arisrvx
stay unscanned: their one writable object is the stop flag their signal
handler sets. The allowlist drops from 22 to 13 lines.

New ctest arix_python_two_apps: two documents, each in an app of its own,
lent in turn to the one interpreter.
Conflicts, all master's #1216 and #1177 against this branch's embedded
Python:
- python_engine.cpp: _arihost stays made at boot by install_arihost (no
  inittab entry); its docstring takes #1216's name for the host,
  pycvc.ari.Host().
- ARIADNE_SCRIPTING_HOSTS.md: the same, in the roadmap's words.
- arigl/main.cpp: the conference camera keeps this branch's kWalkKeys
  comment and gains master's setMouseLookOrbits(true).

Nothing master added calls what this branch removed (g_python, g_wasm,
lent(), script_engine(), the inittab module, the CUDA manager's
instance(), the load bench's globals).

Checked on Windows (MSVC Release): full build; ratchet ok against
#1217's allowlist (22 lines) and master's (59), 13 here; the scan's own
tests; format clean; the host, Python and multi-app ctests, 24 pass and
18 skip (FTXUI and matplotlib, absent here), pycvc_ari and
pycvc_ariadne_harness among the passes.
One conflict, master's #1195 (py_console) in the class this branch
reworked, python_engine.cpp's PythonScriptEngine:
- load_block keeps master's order (the block's object lives on for
  consoles_for) with this branch's take_error(helper); unload comes in
  beside the engine's private EngineState pointer.
- export_console's natives described their own errors through the
  process-wide g_helper this branch removed. export_console now takes
  the helper and its natives hold a reference of their own, let go as
  their consoles are; unload passes none.
- The engine's constructor describes a console that fails to load with
  st.helper, which is up by then.

Checked on Windows (MSVC Release): full build; format clean on changed
lines; the host, Python and multi-app ctests with master's console
tests, 47/47 (skips as before: no FTXUI or matplotlib here), among them
arix_engine_test, which reloads documents with and without a console.
A host's signal state was process-wide: arisrv's g_stop, cvc serve's
g_serve_running, and host_signals' raised flags and saved handlers.
Now each app keeps its own (signals_of(app), an app slot): a stop flag
and the signals trapped for its document. The one thing left
process-wide is the route, the pointer a signal handler follows to the
app its signals go to; a handler can reach nothing else.

- signal_route(app, mode) sets the handlers and the pointer while it
  lives, and puts back the previous ones when it goes, so routes nest.
  mode::stop: SIGINT and SIGTERM set the app's stop flag (also on
  Windows, through std::signal). mode::trap: the six signals ari and
  arigl hand a document's on_signal: are recorded for take_trapped();
  none on Windows, as before.
- The handlers it replaced live in the route, not in a static, so
  host_signals.cpp's g_previous goes. The pointer keeps g_raised's
  name and line: it is where a raised signal goes.
- arisrv and arisrvx: the stop flag is the app's; the route goes up
  where the handlers went before. With no writable object left, both
  are scanned (arisrv in package-linux's release-grpc lane, arisrvx in
  pycvc-linux's).
- cvc serve: the same, so cvc-cli's g_serve_running goes.
- ari and arigl: a trap route from on_start to on_stop (and around
  arigl's window loop), and the app's take_trapped().

curl: the WebSocket client calls the HTTP client's init
(detail::curl_global_init_once), so libcvc keeps one once-flag for
libcurl's global setup, not two; ws_client.cpp's line goes.

The allowlist ends here (roadmap 9 item 5, settled 2026-11-14): the
route pointer, the process's nice level, curl's, ImageMagick's,
HDF5's and Jolt's setup, and state_exec's read-only built-in exception
classes and scope-serial ID source. Its header (and scan.py's), the
scan's README and the roadmap say so; the ratchet stays.

Tests (multi_app_integration_test): each app's flags are its own in
the workload (alone, at once on threads, reversed); a signal reaches
only the routed app, from another thread too; a nested route has the
signals until it goes; the last route puts the process's handlers
back; trap routes give each app only its own signals, each once.

The allowlist goes from 13 lines to 10.
Joe's answer on executables (roadmap 9 item 5, 2026-11-14): "Only
OS-forced globals (Recommended)". The hosts were done; the examples,
which the scan does not cover, still kept state of their own:

- The demo menu (examples/common/demos_menu.cpp) kept how to open each
  demo and whether one was started in two file-scope globals, and the
  program's directory in a static. Its state is now an app slot:
  demos_menu(app, slug) and demo_switch_requested(app), in all ten
  demos.
- terrain_lab: the size-following extents (world half, water grid,
  cloud slab) are an Extents main owns and passes to the water and sky
  builders; spans are labelled with the app's world_units() (SI, one
  unit a metre, as the global was); the sun angles are constants; and
  the building library, cached in a static that kept the first app's,
  is loaded once by main.
- nav_city_drive and nav_city_swarm: eight function statics each (the
  panel's fps tick and chase toggle, the world being rebuilt, the far
  skyline flag, the render profile) are locals of the panel callback's
  and the loop's scope. A second run in one process (the demo switch)
  no longer starts from the first's.

The allowlist: each group says why it stays. scan.py's WHY_IT_STAYS
holds the reasons and render_allowlist writes them above each file's
lines, so a regenerated list keeps them; a scan test fails a line with
no reason. The header, the scan README and roadmap 9 item 5 quote
Joe's four answers, and the roadmap notes what is still open: the CUDA
volume cache is one per app, keyed by device, not one per device.

Checked on Windows: the examples build (ImGui on), terrain_lab renders
offscreen (--capture orbit --frames 3); scan tests 18/18 (one skipped
without nm); ratchet ok against master, #1217 and 50561e2.
No conflicts. Master brings 26 commits (#1171, #1191, #1221, #1236,
#1245, #1248, #1250 and others); none adds a writable global, a function
static or a signal handler to the hosts or examples, and none touches
the allowlist.
@transfix
transfix enabled auto-merge November 15, 2026 20:01
@transfix
transfix merged commit 12350f2 into master Nov 16, 2026
28 checks passed
@transfix
transfix deleted the p0a/last-globals branch November 16, 2026 08:39
transfix added a commit that referenced this pull request Nov 16, 2026
…#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.
transfix added a commit that referenced this pull request Nov 16, 2026
#1276 made server_link take the module object (self) so it finds the
link on its own host, and #1302 landed after it with five calls that
pass nothing: room, bridge_presence, bridge_absent, bridge_post and
listen_chat. Master's pycvc-linux build fails on them. Name self in
those five functions and pass it.
transfix added a commit that referenced this pull request Nov 16, 2026
#1276 moved _arihost's lent relay onto the module's own state, so
server_link() became server_link(self). #1302 (bridged users) was
tested on a base without #1276 and added five calls in the old form:
room, bridge_presence, bridge_absent, bridge_post and listen_chat.
Master has not compiled arisrvx since #1302 landed (pycvc-linux /
cp312 on #1281, run 43951076345: "too few arguments to function
server_link"). Name each one's module parameter self and pass it,
as their neighbours do.
transfix added a commit that referenced this pull request Nov 17, 2026
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.
transfix added a commit that referenced this pull request Nov 17, 2026
…it (#1170)

* Ariadne L4: the gym (WorldGym, pycvc.WorldGym), and pycvc_gl.cars on it

A world document driven headless by reset(seed), step(steer, accel) and
observe(), with a reward of the user's and an episode log: one app per gym,
its clock paused, every draw seeded. WorldVehicles gains per-tick commands,
held goals, reseeding and per-step contact counts; SceneWorld::restart hands
the vehicles the new ground bodies. GymCars and --gym run the cars template's
controllers in a world document; world_gym.ari/.py are the example.

* Gym follow-up: every plant in a scene world, buildings as obstacles, a world per episode

WorldVehicles runs jolt, kinematic, dynamic and dynamic4w entities, a navigator per plant (the
dynamic models' chassis in a world of their own holding the world's colliders); entity_spec and
vehicles.spawn.plant name it; across plants vehicles touch by their chassis boxes, and cvcGL draws a
vehicle with no chassis from its pose. A world's terrain alone is its ground
(SceneWorldBody::ground), so a building is an obstacle. WorldGym's regenerate makes a generated
world per episode from the reset's seed (SceneWorld::regenerate_world). GymCars and --gym take the
cars template's plant names; dyn_bike_plant and dyn_4w_plant gain add_desc.

* Vehicles start on a slope, not inside it

A vehicle in world_gym.ari's generated world (seed 1, agent 3 at about
(-51.7, 46.4)) fell straight down from its first step. The terrain
collider has no hole there: a raycast at every free grid cell hits the
ground. The spot is a slope of about 0.75, and nav_plant placed every
start level at one ground sample (the nearest 2 m grid cell under the
rear axle) plus its resting height. Facing uphill, the Humvee's origin
started under the ground at its own centre and its nose more than a
metre deep; a body that starts below a height field falls through it.

nav_plant: with ground_height set, a start is tilted onto the plane
fitted to the ground under its chassis, its origin its resting height
above that plane, then lifted clear of the highest ground under the
chassis and the wheels at full reach. Level ground and a constant
ground_z keep the pose they had.

WorldVehicles: every plant's ground height (and height_at) is the world's
terrain where it has one, the physics collider's own heights, else the
grid bilinear between its samples, not the nearest sample.

Tests: a downward raycast at every free cell of the generated world finds
the ground at the grid's height; twelve Humvees placed on its slopes
(1 in 3 to 1 in 1, up and across) start above the ground and are on it
3 s later (two fell to z -27 before).

* Generated world: a cell's water class is its own depth

Each terrain cell took its material from one raster sample, its NE corner where the raster and
the mesh share samples. On a steep shore that corner can be dry or shallow while the cell is
metres deep, so the navigator and the physics took deep water for drivable ground: 151 cells
deeper than 0.5 m on world_gym.ari's generated world, the deepest at -1.91 m.

The materials stage now classes each cell's water by the mean of its corners against the sea,
with derived_class's depths (deep below sea - 0.5, shallow below sea, sand for a dry cell the
raster called water). A prop's footprint keeps its own material.

Test: WorldGenerated.ACellsWaterIsTheMeshsDepth checks every ungraded cell's class against its
mean height.

* Terrain edge walls: nothing leaves a world over its edge

add_world_geometry adds four static boxes around the rectangle the collide height fields cover
(world_bodies::edges): 2 m thick, 1 cm outside the edge, from 20 m below the lowest height to
20 m above the highest. They are not items and not ground, so a vehicle touching one has hit an
obstacle. SceneWorld keeps them as the terrain node's bodies, so they go and come with it.

world_gym.ari's generated world, seed 1: from agent 1's start (-122.9, -72.6) toward its goal on
the west shore, the vehicle slid down the slippery underwater slope and off the west edge in 14
of 18 runs (3 masses x 3 top speeds x nav@1 and world_gym.py's policy). Now 0 of 18; seeds 1-20
under both controllers have no agent out.

Tests: PhysicsWorldGeometry.NothingLeavesTheTerrainOverItsEdge (a box sliding at 15 m/s down a
mu 0.1 slope stops at the wall; rays down on the edge still meet the terrain) and
AriadneWorldGym.AGeneratedWorldsEdgeHoldsAVehicleIn (Humvees flat out at each edge stay in). The
body counts of generated and data worlds include the 4 walls.

* World edge modes: walls, a shore and the sea, or nothing

What is at a generated world's edge is now a choice (generated_world_params::edge, world_edge):

- wall (the default): the invisible walls of the previous commit.
- shore: a band at the rim (15 % of half, 40-250 m) becomes coast. From the band's inner end the
  ground eases down to a beach sloping 1 in 50 to the waterline, then under the sea to the island
  preset's shelf depth at the edge. Ground already lower keeps its bed. It wraps any terrain
  generator (fbm, dem, registered), lots stay off the shore, and the sea goes on past the world:
  outer_sea() is a ring at the waterline out 6 km, which cvcGL draws under <id>_water. No walls.
- none: the edge is open.

world_geometry::edge_walls() says whether add_world_geometry adds the walls; a generated world sets
it from its edge (only wall), and every other world_geometry keeps them on.

Ariadne: a generated_world node's `edge: wall | shore | none`. pycvc: generate_world's "edge"
param, and info()["edge"]. docs/ARIADNE.md describes it.

Tests: WorldGenerated.AShoreEdgeLinesTheWorldWithABeachAndTheSea (deep water all round the rim, a
sand beach inside it, the relief untouched past the band, the outer sea ring),
PhysicsWorldGeometry.TheEdgeWallsCanBeLeftOut, AriadneSceneWorld.AGeneratedWorldsEdgeCanBeAShore,
cvcgl_ariadne_realize (the drawn outer sea), test_pycvc_plant_host.py.

* Shore edge: a wider coast and a wandering coastline

Rendered, the shore's blend from the relief to the beach was short enough (about 11 m on a 300 m
world) that high ground met the coast as a rock cliff, and the coastline ran dead straight. The
band is now 20 % of half (50-300 m), the blend takes its inner half (sea floor to waterline by
25 %, beach to 50 %), and the coastline lies up to 15 % of the band further in by a smooth wobble
the seed sets. The edge stays the sea floor and the relief past the band is untouched.

* Shore edge: rounded corners, bays and headlands

The shore's coast followed the world's square outline, corners and all. It now follows a rounded
square, |x|^4 + |y|^4 = half^4 (world_shore_roundness), so the corners curve away into the sea,
and its wobble is up to 35 % of the band on longer waves (2.5 and 0.8 bands), for bays and
headlands. The square's edge is still the sea floor everywhere and the relief past the band is
untouched; the test measures the band from the rounded edge.

* Terrain lab: the world's edge is a live setting (world.edge, an Edge picker)

A generated_world node's edge was only its authored `edge:` key, so the terrain lab's World panel
could not change it. It is now a world.* key like the preset: world.edge (0 wall, 1 shore, 2 none),
seeded from the node, read on Regenerate, and part of the world's signature, so an edit marks the
world pending until Regenerate. world_controls.ari has an Edge combo (Wall, Shore, None) after
Water level. The walls follow the new world's colliders, and cvcGL draws or empties the outer sea
on the swap. pycvc_gl.cars logs it with the other world keys.

Tests: AriadneSceneWorld.TheWorldsEdgeIsALiveSetting (seeded 0; 1 waits, then Regenerate makes a
shore world with no walls; 0 brings them back) and the loader's world_controls check for the
Edge picker. Checked drawn too: an offscreen host switched a walled world to Shore and
regenerated it. 711/711 related ctest.

* world_gym.h: clang-format a comment's spacing

* Ariadne gym: what a differentiable twin of the world reads (WorldGym::fields, WorldGym::plants)

* One simulation tick: 0.06 s by default everywhere, vehicle worlds on the 0.01 s clock, real time catching up 0.25 s a frame

* ariadne_scene_world_test: built with -ffp-contract=off, as the plant it replays bit for bit

* Generated world: the cells round a lowered waterline sliver take their water class again

Master's #1271 lowers the terrain mesh's waterline slivers at the end of the grade stage, after
the materials stage classed each cell's water by its corners' mean height. A cell round a lowered
sample kept the class of the ground before it (sand, or shallow water over half a metre deep), so
WorldGenerated.ACellsWaterIsTheMeshsDepth failed. The materials stage's rule is now cell_class(),
and the cells touching a lowered sample are classed by it again from the lowered mesh.

* python_engine: the bridge ops pass self to server_link

#1276 made server_link take the module object (self) so it finds the
link on its own host, and #1302 landed after it with five calls that
pass nothing: room, bridge_presence, bridge_absent, bridge_post and
listen_chat. Master's pycvc-linux build fails on them. Name self in
those five functions and pass it.

* test_pycvc_gl_nav_lab: the retarget's tick from the sim tick

#1258 wrote the arms run's retarget at 3 s as tick 60, a 0.05 s tick.
#1275 made the sim tick 0.06 s, so the leg starts at tick 50. The test
takes the tick as round(3.0 / cars.DT) for the legs, the goals and the
alone run it compares against.
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