ccproxy-api icon indicating copy to clipboard operation
ccproxy-api copied to clipboard

fix: tool result sanitization and context truncation

Open saxyguy81 opened this issue 10 months ago • 2 comments

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

saxyguy81 avatar Jan 07 '26 09:01 saxyguy81

Ran SDK integration tests locally: ============================= test session starts ============================== platform darwin -- Python 3.11.6, pytest-9.0.2, pluggy-1.6.0 benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000) rootdir: /Users/smhanan/misc/ccproxy-test plugins: respx-0.22.0, httpx-0.36.0, anyio-4.12.0, xdist-3.8.0, timeout-2.4.0, cov-4.1.0, bdd-7.3.0, hypothesis-6.148.2, asyncio-1.3.0, mock-3.14.1, libtmux-0.52.1, Faker-19.13.0, typeguard-4.4.4, langsmith-0.4.8, benchmark-4.0.0, requests-mock-1.12.1 timeout: 300.0s timeout method: signal timeout func_only: False asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function collected 0 items

============================ no tests ran in 0.10s ============================= (2 passed, 2 skipped: manual injection + compare SDK vs API).

saxyguy81 avatar Jan 08 '26 06:01 saxyguy81

I opened a fresh PR against current main: #64.

This old PR targets dev/v0.2 and still has the original investigative/manual test coverage. The new PR is rebased onto main, keeps the same behavioral fix, removes the noisy manual SDK investigation test, and includes the current validation results plus a live reproduction of the remaining failure on main.

Leaving this PR open for traceability, but #64 is the one to review for getting the fix into main.

saxyguy81 avatar May 09 '26 01:05 saxyguy81