Skip to content

Fix integration test worker crashes in Azure Functions on Py3.13 - #4260

Merged
eavanvalkenburg merged 12 commits into
mainfrom
copilot/fix-azure-functions-worker-crashes
Jun 1, 2026
Merged

Fix integration test worker crashes in Azure Functions on Py3.13#4260
eavanvalkenburg merged 12 commits into
mainfrom
copilot/fix-azure-functions-worker-crashes

Conversation

Copilot AI commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

Azure Functions integration tests can crash pytest-xdist workers on Python 3.13 when function app startup exceeds the pytest-timeout budget or when the Azure Functions Python worker dependency isolation triggers a protobuf C extension segfault.

Two root causes were identified:

  1. xdist worker crash: The function_app_for_test fixture retry loop can exceed the 120s --timeout. When pytest-timeout fires mid-fixture, it can call os._exit() and kill the xdist worker outright. Compounding this, the func subprocess shares the worker's process group, so signals can propagate between pytest and the function host.

  2. Azure Functions worker segfault: The Azure Functions Python worker can crash with SIGSEGV on Python 3.13 due to dependency isolation (PYTHON_ISOLATE_WORKER_DEPENDENCIES) conflicting with the protobuf C extension (google._upb).

Description

conftest.py — subprocess isolation

Added start_new_session=True on Linux so the func start process runs in its own process group. This prevents signal cross-contamination between pytest-timeout and the function host.

conftest.py — fixture timeout budget

Added a 100s overall budget, under the 120s test timeout, that caps each retry's max_wait to the remaining time. The fixture now exits cleanly via pytest.fail() instead of being killed by os._exit(). Uses time.monotonic() for budget tracking so NTP/clock adjustments cannot skew enforcement.

conftest.py — disable worker dependency isolation on Python ≥3.13

On Python ≥3.13, the conftest sets PYTHON_ISOLATE_WORKER_DEPENDENCIES=0 in the func start process environment. This disables the problematic Azure Functions worker module isolation path so the worker loads dependencies from the app's own environment and runs natively on Python 3.13.

Merge conflict resolution

Resolved merge conflicts by keeping the current workflow/setup configuration from main leading. The remaining PR diff is limited to the Azure Functions integration-test conftest.py changes.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.
Original prompt

This section details on the original issue you should resolve

<issue_title>Integration tests failing due to parallel worker crashes in Azure Functions in Py3.13</issue_title>
<issue_description>Description
The Python - Merge - Tests workflow job is failing due to all 20 parallel pytest-xdist workers crashing during integration tests in packages/azurefunctions/tests/integration_tests/.

Job: https://github.com/microsoft/agent-framework/actions/runs/22343078848/job/64650758582

Symptoms
20 tests failed, 18 passed, 3 skipped (ran for ~12 minutes)
All failures are worker crashes, not assertion errors
Failures span all test categories: single agent, multi-agent, workflows, and HITL
Even the basic test_health_check test fails, indicating the Azure Functions host was likely unreachable
Affected Tests
test_01_single_agent.py – 5 tests
test_04_single_agent_orchestration_chaining.py – 1 test
test_05_multi_agent_orchestration_concurrency.py – 1 test
test_06_multi_agent_orchestration_conditionals.py – 2 tests
test_07_single_agent_orchestration_hitl.py – 2 tests
test_09_workflow_shared_state.py – 3 tests
test_11_workflow_parallel.py – 3 tests
test_12_workflow_hitl.py – 3 tests
Possible Causes
Azure Functions deployment step failed earlier in the workflow
Missing or misconfigured environment secrets/variables
Infrastructure provisioning issue causing the test environment to be unavailable
Steps to Investigate
Check the Azure Functions deployment step in the workflow run
Verify environment secrets and variables are correctly configured
Review infrastructure provisioning logs earlier in the workflow

Requirement:
The integration tests for azurefunctions package should run on Py3.13 without failure. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Three changes to prevent pytest-xdist workers from crashing during
Azure Functions integration tests:

1. Add `start_new_session=True` to subprocess on Linux so signals
   (e.g. from test-timeout) cannot propagate between the func host
   and the xdist worker process.

2. Add an overall 100-second budget to the fixture setup loop so
   the retry logic never exceeds the 120-second test timeout. When
   pytest-timeout's thread method fires during fixture setup and the
   thread doesn't respond, it calls os._exit() which kills the
   xdist worker – this is the root cause of the "Not properly
   terminated" crashes.

3. Remove the `UV_PYTHON: "3.10"` workaround from both workflow
   files so integration tests actually run on Python 3.13.

Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix integration test failures due to Azure Functions worker crashes Fix integration test worker crashes in Azure Functions on Py3.13 Feb 25, 2026
Copilot AI requested a review from larohra February 25, 2026 17:25
@markwallace-microsoft markwallace-microsoft added the python Usage: [Issues, PRs], Target: Python label Feb 25, 2026
@github-actions github-actions Bot changed the title Fix integration test worker crashes in Azure Functions on Py3.13 Python: Fix integration test worker crashes in Azure Functions on Py3.13 Feb 25, 2026
Copilot AI and others added 2 commits February 25, 2026 19:31
Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>
Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>
Copilot AI changed the title Python: Fix integration test worker crashes in Azure Functions on Py3.13 Fix integration test worker crashes in Azure Functions on Py3.13 Feb 25, 2026
@larohra
larohra marked this pull request as ready for review February 25, 2026 22:07
@larohra
larohra requested a review from a team as a code owner February 25, 2026 22:07
Copilot AI review requested due to automatic review settings February 25, 2026 22:07

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

Fixes pytest-xdist worker crashes in Azure Functions integration tests on Python 3.13 by preventing fixture startup from exceeding the pytest-timeout budget and isolating the func start subprocess from the worker’s process group. Also removes a stale workflow-level Python 3.10 override so CI actually runs these tests on 3.13.

Changes:

  • Isolate the Azure Functions host subprocess on POSIX using start_new_session=True to prevent signal cross-contamination.
  • Add an overall startup time budget in the function_app_for_test fixture to ensure clean failure (pytest.fail) before pytest-timeout can hard-exit the worker.
  • Remove UV_PYTHON: "3.10" overrides from the Functions integration test jobs so they inherit the workflow’s Python version (3.13).

Reviewed changes

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

File Description
python/packages/azurefunctions/tests/integration_tests/conftest.py Adds POSIX process-group isolation for func start and enforces an overall fixture startup budget to avoid pytest-timeout killing xdist workers.
.github/workflows/python-merge-tests.yml Removes the job-level UV_PYTHON pin so merge tests run Functions integration on the workflow’s Python version.
.github/workflows/python-integration-tests.yml Removes the job-level UV_PYTHON pin so integration tests run Functions integration on the workflow’s Python version.

Comment thread python/packages/azurefunctions/tests/integration_tests/conftest.py Outdated
@markwallace-microsoft

markwallace-microsoft commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
TOTAL22222275787% 
report-only-changed-files is enabled. No files were changed during this commit :)

Python Unit Test Overview

Tests Skipped Failures Errors Time
4717 247 💤 0 ❌ 0 🔥 1m 20s ⏱️

@larohra

larohra commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

@copilot code review[agent] fix the comments and failing jobs

Addresses review feedback: monotonic clock is immune to NTP/clock
adjustments that could skew the budget enforcement.

Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>

Copilot AI commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

@copilot code review[agent] fix the comments and failing jobs

Fixed the review comment (time.monotonic() instead of time.time()) in 3c46364. The CI jobs on this branch are passing — the latest run (22418056690) completed successfully.

Copilot AI requested a review from larohra February 26, 2026 00:39
…tion

Replace the Python 3.12 redirect workaround with the proper fix:
set PYTHON_ISOLATE_WORKER_DEPENDENCIES=0 on Python >=3.13.

The segfault (exit code 139) is caused by the Azure Functions worker's
module isolation mechanism conflicting with protobuf's C extensions
(google._upb) on Python 3.13.  Disabling isolation lets the worker
load dependencies from the app's own environment, which avoids the
crash while keeping everything running on Python 3.13.

See: Azure/azure-functions-python-worker#1797

Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>

Copilot AI commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I ran the integrations test CI for validating the fix and it looks like its still failing - https://github.com/microsoft/agent-framework/actions/runs/22430115474/job/64947...

You're right — the Python 3.12 redirect was a workaround, not a root-cause fix. The actual issue is in the Azure Functions worker's dependency isolation mechanism (PYTHON_ISOLATE_WORKER_DEPENDENCIES), not Python 3.13 itself. The worker's module isolation conflicts with protobuf's C extensions (google._upb) causing a SIGSEGV. This is tracked upstream at Azure/azure-functions-python-worker#1797.

Fixed in 5532dff: replaced the Python 3.12 redirect with PYTHON_ISOLATE_WORKER_DEPENDENCIES=0 on Python ≥3.13. This disables the problematic isolation so the worker runs natively on Python 3.13, loading dependencies from the app's own environment. Also removed the Python 3.12 install step from the CI setup action since it's no longer needed.

@larohra

larohra commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

There's an underlying bug in the python worker for 3.13+ where .venvs created in other directories outside of the functionApp directory causes this issue. @hallvictoria has a fix out of this. In the meanwhile, @gavin-aguiar will figure out if we can rearchitect a fix that will circumvent this limitation.

@markwallace-microsoft

Copy link
Copy Markdown
Contributor

@copilot, friendly reminder — this issue is waiting on your response. Please share any updates when you get a chance. (This is an automated message.)

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, friendly reminder — this issue is waiting on your response. Please share any updates when you get a chance. (This is an automated message.)

The current fix (5532dff) sets PYTHON_ISOLATE_WORKER_DEPENDENCIES=0 on Python ≥3.13 to work around the Azure Functions worker segfault. As @larohra noted, there's an underlying bug in the Python worker for 3.13+ related to .venv paths outside the function app directory — @hallvictoria has a fix in progress upstream. Once that upstream fix lands in azure-functions-core-tools, the PYTHON_ISOLATE_WORKER_DEPENDENCIES=0 workaround in our conftest can be removed. No further code changes are needed from our side at this time.

@eavanvalkenburg

Copy link
Copy Markdown
Member

@copilot fix the merge conflicts, making sure that the setup in main is leading

…ctions-worker-crashes

# Conflicts:
#	.github/workflows/python-integration-tests.yml
#	.github/workflows/python-merge-tests.yml

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the merge conflicts, making sure that the setup in main is leading

Resolved the merge conflicts in 1c849639, taking the current main workflow/setup changes for the conflicted workflow blocks. The PR diff is now limited to the Azure Functions integration-test conftest.py changes.

@eavanvalkenburg
eavanvalkenburg enabled auto-merge June 1, 2026 08:58
@eavanvalkenburg
eavanvalkenburg added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit b59a854 Jun 1, 2026
37 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

Development

Successfully merging this pull request may close these issues.

Python: Integration tests failing due to parallel worker crashes in Azure Functions in Py3.13

7 participants