Repository navigation
Import hook: never wrap an already-wrapped loader - #143
Merged
Merged
Conversation
Another finder on sys.meta_path can re-enter the import system and hand back a spec this hook has already wrapped. ALCF's XALT sitecustomize finder (RecorderRTM, on PYTHONPATH on Polaris compute nodes) does exactly that, and the hook then nested GroundhogLoader hundreds deep (494 for `import ase`), overflowing the stack while importing the user script (RecursionError or a segfault, exit 139). Wrap only loaders that are not GroundhogLoader already. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
GroundhogImportHook.find_specwrappedspec.loaderunconditionally. Another finder onsys.meta_pathcan re-enter the import system and hand back a spec this hook already wrapped, and each re-entry added anotherGroundhogLoaderlayer.Found on ALCF Polaris compute nodes, where
PYTHONPATH=/soft/xalt/.../site_packagesinstalls XALT'ssitecustomize.RecorderRTMmeta-path finder: inside a groundhog task,import aseended up 494 loaders deep and importing a script that pulls in academy died withRecursionError(or a segfault, exit 139) inside pydantic. The same env on macOS wraps once.Fix: only wrap loaders that are not already
GroundhogLoader. Test simulates a re-entrant finder that caches and returns the same spec and asserts the depth stays 1.Test plan
uv run pytest(385 passed),uv run ruff check .,uv run ty check .🤖 Generated with Claude Code