Skip to content

.NET: fix: preserve Foreach record values#6208

Merged
TaoChenOSU merged 1 commit into
microsoft:mainfrom
he-yufeng:fix/foreach-preserve-record-values
Jun 5, 2026
Merged

.NET: fix: preserve Foreach record values#6208
TaoChenOSU merged 1 commit into
microsoft:mainfrom
he-yufeng:fix/foreach-preserve-record-values

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Fixes #6183.

Summary

  • preserve each RecordDataValue as a full record when Foreach materializes table rows
  • add a regression test for a multi-field row so the loop value exposes both fields

To verify

  • dotnet test --project tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net10.0 -v Normal --filter-class Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel.ForeachExecutorTest
  • dotnet test --project tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net472 -v Normal --filter-class Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel.ForeachExecutorTest
  • dotnet format agent-framework-dotnet.slnx --verify-no-changes --no-restore --include src\Microsoft.Agents.AI.Workflows.Declarative\ObjectModel\ForeachExecutor.cs tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\ObjectModel\ForeachExecutorTest.cs
  • git diff --check

Copilot AI review requested due to automatic review settings May 30, 2026 14:50

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes a bug in ForeachExecutor where iterating over a TableDataValue only exposed the first field of each record instead of the full record.

Changes:

  • Replace value.Properties.Values.First().ToFormula() with value.ToFormula() so the full record is yielded per iteration.
  • Add a unit test verifying multi-field records expose all fields via the loop variable.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutor.cs Yield full record (not just first property) when iterating a table.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs Adds test asserting all record fields are accessible from the iteration variable.

@moonbox3 moonbox3 added .NET workflows Related to Workflows in agent-framework labels May 30, 2026
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased on current upstream/main and reran the scoped Foreach validation locally.

Validated:

dotnet build .\tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net10.0 -c Debug --tl:off
dotnet test --project .\tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net10.0 -c Debug --no-build -v Normal --report-xunit-trx --ignore-exit-code 8 -- --filter-class Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel.ForeachExecutorTest
git diff --check upstream/main...HEAD

All passed after the rebase.

@he-yufeng he-yufeng force-pushed the fix/foreach-preserve-record-values branch from 4ab383a to 396c775 Compare June 2, 2026 19:52
@peibekwe

peibekwe commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix @he-yufeng! I'm going to land this, then layer a single-column unwrap on top to preserve =[...] literal back-compat, separate PR coming.

@TaoChenOSU TaoChenOSU added this pull request to the merge queue Jun 5, 2026
Merged via the queue into microsoft:main with commit fa9e086 Jun 5, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Declarative Foreach collapses multi-field records to their first field in the loop value variable

5 participants