fix(agent-core): bound Git diff output while reading
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
- [x] I have read the CONTRIBUTING document.
- [x] I have linked a related issue, or explained the problem above.
- [x] I have added tests that prove my feature works.
- [x] Ran
gen-changesetsskill, and included a patch changeset. - [x] This restores the existing diff-size contract and needs no documentation update.
🦋 Changeset detected
Latest commit: 676a072e5009d105385213fe1b3b739d4a13b26d
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