Skip to content

Fix Python initialization leases acquired during owner drain - #214

Merged
leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-fix-owner-drain-reentrancy
Oct 9, 2026
Merged

leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-fix-owner-drain-reentrancy

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix COM apartment initialization bookkeeping when owner cleanup releases a delegate whose captured Python object's __del__ calls ro_initialize(). Counters saved before cleanup previously overwrote newly acquired initializations, including successful S_FALSE calls, leaving a native initialization that public ro_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.

leileizhang (lei9444) and others added 2 commits October 8, 2026 19:13
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
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 87.11% 82.67% 86.83% regions
Python aggregate 72.23% n/a 39.27% branches
Python runtime 98.17% n/a 94.57% branches
Generated Python WinRT projections 70.94% n/a 33.32% branches
Generated Python WinRT implementations 71.97% n/a 46.3% branches
JavaScript aggregate 18.5% 24.91% 56.05% branches
JavaScript runtime 44.27% 45.76% 78.99% branches
Generated WinRT projections 17.36% 19.38% 52.59% branches
Generated WinRT implementations 45.99% 59.19% 60.97% branches
Generated Classic COM projections 11.52% 23.97% 53.4% branches

View workflow run and download full HTML/LCOV/XML reports

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
@lei9444
leileizhang (lei9444) merged commit be85106 into main Oct 9, 2026
33 checks passed
@lei9444
leileizhang (lei9444) deleted the lei9444-fix-owner-drain-reentrancy branch October 9, 2026 01:57
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.

3 participants