route those APIs

This commit is contained in:
lda
2026-05-25 00:23:55 +07:00 Verified
parent 2e252f6252
commit 7a3555e7bc
8 changed files with 155 additions and 18 deletions
+11
View File
@@ -6,6 +6,7 @@ from dataclasses import dataclass
from typing import Any
from wf_core.run_state import ExecutionFrame, LineageState, RunState, StateWrite
from wf_core.run_state import ROOT_LINEAGE_ID, ROOT_SCOPE_ID
from wf_core.runtime.foreach_state import ForeachBarrierState, item_frame_owner
from wf_core.runtime.ops.state import StatePatch
from wf_core.runtime.ops.state import safe_set_nested_value
@@ -69,6 +70,16 @@ def lineage_writes_for_frame(
return pending.patch.writes
def is_root_lineage_frame(frame: ExecutionFrame) -> bool:
"""Return whether a frame currently commits directly to root run state.
This is a migration shortcut, not the final commit policy. Once native
subgraphs can complete, direct commits should be decided by an explicit
scope/lineage commit target rather than only by root ids.
"""
return frame.scope_id == ROOT_SCOPE_ID and frame.lineage_id == ROOT_LINEAGE_ID
def scope_state_for_frame(run: RunState, frame: ExecutionFrame) -> dict[str, Any]:
"""Return the committed state root for the frame's runtime scope."""
scope = run.scopes.get(frame.scope_id)
+11 -1
View File
@@ -18,6 +18,7 @@ from wf_core.run_state import (
StepExecutionResult,
)
from wf_core.runtime.foreach_state import ForeachBarrierState, item_frame_owner
from wf_core.runtime.lineage import append_lineage_writes, is_root_lineage_frame
from wf_core.runtime.ops.frames import frame_context_values
from wf_core.runtime.ops.merges import ReducerDefinition
from wf_core.runtime.ops.overlays import state_view_for_frame
@@ -120,7 +121,16 @@ def _finalize_node_execution(
)
owner = item_frame_owner(frame)
if owner is None:
state_changes = commit_state_patch(run.state, patch)
if is_root_lineage_frame(frame):
state_changes = commit_state_patch(run.state, patch)
else:
append_lineage_writes(
run,
scope_id=frame.scope_id,
lineage_id=frame.lineage_id,
writes=patch.writes,
)
state_changes = {}
else:
parent_frame_id, foreach_node_id, item_index = owner
parent_frame = run.frames[parent_frame_id]
+13 -5
View File
@@ -8,6 +8,9 @@ from wf_core.run_state import (
ExecutionFrame,
FrameStatus,
LineageState,
ROOT_FRAME_ID,
ROOT_LINEAGE_ID,
ROOT_SCOPE_ID,
RunState,
RunStatus,
RuntimeScope,
@@ -27,20 +30,25 @@ def create_run_state(workflow: Workflow, workflow_input: dict[str, object]) -> R
workflow_input=dict(workflow_input),
state=state,
scopes={
"root": RuntimeScope(
id="root",
ROOT_SCOPE_ID: RuntimeScope(
id=ROOT_SCOPE_ID,
workflow_name=workflow.name,
committed_state=state,
)
},
lineages={"root": LineageState(id="root", scope_id="root")},
current_frame_id="root",
lineages={
ROOT_LINEAGE_ID: LineageState(
id=ROOT_LINEAGE_ID,
scope_id=ROOT_SCOPE_ID,
)
},
current_frame_id=ROOT_FRAME_ID,
current_node_id=workflow.start,
)
add_frame(
run,
ExecutionFrame(
id="root",
id=ROOT_FRAME_ID,
kind="workflow",
node_id=workflow.start,
status=FrameStatus.PENDING,