Repository navigation
ariadne: stream DSL verbs with per-document (non-singleton) ownership - #524
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 viaintrinsics_context.document), keyed by its canonical token — not a process-static table keyed byapp*. It is owned until(stream-close)or document teardown:Runtime::Implowns onedocument_scopeandclear()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~streamran at process exit against an already-destroyedapp. 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 + LIFOclear(), resources released outside the lock.intrinsics_contextgains a non-owningdocumentpointer, installed by the host exactly like.channels.Runtime::Implownsdoc_scope_(declared besidechannel_policy_so it outlives the action/resident contexts that point at it);submit_action+ensure_residentinstall it on each lane'sictx;~Implclear()s it beforekill_owner.stream_intrinsics.cpp: the three verbs own/find/close in a per-documentstream_tableheld in the scope. The init: lane has no scope, so(stream-open)there fails cleanly rather than leaking an unowned stream.(stream-open)boundsw/hto[1, 65536]andsubscriber_depth/expected_subscribersto sane ranges — a bad dict fails cleanly instead of truncating a dimension or wrappingsize_tinto a wildframe_poolallocation; 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. Fullariadne_runtime_test+state_exec_evaluator_testgreen locally;git clang-formatclean.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.