Fix tracing-state leak after transform exceptions#9013
Conversation
📝 WalkthroughWalkthrough
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/transforms/inverse/test_traceable_transform.py (1)
32-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a docstring to the new test.
Document that the test verifies tracing state restoration after an exception.
As per path instructions, every Python definition should have an appropriate Google-style docstring.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/transforms/inverse/test_traceable_transform.py` around lines 32 - 42, Add an appropriate Google-style docstring to the test_trace_transform_restores_state_after_exception method documenting that it verifies the tracing state is restored after an exception. Keep the test behavior and assertions unchanged.Source: Path instructions
monai/transforms/inverse.py (1)
404-411: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the context-manager contract.
Add a Google-style
Argssection forto_traceand document that the previous tracing state is restored on both normal and exceptional exits.As per path instructions, Python definitions should use Google-style docstrings documenting their parameters, returns, and raised exceptions where applicable.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@monai/transforms/inverse.py` around lines 404 - 411, Update the trace_transform method docstring to use Google style, adding an Args section describing to_trace and documenting that the prior tracing state is restored when the context manager exits normally or with an exception. Preserve the existing tracing behavior.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@monai/transforms/inverse.py`:
- Around line 404-411: Update the trace_transform method docstring to use Google
style, adding an Args section describing to_trace and documenting that the prior
tracing state is restored when the context manager exits normally or with an
exception. Preserve the existing tracing behavior.
In `@tests/transforms/inverse/test_traceable_transform.py`:
- Around line 32-42: Add an appropriate Google-style docstring to the
test_trace_transform_restores_state_after_exception method documenting that it
verifies the tracing state is restored after an exception. Keep the test
behavior and assertions unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7e06f2a2-40f2-4c16-a380-473f6e7e7b29
📒 Files selected for processing (2)
monai/transforms/inverse.pytests/transforms/inverse/test_traceable_transform.py
Signed-off-by: kyinhub <kevinpyin@gmail.com>
b5b4230 to
55a0e95
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Closes #7701.
Description
TraceableTransform.trace_transform()now restores the previous tracing state even when code inside the context manager raises. The original exception still propagates unchanged.The previous implementation restored
self.tracingonly after a normalyield, so an exception permanently leaked the temporary tracing value into the transform. This caused later inverse transforms to fail withTransform Tracing must be enabledafter a caught CUDA OOM or other runtime exception.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.Validation
upstream/devwith leaked tracing state;python -m pytest tests/transforms/inverse/test_traceable_transform.py -q: 2 passed;ruff checkon both touched files;git diff --check.