Repository navigation
Description
Observed Behavior
When PowerFx is unavailable, WorkflowState.eval() falls back to the Python implementation in WorkflowState._eval_simple().
The fallback evaluator produces incorrect results for expressions involving logical operator precedence, arithmetic associativity, and operators appearing inside string literals.
The following examples demonstrate the incorrect behavior:
1. Incorrect logical operator precedence
s.eval("=Local.a Or Local.b And Local.c")Actual result: False
Expected result: True
And should have higher precedence than Or, so the expression should be evaluated as Local.a Or (Local.b And Local.c).
2. Incorrect subtraction associativity
s.eval("=10 - 2 - 3")Actual result: 11.0
Expected result: 5.0
Subtraction should be evaluated left-to-right: (10 - 2) - 3.
3. Incorrect division associativity
s.eval("=100 / 10 / 2")Actual result: 20.0
Expected result: 5.0
Division should also be evaluated left-to-right: (100 / 10) / 2.
4. Operators inside string literals
s.eval('=Local.text = "a And b"')Actual result: False
Expected result: True, when Local.text contains "a And b".
The underlying problem is that _eval_simple() uses string splitting to identify operators without accounting for operator precedence, associativity, parentheses, or string-literal boundaries.
As a result, expressions evaluated through the Python fallback can produce results that differ from their expected PowerFx semantics.
Expected Behavior
WorkflowState.eval() should produce consistent and predictable results when evaluating expressions through the Python fallback.
Specifically:
-
Logical operator precedence:
Andshould bind more tightly thanOr, ensuring that logical expressions are evaluated in the correct order. -
Arithmetic associativity: Operators with the same precedence should be evaluated left-to-right. For example:
10 - 2 - 3should evaluate to5.100 / 10 / 2should evaluate to5.
-
String literal handling: Operators appearing inside quoted string literals should not be interpreted as expression operators.
-
Parenthesized expressions: Explicit grouping should be respected, allowing parentheses to override the default operator precedence.
-
Backward compatibility: Existing variable resolution, custom-function dispatch, comparison behavior, and other supported expression functionality should continue working as expected.
The Python fallback should produce results consistent with the corresponding PowerFx expressions for the supported expression subset.
Steps to Reproduce
-
Create a
WorkflowStateinstance. -
Configure the state with the following variables:
Local.a = TrueLocal.b = FalseLocal.c = FalseLocal.text = "a And b"
-
Ensure that PowerFx is unavailable so that the Python fallback evaluator is used.
-
Evaluate the following expressions:
s.eval("=Local.a Or Local.b And Local.c") s.eval("=10 - 2 - 3") s.eval("=100 / 10 / 2") s.eval('=Local.text = "a And b"')
-
Observe that the fallback evaluator returns incorrect results for these expressions.
The fallback can also be forced deterministically in tests by setting _powerfx_engine to None.
Minimal Reproduction
from agent_framework_declarative import WorkflowState
s = WorkflowState()
s.set("Local.a", True)
s.set("Local.b", False)
s.set("Local.c", False)
s.set("Local.text", "a And b")
# Incorrect logical operator precedence
print(s.eval("=Local.a Or Local.b And Local.c"))
# Actual: False
# Expected: True
# Incorrect subtraction associativity
print(s.eval("=10 - 2 - 3"))
# Actual: 11.0
# Expected: 5.0
# Incorrect division associativity
print(s.eval("=100 / 10 / 2"))
# Actual: 20.0
# Expected: 5.0
# Operator inside a string literal
print(s.eval('=Local.text = "a And b"'))
# Actual: False
# Expected: TrueError Messages and Stack Traces
N/A
No exception or stack trace is produced. The issue concerns incorrect expression evaluation rather than a runtime failure.
Package Versions
- Package:
agent-framework-declarative - MAF Core Version:
1.25.0 - Installation: Source checkout of
microsoft/agent-framework(main branch). - PowerFx: Unavailable when reproducing the fallback behavior.
Python Version
Python 3.13.15
Operating System
Windows
Regression
Yes. The behavior is reproducible in the current implementation, but the specific version in which it was introduced has not yet been established.
Additional Context
Root Cause
The issue originates in WorkflowState._eval_simple() in:
python/packages/declarative/agent_framework_declarative/_workflows/_state.py
The current implementation uses string operations such as formula.split(" And ", 1) to identify binary operators.
This introduces several problems:
- Incorrect logical precedence:
Andis processed beforeOrin the evaluator's splitting order, effectively givingAndlower precedence thanOr. - Incorrect associativity: Splitting at the first occurrence and recursively evaluating the right-hand side causes chained subtraction and division to be evaluated right-to-left.
- String literal handling: Operators inside quoted strings are incorrectly treated as expression operators.
- Parenthesized expressions: The evaluator does not consistently recognize parentheses as explicit grouping boundaries.
Scope
This issue affects the standalone WorkflowState Python fallback evaluator.
DeclarativeWorkflowState, which is used by WorkflowFactory, follows a different evaluation path and is not affected by the absence of PowerFx in the same way.
Reproduction and Testing
Regression tests can force the Python fallback by setting _powerfx_engine to None, independently of whether PowerFx is installed in the environment.
The regression tests cover:
- Logical operator precedence (
And,Or, and||). - Negation precedence.
- Parenthesized expressions.
- Left-associative subtraction and division.
- Mixed arithmetic operators and their precedence.
- Operators appearing inside string literals.
These tests demonstrate the incorrect behavior in the existing implementation and verify the expected results after the fix.
Suggested Area for Investigation
WorkflowState._eval_simple() and its binary operator parsing logic.
Acknowledgements
- I searched existing issues and did not find a duplicate.
- I personally verified this behavior and the reproduction details are authentic.
- I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
github-actions commentedon Nov 7, 2026
Reproduced on main (
924a6e5) by forcing the fallback (agent_framework_declarative._workflows._state._powerfx_engine = None). Results:Local.a Or Local.b And Local.c→False,10 - 2 - 3→11.0,100 / 10 / 2→20.0,Local.text = "a And b"→False, matching the report. With PowerFx active, the same expressions give the expected values. The cause is inWorkflowState._eval_simple, which splits on the firstAnd/Or/-//occurrence.Support boundary: unclear. I found no maintained spec or ADR defining the Python fallback's semantics, so a maintainer needs to decide the scope. Evidence is in the Actions run; routed to the declarative package owner. Priority is left to maintainers.
fix: correct unary negation precedence in WorkflowState (microsoft#10162
eavanvalkenburg commentedon Nov 9, 2026
We need to take a broader design look before implementing this. Fixing these examples starts to open a Pandora’s box of Power Fx compatibility: precedence, associativity, grouping, quoting, coercion, functions, and error behavior. The fallback should be explicitly best effort when Power Fx is unavailable, not a full replacement. We need to define the supported subset and failure or compatibility contract here before another PR.
eavanvalkenburg commentedon Nov 9, 2026
/plan Follow the existing maintainer decision: define an explicitly best-effort Python fallback, not a second Power Fx implementation. Independently reproduced on current main: mixed And/Or precedence, chained subtraction/division, and operator text inside quoted strings produce incorrect results. First identify the supported subset from maintained docstrings/tests and real standalone WorkflowState callers, distinguishing DeclarativeWorkflowState and WorkflowFactory. Compare minimal bounded corrections with explicitly rejecting or delegating unsupported expressions; describe compatibility and failure behavior, including the fallback after an ordinary Power Fx evaluation error. Do not silently broaden syntax, coercion, functions, grouping, or error semantics. Propose a small maintainable contract and focused regression tests, preserve state-budget protections, and estimate production scope only after the contract is agreed. PR #10163 is already closed pending this design; do not reopen it or start implementation.
github-actions commentedon Nov 9, 2026
Summary
The Python-only
WorkflowState.eval()fallback (_eval_simple) splits formulas on the first" And "," Or "," - "," / "it finds. That gives wrong answers for mixed And/Or, chained-and/, and operator text inside quotes. Per the maintainer decision, the goal is an explicitly best-effort fallback, not a second Power Fx.What I confirmed in the code (read only; nothing run)
WorkflowState(_state.pyeval/_eval_simple). It falls back whenpowerfxisn't importable and after any ordinary (non-budget) Power Fx exception, which is only logged as a warning._PowerFxStateLimitErroris re-raised and never reaches the fallback.DeclarativeWorkflowState/WorkflowFactoryare unaffected. Itsevalhas no_eval_simple. It raisesRuntimeErrorif Power Fx is missing, and re-raises other errors (except "isn't recognized" →None). I found no production caller of the standaloneWorkflowState.evalin the repo; the hosting package'sWorkflowStateis an unrelated class. Real users are therefore external code (unknown)._eval_simpledocstring andtests/test_workflow_state.py):Local./System./Workflow.Inputs.references; literals (string, int/float, true/false);And/Or/||/Not()/!;< > <= >= <> =;+ - * /(None→0,+falls back to string concat, divide-by-zero→None);CUSTOM_FUNCTIONS(UserMessage, MessageText, ...) viawhole_call_args. The docstring does not promise precedence, grouping, quoting or Power Fx parity. Existing tests only use single-operator expressions, so nothing pins the buggy behavior.+and numeric coercion are lenient). That is the "Pandora's box" risk.Recommendation
Code and docs change, kept small. The reported results are real defects even for a best-effort evaluator, because they return a confidently wrong value rather than failing. I'd compare three options:
-//, And before Or, skip quotes)ValueError) and document "install Power Fx for anything else"Suggested direction: B, bounded, with C-style rejection only for forms we know we can't evaluate safely (e.g. mixed forms the parser cannot classify). A is the cheapest but cannot honor quote safety cleanly.
Proposed contract (for agreement; not implemented)
"..."/'...'.Not/!>* />+ -> comparisons >And>Or/||; same-level operators left-to-right. Parentheses: open question below.CUSTOM_FUNCTIONS/Not, other syntax. Today these return the raw text. Keep that existing return behavior for compatibility, but log a warning that the fallback is best-effort. Alternatively raise. Needs your call.+string concat, divide by zero →None). No new coercion or functions.eval/_eval_simpledocstrings (and the packageAGENTS.mdline onWorkflowState) to say "best-effort subset;DeclarativeWorkflowStatedoes not use it".Focused regression tests (all force
_powerfx_engine = None)Local.a And Local.b Or Local.c,10 - 2 - 3 - 1,100 / 10 / 2,2 + 3 * 4.=and+inside strings._PowerFxStateLimitError→ still raised with no fallback.Questions before sizing the work
ValueError(fail loudly, a behavior change)?Once these are agreed I can estimate the production scope. Nothing has been changed, and PR #10163 stays closed.
PratikWayase commentedon Nov 11, 2026
Jose Alvarez (@jpalvarezl) I propose replacing the current
.split()parsing with a tokenizer and precedence-climbing parser to properly handle operator precedence, strings, and comments. Local validation confirms this fixes all four reported issues, adds parenthesis support, and passes 50/52 existing assertions. Before implementing, I'd appreciate your feedback on raisingValueErrorfor unsupported syntax, including basic parentheses, and keeping&/&&unsupported for now.Namraa310806 commentedon Nov 12, 2026
Thanks Eduard van Valkenburg (@eavanvalkenburg) for the investigation and plan. I reported and reproduced this, and I have a tested prototype in the now-closed #10163. I agree with the design-first approach and won't open a PR until the contract is agreed. The fallback should stay best-effort and not become a second Power Fx.
Proposed approach
A bounded correction of the existing evaluator rather than a general-purpose parser. Keep
_eval_simple's structure and replace thestr.splitcalls with one helper that finds the last top-level operator:"a And b"case, not an attempt to support new syntax.(),[],{}are skipped.Precedence for the existing operators, lowest to highest:
Or/||,And, comparisons,+ -,* /,!/Not(), then literals, references and calls.Proposed contract
ValueErrorwould be a separate, explicit compatibility decision._PowerFxStateLimitErrorkeeps propagating with no fallback.+string concat, divide-by-zero→None), variable resolution and custom-function dispatch are unchanged.eval/_eval_simpledocstrings and the AGENTS.md line to say "best-effort subset;DeclarativeWorkflowStateis unaffected."Regression tests (all force
_powerfx_engine = None)10 - 2 - 3 - 1,2 + 3 * 4,a And b Or c)._PowerFxStateLimitErrorstill propagates.I understand the concern about gradually expanding the fallback's semantics. My aim is to correct the documented behavior while keeping the boundaries explicit.
pratik wayase (@PratikWayase), thanks for the parser proposal. It covers the same reported cases, and I'm happy to go with whichever approach the maintainers prefer. I'd appreciate feedback on grouping, on raw-formula versus
ValueErrorfor unsupported input, and on keeping the fallback after ordinary Power Fx errors. Once the contract is settled, I'm glad to implement it and size the scope then.