audit: close review gaps, dedupe control-region and activation helpers

This commit is contained in:
lda
2026-09-04 10:48:29 +07:00 Verified
parent be583661cf
commit 79ce0d3eff
6 changed files with 100 additions and 45 deletions
+21 -11
View File
@@ -345,6 +345,20 @@ class ForeachBarrierState:
)
def _activation_entry(
frame: ExecutionFrame, table: dict[str, Any], foreach_node_id: str
) -> dict[str, Any] | None:
"""Return the mutable activation entry or fail fast on corrupt state."""
entry = table.get(foreach_node_id)
if entry is None:
return None
if not isinstance(entry, dict):
raise WorkflowExecutionError(
f"malformed foreach activation entry for frame {frame.id!r}"
)
return entry
def load_or_begin_foreach_activation(
frame: ExecutionFrame,
foreach_node_id: str,
@@ -359,14 +373,10 @@ def load_or_begin_foreach_activation(
with fresh barrier state. Mode mismatches and malformed tables fail fast.
"""
table = _activation_table(frame)
entry = table.get(foreach_node_id)
entry = _activation_entry(frame, table, foreach_node_id)
if entry is None:
entry = {"next_sequence": 0, "active": None}
table[foreach_node_id] = entry
if not isinstance(entry, dict):
raise WorkflowExecutionError(
f"malformed foreach activation entry for frame {frame.id!r}"
)
next_sequence = entry.get("next_sequence", 0)
if not isinstance(next_sequence, int) or next_sequence < 0:
raise WorkflowExecutionError(
@@ -402,8 +412,8 @@ def save_foreach_activation(
) -> None:
"""Persist barrier progress for the named active activation."""
table = _activation_table(frame)
entry = table.get(activation.foreach_node_id)
if not isinstance(entry, dict):
entry = _activation_entry(frame, table, activation.foreach_node_id)
if entry is None:
raise WorkflowExecutionError(
f"malformed foreach activation entry for frame {frame.id!r}"
)
@@ -425,8 +435,8 @@ def close_foreach_activation(
increasing so child and lineage ids cannot collide across visits.
"""
table = _activation_table(frame)
entry = table.get(activation.foreach_node_id)
if not isinstance(entry, dict):
entry = _activation_entry(frame, table, activation.foreach_node_id)
if entry is None:
raise WorkflowExecutionError(
f"malformed foreach activation entry for frame {frame.id!r}"
)
@@ -448,8 +458,8 @@ def load_foreach_activation(
the caller rather than buffering into the wrong barrier.
"""
table = _activation_table(frame)
entry = table.get(foreach_node_id)
if not isinstance(entry, dict):
entry = _activation_entry(frame, table, foreach_node_id)
if entry is None:
raise WorkflowExecutionError(
f"malformed foreach activation entry for frame {frame.id!r}"
)
+2 -4
View File
@@ -170,7 +170,6 @@ def _step_foreach_concurrent(
step=step,
index=index,
activation=activation,
barrier=barrier,
iterable=iterable,
)
@@ -182,7 +181,6 @@ def _step_foreach_concurrent(
step=step,
index=index,
activation=activation,
barrier=barrier,
reducers=reducers,
)
@@ -260,12 +258,12 @@ def _admit_concurrent_children(
step: ForeachNode,
index: WorkflowIndex,
activation: ForeachActivationState,
barrier: ForeachBarrierState,
iterable: list[object],
) -> None:
if step.concurrent is None:
raise WorkflowExecutionError("concurrent foreach requires concurrent policy")
barrier = activation.barrier
loop_start = index.next_node_id(frame.node_id, "loop")
while (
barrier.next_index < len(iterable)
@@ -333,9 +331,9 @@ def _finish_concurrent_foreach(
step: ForeachNode,
index: WorkflowIndex,
activation: ForeachActivationState,
barrier: ForeachBarrierState,
reducers: Mapping[str, ReducerDefinition] | None = None,
) -> RunState:
barrier = activation.barrier
error_records = [
result.error.to_metadata()
for result in sorted(