audit: walk serial owners in write routing, harden result identity
This commit is contained in:
@@ -94,38 +94,47 @@ def commit_foreach_aware_patch(
|
||||
) -> dict[str, Any]:
|
||||
"""Commit one write patch with foreach-aware routing.
|
||||
|
||||
Ordinary frames commit (or buffer) through their own lineage. Serial
|
||||
item writes commit through the parent scope so they land in root state;
|
||||
concurrent item writes stay buffered in the item lineage for the barrier
|
||||
to merge. Malformed ownership, missing parents, and closed or
|
||||
superseded activations fail closed.
|
||||
Ordinary frames commit (or buffer) through their own lineage. The walk
|
||||
climbs through every serial item owner until it reaches either the
|
||||
workflow/subgraph scope root, where it commits, or a concurrent item
|
||||
boundary, where it buffers in that item lineage for the barrier to
|
||||
merge. Malformed ownership, missing parents, parent cycles, and closed
|
||||
or superseded activations fail closed.
|
||||
"""
|
||||
from wf_core.runtime.foreach_state import (
|
||||
item_frame_owner,
|
||||
require_foreach_activation,
|
||||
)
|
||||
|
||||
owner = item_frame_owner(frame)
|
||||
if owner is None:
|
||||
return commit_patch_for_frame(run, frame, patch)
|
||||
parent_frame = run.frames.get(owner.parent_frame_id)
|
||||
if parent_frame is None:
|
||||
raise WorkflowExecutionError(
|
||||
"foreach item state references missing parent frame "
|
||||
f"{owner.parent_frame_id!r} for child frame {frame.id!r}"
|
||||
current = frame
|
||||
seen: set[str] = set()
|
||||
while True:
|
||||
owner = item_frame_owner(current)
|
||||
if owner is None:
|
||||
return commit_patch_for_frame(run, current, patch)
|
||||
if current.id in seen:
|
||||
raise WorkflowExecutionError(
|
||||
f"cycle detected in foreach parent chain at frame {current.id!r}"
|
||||
)
|
||||
seen.add(current.id)
|
||||
parent_frame = run.frames.get(owner.parent_frame_id)
|
||||
if parent_frame is None:
|
||||
raise WorkflowExecutionError(
|
||||
"foreach item state references missing parent frame "
|
||||
f"{owner.parent_frame_id!r} for child frame {current.id!r}"
|
||||
)
|
||||
activation = require_foreach_activation(
|
||||
parent_frame, owner.foreach_node_id, owner.activation_id
|
||||
)
|
||||
activation = require_foreach_activation(
|
||||
parent_frame, owner.foreach_node_id, owner.activation_id
|
||||
)
|
||||
if activation.barrier.mode == "concurrent":
|
||||
append_lineage_writes(
|
||||
run,
|
||||
scope_id=frame.scope_id,
|
||||
lineage_id=frame.lineage_id,
|
||||
writes=patch.writes,
|
||||
)
|
||||
return {}
|
||||
return commit_patch_for_frame(run, parent_frame, patch)
|
||||
if activation.barrier.mode == "concurrent":
|
||||
append_lineage_writes(
|
||||
run,
|
||||
scope_id=current.scope_id,
|
||||
lineage_id=current.lineage_id,
|
||||
writes=patch.writes,
|
||||
)
|
||||
return {}
|
||||
current = parent_frame
|
||||
|
||||
|
||||
def scope_state_for_frame(run: RunState, frame: ExecutionFrame) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user