Conversation
DABH
force-pushed
the
evidence/sandbox-importer-lock-race
branch
2 times, most recently
from
September 20, 2026 06:33
782ae7f to
84532f3
Compare
DABH
force-pushed
the
evidence/sandbox-importer-lock-race
branch
from
September 20, 2026 06:34
84532f3 to
4bc0a5a
Compare
Evidence for #1833. Both tests fail on main under Python 3.10 with the KeyError(<thread id>) from importlib._bootstrap._ModuleLock.acquire behind the 'Failed validating workflow' flake (#585), and pass with #1833. The natural variant patches no CPython internals and passes on 3.12+, where python/cpython#91351 is fixed.
DABH
force-pushed
the
evidence/sandbox-importer-lock-race
branch
from
September 20, 2026 07:00
4bc0a5a to
cfaefda
Compare
This branch has not been deployed
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.
Draft, not for merge — evidence for #1833 (the
Failed validating workflow/KeyError: <thread id>flake, tracked as #585 since July 2024).Two tests against
main's sandbox importer. Both fail on every Python 3.10 lane here and pass on #1833; both skip on 3.12+, where CPython fixed its side of the bug:test_workflow_sandbox_importer_loaded_module_import_inside_module_lock— the regression test from Skip importlib for already-loaded modules in the workflow sandbox #1833, standalone. Rebuilds_ModuleLock.acquirefrom the interpreter's own_bootstrap.pywith an import of the already-loadedwarningsmodule placed inside the_blocking_on[tid]window, which is what a GC finalizer'sRuntimeWarningdoes mid-import. Fails with the CI signature:_importer.py → importlib.__import__ → _find_and_load → _ModuleLockManager.__enter__ → acquire → KeyError(<tid>).test_workflow_sandbox_importer_survives_gc_finalizer_imports— the same failure with no CPython internals touched: a garbage cycle whose finalizer imports the already-loadedwarningsmodule is kept perpetually pending, andgc.set_threshold(1)runs the collector at nearly every allocation. Onmainunder 3.10 every sandboxed import ofasyncioraisesKeyError(3/3 in CI on all six 3.10 lanes, 300/300 locally); on Skip importlib for already-loaded modules in the workflow sandbox #1833, 0.Why 3.10 only: CPython's C
__import__returns a module already insys.moduleswithout touching a module lock, and since 3.12 the pure-Pythonimportlib._find_and_loaddoes too ("Optimization: we avoid unneeded module locking if the module already exists in sys.modules and is fully initialized"), withacquiremade re-entrant in python/cpython#91351. The sandbox routes every import through pure-Pythonimportlib.__import__, which on 3.10/3.11 acquires the module lock before checkingsys.modules, so every sandboxed import of an already-loaded module opens the window the bug lives in. #1833 does for the sandbox what 3.12 does natively: serve fully-loaded modules straight fromsys.modulesand leave first-time loads (andfromlist/ relative forms) on importlib.Local runs (
_importer.pyswapped betweenmainand #1833, same test file):