Skip to content

fix(test): update session integ test for sliding window conversation manager#2092

Merged
mkmeral merged 1 commit intostrands-agents:mainfrom
mkmeral:fix/update-session-integ-test-for-sliding-window
Apr 8, 2026
Merged

fix(test): update session integ test for sliding window conversation manager#2092
mkmeral merged 1 commit intostrands-agents:mainfrom
mkmeral:fix/update-session-integ-test-for-sliding-window

Conversation

@mkmeral
Copy link
Copy Markdown
Contributor

@mkmeral mkmeral commented Apr 8, 2026

Description

The integration test test_agent_with_file_session_and_conversation_manager fails after #2087 which enforces that the first remaining message after sliding window trimming must be a user message.

The test used window_size=1, which can no longer trim a simple (no-tool) conversation — after one turn the messages are [user, assistant], and trimming to 1 would leave only [assistant], which violates the new user-first rule. The conversation manager now correctly skips trimming in this case, leaving 2 messages instead of the expected 1.

This PR updates the test to use window_size=2 and adds a second agent call before the session reload, which still exercises all the same behaviors:

  • Session manager persists all messages (including ones trimmed from agent memory)
  • Conversation manager trims in-memory messages when the window is exceeded
  • Trimming happens before the session reload (not just after)
  • Restored agent loads the trimmed state correctly
  • removed_message_count is tracked and restored across sessions
  • Full message history is preserved in the session across multiple turns

With window_size=2, two agent calls produce 4 messages which get trimmed to 2 [user, assistant] — a valid window starting with a user message. After restoring and calling again, a third trim verifies the state was correctly persisted and restored.

Related Issues

Follow-up to #2087

Type of Change

Bug fix

Testing

Ran the integration test suite locally. The updated test passes with the new sliding window behavior.

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…forcement

The sliding window conversation manager now enforces that the first
remaining message after trimming is a user message (strands-agents#2087). This makes
window_size=1 unable to trim simple (no-tool) conversations since the
sole remaining message would be an assistant message.

Update the test to use window_size=2 which still validates:
- Session manager persists all messages (including trimmed ones)
- Conversation manager trims in-memory messages after exceeding window
- Restored agent loads trimmed state correctly
- removed_message_count is tracked and restored properly
- Full message history is preserved in session across multiple turns
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mkmeral mkmeral merged commit 289e22a into strands-agents:main Apr 8, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants