Skip to content

Restore detached thread state after nested VM entry - #10175

Open
1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:attachment_restore
Open

1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:attachment_restore

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Addresses the nested-entry restoration issue identified during the bootstrap investigation in #8944.

Summary

  • Preserve the previous attachment state across nested VM entry and saved-context restoration, including unwinding and interpreter initialization.
  • Keep callbacks inside allow_threads from leaving the thread attached during the remaining blocking work. This preserves GC stop-the-world cooperation and keeps suspended critical-section locks released until the outer scope resumes.

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Improved thread attachment handling when entering nested interpreters. Threads now preserve their prior attached or detached state after normal returns and panic unwinding, and remain detached until the enclosing thread-permission scope ends. This prevents nested interpreter activity from unexpectedly changing the parent thread’s attachment state.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T08:26:17.380666Z 5e8a837 PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Interpreter sections and saved thread state now preserve the thread’s attachment status. Section teardown restores the enclosing interpreter only when it was attached on entry. A threading-only regression test covers nested entry from a detached parent during normal return and panic unwinding.

Changes: Interpreter attachment state

Layer / File(s) Summary
Interpreter section lifecycle
crates/vm/src/vm/thread.rs, crates/vm/src/vm/interpreter.rs
InterpreterSection records whether the enclosing interpreter was attached. Section setup and teardown use this state, and the bootstrap and current-VM paths pass it through. A threading-only test checks nested entry and restoration after return or panic unwinding.
Saved thread attachment state
crates/vm/src/vm/thread.rs
SavedThreadState records whether the thread was attached. Saving detaches only an attached thread, and restoring reattaches only when the saved state indicates it was attached.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: youknowone, youknowdot

Merge Risk: Minimal · up to 5e8a8

The change restores the previous thread attachment state after nested interpreter entry and saved-context restoration. No concrete defect was identified, and a regression test covers the detached-parent case, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: restoring the detached thread state after nested VM entry. The raw summary shows the thread.rs and interpreter.rs changes save and restore the prior attachment state o…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: restoring the detached thread state after nested VM entry. The raw summary shows the thread.rs and interpreter.rs changes save and restore the prior attachment state on nested entry and exit, and add a test for this. The title is specific and matches the PR objectives.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cfd00b0 and 5e8a837.

Files selected for processing: 2

  • crates/vm/src/vm/interpreter.rs
  • crates/vm/src/vm/thread.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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.

1 participant