Skip to content

Python: Finalize abandoned graph workflow streams without OTel context leaks - #8398

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
ryo-whaletech:fix/graph-workflow-stream-span
Sep 16, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
ryo-whaletech:fix/graph-workflow-stream-span

Conversation

@ryo-whaletech

Copy link
Copy Markdown
Contributor

Motivation & Context

Abandoning a graph Workflow.run(..., stream=True) after a visible event can finalize the generator from another Python Context while its workflow.run span is still attached, logging Failed to detach context. #7798 established the corresponding lifecycle constraint for functional workflows and identified graph workflows as the remaining follow-up.

Description & Review Guide

  • What are the major changes? Start the graph run span unattached, activate it around initial execution and each non-yielding runner pull, and end it in finally. Add abandonment cleanup coverage and assert the outer-to-workflow-to-executor span chain.
  • What is the impact of these changes? A caller can stop consuming a graph stream without an OTel context-detach error; graph events, results, errors, and executor span parenting remain intact.
  • What do you want reviewers to focus on? The activation boundary around each runner pull and the preservation of executor processing span parents without holding an OTel token across a caller-visible yield.

Related Issue

Fixes #8397

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.

🟢 Approval recommended

No unresolved blocking issues were identified.

Pull request overview

Updates graph workflow tracing to prevent OpenTelemetry context leaks when streams are abandoned while preserving span parenting.

Changes:

  • Scopes workflow span activation around execution and runner pulls.
  • Adds abandoned-stream cleanup tests.
  • Verifies span hierarchy and caller context preservation.
File summaries
File Summary
python/packages/core/tests/workflow/test_workflow.py Tests abandoned-stream cleanup.
python/packages/core/tests/workflow/test_workflow_observability.py Verifies span hierarchy and context preservation.
python/packages/core/agent_framework/_workflows/_workflow.py Updates graph workflow span lifecycle.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.


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

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.

I reviewed the complete diff and found no actionable code issues. Since this PR is still a draft, I’m leaving this as a comment rather than an approval; please mark it ready when you want the approval-gated checks and final review.

Merged via the queue into microsoft:main with commit 2678cd3 Sep 16, 2026
42 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — a8b1385c Deployed Sep 16, 2026 by eavanvalkenburg via add_label #22982
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: [Bug]: Graph workflow stream abandonment logs an OpenTelemetry context detach error

3 participants