Skip to content

Fix EvaluateRule action failing when the target workflow has GlobalParams (#626) - #760

Open
Martin Brekhof (MBrekhof) wants to merge 1 commit into
microsoft:mainfrom
MBrekhof:fix/evaluate-rule-action-global-params
Open

Martin Brekhof (MBrekhof) wants to merge 1 commit into
microsoft:mainfrom
MBrekhof:fix/evaluate-rule-action-global-params

Conversation

@MBrekhof

Copy link
Copy Markdown

Fixes #626.

Problem

An EvaluateRule action that chains into a workflow with GlobalParams always fails. The action forwards the source rule's RuleResultTree.Inputs, which already contain the evaluated global params. The target workflow then evaluates its own GlobalParams again, so the same name is defined twice:

Exception while executing EvaluateRuleAction: Error while compiling rule `r1`: The identifier 'g' was defined more than once

With the default EnableExceptionAsErrorMessage = true, nothing is thrown, but ActionRuleResult.Exception carries a GlobalParam/input collision error and Output is null. The existing workaround was "inputFilter": [], which also drops every real input.

Repro: workflow wf with GlobalParams: [{ g = input1.X }], rule r2 with OnSuccess: EvaluateRule { workflowName: wf, ruleName: r1 }, then ExecuteActionWorkflowAsync("wf", "r2", input1).

Solution

EvaluateRuleAction.Run now drops forwarded params named like the target workflow's GlobalParams before chaining (after inputFilter, before additionalInputs). The target workflow recomputes them from the remaining inputs.

  • Names are compared the way the expression parser compares identifiers: case-insensitive unless ReSettings.IsExpressionCaseSensitive is set.
  • Nothing is dropped when EnableScopedParams is false, because globals are not evaluated then.
  • additionalInputs are added after the drop and are still evaluated against the full source inputs, so they can reference source globals.
  • A source global is still forwarded when the target workflow declares no global with that name.
  • Direct calls to ExecuteActionWorkflowAsync are unchanged. A caller input that collides with a global still raises the existing collision error.
  • The workflow's global names are read from the stored workflow (RulesCache.GetGlobalParamNames), not via GetWorkflow, which resolves WorkflowsToInject. RegisterRule only compiles the top-level workflow's globals.
  • No public API change: the new helpers are internal.

Tests

test/RulesEngine.UnitTest/Issue626Test.cs:

  • chaining into a workflow with globals works through ExecuteActionWorkflowAsync (with and without EnableExceptionAsErrorMessage) and through ExecuteAllRulesAsync
  • a forwarded G is replaced by the target's recomputed g (case-insensitive default)
  • with IsExpressionCaseSensitive = true, G and g both stay available
  • a source global is still forwarded to a target workflow without that global
  • additionalInputs work together with globals
  • EnableScopedParams = false leaves an input named like a global untouched

Five of these fail on main. The other three guard against dropping too much. The full suite passes on net8.0, net9.0 and net10.0.

🤖 Generated with Claude Code

…rams (microsoft#626)

The inputs an EvaluateRule action forwards come from RuleResultTree.Inputs,
which already holds the source rule's evaluated GlobalParams. The target
workflow then evaluates its own GlobalParams again, so chaining into any
workflow with globals failed with "The identifier 'x' was defined more than
once" (or a GlobalParam/input collision error).

EvaluateRuleAction now drops forwarded params named like the target
workflow's GlobalParams before the call; the target recomputes them from the
remaining inputs. Names are compared the way the expression parser compares
identifiers (IsExpressionCaseSensitive), nothing is dropped when
EnableScopedParams is off, and additionalInputs are added after the drop so
they behave as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action Workflow and global params do not work together

2 participants