Skip to content

fix(test): drop the shadowed can_read_body double on the slot-race request - #8577

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/slot-race-duplicate-can-read-body
Closed

fix(test): drop the shadowed can_read_body double on the slot-race request#8577
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/slot-race-duplicate-can-read-body

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

Problem / Motivation

Backend Lint fails on main. flake8 reports:

test/test_slot_close_recreation_race.py:131:5: F811 redefinition of unused 'can_read_body' from line 119

Reproduced against main's tip in a clean worktree, so this is main's own code and not one PR's diff. Every open PR inherits it through its merge ref.

Why it matters

The gate stops naming a defect and starts naming whichever PR happened to run next. It cost one PR a red Backend Lint & Type Check today whose diff contains zero Python files at all, and it will do the same to every other open PR until it clears.

There is also a smaller latent problem underneath the lint finding: the class declares the same property twice, so one of the two definitions is dead code and which one is live depends on declaration order rather than on anything a reader would notice.

What changed (motivation -> approach -> change)

Two changes added the same property independently -- #8536 gave the _Req double a body surface, then #8549 gave it a can_read_body surface -- and the class ended up declaring can_read_body twice. Python keeps the later definition, so the earlier one was already dead with the later one silently in effect.

Removing the earlier one is behaviour-preserving rather than a choice between two behaviours, and that is measurable rather than asserted. _raw is b"" exactly when body is None and a JSON encoding otherwise, so bool(self._raw) (removed) and self._has_body (kept) return the same answer on every constructor path:

body removed definition kept definition agree
None False False yes
{} True True yes
{"a": 1} True True yes

The definition kept is the documented one, whose docstring states the contract the __init__ comment reasons about: a bodyless request must report nothing to read, so read_bounded_json(..., allow_absent=True) takes its empty-object path instead of raising.

Tests

N/A for new tests -- this removes dead code from an existing test helper and adds no behaviour. It is verified by the existing suite and the linter, below.

Manual verification

  • flake8 test/test_slot_close_recreation_race.py -- clean; the F811 is gone.
  • pytest test/test_slot_close_recreation_race.py -- 42 passed.
  • Equivalence of the two definitions checked over all three constructor paths, as tabled above, so nothing depends on which one survived.

Related Issues

Follows #8536 and #8549, which each added the property. Found while driving another PR's checks, where the same failure appeared on a diff with no Python in it.

Pattern harvest

Rule candidate: review-prompt

Pattern: two changes adding the same member to the same class produce a silent shadow, not a conflict. Neither PR conflicts textually, because each inserts at a different point in the class body, so git merges both cleanly and the language keeps only the last one. The result passes every behavioural test -- the surviving definition is one the authors intended -- and shows up only as a lint finding at a line neither author wrote in isolation.

The generalizable check is for the reviewer of the SECOND such PR: when a change adds a property or method to a test double or shim to satisfy a contract, grep the class for that member first. A duplicate is invisible in the diff, because the diff shows only the added block and not the one already there a dozen lines up.

…quest

Backend Lint fails on main: flake8 reports F811 at
test/test_slot_close_recreation_race.py:131, a redefinition of
can_read_body from line 119. Every open PR inherits it through its merge
ref, so the gate reports whichever PR ran next rather than a defect in
that PR.

Two changes added the same property independently -- #8536 gave the
double a body surface, then #8549 gave it a can_read_body surface -- and
the class ended up declaring the property twice. Python keeps the later
definition, so the first was already dead code with the second silently
in effect.

Removing the earlier one is behaviour-preserving rather than a choice
between them, and that is measurable: _raw is b"" exactly when body is
None and a JSON encoding otherwise, so bool(self._raw) and
self._has_body return the same answer on every constructor path -- False
for no body, True for an explicitly-passed {} and for a populated one.
Checked over all three.

The definition kept is the documented one, whose docstring states the
contract the __init__ comment reasons about: a bodyless request must
report nothing to read so read_bounded_json(..., allow_absent=True)
takes its empty-object path.

Verified: flake8 clean on the file, and all 42 tests in it pass.
@chenmingwei23
chenmingwei23 requested a review from a team as a code owner September 4, 2026 22:32
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 2ce240937db19a1ad779c83497309a16fbfd7b21 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Removes the shadowed, already-dead earlier definition — the surviving property is unchanged at runtime, and the equivalence claim checks out against the constructor.

[DESIGN-REVIEWED] 2ce2409

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 2ce240937db19a1ad779c83497309a16fbfd7b21 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2ce2409

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 2ce240937db19a1ad779c83497309a16fbfd7b21: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

The diff removes the shadowed can_read_body (formerly returning bool(self._raw)); the effective definition at line 127 returns self._has_body and remains. Python binds the last definition, so the removed one was dead. For both call patterns (body=None → both False; explicit {} → both True) the two agreed, so removal is a behavioral no-op. Test-only file. Nothing survives falsification.

No findings.

[OPUS-REVIEWED] 2ce2409

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 2ce240937db19a1ad779c83497309a16fbfd7b21: <one-sentence reason>

@iamwhatever

Copy link
Copy Markdown
Collaborator

fix is here #8583

@iamwhatever iamwhatever closed this Sep 4, 2026
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 4, 2026
@bolichen97
bolichen97 deleted the fix/slot-race-duplicate-can-read-body branch September 6, 2026 03:56
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