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:
- Clear all messages (matching TypeScript behavior), or
- 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.
Steps to Reproduce
With
window_size=0and 2 messages:trim_index = len(messages) - 0 = 2. Thewhile trim_index < len(messages)loop condition (2 < 2) is immediately false, so theelseclause fires — treating it as "no valid trim point found".e=None(routine management): logs a warning and leaves messages unchangedeset (overflow): raisesContextWindowOverflowExceptionTypeScript explicitly supports
window_size=0as "remove all messages" and has a test for it.Expected Behavior
window_size=0should either:ValueErrorif it's not a valid configurationActual Behavior
window_size=0silently fails to clear messages during routine management, or raises an exception during overflow handling.Possible Solution
Either add a special case for
window_size=0before the trim loop, or validatewindow_size >= 1in__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.