fix(prewarm): critical imports must fail the script, normalize dep specs#1609
Merged
fix(prewarm): critical imports must fail the script, normalize dep specs#1609
Conversation
Two issues from code review: 1. (High) The warmup script wrapped ALL imports in try/except, so a broken environment (missing ipykernel) would still exit 0 and be admitted to the pool. Now ipykernel and IPython are bare imports that crash the script on failure, matching the old behavior. 2. (Medium) User-configured dependency specifiers (e.g. "numpy>=1.24", "scikit-learn") were passed raw to importlib.import_module(), which would silently fail. Added normalize_module_name() to strip version specs and convert hyphens, restoring the old package_import_name() behavior.
Contributor
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
Fixes two issues from Codex code review of #1608:
(High) Broken env admitted to pool: The warmup script wrapped ALL imports in
try/except, so missing ipykernel/IPython would silently succeed and the env would be marked.warmed. NowipykernelandIPythonare bare imports that crash the script on failure, matching the pre-prewarm behavior.(Medium) User dep specs not normalized: Dependency specifiers like
numpy>=1.24orscikit-learnwere passed raw toimportlib.import_module(), which silently failed. Addednormalize_module_name()to strip version specs and convert hyphens to underscores, restoring the oldpackage_import_name()behavior.Test plan
uv run pytest python/prewarm/tests/ -v)test_normalize_module_name,test_collect_modules_normalizes_specs,test_build_warmup_script_critical_imports_not_wrappedkernel-env::warmuptests pass (cargo test -p kernel-env -- warmup)cargo xtask lint)