Skip to content

feat(pr-review): implement compact diff handling with on-demand file inspection#256

Merged
tmseidel merged 2 commits into
developfrom
feature/compact-diff-handling
Jul 10, 2026
Merged

feat(pr-review): implement compact diff handling with on-demand file inspection#256
tmseidel merged 2 commits into
developfrom
feature/compact-diff-handling

Conversation

@tmseidel

Copy link
Copy Markdown
Owner

No description provided.

…inspection

Replace full diff embedding (up to 60K chars) with compact file-list summary
(~350-3500 chars) to prevent context overflow in agentic PR reviews.
Add DiffSummary class that parses unified diffs into file tables with change
counts. Introduce pr-diff tool allowing agents to inspect specific files
on-demand rather than processing the entire diff upfront.
Changes:
- DiffSummary: parses diffs, generates markdown tables, extracts per-file hunks
- pr-diff tool: registered in ToolCatalog, executed by AgentToolRouter
- AgentRunContext/ToolCallContext: carry diffSummary through the agent loop
- AgentReviewService: builds compact summary instead of embedding full diff
- V30 migration: enables pr-diff for bots with agentic-review workflow
Reduces initial token usage by 95-99% while maintaining review quality.
Agent can focus on important files first and handle PRs with hundreds of files.
Docs: MIGRATION_1.14_TO_1.15.md, PR_WORKFLOWS_AGENTIC_REVIEW.md updated.
@tmseidel tmseidel requested a review from max-california July 10, 2026 00:20
max-california

This comment was marked as low quality.

@tmseidel tmseidel linked an issue Jul 10, 2026 that may be closed by this pull request
…inspection

Replace full diff embedding (up to 60K chars) with compact file-list summary
(~350-3500 chars) to prevent context overflow in agentic PR reviews.
Add DiffSummary class that parses unified diffs into file tables with change
counts. Introduce pr-diff tool allowing agents to inspect specific files
on-demand rather than processing the entire diff upfront.
Changes:
- DiffSummary: parses diffs, generates markdown tables, extracts per-file hunks
- pr-diff tool: registered in ToolCatalog, executed by AgentToolRouter
- AgentRunContext/ToolCallContext: carry diffSummary through the agent loop
- AgentReviewService: builds compact summary instead of embedding full diff
- V30 migration: enables pr-diff for bots with agentic-review workflow
Reduces initial token usage by 95-99% while maintaining review quality.
Agent can focus on important files first and handle PRs with hundreds of files.
Docs: MIGRATION_1.14_TO_1.15.md, PR_WORKFLOWS_AGENTIC_REVIEW.md updated.
@tmseidel tmseidel requested a review from max-california July 10, 2026 11:11
max-california

This comment was marked as low quality.

@tmseidel tmseidel requested a review from max-california July 10, 2026 11:14
Repository owner deleted a comment from max-california Jul 10, 2026
@tmseidel tmseidel requested review from max-california and removed request for max-california July 10, 2026 11:18

@max-california max-california left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Agentic Code Review

Now I have a thorough understanding of the codebase. Let me compile my review.


Review Summary

This PR replaces the full-diff-in-prompt approach for the agentic PR review workflow with a compact file-list summary (via new DiffSummary) and a new pr-diff on-demand tool. The change is well-scoped, well-tested, and correctly handles backward compatibility for non-review code paths. The design reduces token usage significantly and prevents context-window overflow for large PRs. No blocking issues found.


Findings

1. Minor: rawBlock omits the diff --git header line (DiffSummary.java:92-95)

When the inner parsing loop builds rawBlock, it starts appending after advancing i past the diff --git line. The returned hunk therefore lacks the traditional diff --git a/… b/… header. It still contains ---/+++ and all hunk content, so the LLM gets the practical information it needs, but the format is slightly non-standard. Not a blocker — just worth noting that any future consumer expecting strict diff --git headers won't find them.

// i++ moves past the "diff --git" line before the block-building loop
i++;
while (i < lines.length && !lines[i].startsWith("diff --git ")) {
    String line = lines[i];
    blockBuilder.append(line).append("\n");
    ...
}

2. Nit: pr-diff returns success=true when file not found (AgentToolRouter.java:234-239)

When the requested file path isn't in the diff, the tool returns success=true with a message listing all changed files. This is arguably a design choice — the tool ran without system error, and the message helps the LLM retry — but it's semantically misleading since the tool didn't return any diff hunks. Consider using success=false to signal to the LLM that it needs to choose a different file; the changedFiles list in the error message would still guide it.

3. Nit: ToolExecutionService.executeContextTool() has no pr-diff branch (ToolExecutionService.java:90-103)

pr-diff is registered as ToolKind.CONTEXT for both CODING and WRITER roles. In executeWriter the router intercepts it explicitly (correct). But in executeCoding it would fall through to executeContextTool, which has no case "pr-diff" and would return "Repository tool 'pr-diff' is not implemented". In practice this is harmless because coding workflows don't call pr-diff, but it's a latent inconsistency. Consider either removing Role.CODING from the tool registration or adding a defensive handler.

4. Nit: DiffSummary.statLine() says "0 files" when empty (DiffSummary.java:141-142)

For an empty diff, the output is "0 files" rather than something like "0 files changed" or "no changes". The fileTable() correctly returns "(no changes)" for this case, so there's a minor inconsistency between the two methods. Very low impact — statLine for empty diffs is only used in log messages.

5. Observation: No fallback to embedded diff for tiny PRs

For a 1-file / 3-line PR, the compact approach adds an extra tool-call round compared to the old behavior. This is a conscious trade-off and correct for the overall goal — the consistency and token savings for large PRs outweigh the minor latency for tiny ones.


What looks good

  • DiffSummary parsing: Correctly handles new files (/dev/null), deleted files, renames (rename to), binary files, and multi-file diffs. The path resolution logic prioritises +++---rename to → header fallback, which matches git's conventions.
  • Thread safety: DiffSummary and FileEntry are immutable; AgentRunContext.diffSummary is set once before the review loop runs.
  • Backward compatibility: The 5-arg ToolCallContext constructor preserves existing callers (CodingAgentStrategy, WriterAgentStrategy) with diffSummary=null.
  • Error handling: Null/blank diffs, missing diffSummary, and unknown file paths all produce clear, actionable error messages.
  • Database migrations: Both H2 and PostgreSQL V30 scripts are idempotent (NOT EXISTS guard), selective (only bots with agentic-review workflow), and follow the existing versioning convention.
  • Tests: DiffSummaryTest covers empty/null input, single/multi-file, new/deleted/renamed files, fileTable, fileDiff extraction, and pluralisation.
  • Documentation: The migration guide (MIGRATION_1.14_TO_1.15.md) is thorough with verification queries, manual intervention steps, rollback instructions, and behavior comparisons.

Verdict

The implementation is correct, well-structured, and delivers the intended token-efficiency gains. All findings above are non-blocking nits or observations.


Read-only agentic review by AI Git Bot

@tmseidel tmseidel merged commit c1951dd into develop Jul 10, 2026
1 check passed
@tmseidel tmseidel deleted the feature/compact-diff-handling branch July 10, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compact Diff for Agentic PR Review

2 participants