Skip to content

ariadne: stream DSL verbs with per-document (non-singleton) ownership - #524

Merged
transfix merged 1 commit into
masterfrom
feat/stream-dsl-intrinsics
Oct 2, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/stream-dsl-intrinsics

Conversation

@transfix

@transfix transfix commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Summary

Phase-2 streaming PR6-core: the Ariadne DSL surface for cvc::stream — (stream-open) / (stream-info) / (stream-close), usable from a document's action/resident lanes (STATE_BINARY_STREAMING.md §4.1). The cvcGL sink (gl-bind-stream + a "stream" scene-node realizer) follows as PR7.

Ownership — model B (per-document, non-singleton)

An opened stream lives in the calling document's se::document_scope (reached via intrinsics_context.document), keyed by its canonical token — not a process-static table keyed by app*. It is owned until (stream-close) or document teardown: Runtime::Impl owns one document_scope and clear()s it in ~Impl, so a stream the author left open is closed there while the app and its state tree are still alive.

This replaces an earlier model A (a process-static unordered_map<const app*, …> owning table) that hung at teardown — an unclosed stream's ~stream ran at process exit against an already-destroyed app. Ownership now follows the owning object's lifetime, never a global.

Changes

  • se::document_scope (state_exec/intrinsics.h): a generic, RTTI-free typed-slot resource store — slot<T>(key) get-or-create + LIFO clear(), resources released outside the lock. intrinsics_context gains a non-owning document pointer, installed by the host exactly like .channels.
  • Runtime::Impl owns doc_scope_ (declared beside channel_policy_ so it outlives the action/resident contexts that point at it); submit_action + ensure_resident install it on each lane's ictx; ~Impl clear()s it before kill_owner.
  • stream_intrinsics.cpp: the three verbs own/find/close in a per-document stream_table held in the scope. The init: lane has no scope, so (stream-open) there fails cleanly rather than leaking an unowned stream.
  • Robustness (adversarial-review folded): (stream-open) bounds w/h to [1, 65536] and subscriber_depth/expected_subscribers to sane ranges — a bad dict fails cleanly instead of truncating a dimension or wrapping size_t into a wild frame_pool allocation; the verbs null-check the typed slot.

Tests

AriadneStreamIntrinsics.* (5): open/info/close round-trip; scoping to the document prefix; document-teardown auto-closes an unclosed stream (the case that hung under model A — now 3 ms); out-of-range sizing fails cleanly; init-lane open fails without a scope. Full ariadne_runtime_test + state_exec_evaluator_test green locally; git clang-format clean.

Review

Adversarial lifetime/thread-safety review ran against the diff: verdict core ownership/teardown model is correct (teardown order, double-clear idempotence, member-destruction order, captured-pointer stability, single-threaded verb model all verified). The three actionable hygiene findings (sizing validation, null-safe slot, a stale comment) are folded in. Inherited register_action_intrinsics &app-capture semantics (shared by the net/nav intrinsics) are unchanged and out of scope.

Phase-2 streaming PR6-core: the Ariadne DSL surface for cvc::stream —
(stream-open) / (stream-info) / (stream-close) on a document's
action/resident lanes (STATE_BINARY_STREAMING.md §4.1).

Ownership is model B: a generic, non-singleton per-document resource
scope. The opened stream lives in the CALLING DOCUMENT's
se::document_scope (reached via intrinsics_context.document), keyed by
its canonical token — NOT a process-static table keyed by app*. It is
owned until (stream-close) or document teardown: Runtime::Impl owns one
document_scope and clear()s it in ~Impl, so a stream the author left
open is closed there while the app and its state tree are still alive.

This replaces the earlier model A (a process-static
unordered_map<const app*, ...> owning table), which hung at teardown —
an unclosed stream's ~stream ran at process exit against an already
destroyed app. Ownership now follows the owning object's lifetime, never
a global.

- se::document_scope (state_exec/intrinsics.h): RTTI-free typed-slot
  resource store, slot<T>(key) get-or-create + LIFO clear(); resources
  released outside the lock. intrinsics_context gains a non-owning
  document pointer, installed by the host like .channels.
- Runtime::Impl owns doc_scope_ (declared beside channel_policy_ so it
  outlives the action/resident contexts that point at it); submit_action
  and ensure_resident install it on each ictx; ~Impl clear()s it before
  kill_owner.
- The init: lane has no document scope, so (stream-open) there fails
  cleanly rather than leaking an unowned stream.
- Robustness (adversarial-review folded): (stream-open) bounds w/h to
  [1, 65536] and subscriber_depth/expected_subscribers to sane ranges,
  so a bad dict fails cleanly instead of truncating a dimension or
  wrapping size_t into a wild frame_pool allocation; the verbs null-check
  the typed slot so a future key/type collision errors rather than
  deref-crashing.
- Tests: open/info/close round-trip; scoping to the document prefix;
  document-teardown auto-closes an unclosed stream (the case that hung
  under model A); out-of-range sizing fails cleanly; init-lane open fails
  without a scope.
@transfix
transfix enabled auto-merge October 2, 2026 02:20
@transfix
transfix merged commit ccde055 into master Oct 2, 2026
13 checks passed
@transfix
transfix deleted the feat/stream-dsl-intrinsics branch October 29, 2026 20:53
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