Skip to content

git_diff truncation is head-only, dropping the end of large diffs #770

Closed

Description

@will-lamerton

Rewritten 2026-08-09. The original framing of this issue was wrong. It claimed git_diff returned the full diff with no ceiling. There has been a 500-line cap since before the #772 work started. The real defect is the shape of that truncation, described below.

Problem

source/tools/git/git-diff.tsx:69 caps the diff, and source/tools/git/utils.ts:654 implements the cap:

const truncatedContent = lines.slice(0, maxLines).join('\n');

Truncation is head-only, at 500 lines. That is the same flaw #764 fixed for execute_bash, and it bites harder here.

A diff is ordered by path, so the first 500 lines are the first file or two alphabetically, not the important ones. Cutting a large diff at the head gives the model source/ai-sdk-client/... in full and silently drops everything after it. For the common case of orienting in a branch's changes, that is close to the least useful 500 lines available.

Because tool results persist in the conversation, those 500 lines are also re-sent on every subsequent step of the agent loop.

Secondary, cosmetic: when truncation fires, the result carries two footers. utils.ts:673 appends ... [Diff truncated: showing 500 of N lines], then git-diff.tsx:71 appends [Total: N lines] on top of it. One of them should go.

Fix

Preferred, and specific to this tool: when the diff exceeds the cap, return the --stat summary instead of a head slice, plus a note that the model should request specific paths with git_diff({paths: [...]}). A file-level summary is the right granularity for orienting in a large diff, and it is dramatically cheaper than 500 lines of one file. The model can then pull the hunks it actually needs.

Fallback if that is too large a change: head-plus-tail elision, matching what #764 did for bash, so at least both ends of the diff survive.

Either way, drop the duplicate footer, and reconsider whether 500 lines is the right ceiling for something re-sent on every step.

args.stat mode correctly skips truncation already, since stat output is compact. Leave that path alone.

Related

Partly covered by a global tool-result cap (#769) if that lands, but the --stat fallback is smarter than anything a generic cap can do, so this is worth handling specifically either way.

Activity

  1. added
    enhancement
    performance
    on Aug 3, 2026
  2. will-lamerton commented on Aug 3, 2026

    @will-lamerton
    MemberAuthor

    Part of #772.

  3. RealBhupesh commented on Aug 4, 2026

    @RealBhupesh
    Contributor

    I’d like to take this child issue from #772. I found that main already caps git_diff at 500 lines, but the current head-only truncation can hide the end of a diff where important changes often appear. I plan to preserve both the beginning and end with an explicit omitted-range marker, add regression tests, and include a patch changeset. I’ll open a ready-for-review PR after validation.

  4. RealBhupesh commented on Aug 4, 2026

    @RealBhupesh
    Contributor

    Implemented in PR #785: #785

    The change keeps git_diff results bounded at 500 lines. Oversized full diffs now return git diff --stat plus guidance to request a specific file, while the fallback preserves both the beginning and end if the summary command is unavailable. Regression coverage and a patch changeset are included.

    Validation completed with formatting, type, lint, focused tests, and the full suite. The full suite has one unrelated existing failure in source/app/components/settings-tabs.spec.tsx:109.

  5. changed the title [-]git_diff returns the full diff with no ceiling[/-] [+]git_diff truncation is head-only, dropping the end of large diffs[/+] on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions