mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-03 16:25:53 +00:00
When a user sends /stop to interrupt an active agent turn, the task is cancelled via CancelledError. Previously, the cancellation handler just logged and re-raised, discarding any tool results and assistant messages accumulated during the interrupted turn. The runtime checkpoint mechanism already persists partial turn state (assistant messages, completed tool results, pending tool calls) into session metadata via _emit_checkpoint. However, this checkpoint was only materialized into session history on the NEXT incoming message via _restore_runtime_checkpoint — not at cancellation time. Now the CancelledError handler in _dispatch calls _restore_runtime_checkpoint immediately, so the partial context is preserved in session history. This means the next message the user sends will see all the work that was done before /stop, rather than starting from scratch. Fixes #2966 Includes 3 tests verifying checkpoint restoration on cancellation.