Skip to content

Feat:Implement chat.abort WebSocket RPC for Streaming Run Interruption #317

@flyflypeng

Description

@flyflypeng

Problem Statement

Currently, once a chat streaming run starts, users have no way to interrupt it. This creates several UX problems:

  1. Long-running generations : When the agent produces lengthy responses, users must wait for completion before starting a new interaction
  2. Stuck tool loops : If the agent enters an unintended tool execution loop, there's no escape mechanism
  3. Changed intent : Users may realize they asked the wrong question or want to rephrase, but cannot stop the current generation
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions