Skip to content

fix: prune stale tool results during session repair#2299

Open
he-yufeng wants to merge 1 commit into
strands-agents:mainfrom
he-yufeng:fix/session-tool-result-repair
Open

fix: prune stale tool results during session repair#2299
he-yufeng wants to merge 1 commit into
strands-agents:mainfrom
he-yufeng:fix/session-tool-result-repair

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • prune orphaned or duplicate toolResult blocks while repairing restored session histories
  • keep the existing matching results and add only the missing interruption results, so the next user message matches the preceding assistant toolUse blocks
  • add a regression test for mixed duplicate/stale/missing tool-result history

Fixes #2296

Tests

  • .venv\Scripts\python.exe -m pytest tests\strands\session\test_repository_session_manager.py -q -k "fix_broken_tool_use"
  • .venv\Scripts\python.exe -m pytest tests\strands\session\test_repository_session_manager.py -q
  • $env:RUFF_CACHE_DIR='.tmp\ruff-cache'; .venv\Scripts\python.exe -m ruff check src\strands\session\repository_session_manager.py tests\strands\session\test_repository_session_manager.py
  • $env:RUFF_CACHE_DIR='.tmp\ruff-cache'; .venv\Scripts\python.exe -m ruff format --check src\strands\session\repository_session_manager.py tests\strands\session\test_repository_session_manager.py
  • .venv\Scripts\python.exe -m py_compile src\strands\session\repository_session_manager.py tests\strands\session\test_repository_session_manager.py
  • git diff --check

@xiaosu19
Copy link
Copy Markdown

Thanks for the fix! We hit this in production with AgentCore Memory + GLM-5 on Bedrock. Verified that the root cause matches — our workaround was to prevent corrupted history at the application layer (BeforeToolCallEvent + cancel_tool), but this SDK-level fix is the proper solution.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

bug: repository_session_manager adds incorrect number of toolResult blocks when fixing orphaned toolUse

2 participants