Skip to content

.NET: Add timeout for wait-for-first-completion - #7911

Merged
westey (westey-m) merged 4 commits into
microsoft:mainfrom
westey-m:dotnet-wait-for-first-completion-timeout
Aug 27, 2026
Merged

.NET: Add timeout for wait-for-first-completion#7911
westey (westey-m) merged 4 commits into
microsoft:mainfrom
westey-m:dotnet-wait-for-first-completion-timeout

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation & Context

Without a timeout, background_agents_wait_for_first_completion can suspend the calling agent's run indefinitely when a child task never completes. Bounding the wait returns control to the model so it can inspect status, retry the wait, or take another action while the child tasks continue running.

Description & Review Guide

  • What are the major changes? Adds a host-configurable BackgroundAgentsProviderOptions.WaitTimeout with a five-minute default, bounds the wait tool using that timeout, and returns a normal retry-oriented message when the timeout expires. Adds tests for defaults, validation, model-facing tool metadata, completion, timeout behavior, and retained task state.
  • What is the impact of these changes? Existing callers receive a five-minute bound by default and can configure another positive duration. Timeout does not cancel or remove child tasks, and the timeout remains outside the model-facing tool arguments.
  • What do you want reviewers to focus on? Please focus on the timeout/completion race, the decision to retain child tasks after timeout, and the public TimeSpan configuration surface.

Related Issue

Fixes #7454

This is the .NET implementation. #7908 and #7904 address the Python implementation.

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 is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • 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.

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

Adds a configurable timeout to prevent background-agent waits from blocking indefinitely.

Changes:

  • Adds a five-minute default WaitTimeout.
  • Preserves running tasks after timeout.
  • Adds validation and timeout behavior tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
BackgroundAgentsProviderOptions.cs Defines the timeout option and default.
BackgroundAgentsProvider.cs Applies timeout validation and bounded waiting.
BackgroundAgentsProviderTests.cs Tests defaults, validation, metadata, and timeout behavior.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@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: Findings reported
Scope: full PR (2 commit(s)): 7f414cedbe1c, 69816930c557
Model: gpt-5.6-sol

Overview

The PR adds a host-configurable timeout that returns control without cancelling child tasks, and its completion-race recheck plus retained-state tests protect the intended retry behavior. The model-facing schema correctly keeps timeout configuration host-only. One contract gap remains: the public option accepts positive durations that the underlying timer rejects when the wait tool is invoked.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: dotnet/src/Microsoft.Agents.AI/Harness/BackgroundAgents/BackgroundAgentsProvider.cs

This was referenced Sep 4, 2026
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

3 participants