Expand description
Interrupt signal handling for graceful checkpoint save.
This module provides signal handling for the Ralph pipeline, ensuring clean shutdown when the user interrupts with Ctrl+C.
When an interrupt is received:
- If the reducer event loop is running, the handler sets a global interrupt request
flag and returns. The event loop consumes that flag and performs the reducer-driven
termination sequence (
RestorePromptPermissions->SaveCheckpoint-> shutdown). - If the event loop is not running yet (early startup), the handler falls back to a best-effort checkpoint save and exits with the standard SIGINT code (130).
§Ctrl+C Exception for Safety Check
The interrupted_by_user flag distinguishes user-initiated interrupts (Ctrl+C)
from programmatic interrupts (AwaitingDevFix exhaustion, completion marker emission).
When set to true, the pre-termination commit safety check is skipped because
the user explicitly chose to interrupt execution. This respects user intent while
ensuring all other termination paths commit uncommitted work before exiting.
Structs§
- Event
Loop Active Guard - RAII guard that marks the reducer event loop as active.
- Interrupt
Context - Context needed to save a checkpoint when interrupted.
Functions§
- clear_
interrupt_ context - Clear the global interrupt context.
- event_
loop_ active_ guard - Mark the reducer event loop as active for the duration of the returned guard.
- is_
user_ interrupt_ requested - Check if a user interrupt request is pending without consuming it.
- request_
exit_ 130_ after_ run - Request that the process exit with code 130 once the pipeline returns.
- request_
user_ interrupt - Request that the running pipeline treat the run as user-interrupted.
- set_
interrupt_ context - Set the global interrupt context.
- setup_
interrupt_ handler - Set up the interrupt handler for graceful shutdown with checkpoint saving.
- take_
exit_ 130_ after_ run - Consume a pending exit-130 request.
- take_
user_ interrupt_ request - Consume a pending user interrupt request.
- user_
interrupted_ occurred - Check if a user interrupt has occurred at any point during this process lifetime.