sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] Conversation summarization does not observe parent cancellation

Open ekumar96 opened this issue 2 months ago • 1 comments

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

Python

Strands Version

1.55.0

Language Runtime Version

Python 3.12.12

Operating System

Amazon Linux 2, x86_64

Installation Method

other

Steps to Reproduce

  1. Install Strands 1.55.0:

    pip install "strands-agents==1.55.0"
    
  2. Run this minimal reproduction:

    import threading
    from types import SimpleNamespace
    
    from strands.agent.conversation_manager import SummarizingConversationManager
    
    
    parent_signal = threading.Event()
    
    
    class RecordingModel:
        def stream(self, *args, cancel_signal=None, **kwargs):
            print(f"received parent signal: {cancel_signal is parent_signal}")
            assert cancel_signal is parent_signal, (
                "summarization did not receive the parent cancellation signal"
            )
    
    
    agent = SimpleNamespace(model=RecordingModel(), cancel_signal=parent_signal)
    manager = SummarizingConversationManager()
    manager._generate_summary_with_model(
        [{"role": "user", "content": [{"text": "Summarize this message."}]}],
        agent,
    )
    
  3. Observe that the model receives cancel_signal=None.

The example invokes the internal summarization path directly so it does not require a real model or enough messages to trigger context reduction.

Expected Behavior

The summarization model receives the parent Agent's current cancellation signal. Setting that signal should stop an in-flight summarization through the same cooperative cancellation mechanism used by normal Agent model calls.

The example should print:

received parent signal: True

Actual Behavior

The example prints:

received parent signal: False

It then raises:

AssertionError: summarization did not receive the parent cancellation signal

SummarizingConversationManager._generate_summary_with_model() calls generate_summary(), which invokes model.stream() without a cancel_signal. A summarization call may therefore continue after a caller disconnects, an application timeout expires, or the parent Agent is cancelled.

Additional Context

Current implementation:

https://github.com/strands-agents/harness-sdk/blob/main/strands-py/src/strands/agent/conversation_manager/summarizing_conversation_manager.py

Shared limits and descendant usage accounting are tracked separately as a feature request.

Possible Solution

Pass agent.cancel_signal through _generate_summary_with_model() and generate_summary() to model.stream(cancel_signal=...).

Add a test that starts a blocking summarization stream, cancels the parent invocation, and verifies that the summarization stream observes the signal and teardown completes promptly.

Related Issues

https://github.com/strands-agents/harness-sdk/issues/4299

ekumar96 avatar Sep 11 '26 17:09 ekumar96

I reproduced this on current main and can confirm the diagnosis. The shared helper generate_summary in strands-py/src/strands/agent/conversation_manager/compression/context_compression.py calls model.stream() with only the messages, tool specs, and system prompt, while the normal invocation path passes cancel_signal=agent._cancel_signal in event_loop.py. Model.stream() already declares the cancel_signal keyword, so the plumbing exists end to end and the helper just drops it.

One addition: there is a second caller with the same gap. _context_manager/modes/agentic/agentic_context.py also calls generate_summary(eligible, agent.model) with no signal, so summarization run by the agentic context-management mode is equally uncancellable.

If maintainers open this to contribution, I can provide a fix for it. Scope: add an optional cancel_signal parameter to generate_summary, pass agent.cancel_signal from both callers, and add regression tests asserting the signal reaches model.stream on both paths, plus a cancellation test where a blocking summarization stream observes the signal and tears down promptly. Whether the dedicated summarization_agent path should forward the parent's signal into its own invocation is a maintainer call, happy to include or exclude it. I'll wait for maintainer's confirmation.

roshangardi avatar Sep 11 '26 19:09 roshangardi