Skip to content

fix(core): add diff size limits to prevent UI freeze with large changesets#35546

Open
UR-xiaoyang wants to merge 2 commits into
anomalyco:devfrom
UR-xiaoyang:fix/review-panel-large-diff-freeze
Open

fix(core): add diff size limits to prevent UI freeze with large changesets#35546
UR-xiaoyang wants to merge 2 commits into
anomalyco:devfrom
UR-xiaoyang:fix/review-panel-large-diff-freeze

Conversation

@UR-xiaoyang

Copy link
Copy Markdown

Issue for this PR

Closes #31916
Related to #35401, #33195, #29873

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR fixes the UI freeze/hang issue when opening the Review/Diff panel with large changesets (10,000+ files or large patches).

Root Cause:
The diff viewer was rendering unbounded diffs, causing the event loop to block when processing large changesets. This manifested as:

  • TUI hanging at 100% CPU
  • Web UI becoming completely unresponsive
  • Process requiring force-kill

Solution:
Added configurable size limits with intelligent truncation:

  1. Core changes (packages/core):

    • Added ConfigDiff.Info schema with max_files (default: 1000) and max_patch_bytes (default: 100KB)
    • Created truncateDiffs utility function with truncation logic
    • Added unit tests covering all truncation scenarios
  2. TUI changes (packages/tui):

    • Applied truncation before rendering in diff viewer
    • Display truncation warning in header when limits exceeded
  3. Web App changes (packages/app):

    • Applied truncation before rendering in review panel v2
    • Display truncation warnings in stats area

Users can customize limits via config:

{
  "diff": {
    "max_files": 2000,
    "max_patch_bytes": 204800
  }
}

How did you verify your code works?

  1. Unit tests: Created comprehensive tests for truncateDiffs function covering:

    • File truncation when exceeding max_files
    • Patch truncation when exceeding max_patch_bytes
    • Default limits behavior
    • Diffs without patches
    • Combined file and patch truncation
  2. Integration testing: Verified with standalone test simulating:

    • 15,000 files scenario (truncated to 1,000) ✓
    • 200KB patch scenario (truncated with notice) ✓
    • Normal workflow (50 files, no truncation) ✓
    • Custom config (respects user limits) ✓

All tests passed successfully.

Screenshots / recordings

N/A - This is a performance/stability fix without visual UI changes (only adds warning text when truncation occurs).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

UR-xiaoyang and others added 2 commits July 5, 2026 22:23
…ge changesets

- Add diff config in packages/core/src/config/diff.ts with max_files (default: 1000) and max_patch_bytes (default: 100KB)
- Create truncateDiffs utility in packages/core/src/util/truncate-diff.ts
- Apply truncation in TUI diff viewer (packages/tui/src/feature-plugins/system/diff-viewer.tsx)
- Apply truncation in Web review panel (packages/app/src/pages/session/v2/review-panel-v2.tsx)
- Display truncation warnings in UI when limits are exceeded

Fixes anomalyco#31916 (related to anomalyco#35401, anomalyco#33195, anomalyco#29873)

When the Git working tree has 10k+ changed files or very large patches, the diff viewer now truncates the data to prevent freezing. Users can increase limits via config:

{
  "diff": {
    "max_files": 2000,
    "max_patch_bytes": 204800
  }
}

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Test file truncation when exceeding max_files limit
- Test patch truncation when exceeding max_patch_bytes limit
- Test default limits are applied correctly
- Test handling of diffs without patches
- Test combined file and patch truncation

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PRs Found

I found two potentially related PRs addressing similar issues:

  1. PR fix(ui): prepare diffs off the render thread #31309 - fix(ui): prepare diffs off the render thread

    • Related to: UI freezing with diffs rendering
    • Overlap: Both address the same root cause (diff rendering performance), but take different approaches
  2. PR fix: add large diff guard to TimelineDiffView to prevent render freeze #33198 - fix: add large diff guard to TimelineDiffView to prevent render freeze

    • Related to: Large diff rendering causing UI freeze
    • Overlap: Similar solution scope (guarding against large diffs), focuses on a specific component

These PRs address the same performance issue (UI freeze with large changesets) that PR #35546 is fixing. You may want to review if there's any overlap in implementation or if these previous attempts should be considered in the current solution.

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.

TUI hangs on 'Preparing to write...' with large file content (unbounded diff rendering)

1 participant