Skip to content

Streaming runs can't be canceled gracefully #1895

@habema

Description

@habema

Problem

When canceling a streaming run with result.cancel(), it stops immediately and discards the current turn. This means:

  • The incomplete turn isn't saved to the session
  • Usage tracking is cut off mid-turn
  • Can't resume the session cleanly

This is painful if the user interrupts a long task - all progress from current turn is lost, and its usage cant be tracked.

Current behavior

result = Runner.run_streamed(agent, "Task", session=session)
async for event in result.stream_events():
    if timeout:
        result.cancel()  # Stops immediately, turn is discarded

Would be nice to have a way to let the current turn complete before stopping.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions