Repository navigation
fix(hooks): register dynamically loaded hook modules - #606
Open
林SO (Linxiushen) wants to merge 1 commit into
Open
林SO (Linxiushen) wants to merge 1 commit into
林SO (Linxiushen) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused implementation correctly addresses the loader defect and includes comprehensive regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes dynamic hook loading by registering path-unique modules, enabling postponed annotations and pickle support.
Changes:
- Registers hook modules in
sys.moduleswith deterministic path-based names. - Restores prior module state when loading fails.
- Adds regression coverage for dataclasses, pickling, module isolation, and failures.
| File | Description |
|---|---|
agentlightning/hooks.py |
Adds collision-resistant module registration and rollback. |
tests/test_hooks.py |
Tests successful loading, isolation, pickling, and cleanup. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Fixes #605
Custom rollout hooks containing a dataclass and
from __future__ import annotationsfail during loading becauseload_hooksdoes not register the executing module insys.modules. Register the module before execution, use a name derived from its resolved path so different hook files do not collide, and restore the previous registration if execution, validation, or construction fails.The regression tests load real Python files and execute
on_enqueuewithRolloutCreate. They cover postponed annotations, independent module identities through pickle round trips, and rollback after module execution, class validation, or constructor errors. On the original source these tests produce 6 failures and 2 passes; all 8 pass with the fix.Validation:
uv sync --frozen --no-default-groups --extra dev --group dev --group verl-cpufollowed byuv run --locked --no-sync pytest -v --durations=20 tests: 128 passed, on Linux/Python 3.12.14 with CPU PyTorch.uv run --locked --no-sync pyright: 0 errors, 0 warnings.uv build: source distribution and wheel built successfully.Developed with Codex assistance and independent agent review. No GPU training was run; this change is confined to the Python hook loader.