Skip to content

Clean up ContextManagers when a manager fails to enter - #954

Open
remote-controlled-man wants to merge 1 commit into
AnswerDotAI:mainfrom
remote-controlled-man:codex/prflow-d691bf908bd0
Open

remote-controlled-man wants to merge 1 commit into
AnswerDotAI:mainfrom
remote-controlled-man:codex/prflow-d691bf908bd0

Conversation

@remote-controlled-man

Copy link
Copy Markdown

Found while adding setup-error coverage for fastai/fastai#4186. If an early manager acquires a lock and a later manager raises in __enter__, ContextManagers.__enter__ exits without unwinding its ExitStack. The lock stays acquired while the wrapper or traceback is still reachable, so subsequent work can block.

Unwind the already-entered stack with the exception information before propagating the entry failure. Add regression coverage using a real lock and temporary environment state, plus reverse exit order, identical RuntimeError/KeyboardInterrupt objects, later managers/body not entered, successful entry and empty collections. The notebook documents the failure behavior.

Validation on macOS, Python 3.12:

  • The lock/environment regression fails on unchanged main and passes with this fix.
  • Complete native nbdev-test --n-workers 2 suite: passed, with no notebook selection or added skips.
  • Complete 03_xtras.ipynb test, nbdev-clean, source export and clean/diff checks: passed.

The other OS/Python combinations in the CI matrix were not run locally.

AI assistance: OpenAI Codex assisted implementation, tests and review.

Copilot AI balanced review requested due to automatic review settings October 31, 2026 06:03

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

This branch has not been deployed

No deployments
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