Skip to content

.NET: Fix flaky MultiStepOperationTimeout unit test - #10231

Merged
Vincent Biret (baywet) merged 1 commit into
mainfrom
baywet/fix-flaky-multistep-timeout-test
Nov 10, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
mainfrom
baywet/fix-flaky-multistep-timeout-test

Conversation

@baywet

Copy link
Copy Markdown
Member

Motivation & Context

MultiStepOperationTimeoutTests.RunStep_CompletedStepDoesNotResetTimeoutAsync fails intermittently in CI and has been kicking unrelated PRs (e.g. #10175) out of the merge queue. Example failure on dotnet-test (net472, windows-latest, Release): https://github.com/microsoft/agent-framework/actions/runs/42819308461

Assert.Throws() Failure: No exception was thrown
Expected: typeof(System.TimeoutException)

Description & Review Guide

  • What are the major changes? The test used a 100 ms timeout followed by a fixed Task.Delay(200) and then expected RunStep to throw. On a loaded runner (notably .NET Framework), the CancelAfter timer callback may not have run yet when the delay completes, so the token is not cancelled and no TimeoutException is thrown. The test now waits for the timeout token's cancellation itself (bounded by a 30 s safety delay) before asserting.
  • What is the impact of these changes? Test-only change; no production code changes. The test remains deterministic and still verifies that a completed step does not reset the shared timeout.
  • What do you want reviewers to focus on? Whether the bounded wait on the token preserves the intent of the test.

Related Issue

N/A - trivial change: test-only fix for a timing race in an existing unit test.

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: failure investigation, test fix, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Wait for the timeout token to be cancelled instead of a fixed delay, which could finish before the timer callback on loaded runners.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 85e502db-0565-4d9c-94bb-b86f57fc296c

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.

🟢 Approval recommended

No active review issues are recorded for this test-only timeout synchronization change.

No open issues 🎉

What changed in this PR

This test-only change addresses intermittent CI failures in the .NET shared-timeout test by waiting for token cancellation rather than assuming a fixed delay is sufficient. Production code is unchanged.

Changes:

  • Replace the fixed 200 ms delay with a cancellation-driven wait.
  • Bound the wait with a 30-second safety delay and assert that cancellation completed first.
  • Retain assertions for the completed step’s result and the subsequent timeout exception.
File Description
dotnet/​tests/​Microsoft.Agents.AI.UnitTests/​Harness/​MultiStepOperationTimeoutTests.cs Synchronizes the timeout assertion with token cancellation to avoid the fixed-delay race.

Review effort: Balanced

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 1

Result: No findings
Scope: full PR (1 commit(s)): a80fcab03890
Model: gpt-5.6-sol

Overview

This test-only change replaces a fixed delay with a bounded wait for the timeout token's actual cancellation, directly addressing the timer-callback race described in the PR. Cancellation registration handles already-cancelled tokens, RunContinuationsAsynchronously avoids callback-thread continuation hazards, and the final assertion still exercises the production RunStep timeout path. No Critical, High, or Medium defect was established.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

@github-code-quality

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 0982141 baywet/fix-flaky-mul... a80fcab +/-
86% 86% 0%
View coverage of the 5 most impacted files.
File main 0982141 baywet/fix-flaky-mul... a80fcab +/-
/home/runner/wo...SessionStore.cs 100% 56% -44%
/home/runner/wo...SkillsSource.cs 89% 89% 0%
/home/runner/wo...gerMessage.g.cs 78% 79% +1%
/home/runner/wo...iveExtractor.cs 92% 93% +1%
/home/runner/wo...rdExtensions.cs 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@baywet
Vincent Biret (baywet) added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 6b675d6 Nov 10, 2026
44 of 45 checks passed
@baywet
Vincent Biret (baywet) deleted the baywet/fix-flaky-multistep-timeout-test branch November 10, 2026 14:04

This branch was previously deployed

2 inactive deployments
github-app-auth — a80fcab0 Deployed Nov 10, 2026 by baywet via team_check #9196
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants