scope / lineage in frame

more structs to prepare for subgraph
This commit is contained in:
lda
2026-05-24 23:53:52 +07:00 Verified
parent 6afc9a8c9a
commit 12c70513ba
3 changed files with 99 additions and 1 deletions
+25
View File
@@ -40,6 +40,29 @@ class StateWrite:
reducer: ReducerRef
@dataclass(slots=True)
class RuntimeScope:
"""Committed workflow state root for one workflow activation.
During migration, the root scope intentionally shares `RunState.state` so
existing runtime code can keep using the compatibility state dict.
"""
id: str
workflow_name: str
committed_state: dict[str, Any] = field(default_factory=dict)
@dataclass(slots=True)
class LineageState:
"""Ordered pending writes owned by one lineage inside a runtime scope."""
id: str
scope_id: str
parent_id: str | None = None
writes: list[StateWrite] = field(default_factory=list)
@dataclass(slots=True)
class ExecutionFrame:
id: str
@@ -108,6 +131,8 @@ class RunState:
output: dict[str, Any] = field(default_factory=dict)
trace: list[TraceEntry] = field(default_factory=list)
frames: dict[str, ExecutionFrame] = field(default_factory=dict)
scopes: dict[str, RuntimeScope] = field(default_factory=dict)
lineages: dict[str, LineageState] = field(default_factory=dict)
ready_frame_ids: list[str] = field(default_factory=list)
current_frame_id: str | None = None
current_node_id: str | None = None
+16 -1
View File
@@ -4,7 +4,14 @@ from copy import deepcopy
from wf_core.models.workflow import Workflow
from wf_core.paths import set_nested_value
from wf_core.run_state import ExecutionFrame, FrameStatus, RunState, RunStatus
from wf_core.run_state import (
ExecutionFrame,
FrameStatus,
LineageState,
RunState,
RunStatus,
RuntimeScope,
)
from wf_core.runtime.scheduler import add_frame
@@ -19,6 +26,14 @@ def create_run_state(workflow: Workflow, workflow_input: dict[str, object]) -> R
status=RunStatus.PENDING,
workflow_input=dict(workflow_input),
state=state,
scopes={
"root": RuntimeScope(
id="root",
workflow_name=workflow.name,
committed_state=state,
)
},
lineages={"root": LineageState(id="root", scope_id="root")},
current_frame_id="root",
current_node_id=workflow.start,
)