Skip to content

[BUG] SlidingWindowConversationManager: window_size=0 fails to clear messages #2205

@opieter-aws

Description

@opieter-aws

Steps to Reproduce

With window_size=0 and 2 messages: trim_index = len(messages) - 0 = 2. The while trim_index < len(messages) loop condition (2 < 2) is immediately false, so the else clause fires — treating it as "no valid trim point found".

  • With e=None (routine management): logs a warning and leaves messages unchanged
  • With e set (overflow): raises ContextWindowOverflowException

TypeScript explicitly supports window_size=0 as "remove all messages" and has a test for it.

Expected Behavior

window_size=0 should either:

  1. Clear all messages (matching TypeScript behavior), or
  2. Be rejected at construction time with a ValueError if it's not a valid configuration

Actual Behavior

window_size=0 silently fails to clear messages during routine management, or raises an exception during overflow handling.

Possible Solution

Either add a special case for window_size=0 before the trim loop, or validate window_size >= 1 in __init__.

Additional context

This was a finding from an agentic cross-SDK consistency scan between Python and TypeScript SDKs (strands-agents/sdk-typescript#789). The finding has been triaged, but verify that this needs an actual fix.

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