Expand description
SRD-88 — the task-local ExecutionContext.
The load-bearing seam for running multiple executions concurrently in one
process, all sharing one session. A deeply-nested fiber finds its
execution’s isolated state — exec_id, stop flag, and (as the
de-globalization proceeds in later pushes) observer / output channel /
scene tree — by reading this task-local context instead of a
process-global static.
Axiom A1 — additive de-globalization. The process-globals
(SESSION_STOP, GLOBAL_OBSERVER, CHANNEL, …) remain the process
default. Code that does not run inside scope (bootstrap, the CLI,
single-run nmbrs run, tests) reads the default — behavior is identical to
before this seam existed. Only concurrent executions scope a context and
get isolation, so the migration is safe and incremental: each accessor that
learns to consult the context is a no-op until someone scopes one.
Axiom A2 — exec_id is the only new global. Allocating exec_id needs
one process-global counter so two concurrent fresh executions can’t both
claim the same id. alloc_exec_id is that single synchronization point.
Structs§
- Execution
Context - Per-execution context (SRD-88 §3). Grows as the de-globalization proceeds;
Push 1 carries the
exec_id, the per-execution stop flag, and the per-execution observer (display/lifecycle routing).
Functions§
- alloc_
exec_ id - Allocate the next process-unique
exec_id. - current_
channel - The current execution’s output channel, if a scoped context set one.
Noneoutside a scope OR when the scoped context has no channel — the caller falls back to the process-globalCHANNEL(A1). - current_
exec_ id - The current execution’s
exec_id, or1(the legacy single-execution default) outside any execution scope. - current_
observer - The current execution’s observer, if a scoped context set one.
Noneoutside a scope OR when the scoped context has no observer — the caller falls back to the process-globalGLOBAL_OBSERVER(A1). - current_
phase_ node - The scene node of the phase the current task is executing, if set (inside a
run_phasebody or a fiber it propagated).Noneon tasks/threads outside any phase (e.g. the metrics scheduler) — readers fall back to the first-running DFS heuristic (A1). Distinct fromcurrent_scene_tree: that is the execution’s whole tree; this is the one node the task is in. - current_
phase_ start_ ms - Epoch millis at which the phase the current task is executing started, if
set.
Noneoutside any phase body (the metrics scheduler thread, CLI paths, unit tests that never scoped one) — a caller then has no phase to be relative to and must say so rather than invent an origin. - current_
scene_ tree - The current execution’s scene tree, if scoped AND installed (
Noneotherwise — the caller falls back to the process-globalGLOBAL_TREE, A1). - current_
stop - The current execution’s stop flag, if scoped (
Noneoutside a scope, so the caller falls back to the process-global stop — A1). - install_
scene_ tree - Install
treeinto the current execution’s context, returningtrueif a context was scoped (so the caller installs into the global only when there is no execution scope). The pre-map walker calls this so each execution’s lifecycle mutations land on its own tree. - propagate
- Wrap
futso it runs under the CURRENT execution context — captured now (at the call site, which is still inside the parent’s scope) and re-established as the task-local inside a freshly-spawned task. A no-op pass-through when there is no current context (single-run / CLI / tests — axiom A1). - scope
- Run
futwithctxas the task-localExecutionContextfor the whole future. Concurrent executions each scope their own context, so their task-local reads (stop flag,exec_id, …) resolve independently. - try_
current - The current task’s
ExecutionContext, if running inside ascope. - with_
current_ phase - Run
futas the body of the phase atscene_node_id(SRD-100 P1c): scopes the task-local [CURRENT_PHASE] for the future’s duration.run_phasewraps itself with this so its whole body — the activity loop and every fiber itpropagates — resolves to this phase’s node, and any ambient emit nests under its depth.