Skip to content

Python: Add timeout for wait-for-first-completion - #7908

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
westey-m:python-wait-for-first-completion-timeout
Aug 27, 2026
Merged

Python: Add timeout for wait-for-first-completion#7908
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
westey-m:python-wait-for-first-completion-timeout

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation & Context

Without a timeout, waiting for background agents can continue indefinitely.

Description & Review Guide

Allow developers to specify a timeout.

Related Issue

Fixes #7454

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 balanced review requested due to automatic review settings August 27, 2026 10:33
@westey-m
westey (westey-m) deployed to github-app-auth August 27, 2026 10:33 — with GitHub Actions Active
@westey-m
westey (westey-m) deployed to github-app-auth August 27, 2026 10:33 — with GitHub Actions Active
@westey-m
westey (westey-m) deployed to github-app-auth August 27, 2026 10:33 — with GitHub Actions Active
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 27, 2026
@github-actions github-actions Bot changed the title Add timeout for wait-for-first-completion Python: Add timeout for wait-for-first-completion Aug 27, 2026

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 bounded wait for Python background agents, preventing indefinite blocking.

Changes:

  • Adds a five-minute default and configurable wait timeout.
  • Returns normally on timeout without stopping background tasks.
  • Adds validation and timeout-focused tests.

Reviewed changes

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

Show a summary per file
File Description
_background_agents.py Implements timeout behavior and validation.
_agent.py Exposes timeout through harness creation.
_agent.pyi Updates the public typing signature.
test_harness_background_agents.py Tests defaults, validation, and timeout behavior.
test_harness_agent.py Tests harness timeout forwarding.
_workflows/_agent.py Formatting-only change.
_harness/_loop.py Formatting-only changes.

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

Comment thread python/packages/core/agent_framework/_harness/_background_agents.py Outdated
Comment thread python/packages/core/agent_framework/_harness/_agent.pyi Outdated
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_harness
   _agent.py132298%203, 642
   _background_agents.py3503988%144–145, 147–150, 152–153, 197, 222–223, 248–250, 253–254, 257–258, 426, 436, 440–443, 457, 495–496, 543, 594, 597, 625, 634, 638, 645–646, 701–704
   _loop.py303797%493, 532, 626, 703, 746, 821, 977
packages/core/agent_framework/_workflows
   _agent.py3243290%80, 84, 128–129, 278, 291, 358, 369, 371, 427, 438, 493, 563, 641, 671, 699, 746, 755, 816, 823, 829–830, 841, 873, 880, 901, 910, 914, 916–918, 925
TOTAL48235448390% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9774 36 💤 0 ❌ 0 🔥 2m 38s ⏱️

@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 (1 commit(s)): 279186443070
Model: gpt-5.6-sol

Overview

The PR adds a provider-controlled, validated timeout and preserves timed-out tasks so their results can be observed later. The new tests cover validation, propagation, timeout return, and retained task state. However, returning control while timed-out tasks continue running creates an unbounded allocation loop with no automatic production cleanup, exposing shared process resources to persistent exhaustion.

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

Affected areas: python/packages/core/agent_framework/_harness/_background_agents.py

Comment thread python/packages/core/agent_framework/_harness/_background_agents.py
@westey-m
westey (westey-m) deployed to github-app-auth August 27, 2026 10:39 — with GitHub Actions Active
@westey-m
westey (westey-m) deployed to github-app-auth August 27, 2026 14:20 — with GitHub Actions Active
Merged via the queue into microsoft:main with commit 6ed829c Aug 27, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

3 participants