Repository navigation
Fix Python initialization leases acquired during owner drain - #214
Merged
Merged
Conversation
Preserve successful initializations acquired by captured finalizers during native owner cleanup. Reserve manual and pending-close leases before Python reentry and restore them on failed cleanup. Add real delegate/native-balance regressions for STA and MTA, including retry and nested pairing paths. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7c6c22be-5bc5-4ef3-a9e9-aff640a91c27
Resolve the sibling regression runner by filename so isolated and embeddable Python execute the same complete scenario matrix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7c6c22be-5bc5-4ef3-a9e9-aff640a91c27
Mixed-language test coverageWorkflow status: ✅ Passed
|
Kai Tao (vanzue)
approved these changes
Oct 8, 2026
Resolve the #205 runtime integration without weakening callback-close checks or owner-thread recovery. Reserve and restore the exact local or foreign cleanup-failure lease before Python reentry, retaining the retry guard and new initializations acquired during drain. Extend real local/foreign recovery and native-balance regression coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7c6c22be-5bc5-4ef3-a9e9-aff640a91c27
shisan (qiutongMS)
approved these changes
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix COM apartment initialization bookkeeping when owner cleanup releases a delegate whose captured Python object's
__del__callsro_initialize(). Counters saved before cleanup previously overwrote newly acquired initializations, including successfulS_FALSEcalls, leaving a native initialization that publicro_uninitialize()could no longer balance.This is a pre-existing owner-drain accounting defect, distinct from the synchronous callback teardown issue addressed by #205.
Changes
Subtract the closing initialization from the current managed count after owner drain, rather than a saved snapshot. Manual closes and pending-close retries reserve their own in-flight lease before Python reentry and restore it on cleanup failure, preserving newly acquired initializations and preventing double consumption.
Preserve the callback-close guard, owner-thread recovery, native reference ownership, async cancellation policy, and public API.
Regression coverage
Add real delegate-finalizer cases for STA/MTA, context/manual close, nested initialization, failed cleanup, and pending-close retry. Check native reference release, successful public initialization pairing, and entry into the opposite apartment model once all initializations are balanced. Retain the existing unscoped lifetime and callback teardown regressions.