[controllers] fix: clear state on thread start failure - #261
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
📝 WalkthroughWalkthroughCudaGPUController.keep() and MacMGPUController.keep() now wrap thread startup in try/except blocks that reset ChangesThread Start Failure Cleanup
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 (1)
src/keep_gpu/single_gpu_controller/cuda_gpu_controller.py (1)
127-132: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting shared thread-start cleanup helper.
The try/except-reset-reraise block is now duplicated verbatim across CUDA, MacM, and ROCm controllers (ROCm additionally calls
_shutdown_rocm_smi()). Could be pulled into a small helper onBaseGPUController(e.g., accepting an optional cleanup callback) to avoid drift between the three.🤖 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 `@src/keep_gpu/single_gpu_controller/cuda_gpu_controller.py` around lines 127 - 132, The thread-start failure cleanup in CudaGPUController.start is duplicated across multiple GPU controllers, so extract it into a shared helper on BaseGPUController to keep the reset-and-reraise behavior consistent. Move the self._thread/self._stop_evt reset logic into a small reusable method that wraps thread.start() and accepts an optional cleanup callback for controller-specific work like ROCm’s _shutdown_rocm_smi(), then update the CUDA, MacM, and ROCm start paths to call that helper instead of inlining the try/except block.
🤖 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 `@src/keep_gpu/single_gpu_controller/cuda_gpu_controller.py`:
- Around line 127-132: The thread-start failure cleanup in
CudaGPUController.start is duplicated across multiple GPU controllers, so
extract it into a shared helper on BaseGPUController to keep the
reset-and-reraise behavior consistent. Move the self._thread/self._stop_evt
reset logic into a small reusable method that wraps thread.start() and accepts
an optional cleanup callback for controller-specific work like ROCm’s
_shutdown_rocm_smi(), then update the CUDA, MacM, and ROCm start paths to call
that helper instead of inlining the try/except block.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 45b8f5e5-dc30-49ec-a27e-a8a0b1efbc6c
📒 Files selected for processing (4)
src/keep_gpu/single_gpu_controller/cuda_gpu_controller.pysrc/keep_gpu/single_gpu_controller/macm_gpu_controller.pytests/cuda_controller/test_keep_and_release.pytests/macm_controller/test_macm_backoff.py
|
Resolved CodeRabbit nitpick: I checked the suggested shared helper and am leaving the cleanup explicit in this PR. The duplicated block is intentionally tiny and backend-local, while ROCm has controller-specific vendor cleanup and CUDA/MPS do not. Moving this into |
Summary
_threadand_stop_evtwhenThread.start()raises_threadand_stop_evtwhenThread.start()raisesWhy
A thread/resource startup failure can happen before a keep worker ever runs. CUDA and MPS previously left a stale thread object and stop event behind on that path, while ROCm already cleaned them up. This aligns all single-GPU controllers with the startup lifecycle contract in
AGENTS.md.Local verification
_threadretained the fakeFailingThreadobject.PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$PWD/src pytest -p no:cacheprovider tests/cuda_controller/test_keep_and_release.py::test_cuda_keep_clears_state_when_thread_start_fails tests/macm_controller/test_macm_backoff.py::test_macm_keep_clears_state_when_thread_start_fails -q(2 passed)PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$PWD/src pytest -p no:cacheprovider tests/cuda_controller/test_keep_and_release.py tests/macm_controller/test_macm_backoff.py tests/rocm_controller/test_rocm_backoff.py -q(63 passed, 2 skipped)PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$PWD/src pytest -p no:cacheprovider tests/cuda_controller tests/macm_controller tests/rocm_controller tests/single_gpu_controller tests/global_controller tests/utilities/test_platform_manager.py tests/utilities/test_gpu_info.py -q(259 passed, 11 skipped)pre-commit run --all-files --show-diff-on-failurePYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$PWD/src pytest -p no:cacheprovider tests -q(1022 passed, 11 skipped)git diff --check2 passed)Local review
Local subagent review completed with no Critical, Important, or Minor findings. Reviewer confirmed the cleanup preserves the original exception, avoids unnecessary cache/vendor cleanup, matches ROCm behavior, and needs no docs update because the AGENTS lifecycle contract already covers this behavior.
Summary by CodeRabbit