Skip to content

fix(agent-core): bound Git diff output while reading#2171

Open
morluto wants to merge 2 commits into
MoonshotAI:mainfrom
morluto:codex/audit-git-diff
Open

fix(agent-core): bound Git diff output while reading#2171
morluto wants to merge 2 commits into
MoonshotAI:mainfrom
morluto:codex/audit-git-diff

Conversation

@morluto

@morluto morluto commented Jul 25, 2026

Copy link
Copy Markdown

Related Issue

Resolve #2169

Problem

The Git services applied their 1 MiB file-diff limit only after collecting complete subprocess stdout. Large diffs could therefore create memory spikes proportional to the full diff even though callers received at most 1 MiB.

The old limit also measured JavaScript string length rather than UTF-8 bytes, allowing multibyte responses to exceed the intended byte ceiling.

A representative 24 MiB modified file increased peak RSS to 331 MiB before this change and 231 MiB afterward. The measurement includes Git, fixture data, decoding, and V8 overhead; the code-level guarantee is that the retained diff response is now bounded rather than scaling with complete stdout.

What changed

  • Bound file-diff stdout while consuming it in both the legacy and v2 engines.
  • Retain at most 1 MiB by UTF-8 byte count.
  • Stop at a valid Unicode boundary.
  • Record whether later output was discarded.
  • Continue draining stdout after reaching the limit so Git cannot block on a full pipe.

Other Git commands, stderr collection, timeout behavior, and exit-code handling are unchanged.

Regression tests exercise both services through their existing public boundaries with a 1.2 MiB multibyte diff. They fail on the previous implementation because it returns truncated: false and exceeds the byte limit.

Validation:

  • Legacy Git service tests: 7 passed
  • V2 Git service tests: 8 passed
  • Both package typechecks
  • V2 domain lint and root lint
  • git diff --check
  • Changeset validation

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, and included a patch changeset.
  • This restores the existing diff-size contract and needs no documentation update.

@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 676a072

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

[Bug] File diff buffers complete Git stdout before applying the 1 MiB limit

1 participant