Skip to content

No singletons, Ariadne part 1: constants, counters and caches [4.0, breaking] - #1155

Closed
transfix wants to merge 7 commits into
masterfrom
p0a/no-singletons-ariadne
Closed

transfix wants to merge 7 commits into
masterfrom
p0a/no-singletons-ariadne

Conversation

@transfix

@transfix transfix commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

No singletons, Ariadne part 1: constants, counters and caches. Stacked on #1152 (the allowlist ratchet); merge that first. Breaking (4.0).

libcvc keeps no process-wide state in code we control (Joe, 2026-11-11). This PR removes 49 of Ariadne's allowlist lines without changing the registries' API. Those come next.

Bugs it fixes

  • WebSocket handles were process-wide. A document in one app could ws-send to, ws-recv from or ws-close another app's connection by handle, and the 16-connection cap was shared. The table is now the app's (app.slot).
  • The section epoch was the process's. Two apps writing the same room stamped one epoch, so a second relay in the process looked like the same run. Each app now has its own (section_epoch(app)).
  • The building-library cache was process-wide. It held one app's loaded libraries for every app, and its path key ignored which app's file handlers loaded them. It is now the app's.
  • open-url's one-a-second limit was shared across every app's documents. It is now the app's.
  • Runtime owner ids came from a process-wide counter. They tag processes on the app's scheduler, so they are now counted per app.
  • Room-lane message ids came from a process-wide counter. Each relay and lane session now numbers its own, under a random tag, as room-call messages already did (P0a: the action-intrinsic providers are each app's own; cvc::app::slot<T>() [4.0, breaking] #1137). The helper is shared (conference/message_ids.h).

Constants built at first use

These were function-local statics: immutable, but built lazily and shared. They are now constexpr, or built where they are used, or held by their owner:

  • ariadne.cpp: the repeat index token; the special-form allow-set (per engine).
  • keys.cpp's key-name table and requires.cpp's capability-token table: static constexpr arrays, read-only data. capability_tokens() returns by value.
  • world_rules.cpp: the yes/no word lists (constexpr). world_rules::avatar() / controller() fall back to new fallback_avatar / fallback_controller members.
  • oidc_host.cpp: kReply (constexpr). options_dict returns a new empty dict instead of a shared mutable one.
  • net_intrinsics.cpp: kName (constexpr); the credential placeholder's per-thread RNG (now std::random_device per placeholder).
  • script_engine.cpp: the two parsed program bodies (parsed per call).
  • tvision_backend.cpp: the palettes, now view members. ftxui_backend.cpp: TERM is read when asked.

Public API changes

  • section_epoch(cvc::app &).
  • capability_tokens() returns std::vector<CapabilityToken> by value.
  • lane_offer_message(..., serial) / lane_answer_message(..., serial): the caller passes its sender's serial.
  • world_rules gains fallback_avatar and fallback_controller.

Tests

  • multi_app_integration_test (new). Six apps each run a workload, and each app's transcript must be the same three ways: alone, all at once on six threads, and all alive in reverse order. Different apps' transcripts must differ, so seeing another app's state shows. The workload covers the file handler tables, action intrinsics, the state tree and sections; each later PR adds its subsystem.
    • EachAppHasItsOwnSectionEpoch: two apps differ, and making another app moves neither.
  • RoomSceneTest.StockWorldsMatchTheirTwins compared two apps' leaves, epoch included, so it only passed while the epoch was process-wide. It now writes both with one epoch.
  • The section tests pass the writer's app.

Locally (Windows, MSVC 2022): the whole tree builds. These pass:

  • multi_app_integration_test 2, ariadne_registries_test 7, app_test 121;
  • ariadne_requires_test 18, ariadne_runtime_test 262, ariadne_loader_test 228, ariadne_media_test 55;
  • ariadne_script_engine_test 30, ariadne_data_test 14, world_rules_test 7, room_scene_test 21;
  • holon_sync_test 25, room_avatar_test 9, room_chat_test 14, ariadne_host_test 46;
  • the cvcGL media, stream, realize and room-view tests.

Allowlist: -49 lines (cvc 358 -> 309)

CI

This PR targets #1152's branch, and ci.yml runs only on PRs into master, so the full run comes from the push to ci/full/no-singletons-ariadne: https://github.com/transfix/libcvc/actions/runs/43154365904. Once #1152 merges, this PR retargets to master and runs there.

…t out

libcvc keeps no process-wide state in code it controls. The scan blocked
new statics, but a change could add the new symbol's line to the
allowlist, and changes did: the list went on growing.

- ratchet.py (new) fails a change whose allowlist has a line its base's
  does not; a moved or renamed object counts as new. It runs in the
  clang-format (changed lines) job, which needs only git and is a
  required check.
- scan.py leaves third-party libraries' own statics out and counts them
  (THIRD_PARTY): Boost's, VTK's per-file Schwarz counters, libigl's,
  Eigen's, pocketfft's, the standard library's. Vendored code built into
  libcvc (SDF, cvc-mesher) stays scanned.
- allowlist.txt drops those 289 lines. The 510 left are libcvc's own
  objects still to move (cvc 358, cvcGL 102, pycvc 32, cvc-cli 9,
  pycvc_gl 7, cvc_physics_jolt 2); the list only shrinks, to empty.
- The scan's message, README and the roadmap say so.

Tests: test_scan.py covers the third-party patterns (and that ours
still count) and the ratchet (deletions pass, an added or moved line
fails, the command's exit codes).
libcvc keeps no process-wide state in code we control. This removes 49
of Ariadne's allowlist lines (cvc 358 -> 309) without touching the
registries' API.

Bugs fixed:
- WebSocket handles were process-wide: one app's documents could send
  to, read or close another app's connection by handle, and the cap was
  shared. The table is the app's (app.slot).
- The section epoch was the process's; each app has its own
  (section_epoch(app)).
- The building-library cache, open-url's rate limit and the Runtime
  owner ids are the app's.
- Room-lane message ids are per sender under a random tag, as room-call
  ids are; the helper is shared (conference/message_ids.h).

Constants built at first use are constexpr, built where used, or held
by their owner: the repeat token, the special-form set, the key-name
and capability-token tables (static constexpr), world_rules' word lists
and fallbacks (new fallback_avatar / fallback_controller members),
OIDC's kReply and options_dict, the placeholder RNG, the script
engine's parsed bodies, tvision's palettes, ftxui's TERM check.

API: section_epoch(app); capability_tokens() by value;
lane_offer_message / lane_answer_message take the sender's serial.

Tests: multi_app_integration_test (new): six apps' workloads give the
same transcript alone, at once on threads and in reverse order, and
differ from each other. StockWorldsMatchTheirTwins writes both apps
with one epoch (it relied on the shared one).
…riadne

# Conflicts:
#	tools/singleton_scan/allowlist.txt
#1159 (O7c) kept the last source sea_surface found in a thread_local, so
the velocity a fluid field reads after a cell's height at the same point
and time did not invert the sideways move again. A thread_local that
keeps state between calls is a static cache, which libcvc's no-singletons
rule forbids (VOLROVER-LIBRARY-PORTS-ROADMAP.md 1.3,
tools/singleton_scan). #1159's release-grpc job, where the scan runs, was
cancelled, so the scan never judged it; the next PR that merges master
would fail that lane on it.

The memo now belongs to the caller:

- sea_surface::source_memo, and height() / velocity() overloads that take
  one. The plain reads share nothing.
- fluid_surface::height_with / velocity_with and a surface_memo the
  caller owns; the defaults ignore it. ocean_surface passes it to the sea.
- field_set::apply keeps one memo per cell, for the cell's height and its
  velocity at the same clipped centre.

The memo is keyed on the point, the time and the digest as before, so
every value is unchanged.
sea_surface::source kept the last source a thread found in a thread_local
(O7c, #1159), which landed after the writable-data allowlist was cut (#1152),
so the scan fails on master and on every PR into it. The band for one time
(frame) now keeps them, one a slot in a 64-slot table picked by the point's
bits, under its own mutex. A fluid field's height-then-velocity pair still
finds its source the second time; the values are unchanged (the platform
digest test passes as before).
…ead_local"

This reverts commit c7a4f2c. Joe picked #1181 as the fix for
master's thread_local in sea_surface::source (the caller owns the memo); it is
merged in next, so this PR carries that fix, not a competing one.
@transfix

Copy link
Copy Markdown
Owner Author

Replaced by #1203, which lands the whole no-singletons stack as one PR. This branch's head is an ancestor of #1203's branch, so its commits are all there; the branch is kept.

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