fix: tool result sanitization and context truncation #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary\n- prevent mixed content in tool_result user messages by only summarizing orphaned tool_results when no valid tool_results remain\n- truncate context before sanitization (token estimation + fallback content truncation) to avoid creating orphaned tool blocks\n- normalize Anthropic SSE errors and expand coverage\n- add missing tests/fixtures package marker; minor lint/mypy compliance tweaks\n\n## Testing\n- PYTHONPATH=. pytest tests/test_tool_result_sanitization.py tests/plugins/claude_api/unit/test_native_anthropic_sanitization.py tests/unit/llms/test_context_window_management.py tests/unit/llms/test_truncation_creates_orphans.py tests/unit/streaming/test_deferred_stream_errors.py tests/plugins/claude_sdk/integration/test_sdk_compaction_behavior.py