Repository navigation
Conversation
Introduce a restart-based retry strategy for actor tasks that cannot recover through retries in the same process. Faults such as a poisoned CUDA context or a failed engine subprocess can leave the actor alive but unusable, requiring a fresh process for recovery. Support recovery by restarting the actor process before retrying the task. Add an actor-only restart_on_exceptions option with case-insensitive substring matching against exception types, messages, and cause/context chains. Matching exceptions trigger a worker exit, allowing Ray to reconstruct the actor in a fresh process. Use max_restarts to control actor reconstruction and max_task_retries to control task retries. The new option is disabled by default and does not change either budget. Actor reconstruction reruns the constructor but does not restore application state. Propagate restart requests from async streaming generators to the task thread before exiting, avoiding event-loop termination hangs. Cover static and dynamic generator failures and safely handle exceptions whose __str__ fails. Document the recovery semantics and add tests for restart-budget exhaustion, retry precedence, and partial-output recovery. Validation: - Rebuilt //:_raylet. - Original test module and repository conftest: 22 passed using current source and freshly built native artifacts in an isolated package. - Applicable pre-commit hooks and git diff --check passed. Signed-off-by: dragongu <andrewgu@vip.qq.com>
991958f to
09134f6
Compare
There was a problem hiding this comment.
Code Review
This pull request implements the restart_on_exceptions feature for Ray actors, allowing actors to automatically restart on a fresh process when specific exception substring patterns are matched. The changes span across documentation, Python option validation, Cython bindings, C++ task specifications, and protobuf definitions, alongside comprehensive unit tests. The feedback suggests a minor but important improvement in python/ray/_raylet.pyx to explicitly check if __cause__ is not None instead of using the or operator, preventing potential issues with custom exceptions that evaluate to False in a boolean context.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Reviewed by Cursor Bugbot for commit 09134f6. Configure here.
Check exception causes explicitly against None instead of evaluating their truthiness. Add regression coverage for falsey causes and causes whose __bool__ raises, preserving cause precedence over context. Move option validation and exception-matching unit tests to tests/unit, leaving actor recovery integration tests in the existing module. Document the new C++ pattern accessors with Doxygen comments. Validation: - Rebuilt //:_raylet. - Original unit and integration test files with repository conftests: 24 passed using current source and freshly built native artifacts in an isolated package. - Applicable pre-commit hooks and git diff --check passed. Signed-off-by: dragongu <andrewgu@vip.qq.com>

Description
Support retrying actor tasks in a fresh process when they raise exceptions that cannot be recovered from by retrying in the same process.
For example, a CUDA error can leave the GPU context unusable, or an engine failure can leave an actor with a dead subprocess. The actor process may remain alive, but subsequent attempts in that process continue to fail. Recovering requires restarting the actor rather than retrying the task in place.
This PR adds an actor-only
restart_on_exceptionsoption. Users specify case-insensitive substring patterns to match exception type names, messages, and__cause__/__context__chains. When an exception matches, Ray terminates the actor worker, reconstructs the actor if its restart budget permits, and retries the failed task if its task-retry budget permits.The option is disabled by default and reuses the existing
max_restartsandmax_task_retriessettings. Non-matching exceptions retain their existing behavior.Additional information
Usage
restart_on_exceptionsselects which exceptions require process-level recovery;max_restartslimits actor reconstruction, andmax_task_retrieslimits retries of failed calls. Settingrestart_on_exceptionsalone does not enable either budget.Behavior and implementation
retry_exceptions=Trueis enabled.__str__fails are formatted safely.SystemExiton the shared event loop, which can leave the task thread waiting indefinitely for its future.This PR is Core-only. Ray Data integration is deferred to a follow-up.
Testing
git diff --checkpassed.The isolated package avoids the older Ray wheel installed in the shared virtual environment, which cannot load the current conftest without the source
PYTHONPATH. Protobuf staging applied the existing BUILD import rewrites using Python becauseunzipis unavailable. A full package build and the complete Core regression suites have not been validated.