Skip to content

fix: prune stale tool results during session repair#2299

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

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
Contributor

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!

@he-yufeng he-yufeng force-pushed the fix/session-tool-result-repair branch from d530240 to 6968cd6 Compare May 27, 2026 09:48
@github-actions github-actions Bot added size/s and removed size/s labels May 27, 2026
@he-yufeng
Copy link
Copy Markdown
Contributor Author

Rebased this onto current main and revalidated the focused session-manager path. Current head is 6968cd6. Validation from strands-py: uv run pytest tests/strands/session/test_repository_session_manager.py -q --basetemp ...tmp\pytest-2299 -p no:cacheprovider: 42 passed; uv run ruff check src/strands/session/repository_session_manager.py tests/strands/session/test_repository_session_manager.py; uv run ruff format --check src/strands/session/repository_session_manager.py tests/strands/session/test_repository_session_manager.py; python -m py_compile strands-py\src\strands\session\repository_session_manager.py strands-py\tests\strands\session\test_repository_session_manager.py; git diff --check origin/main...HEAD.

@yonib05 yonib05 added area-persistence Session management or checkpointing area-context Session or context related labels May 27, 2026
@opieter-aws
Copy link
Copy Markdown
Contributor

Closing in favor of #2320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-context Session or context related area-persistence Session management or checkpointing size/s

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

4 participants