Skip to content

Python: fix: correct WorkflowState fallback expression evaluation (#10612) - #10163

Closed
Patel Namraa (Namraa310806) wants to merge 2 commits into
microsoft:mainfrom
Namraa310806:fix/10612-workflowstate-fallback-evaluator
Closed

Patel Namraa (Namraa310806) wants to merge 2 commits into
microsoft:mainfrom
Namraa310806:fix/10612-workflowstate-fallback-evaluator

Conversation

@Namraa310806

Copy link
Copy Markdown
Contributor

Motivation & Context

When the PowerFx engine is unavailable, the standalone Python WorkflowState evaluator falls back to _eval_simple().

The fallback evaluator produced incorrect results because it split expressions at the first operator occurrence without accounting for operator precedence, associativity, quoted strings, or nested expressions.

Examples reproduced on main:

  • Local.a Or Local.b And Local.c — incorrect logical precedence.
  • 10 - 2 - 3 — evaluated as 11.0 instead of 5.
  • 100 / 10 / 2 — evaluated as 20.0 instead of 5.
  • Local.text = "a And b" — incorrectly interpreted the operator inside the string literal.

This change fixes these issues in the standalone WorkflowState fallback evaluator.

Description & Review Guide

  • What are the major changes?

    • Added top-level operator detection that respects quoted strings and bracket nesting.
    • Added matching-parenthesis detection for parenthesized expressions.
    • Reworked expression evaluation to respect logical and arithmetic operator precedence.
    • Fixed arithmetic evaluation to preserve left associativity.
    • Added regression tests covering logical precedence, arithmetic precedence, associativity, and operators inside string literals.
  • What is the impact of these changes?

    Expressions evaluated through the Python fallback now produce the expected results for the covered operator combinations. The change is limited to the standalone WorkflowState fallback evaluator.

  • What do you want reviewers to focus on?

    • Correctness of operator precedence and associativity.
    • Handling of quoted strings and nested expressions.
    • Preservation of existing fallback behavior.

Related Issue

Fixes #10162

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details:

AI was used to polish the issue report and PR description, review the fix for correctness and edge cases, and improve code comments where needed. I reviewed and verified the changes.

Contribution Checklist

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Nov 7, 2026
@github-actions github-actions Bot changed the title fix: correct WorkflowState fallback expression evaluation (#10612) Python: fix: correct WorkflowState fallback expression evaluation (#10612) Nov 7, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

Patel Namraa (@Namraa310806) Thanks for the detailed work and tests. I’m closing this PR because we need to step back and define the fallback contract before expanding it. Matching Power Fx precedence, associativity, grouping, quoting, coercion, functions, and error semantics opens a much larger compatibility surface than this fix suggests. The Python path should provide best-effort behavior when Power Fx is unavailable, not become a second full Power Fx implementation. We’ll use #10162 to decide the supported subset and behavior before accepting another implementation.

This branch was previously deployed

1 inactive deployment
github-app-auth — dcfb1475 Deployed Nov 8, 2026 by Namraa310806 via add_label #27355
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: WorkflowState fallback evaluator ignores And/Or precedence and evaluates chained - and / right-to-left

4 participants