Keep large PR reviews complete instead of degrading (#874)

This commit is contained in:
Glenn Jocher
2026-08-15 19:45:31 +02:00
committed by GitHub
parent fd072b38ef
commit 7ddc323ee0
4 changed files with 13 additions and 10 deletions
+1 -1
View File
@@ -28,4 +28,4 @@
# ├── test_summarize_pr.py
# └── ...
__version__ = "0.3.7"
__version__ = "0.3.8"
+6 -7
View File
@@ -536,12 +536,11 @@ def generate_pr_review(
if file_contents:
full_files_section = f"FULL FILE CONTENTS:\n{chr(10).join(file_contents)}\n\n"
# Calculate remaining budget for diff and check if truncation needed
diff_budget = max(
1000, REVIEW_PROMPT_CHARS - len(guidelines_section) - len(full_files_section) - len(history_section)
)
# Remaining budget for the diff: agent turns cache the prompt and page any remainder via read_diff, so the agent
# inlines ~5k diff lines while single-shot models keep the one-request ceiling
prompt_chars = REVIEW_PROMPT_CHARS * (2 if is_agent_review_model else 1)
diff_budget = max(1000, prompt_chars - len(guidelines_section) - len(full_files_section) - len(history_section))
diff_truncated = len(augmented_diff) > diff_budget
is_large_pr = diff_truncated or len(file_list) > 30
if is_agent_review_model: # must match the get_agent_response fallback gate
visibility_section = ( # function tools carry their own schema descriptions; only cross-tool rules belong here
"EVIDENCE - every finding needs it:\n"
@@ -629,8 +628,8 @@ def generate_pr_review(
'{"comments": [{"file": "exact/path", "line": N, "side": "RIGHT", "severity": "HIGH", "message": "..."}], "summary": "..."}\n\n'
"JSON rules: exact paths (no ./), severity: CRITICAL|HIGH|MEDIUM|LOW|SUGGESTION\n"
f"Files changed: {len(file_list)} ({', '.join(file_list[:30])}{'...' if len(file_list) > 30 else ''}), Lines: {lines_changed}\n"
f"{'Large or truncated PR: the diff below is incomplete. ' if is_large_pr else ''}"
f"{'Use list_changed_files and read_diff to inspect changed files not shown in the initial prompt. ' if is_large_pr and is_agent_review_model else ''}\n"
f"{'Large PR: the diff below is truncated. ' if diff_truncated else ''}"
f"{'Use list_changed_files and read_diff to inspect changed files not shown in the initial prompt. ' if diff_truncated and is_agent_review_model else ''}\n"
)
messages = [
+5 -1
View File
@@ -424,7 +424,9 @@ def get_agent_response(
"tools": tools,
"parallel_tool_calls": True, # batched tool calls share one turn, so the history is re-billed fewer times
"prompt_cache_key": f"agent-run:{uuid4().hex}",
"context_management": [{"type": "compaction", "compact_threshold": 200_000}],
# Overflow guard only: compaction collapses the run to a few thousand tokens and drops the evidence gathered so
# far, so it only fires at the long-context billing boundary (2x input above 272k tokens on gpt-5.6)
"context_management": [{"type": "compaction", "compact_threshold": 272_000}],
}
if "gpt-5" in model:
base_data["reasoning"] = {"effort": reasoning_effort or "medium"}
@@ -452,6 +454,8 @@ def get_agent_response(
total_usage = _add_openai_usage(total_usage, response_json)
previous_response_id = response_json.get("id")
output_items = response_json.get("output", [])
if any(item.get("type") == "compaction" for item in output_items):
print("WARNING ⚠️ context compacted server-side; earlier tool results are summarized, not verbatim")
turn_calls = _response_tool_calls(output_items)
turn_cost = (
_openai_usage_cost(response_json.get("usage") or {}, model)
+1 -1
View File
@@ -294,7 +294,7 @@ def test_get_agent_response_calls_function_tools(mock_post):
assert first_payload["store"] is True
assert first_payload["service_tier"] == "default"
assert first_payload["reasoning"] == {"effort": "medium"}
assert first_payload["context_management"] == [{"type": "compaction", "compact_threshold": 200_000}]
assert first_payload["context_management"] == [{"type": "compaction", "compact_threshold": 272_000}]
assert first_payload["prompt_cache_key"].startswith("agent-run:")
assert "include" not in first_payload
assert "previous_response_id" not in first_payload