Skip to content

fix(test): reset item._request after a timeout escape - #37941

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/timeout-escape-reset-request
Nov 16, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/timeout-escape-reset-request

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: test/test_worker_memory_retention.py passes on an xdist worker even after an earlier test on that worker timed out.

test_no_collected_item_waits_with_a_request_built (added by #37814) asserts that no other collected item still holds a built _request. When pytest-timeout's pytest.fail escapes pytest_runtest_protocol, the rootdir conftest.py escape guard writes the missing reports and runs teardown, but it never takes runtestprotocol's last step. The timed-out item keeps its TopRequest and funcargs, so the retention test then fails on that worker and blames collection. The same fix is already on the release PR #37884.

Why it matters

Any timeout on a worker turns a second, unrelated test red. That makes test_worker_memory_retention.py depend on what ran before it, which breaks the tests-are-deterministic rule and sends readers after a collection bug that does not exist.

Not a goal

  • Changing how the escape guard builds or times the missing reports.
  • Changing pytest-timeout settings or any timed-out test.

What changed (motivation → approach → change)

The escape guard in conftest.py skips the step runtestprotocol runs after every test. It now takes that step itself: when the item has a _request, it sets item._request = False and item.funcargs = None, the state pytest leaves behind. This is a cherry-pick of the second commit of #37884; main already has #37814.

Backwards compatibility

Compatible: only the test harness changes, and it now leaves a timed-out item in the same state as every other finished item.

Removes nothing: the guard drops per-item request state that pytest itself drops after every normal test.

Tests

test/test_xdist_escaped_failure_guard.py gains test_an_escape_drops_the_request_as_runtestprotocol_would, parametrized over the guard's three branches (no-call, no-teardown, all-logged). Each drives the guard with an item holding a request and checks the request and fixture values are gone.

Proof: PROVEN test/test_xdist_escaped_failure_guard.py::test_an_escape_drops_the_request_as_runtestprotocol_would[no-call], test/test_xdist_escaped_failure_guard.py::test_an_escape_drops_the_request_as_runtestprotocol_would[no-teardown], test/test_xdist_escaped_failure_guard.py::test_an_escape_drops_the_request_as_runtestprotocol_would[all-logged] (head cc78fe1)

Determinism: test/test_xdist_escaped_failure_guard.py passed 5 repeats at -n 2 (10 passed each). test/test_xdist_escaped_failure_guard.py and test/test_worker_memory_retention.py together passed in one shuffled order and its reverse at -n 0 (24 passed, 1 skipped each).

Manual verification

N/A -- the unit tests drive every branch of the changed guard.

Related Issues

Part of #37771

Follows #37814. Same fix as the second commit of #37884.

Sibling sweep

Swept: git grep -n "runtestprotocol|_request = False|funcargs = None" -- '*.py'
Sibling: conftest.py:709 -- not affected -- the item-collected hook already drops _request at collection time

Pattern harvest

Not generalizable: the escape guard is the one place that stands in for runtestprotocol, and it now mirrors that function's final cleanup.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

When pytest-timeout's pytest.fail escapes pytest_runtest_protocol, the
rootdir conftest's escape guard synthesizes the missing reports and runs
teardown, but runtestprotocol's last step never ran: the item keeps its
rebuilt TopRequest and funcargs. On the same xdist worker,
test_no_collected_item_waits_with_a_request_built then fails beside the
timed-out neighbour and blames collection.

The guard now takes that step itself (item._request = False,
item.funcargs = None), as runtestprotocol does, and a parametrized test
drives each of its three branches with an item holding a request.
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision cc78fe1711559094b9cc1719488c20b1f3901164 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision cc78fe1711559094b9cc1719488c20b1f3901164 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of cc78fe1711559094b9cc1719488c20b1f3901164 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: this is a test-harness-only change, and it adds the same request/funcargs cleanup that pytest's runtestprotocol runs as its last step.

[DESIGN-REVIEWED] cc78fe1

Description read

[DESCRIPTION-READ] f06f76a74542edfba36e27f4575bc70f41ba52d88076f12168587d6649175b7d

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed cc78fe1711559094b9cc1719488c20b1f3901164 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] cc78fe1

Verdict parsed from the review's SHA-scoped output markers for commit cc78fe1711559094b9cc1719488c20b1f3901164.

False positive or not applicable? A repository writer can comment:
/ai-review override fable cc78fe1711559094b9cc1719488c20b1f3901164 false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of cc78fe1711559094b9cc1719488c20b1f3901164 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] cc78fe1

False positive or not applicable? A repository writer can comment:
/ai-review override gpt cc78fe1711559094b9cc1719488c20b1f3901164 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 16, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 6% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

Small change to the test harness only. When a test times out and the failure escapes, the pytest_runtest_protocol escape guard in conftest.py now does the last step of runtestprotocol itself. If the item has a _request, the guard sets item._request = False and item.funcargs = None. It does this after its teardown branches and before logfinish, which is the same point where pytest does it in a normal run.

How I checked it:

  • Branches: the cleanup runs on all three branches of the guard (no-call, no-teardown, all-logged). It does not run when the outcome is not a Failed escape, because the guard returns early in that case.
  • State: the guard leaves an item in the state that compact_collected_item (around conftest.py:708) expects. It is also the state that test_no_collected_item_waits_with_a_request_built in test/test_worker_memory_retention.py checks with getattr(item, '_request', False).
  • Repeat runs: if the item runs again (for example under rerunfailures), runtestprotocol rebuilds the request when _request is falsy, so clearing it is safe.
  • Repeat cleanup: if the escape happens after pytest's own cleanup already ran, clear

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit cc78fe1711 · 32 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 16, 2026 12:04

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: fix (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: test-harness fix; the xdist escaped-failure guard in conftest.py now drops the item's request and fixture values the way runtestprotocol would, with a parametrized test for it.

@KiroCrewCaptain
KiroCrewCaptain merged commit 8b93796 into main Nov 16, 2026
98 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/timeout-escape-reset-request branch November 16, 2026 12:05
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants