Skip to content

Ariadne async execution semantics: scheduler_base + async_scheduler parity (1/5) - #435

Merged
transfix merged 4 commits into
masterfrom
design/ariadne-async-runtime
Sep 27, 2026
Merged

transfix merged 4 commits into
masterfrom
design/ariadne-async-runtime

Conversation

@transfix

Copy link
Copy Markdown
Owner

Ariadne async execution semantics — the single app-wide scheduler + await

Foundational runtime work so Ariadne's program lanes (init: / action on: / future
on:tick·on:key residents / spawned) run cooperatively on one long-lived
async_stackless_evaluator + scheduler
, with (await …)/(sleep …)/(msg-recv …)
suspending across frames instead of blocking the UI thread. Closes the P2 §4.7
(long-lived cross-frame scheduler) + P2-prereq (state_exec parity) gaps from the roadmap.

Design decision (recorded in CVCGL-UI-DSL-ROADMAP.md §4.7)

One app-wide scheduler for the whole host, namespaced per document — not one per .ari.
All program lanes share one cooperative timeline (cross-document spawn/msg, one per-frame
time budget); isolation is kept by a per-Runtime owner scope (process-group tag),
per-process chroot to the doc prefix, and a per-document child env over a shared
immutable base, with Runtime teardown reaping its process group. The reactive READ lane
stays a separate per-Runtime synchronous stackless_evaluator
(predicates must return
instantly — never parked). Message delivery/wake must be MPSC-safe so a worker thread
(e.g. a nav step on app.computePool()) can resolve an (await …)/(msg-recv …).

This PR (Commits 1–2 of 5 — foundation)

  1. scheduler_base — extract the intrinsic-facing scheduler interface (the ~18 methods
    intrinsics.cpp invokes) + the shared vocabulary structs. scheduler derives;
    intrinsics_context.sched re-typed to scheduler_base* (the 3 production assignment sites
    upcast implicitly). Pure refactor, behavior-identical.
  2. async_scheduler implements scheduler_base — so the DSL intrinsics drive the async
    scheduler identically to the sync one. Ports the methods it lacked (sleep / receive_message /
    deliver_to_receivers / pop_pending_message / pending_message_count + pending_messages_ FIFO
    • current_pid_/current_proc_); wires wake_sleeping_processes() into step() and the
      per-step eval_deadline_guard; fixes a latent completion-branch bug that clobbered the
      waiting status set by sleep/msg-recv.

Follow-ups (same branch, incoming)

  1. Switch async_scheduler's inner evaluator to async_stackless_evaluator (drive via task<>).
  2. Add (await expr) on the scheduled path.
  3. (Likely its own PR) the Ariadne integration: app-wide scheduler on cvc::app, per-frame
    pump, per-Runtime owner scopes, action-lane submit-and-return.

Testing

build-ari: core cvc lib + pycvc_exec build clean; 518 tests pass across
state_exec_{scheduler,intrinsics,multiprocess,advanced_integration,integration,async} +
ariadne_runtime, including +7 new AsyncScheduler[Intrinsics]Test cases proving the
async scheduler drives spawn/sleep/msg-recv through the intrinsic layer, sleep→wake,
deliver-wakes-receiver, and the message queue.

One long-lived async_stackless_evaluator + async_scheduler for the whole host,
NOT one per .ari document. All program lanes (init:/action/on:tick·on:key
residents/spawned) schedule on one cooperative timeline; isolation is kept by
namespacing on that shared scheduler — per-Runtime owner scope (process-group tag),
per-process chroot to the document prefix, and a per-document child env over a
shared immutable base — with Runtime teardown reaping its process group. The
reactive READ lane stays a separate per-Runtime synchronous stackless_evaluator
and is never placed on the shared scheduler (predicates must return instantly).
Message delivery/wake must be MPSC-safe so a worker thread (e.g. compute-pool nav
step) can resolve an (await ...)/(msg-recv ...) by msg-send from off the UI thread.

Foundation for the P2 action lane + P2-prereq state_exec parity work.
…nterface

P2-prereq for the async execution semantics (CVCGL-UI-DSL §4.7/§8): the DSL
intrinsics (spawn/sleep/msg-send/msg-recv/self/ps/kill/pause/resume + the
state-watch registry) reached the scheduler through intrinsics_context.sched,
hard-typed to the synchronous `scheduler`. That blocked driving them from the
coroutine async_scheduler. Extract scheduler_base: an abstract interface of
exactly the ~18 methods intrinsics.cpp invokes, plus the shared vocabulary
structs (scheduling_policy/execute_options/process_info/scheduler_stats moved
out of scheduler.h). `scheduler` now derives from it; intrinsics_context.sched
is re-typed to scheduler_base* (the three production assignment sites upcast
implicitly — no change). The driver surface (step/run/stop/has_runnable/
load_settings) stays off the base: the host that pumps a scheduler holds the
concrete type.

Pure refactor, behavior-identical. Verified: core cvc lib + pycvc_exec build
clean; state_exec_{scheduler,intrinsics,multiprocess,advanced_integration,
integration,async} + ariadne_runtime = 511 tests PASS.

Next: async_scheduler derives from scheduler_base (implement its missing
sleep/receive_message/deliver_to_receivers/pop_pending_message/current_pid/
current_process + wake_sleeping + deadline guard).
…ing parity)

Commit 2 of the async execution semantics. async_scheduler now derives from
scheduler_base, so the DSL intrinsics drive it identically to the sync
scheduler. Ported the methods it lacked (bodies mirror scheduler.cpp):
sleep, receive_message, deliver_to_receivers, pop_pending_message,
pending_message_count (+ total_pending_messages), plus the pending_messages_
FIFO and current_pid_/current_proc_ tracking with current_pid()/current_process().

Wired the two gaps its step loop had vs the sync scheduler:
  - wake_sleeping_processes() at the top of step() (a slept/msg-waiting process
    could never wake before);
  - the per-step eval_deadline_guard in execute_process_step (an uncapped nested
    eval / long builtin inside one step is now bounded by the process's remaining
    time budget).
Also fixed a latent bug in async execute_process_step: its completion branch
unconditionally reset status to `ready`, clobbering the `waiting` that
sleep/msg-recv set — now guarded with `else if (status == running)`, matching sync.

Still drives a synchronous stackless_evaluator inner (Commit 3 switches it to
async_stackless_evaluator). Verified: +7 tests (AsyncSchedulerTest x4 at the
scheduler API — spawn/run, recv-suspends+deliver-wakes, queue+pop, sleep→wake;
AsyncSchedulerIntrinsicsTest x3 through the intrinsic layer with
ictx.sched=&async_scheduler). Full state_exec + ariadne suite: 518 tests PASS.
…eduled evaluator)

Commit 3 of the async execution semantics. Per roadmap §8.12 the scheduled
evaluator IS async_stackless_evaluator; async_scheduler's inner evaluator_ is now
that type (was a plain stackless_evaluator). create_state/ctor are unchanged
(both forward to the inner stackless evaluator); execute_process_step drives one
evaluator step to completion at the leaf via `evaluator_.step(state).sync_wait()`,
which consumes the coroutine's per-step suspend_point.

Deliberately NOT propagating that suspend_point up into step()/run() as a true
co_await chain: it only buys intra-run interleaving when a coroutine executor
drives the scheduler, which neither sync_step/sync_run nor the planned per-frame
pump do — and a multi-level co_await that suspends across sync_wait is not robust
here (an earlier attempt mis-returned the process result). DSL-level await/parking
across frames is delivered by the scheduler's waiting-status mechanism
(sleep/msg-recv wake), not the C++ suspend_point. When a real async executor is
added, only execute_process_step's drive changes — not the evaluator type.

Verified: 518 state_exec + ariadne tests PASS (incl. the AsyncScheduler* suites
now running through async_stackless_evaluator).
@transfix

Copy link
Copy Markdown
Owner Author

Commit 3 landed (c8e152d61): async_scheduler now drives async_stackless_evaluator (the roadmap-mandated scheduled evaluator), via a leaf sync_wait per step. This PR is now the complete state_exec scheduler foundation (Commits 1–3): scheduler_base + async_scheduler sleep/messaging parity + the async_stackless evaluator. All 518 state_exec + ariadne tests pass locally. The DSL (await …) form + the Ariadne integration (app-wide long-lived scheduler, per-frame pump, per-Runtime owner scopes, action-lane submit-and-return) follow in a separate PR — await's across-frames semantics are only observable once the pump exists.

@transfix
transfix merged commit 58cfc09 into master Sep 27, 2026
13 checks passed
@transfix
transfix deleted the design/ariadne-async-runtime branch October 29, 2026 20:51
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