mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
## Description Large native Claude Code requests on the Anthropic path can still forward with zero request compression after CCR tool injection is deferred on a frozen prefix. The stale skip branch treats deferred injection as a reason to bypass request compression entirely, even though the later sticky CCR path already knows when new markers actually require the tool. This removes that stale bypass so compression still runs while the reversible CCR path stays intact. Closes #2291. ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - Remove the stale `should_skip_ccr_request_compression` branch from `headroom/proxy/handlers/anthropic.py`, so deferred CCR tool injection no longer bypasses request compression in token, non-cache, or cache mode. - Keep the existing sticky CCR injection path as the only place that decides whether historical markers need the retrieval tool reintroduced. - Update `tests/test_proxy/test_anthropic_ccr_deferred_injection.py` to cover the two broken zero-compression cases and preserve the already-reversible frozen-prefix path. ## Testing - [x] Unit tests pass (`uv run pytest tests/test_proxy/test_anthropic_ccr_deferred_injection.py::test_cache_mode_compresses_delta_but_replays_cached_prefix_when_markers_are_historical tests/test_proxy/test_anthropic_ccr_deferred_injection.py::test_non_token_non_cache_mode_keeps_compression_and_injects_tool_for_new_markers tests/test_proxy/test_anthropic_ccr_deferred_injection.py::test_existing_retrieve_tool_keeps_reversible_ccr_path_when_prefix_is_frozen tests/test_openai_tool_search_deferral.py tests/test_openai_responses_compression_units.py -q`) - [x] Linting passes (`uv run ruff check .`) - [ ] Type checking passes (`uv run mypy headroom`) - [x] New tests added for new functionality when applicable - [ ] Manual testing performed ### Test Output ```text ======================= 53 passed, 1 warning in 12.71s ======================== All checks passed! 1310 files already formatted ``` ## Real Behavior Proof - Environment: synced branch and base worktrees on a local Windows proxy test host - Exact command / steps: run the updated Anthropic deferred-injection regressions directly against the base package tree and the branch package tree, then run the focused branch pytest suite above - Observed result: the base package tree fails the two updated zero-compression regressions (`FAIL test_cache_mode_compresses_delta_but_replays_cached_prefix_when_markers_are_historical`, `FAIL test_non_token_non_cache_mode_keeps_compression_and_injects_tool_for_new_markers`) while preserving the already-reversible path; the branch package tree prints three `PASS` lines for the same trio and keeps the neighboring OpenAI suites green in the 53-test focused run - Not tested: a live upstream Claude Code request with the reporter's exact provider/model credentials ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] I have updated the CHANGELOG.md if applicable ## Additional Notes `CHANGELOG.md` is not applicable here because Headroom's release pipeline derives it from conventional commits. Scope is limited to the Anthropic CCR request-compression seam that current #2291 evidence exercises. OpenAI tool-search deferral is untouched because the current live issue is a native Claude Code path and the concrete stale skip branch on `origin/main` is in `anthropic.py`. Co-authored-by: Tejas Chopra <chopratejas@gmail.com>
This commit is contained in:
parent
1d79e70f95
commit
26b43f64d6
2 changed files with 223 additions and 276 deletions
|
|
@ -490,7 +490,7 @@ def test_existing_retrieve_tool_keeps_reversible_ccr_path_when_prefix_is_frozen(
|
|||
assert [tool["name"] for tool in forwarded["tools"]] == ["headroom_retrieve"]
|
||||
|
||||
|
||||
def test_cache_mode_skip_replays_cached_compressed_prefix_when_tool_injection_is_deferred(
|
||||
def test_cache_mode_compresses_delta_but_replays_cached_prefix_when_markers_are_historical(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
captured: dict[str, object] = {}
|
||||
|
|
@ -574,13 +574,14 @@ def test_cache_mode_skip_replays_cached_compressed_prefix_when_tool_injection_is
|
|||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert captured.get("compression_calls", []) == []
|
||||
assert len(captured.get("compression_calls", [])) == 1
|
||||
forwarded = captured["body"]
|
||||
# Tool injection is deferred (no CCR tool this turn), but the frozen
|
||||
# prefix was cached COMPRESSED last turn. Replay it byte-identical so the
|
||||
# prompt cache still hits instead of busting on original bytes (#1850);
|
||||
# the mutable tail stays original. Tool absent AND cache intact.
|
||||
assert forwarded["messages"] == previous_forwarded_messages + original_messages[1:]
|
||||
# the historical marker does not force tool injection back on. Tool absent
|
||||
# AND cache intact.
|
||||
assert forwarded["messages"] == previous_forwarded_messages
|
||||
assert "tools" not in forwarded
|
||||
|
||||
|
||||
|
|
@ -755,7 +756,7 @@ def test_token_mode_cached_messages_skip_cache_update_when_pipeline_result_is_un
|
|||
assert forwarded["messages"] == marker_messages
|
||||
|
||||
|
||||
def test_non_token_non_cache_mode_still_skips_marker_emission_when_tool_is_unavailable(
|
||||
def test_non_token_non_cache_mode_keeps_compression_and_injects_tool_for_new_markers(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
captured: dict[str, object] = {}
|
||||
|
|
@ -828,11 +829,16 @@ def test_non_token_non_cache_mode_still_skips_marker_emission_when_tool_is_unava
|
|||
},
|
||||
)
|
||||
|
||||
marker_message = {
|
||||
"role": "user",
|
||||
"content": "[100 items compressed to 10. Retrieve more: hash=abc123def456abc123def456]",
|
||||
}
|
||||
|
||||
assert response.status_code == 200
|
||||
assert captured.get("compression_calls", []) == []
|
||||
assert len(captured.get("compression_calls", [])) == 1
|
||||
forwarded = captured["body"]
|
||||
assert forwarded["messages"] == original_messages
|
||||
assert "tools" not in forwarded
|
||||
assert forwarded["messages"] == [marker_message]
|
||||
assert [tool["name"] for tool in forwarded["tools"]] == ["headroom_retrieve"]
|
||||
|
||||
|
||||
def test_non_token_non_cache_mode_keeps_reversible_path_and_records_waste_signals(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue