Skip to main content

Module interrupt

Module interrupt 

Source
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§

EventLoopActiveGuard
RAII guard that marks the reducer event loop as active.
InterruptContext
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.