Skip to content

Fix loop export reference inference and Jinja template resolution for loop contexts#349

Open
zhongkaifu wants to merge 1 commit intomainfrom
codex/fix-test-failures-in-loop-binding-and-context
Open

Fix loop export reference inference and Jinja template resolution for loop contexts#349
zhongkaifu wants to merge 1 commit intomainfrom
codex/fix-test-failures-in-loop-binding-and-context

Conversation

@zhongkaifu
Copy link
Copy Markdown
Owner

Motivation

  • Tests were failing because references to loop outputs sometimes omitted the exports segment and validation rejected inferred paths.
  • Nested loop source checks incorrectly treated loop/loop_ctx references as non-array sources during model validation.
  • Template evaluation did not resolve bare {{ ... }} reference paths against the binding context early, causing length/count and built-in function usages to return incorrect values.

Description

  • Make BindingContext tolerant of both wrapped (result_of.<loop>.exports.<key>) and flattened (result_of.<loop>.<key>) loop result shapes by skipping the exports segment when the runtime result is flattened and by improving the inference path logic in resolve_binding/_get_from_context.
  • Adjust BindingContext template handling so a bare Jinja template {{ ... }} that looks like a simple reference to loop/loop_ctx/result_of is resolved via ctx.get_value before generic Jinja evaluation, and fall back to the context value when a Jinja Undefined is produced.
  • Skip loop source schema checks for paths that are loop or start with loop./loop_ctx. in Workflow.validate_loop_body_subgraphs to avoid false positives for loop-local references.

Testing

  • Reproduced the original failures and ran the focused test set covering loop binding inference and template resolution.
  • Executed pytest -q tests/test_reference_templates.py::test_reference_allows_builtin_function_invocation tests/test_reference_templates.py::test_eval_params_renders_interpolated_templates tests/test_loop_binding_inference.py::test_missing_exports_segment_is_inferred tests/test_loop_state_isolation.py::test_nested_loop_results_do_not_leak_across_outer_iterations tests/test_reference_templates.py::test_binding_context_resolves_length_field tests/test_reference_templates.py::test_binding_context_resolves_count_field and all tests passed.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant