Skip to content

Python: preserve background execution identity across completion waits - #9442

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
CorgiBoyG:fix/background-wait-continuation-identity
Oct 22, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
CorgiBoyG:fix/background-wait-continuation-identity

Conversation

@CorgiBoyG

@CorgiBoyG RongJie G (CorgiBoyG) commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

A background completion waiter can resume after another caller has continued the same task ID. It recognizes the original execution as completed but previously looked up the task again by ID, potentially consuming the continuation instead. A running continuation raises InvalidStateError; a finished continuation can be finalized or reported by the stale waiter.

Description & Review Guide

  • What are the major changes? Keep the task object selected from the original wait set. Remove its runtime reference and persist its completion only while it remains the current execution for the ID. Add twelve continuation race cases and one concurrent-waiter case.
  • What is the impact of these changes? Waiters report the execution they observed and leave newer continuations intact. The existing task-retention, timeout, and session-release policies remain unchanged.
  • What do you want reviewers to focus on? Execution identity at the wait boundary, conditional runtime removal and persistence, and preservation of the continuation's result and session state.

Related Issue

Fixes #9441

This addresses a local wait/continuation race, separate from the task-retention work in #9387 and distributed-runtime work in #9040.

Ready for review after CI completed successfully. Maintainer confirmation of the scoped direction requested in #9441 remains pending.

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.

Signed-off-by: CorgiBoyG <111257566+CorgiBoyG@users.noreply.github.com>

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

Static review found no blocking issues in the scoped fix or regression coverage; tests were not executed.

0 open findings

What changed in this PR

Fixes #9441 by preserving background execution identity across completion waits, without changing task-retention or session-release policies.

Changes:

  • Finalizes the exact execution observed by the waiter.
  • Guards runtime removal and persistence against newer continuations.
  • Adds 12 continuation-race cases and one concurrent-waiter test.
File Description
python/​packages/​core/​tests/​core/​test_harness_background_agents.py Adds deterministic continuation-race and concurrent-waiter coverage.
python/​packages/​core/​agent_framework/​_harness/​_background_agents.py Preserves execution identity and protects newer continuation state.

🧠 Review effort: Balanced


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

@CorgiBoyG

Copy link
Copy Markdown
Contributor Author

Eduard van Valkenburg (@eavanvalkenburg), this PR is now ready for review. CI completed with 33 successful checks, 21 skipped checks, and no failures or pending checks; all required checks passed. The Python test matrix, code quality, coverage, API compatibility, and CLA checks passed.

The fix remains scoped to the wait/continuation execution-identity race in #9441, with twelve deterministic continuation cases and one concurrent-waiter regression. The tested commit remains ea6c0e1954f30dd5e30751a867e5c14f2fb60119.

The direction-confirmation request in #9441 is still pending, so the corresponding checklist item remains unchecked. Could you review the scoped approach when you have time? Thank you.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the background-task completion race fix and its continuation/concurrent-waiter coverage. The identity checks prevent a stale waiter from removing or persisting over the current execution.

Merged via the queue into microsoft:main with commit 70ba23a Oct 22, 2026
58 checks passed

This branch was successfully deployed

1 active deployment
github-app-auth — ea6c0e19 Deployed Oct 19, 2026 by CorgiBoyG via add_label #25753
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

Development

Successfully merging this pull request may close these issues.

Python: Background completion waiter can finalize a newer continuation under the same task ID

3 participants