-
Notifications
You must be signed in to change notification settings - Fork 117
Feat:Implement chat.abort WebSocket RPC for Streaming Run Interruption #317
Copy link
Copy link
Closed
Description
Problem Statement
Currently, once a chat streaming run starts, users have no way to interrupt it. This creates several UX problems:
- Long-running generations : When the agent produces lengthy responses, users must wait for completion before starting a new interaction
- Stuck tool loops : If the agent enters an unintended tool execution loop, there's no escape mechanism
- Changed intent : Users may realize they asked the wrong question or want to rephrase, but cannot stop the current generation
- Resource waste : Continued processing of unwanted responses consumes unnecessary compute resources
The chat.abort method is compatible with the chat.abort method provided by OpenClaw, following the same RPC interface specification and parameter format to ensure seamless client migration or reuse of existing implementations.
Proposed Solution
Implement a chat.abort WebSocket RPC method that allows clients to signal cancellation of an active streaming run.
Key Features
- Lock-free abort signaling : Uses Arc for thread-safe cancellation flags keyed by run_id
- Partial response recovery : Returns any text generated before abort, so users don't lose progress
- Clean event semantics : Introduces AgentEvent::Cancelled variant instead of magic string detection
- Full pipeline integration :
- WebSocket handler receives abort command
- Sets atomic flag in global abort registry
- Notifies agent loop via run_control::abort_runs
- Stream detects abort and publishes "aborted" event with partial text
Observability
INFO-level logging added at key checkpoints:
- Abort completion with session/run/chat IDs
- Abort firing with run count
- Agent loop cancellation detection
- Stream abort response detection
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels