Skip to content

desktop: diff pane renders empty despite correct +/- stats (v2.1.4, Windows) #58881

Closed as duplicate

Description

@crraay

Summary

Clicking a changed file in the desktop Git Changes sidebar shows the correct +N -M stats in the header, but the diff content area is completely blank. CLI git diff renders the same diff correctly, so the repository data is fine.

Environment

  • opencode version: 2.1.4 (desktop app, OpenCode.exe product version 2.1.4.0)
  • OS: Windows_NT 10.0.26200 (Windows 11, win32 x64)
  • Terminal: Unavailable: not a terminal session (OpenCode desktop app)
  • Shell: Unavailable: $ComSpec not set in this environment
  • Install/channel: latest (auto-updater channel @opencodedesktop-updater)
  • Active plugins: none found (no opencode.json(c), no .opencode/ in project, no global ~/.config/opencode/opencode.json)

Reproduction

  1. Open a project in OpenCode desktop 2.1.4 on Windows 11.
  2. Rewrite README.md (~11 insertions, 16 deletions).
  3. Open the "Git changes" sidebar and click README.md.
  4. Header shows README.md +11 -16, but the diff pane stays empty (blank even after switching between diff views).

So far only README.md has shown this; other files were not affected (small sample).

Expected Behavior

The pane shows the unified diff with removed/added lines, as git diff does.

Actual Behavior

The pane is blank. The stats in the header are correct, which suggests the diff is computed fine but the renderer produces nothing.

Additional Context

Activity

  1. opencode-agent commented on Oct 25, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report! I think this is a duplicate of #57441, which reports the same blank diff pane with correct +/- stats in Desktop 2.x on Windows 11, also in a repo with core.autocrlf=true and LF working-tree files.

    Possible duplicates and related issues, ordered from most to least likely:

    It would help to add your details to #57441: it still happens on 2.1.4, the HEAD blob has CRLF while the working-tree file is LF-only, and only README.md is affected. Any DevTools console errors or a small sample patch would help there too.

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. crraay commented on Oct 26, 2026

    @crraay
    Author

    Root cause found: server returns a corrupt patch

    The blank pane is not a renderer/syntax-highlighting failure — GET /api/vcs/diff?mode=working returns a structurally invalid patch for affected files. The frontend patch parser silently rejects it (hence no console errors), while the +/- stats are computed elsewhere and stay correct.

    Evidence

    For README.md in my repro repo, git diff produces one valid hunk:

    @@ -1,39 +1,34 @@    (1 hunk, `git apply --stat` OK)
    

    The API returns the same diff as 12 overlapping hunks, all starting at line 1:

    @@ -1,34 +1,34 @@
    @@ -1,34 +1,34 @@
    @@ -1,35 +1,34 @@
    ... (x8)
    @@ -1,39 +1,34 @@
    

    git apply rejects it:

    error: corrupt patch at line 150
    exit=128
    

    Hunks 4–12 are also internally inconsistent (declare 35 old lines but contain 34).

    Not file- or encoding-specific

    Test matrix on a second 5-line ASCII file (.github/workflows/README.md), all via the same endpoint, comparing against git diff ground truth:

    Change API hunks git apply --stat
    Edit line 1 only 1 OK
    Append text → 1 new final line 1 OK
    Add blank line + text at EOF (ASCII) 2 overlapping corrupt patch at line 25
    Same, keeping trailing LF 2 overlapping corrupt
    Cyrillic line at EOF 2 overlapping corrupt
    Line-1 edit + lines at EOF 2 overlapping corrupt
    hexlet-check.yml: 3 edits, no EOF change 1 (merged) OK
    README.md (original report) 12 overlapping corrupt patch at line 150

    So: not encoding-related (pure ASCII corrupts too), not about the number of changed regions (3 regions in hexlet-check.yml merged into one valid hunk). The reliable trigger observed is changes that add multiple lines at end-of-file; each changed group appears to emit its own full-context hunk, all with -1 as the old start, so they overlap and their declared counts don't match their content.

    This looks related to the structuredPatch calls with context: Number.MAX_SAFE_INTEGER / Infinity mentioned in #29768 — hunks with full-file context are being concatenated instead of merged (or are being generated against different base line counts).

    Minimal reproduction

    # Take a 5-line file ending with LF and append two lines:
    $content = [System.IO.File]::ReadAllText("probe.txt")
    [System.IO.File]::WriteAllText("probe.txt", $content + "`nnew ascii line at eof`n")
    
    # Query the endpoint (opencode-cli.exe ships with the desktop app):
    & opencode-cli.exe api get "/api/vcs/diff?mode=working&location[directory]=C:\path\to\repo" > diff.json
    
    # .data[0].patch contains: "@@ -1,3 +1,7 @@" followed by "@@ -1,5 +1,7 @@"
    # (overlapping, both starting at old line 1). Validate it:
    git apply --stat patch.txt
    # -> error: corrupt patch at line 25, exit 128

    Sanity check with plain git on the same file: git diff → single hunk @@ -3,3 +3,5 @@, applies fine.

    Environment: OpenCode Desktop 2.1.4, Windows 11 (10.0.26200), no plugins. Reproduced deterministically ~6/6 times. Console shows no errors (the failure is silent).

  3. crraay commented on Oct 26, 2026

    @crraay
    Author

    Root cause identified

    Follow-up to my previous comment: traced this through the OpenCode source into git itself. The blank pane is a Windows-only integer overflow in git's xdiff, triggered by OpenCode passing INT_MAX as the diff context.

    The chain

    1. The desktop Git changes pane calls the endpoint without a context — packages/gui-extensions/src/review/model.ts:184
      .server.client.vcs.diff({ location: { directory: view().directory }, mode: "working" })
    2. The API schema has no upper bound — packages/protocol/src/groups/vcs.ts:31 (NonNegativeInt, optional)
    3. Core substitutes a "full file" sentinel — packages/core/src/vcs.ts:239
      context: options?.context ?? PATCH_CONTEXT_LINES   // = 2_147_483_647
      defined at packages/core/src/vcs/patch.ts:6
    4. The git adapter interpolates it raw — packages/core/src/plugin/vcs/git.ts:
      `--unified=${options?.context ?? PATCH_CONTEXT_LINES}`   // -> --unified=2147483647
    5. git 2.45.2.windows.1 overflows and emits a corrupt patch, which the API returns verbatim.

    The overflow inside git

    xdiff/xemit.c, xdl_get_hunk():

    long max_common = 2 * xecfg->ctxlen + xecfg->interhunkctxlen;
    long max_ignorable = xecfg->ctxlen;
    ...
    s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0);

    xdemitconf_t.ctxlen is a long — 32-bit on Windows (LLP64), 64-bit on Linux/macOS. So 2 × 2147483647 wraps to -2, making distance > max_common always true: every change group is emitted as its own hunk, and s1 clamps each hunk's start to line 1. Result: N overlapping whole-file hunks whose declared line counts don't match their content.

    Evidence

    Experiment Result
    API patch vs. git diff --patch --no-ext-diff --no-renames --unified=2147483647 byte-identical (12,479 bytes)
    --unified threshold (binary search) OK at 1073741823, broken at 1073741824 = 2³⁰ — exactly where 2 × ctxlen overflows int32
    Change groups in README.md vs. hunks in corrupt patch 12 groups → 12 hunks (and 3 groups → 3 hunks for another file)
    Same command in WSL (Linux, 64-bit long, git 2.43) valid patch, git apply --stat exit 0
    git apply --stat on the API's patch error: corrupt patch at line 150, exit 128

    Why the pane is blank while +11 -16 is correct

    The stats come from a separate git diff --numstat call (plugin/vcs/git.ts), which is unaffected by the overflow — so the header numbers are right. The patch itself fails in the client's patch parser, and the failure is swallowed: the only handler is a console.debug (review/model.ts:186), which is why the DevTools console shows nothing.

    This also explains why only some files go blank: a file's overflowed hunks happen to keep self-consistent counts when its old and new line counts are equal (reproduced: a 3-change file stayed parseable, while README.md with 39 → 34 lines did not).

    Scope

  4. opencode-agent commented on Oct 26, 2026

    @opencode-agent
    Contributor

    Closing this as a duplicate of #57441, since there hasn't been a reply in the past day saying how it's different. Please follow #57441 for updates. It would help a lot if you added your details there: it still happens on 2.1.4, the HEAD blob has CRLF while the working-tree file is LF-only, and so far only README.md is affected. DevTools console errors or a small sample patch would help too. If this turns out to be a different problem, reply here and it can be reopened. Thanks again for the detailed report!

  5. neriousy commented on Nov 23, 2026

    @neriousy
    Member

    Closing as a duplicate of #57441: same empty diff pane with correct +/- stats on Windows. Please follow that issue for updates and add any extra details there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions