Skip to content

Keep the mutex handoff test waiter locked until observation - #9273

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/lock-handoff-test-order
Oct 21, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/lock-handoff-test-order

Conversation

@youknowone

Copy link
Copy Markdown
Member

Summary

Keep the existing native unlock_hands_off_to_starved_waiter test's waiter holding its mutex until the parent has sampled the immediate fast-acquire attempt. Previously, the waiter could acquire and unlock before that assertion, allowing a correct handoff to look like failure.

The parent still attempts lock_fast immediately after unlock, without waiting for a waiter-acquired acknowledgement. It then releases any accidentally acquired lock, drops the owned release channel, joins the waiter, and asserts the captured result. This preserves the existing observation while avoiding a failure assertion that strands the waiter.

This is a separate, main-based CI repair discovered while validating the Python 3.15 AST extraction in #9272. Only the existing Rust test changes. There are no production locking changes, Python-behavior Rust tests, new snippets, library changes, skips, increased sleeps, or weakened assertions.

Validation

  • Guarded Linux cargo test --locked --offline -p rustpython-vm --features threading --lib --no-run passed.
  • The exact existing test passed in three separate processes, each with a 30-second external deadline: one passed, none ignored, 0.02 seconds per run. This was a fixed small check, not stress testing or rerun-until-green.
  • Strict affected-package all-target Clippy and applicable configured hooks passed.
  • Builds used one Cargo job, disabled incremental compilation, a six-GiB per-process address-space limit, disabled core dumps, resource reserves, and external timeouts. Existing dependency caches were reused.

Limits

The inherited test failed at its fast-acquire assertion in #9272's Linux job; its source is unchanged from that PR's base. The source demonstrates the early-unlock ordering flaw, but these checks do not prove that interleaving caused the hosted failure or eliminate all possible flakiness.

The existing HAS_PARKED flag precedes parking-lot queue insertion, so the unchanged 20 ms setup delay is still a scheduling assumption. This is not exhaustive fairness proof. Channel drop releases the waiter on parent unwind, but does not provide universal cleanup for panics while a mutex is held or broken mutex implementations. No full native suite or cross-platform local run is claimed.

AI assistance

Codex assisted with source review, the minimal test repair, bounded validation, and PR preparation for the maintainer-directed Python 3.15 upgrade. The model version was not exposed. No claim of manual human testing is made.

Hold the existing waiter's lock through the parent's immediate fast-acquire
sample, then release and join it before asserting the recorded outcome.
Do not change the production mutex or its existing fairness setup delay.

Assisted-by: OpenAI Codex:model-version-unavailable
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone marked this pull request as ready for review October 21, 2026 16:09
@youknowone
youknowone merged commit a2c8642 into RustPython:main Oct 21, 2026
21 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T16:33:06.332630Z f6b1a71 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6b1a71165

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

#[test]
fn unlock_hands_off_to_starved_waiter() {
let m = Arc::new(PyMutex::new());
let (release_waiter, wait_for_release) = std::sync::mpsc::channel::<()>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required AI-assistance trailer

The commit message explicitly says Codex assisted, but it contains no Assisted-by: AGENT_NAME:MODEL_VERSION trailer. RustPython requires that exact trailer for every AI-assisted contribution, so this commit's metadata must be corrected before integration.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

std::thread::spawn(move || {
m.lock();
// Keep ownership until the parent has checked the handoff.
let _ = wait_for_release.recv();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep normal acquisition from satisfying the handoff test

If the implementation regresses to a normal (non-TOKEN_HANDED_OFF) wake-up and the unparked waiter is scheduled before the parent reaches lock_fast, the waiter can acquire the now-unlocked mutex normally. This new recv then keeps that ordinary acquisition locked until after the check, so lock_fast returns false and the handoff test passes despite no direct handoff; the test needs to observe the handoff token/state without allowing an ordinary acquisition to satisfy the assertion.

Useful? React with 👍 / 👎.

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