sched: address R1 findings on shared traversal and resolver threading

This commit is contained in:
lda
2026-09-08 10:15:36 +07:00 Verified
parent 0ded9b0d40
commit 46c2763b66
8 changed files with 232 additions and 124 deletions
+44 -41
View File
@@ -3,7 +3,6 @@ from __future__ import annotations
from collections.abc import Mapping, Sequence
from typing import Any
from wf_core.conditions import safe_resolve_path
from wf_core.errors import WorkflowExecutionError
from wf_core.local_paths import LocalPathError, set_local_value
from wf_core.models.input_bindings import (
@@ -14,7 +13,11 @@ from wf_core.models.input_bindings import (
StepInputBinding,
)
from wf_core.models.json_values import JsonValue
from wf_core.runtime.input_sources import SourceResolver
from wf_core.runtime.input_sources import (
GraphSourceResolver,
SourceResolver,
resolve_composed_expression,
)
def resolve_input_expression(
@@ -27,11 +30,6 @@ def resolve_input_expression(
location: str,
) -> JsonValue:
"""Resolve one composite expression while preserving its payload location."""
from wf_core.runtime.input_sources import (
GraphSourceResolver,
resolve_composed_expression,
)
resolver = GraphSourceResolver(
state=state, workflow_input=workflow_input, context=context
)
@@ -48,13 +46,44 @@ def resolve_input_expression_with_resolver(
location: str,
) -> JsonValue:
"""Resolve one expression through an explicit typed source resolver."""
from wf_core.runtime.input_sources import resolve_composed_expression
return resolve_composed_expression(
expression, resolver=resolver, label=label, location=location
)
def resolve_step_input_bindings_with_resolver(
bindings: Sequence[StepInputBinding],
*,
resolver: SourceResolver,
label: str,
) -> dict[str, Any]:
"""Build one node-local payload through an explicit graph resolver."""
payload: dict[str, Any] = {}
for binding in bindings:
location = str(binding.target)
if isinstance(binding, InputValueBinding):
value = binding.value
elif isinstance(binding, InputPathBinding):
try:
value = resolver.resolve_path(binding.path)
except (ValueError, WorkflowExecutionError) as exc:
raise WorkflowExecutionError(f"{label} {location}: {exc}") from exc
elif isinstance(binding, InputExpressionBinding):
value = resolve_input_expression_with_resolver(
binding.expression,
resolver=resolver,
label=label,
location=location,
)
else:
raise WorkflowExecutionError(f"unsupported input binding for {label}")
try:
set_local_value(payload, binding.target, value)
except LocalPathError as exc:
raise WorkflowExecutionError(f"{label} {location}: {exc}") from exc
return payload
def resolve_step_input_bindings(
bindings: Sequence[StepInputBinding],
*,
@@ -64,35 +93,9 @@ def resolve_step_input_bindings(
label: str,
) -> dict[str, Any]:
"""Build one node-local payload from simple or composite input bindings."""
payload: dict[str, Any] = {}
for binding in bindings:
location = str(binding.target)
if isinstance(binding, InputValueBinding):
value = binding.value
elif isinstance(binding, InputPathBinding):
try:
value = safe_resolve_path(
str(binding.path),
state=state,
workflow_input=workflow_input,
context=context,
)
except (ValueError, WorkflowExecutionError) as exc:
raise WorkflowExecutionError(f"{label} {location}: {exc}") from exc
elif isinstance(binding, InputExpressionBinding):
value = resolve_input_expression(
binding.expression,
state=state,
workflow_input=workflow_input,
context=context,
label=label,
location=location,
)
else:
raise WorkflowExecutionError(f"unsupported input binding for {label}")
try:
set_local_value(payload, binding.target, value)
except LocalPathError as exc:
raise WorkflowExecutionError(f"{label} {location}: {exc}") from exc
return payload
resolver = GraphSourceResolver(
state=state, workflow_input=workflow_input, context=context
)
return resolve_step_input_bindings_with_resolver(
bindings, resolver=resolver, label=label
)