[Bug]: Pull request Code tab fails on self-managed GitLab older than 15.7 ("GitLab CLI command failed") #15660
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Add a project hosted on a self-managed GitLab older than 15.7 (observed on GitLab 14.10.5), with
glabauthenticated for that host. - Open Pull Requests and select any merge request. Summary and Timeline load normally.
- Open the Code tab.
Expected behavior#
The merge request diff loads. If the GitLab instance cannot serve it, the error says why (for example, that the GitLab version is too old) instead of a generic CLI failure.
Actual behavior#
The Code tab shows "0 files" and this error, for every merge request on the instance:
Failed to fetch remote environment endpoint https://<remote-host>/api/pull-requests/diff (PullRequestOperationError: Pull request operation diff failed: GitLab CLI command failed.).
diffPage in apps/server/src/pullRequest/GitLabPullRequestCli.ts reads GET /projects/:id/merge_requests/:iid/diffs. GitLab added that endpoint in 15.7, so older instances answer 404. The 404 is mapped to GitLabCliCommandError, which is why the UI only says "GitLab CLI command failed."
Single-commit diffs (repository/commits/:sha/diff) and the other merge request reads (notes, discussions, commits) work on the same instance.
Impact#
Blocks work completely
Version or commit#
main @ 4ee6bfd50e (same code path); observed with desktop 0.0.45-nightly.20261002.2595
Environment#
macOS 27.0, T3 Code Nightly desktop connected to a remote Linux server environment, self-managed GitLab 14.10.5
Logs or stack traces#
$ glab api version
{"version":"14.10.5","revision":"02cdf459a13"}
$ glab api "projects/<project>/merge_requests/<iid>/diffs?per_page=1&page=1"
{"error":"404 Not Found"}glab: HTTP 404
Screenshots, recordings, or supporting files#
Not attached: the screenshot shows internal host and project names. The error text above is copied from it.
Workaround#
None inside T3 Code. The diff can be reviewed in the GitLab web UI.
Additional context#
GitLab 14.10.5 still serves GET /projects/:id/merge_requests/:iid/changes?access_raw_diffs=true (deprecated in 15.7, not removed). Each entry has the same fields as /diffs (old_path, new_path, diff, new_file, renamed_file, deleted_file, a_mode, b_mode), wrapped in a changes array, and the response is not paginated. Falling back to it when /diffs returns 404 and serving it as a single slice would cover these instances. What I measured on 14.10.5:
access_raw_diffs=truematters. Without it, 173 of 247 files in one merge request came back with an emptydiff. With it, 2 did.- That 247-file response was about 2.4 MB, under the current 8 MB
DIFF_MAX_OUTPUT_BYTES. - On very large merge requests GitLab caps the stored diff and returns
changes_countas a string ending in+. One merge request reported"247+"and returned 247 files, whilegit diff --shortstatbetween itsdiff_refsshows 3,380 changed files./versions/:idreturns the same 247 files, and/repository/comparestops at 1,000 files withcompare_timeout: true. The fallback slice should be marked truncated whenchanges_countends in+, so the UI does not present a partial diff as complete.
juliusmarminge added labelsbug
juliusmarminge added labelsvia-triage
Note
Grok responding on behalf of Julius.
Fixed by #15886, which just merged to main. On GitLab older than 15.7, the Code tab now falls back to the merge request `/changes` endpoint when `/diffs` returns 404, so the diff loads instead of failing with "GitLab CLI command failed." Thanks for the detailed report, @jinl96. If it still fails on your instance after updating, please reopen with the new error.
juliusmarminge closed this
Sign in to join this conversation.
Note
Grok responding on behalf of Julius.
Triage#
Thanks for the detailed report, @jinl96. Including the GitLab version, the 404, and the empty-
diffmeasurement made this easy to trace.What I found#
What you describe matches
mainat4ee6bfd50e, and I didn't find an existing issue for it.diffPageinapps/server/src/pullRequest/GitLabPullRequestCli.ts, which callsGET /projects/:id/merge_requests/:iid/diffs. GitLab added that endpoint in 15.7, the same release that deprecatedGET .../merge_requests/:iid/changes, so a 404 from 14.10.5 is expected. Summary, timeline, and commit diffs still work because they use older routes:notes,discussions,commits, andrepository/commits/:sha/diff.apps/server/src/vcs/VcsProcess.tsclassifiesglabstderr that contains404asnot-found, butGitLabCliCommandError.fromVcsErrorstill turns it into aGitLabCliCommandErrorwhose detail is justGitLab CLI command failed.. The provider then wraps that asPull request operation diff failed: .... TheFailed to fetch remote environment endpoint .../api/pull-requests/diffprefix is the desktop client relaying that failure from the remote environment.Likely fix area#
.../changes?access_raw_diffs=truewhen/diffsreturns 404, and return the result as a single slice withnextCursor: null. A few details matter:decodeMergeRequestDiffsJsonexpects a bare array, but/changeswraps the files in achangesarray and isn't paginated./diffspaging check shouldn't run on that array. With 100 or more files, it would ask for a next page that/changescan't serve.access_raw_diffs=trueis needed. Without it, GitLab applies the database diff size limits, which would explain the emptydiffyou saw.changes_countends in+oroverflowis true, because/changesentries don't havetoo_largeorcollapsed.DIFF_MAX_OUTPUT_BYTES(8 MiB) would still fail. Your 2.4 MB case fits.not-foundcase could get a clearer detail than "GitLab CLI command failed."A maintainer will decide on the fix direction.