Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

When opening a closed/merged PR via URI link (e.g., vscode-insiders://github.vscode-pull-request-github/checkout-pull-request?...), the extension fetches the branch but fails to enter review mode because the PR state doesn't match the useReviewMode setting.

Changes

Track explicitly switched PRs

  • Added _switchedToPullRequest property to store the PR the user explicitly switched to via the switch() method
  • Set this property when switch() is called
  • Clear it when exiting review mode

Bypass state checks for explicit switches

  • In validateState(), check if current PR matches _switchedToPullRequest
  • If matched, enter review mode regardless of PR state (closed/merged) or settings
// Before: Would clear review mode for closed PRs based on setting
if (pr.isClosed && !useReviewConfiguration.closed) {
    await this.clear(true);
    return;
}

// After: Bypass check if user explicitly switched to this PR
const isSwitchedToPullRequest = this._switchedToPullRequest?.number === pr.number;
if (pr.isClosed && !useReviewConfiguration.closed && !isSwitchedToPullRequest) {
    await this.clear(true);
    return;
}

This ensures explicit user actions (clicking links, using checkout commands) always show the PR, while respecting settings for automatic branch-based activation.

Original prompt

This section details on the original issue you should resolve

<issue_title>Trying to open a closed PR results in NOP</issue_title>
<issue_description>Testing microsoft/vscode#274805

Repro Steps

  1. Load vscode repo in Insiders
  2. Open this link in browser: vscode-insiders://github.vscode-pull-request-github/checkout-pull-request?%7B%22owner%22%3A%22microsoft%22%2C%22repo%22%3A%22vscode%22%2C%22pullRequestNumber%22%3A273860%7D
  3. It will show progress (good), it will ask you to fetch the PR (good), it will create a branch (good)

Actual Result
After a while, nothing happens.

Expected Result
To see the PR.

Git Log

2025-11-05 14:45:52.770 [info] > git rev-parse refs/remotes/origin/dev/dmitriv/glob-2 [64ms]
2025-11-05 14:45:52.936 [info] > git status -z -uall [161ms]
2025-11-05 14:45:53.031 [info] > git for-each-ref --sort -committerdate --format %(refname)%00%(objectname)%00%(*objectname) [252ms]
2025-11-05 14:46:26.715 [info] > git config --get commit.template [62ms]
2025-11-05 14:46:26.774 [info] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track)%00%(upstream:remotename)%00%(upstream:remoteref) --ignore-case refs/heads/dev/dmitriv/glob-2 refs/remotes/dev/dmitriv/glob-2 [115ms]
2025-11-05 14:46:26.779 [warning] [Git][revParse] Unable to read file: ENOENT: no such file or directory, open 'c:\Users\dmitriv\repos\vscode\.git\refs\remotes\origin\dev\dmitriv\glob-2'
2025-11-05 14:46:26.838 [info] > git rev-parse refs/remotes/origin/dev/dmitriv/glob-2 [60ms]
2025-11-05 14:46:27.000 [info] > git status -z -uall [158ms]
2025-11-05 14:46:27.091 [info] > git for-each-ref --sort -committerdate --format %(refname)%00%(objectname)%00%(*objectname) [244ms]

GitHug Pull Request Log

2025-11-05 14:45:22.214 [info] [Review+0] Switch to Pull Request microsoft/vscode#273860 - start
2025-11-05 14:45:22.283 [info] [PullRequestGitHelper] Fetch tracked branch refs/remotes/origin/dev/dmitriv/glob-2
2025-11-05 14:45:23.697 [info] [PullRequestGitHelper] Branch dev/dmitriv/glob-2 doesn't exist on local disk yet. Creating from remote.
2025-11-05 14:45:26.623 [info] [PullRequestGitHelper] associate dev/dmitriv/glob-2 with Pull Request microsoft/vscode#273860
2025-11-05 14:45:27.484 [info] [Review+0] Switch to Pull Request microsoft/vscode#273860 - done
2025-11-05 14:45:27.484 [info] [Review+0] Validate state in progress
2025-11-05 14:45:27.484 [info] [Review+0] Validating state...
2025-11-05 14:45:27.501 [info] [FolderRepositoryManager+0] Found GitHub remote for folder c:\Users\dmitriv\repos\vscode
2025-11-05 14:45:27.502 [info] [FolderRepositoryManager+0] Using in-memory cached assignable users.
2025-11-05 14:45:27.597 [info] [Review+0] Found matching pull request metadata for current branch dev/dmitriv/glob-2. Repo: microsoft/vscode PR: 273860
2025-11-05 14:45:27.597 [info] [Review+0] current branch dev/dmitriv/glob-2 is associated with pull request microsoft/vscode#273860
2025-11-05 14:45:27.597 [info] [Review+0] Resolving pull request
2025-11-05 14:45:29.003 [info] [GitHubRepository+0] Fetch branch main - enter
2025-11-05 14:45:29.346 [info] [GitHubRepository+0] Fetch branch main - done: true
2025-11-05 14:45:29.346 [info] [Review+0] Resolved PR microsoft/vscode#273860, state is CLOSED
2025-11-05 14:45:30.030 [info] [Review+0] Found matching pull request metadata on GitHub for current branch dev/dmitriv/glob-2. Repo: microsoft/vscode PR: 273860
2025-11-05 14:45:30.030 [info] [PullRequestGitHelper] associate dev/dmitriv/glob-2 with Pull Request microsoft/vscode#273860
2025-11-05 14:45:30.665 [info] [Review+0] This PR is closed
```</issue_description>

<agent_instructions>In revieweManager.ts, add the concept of a `_switchedToPullRequest`, which is the last PR that the user `switch`ed to. If the current branch in `validateState` is the `_switchedToPullRequest`, regardless of opened/closed/merged state, use review mode.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@alexr00</author><body>
So, by default we don't enter review mode for closed PRs. This is controlled by the setting `githubPullRequests.useReviewMode`.  It does seem confusing though that we wouldn't enter review mode for a PR that was opened via a link like this.</body></comment_new>
<comment_new><author>@dmitrivMS</author><body>
Agreed, I think it should open PR regardless of the setting in this scenario.</body></comment_new>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with fetching closed pull requests Fix: Enter review mode for explicitly switched PRs regardless of state Nov 11, 2025
Copilot AI requested a review from alexr00 November 11, 2025 10:43
@alexr00 alexr00 marked this pull request as ready for review November 11, 2025 11:01
@alexr00 alexr00 enabled auto-merge (squash) November 11, 2025 11:01
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Nov 11, 2025
@alexr00 alexr00 merged commit 13ee529 into main Nov 11, 2025
6 checks passed
@alexr00 alexr00 deleted the copilot/fix-closed-pr-fetch-issue branch November 11, 2025 11:12
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.

Trying to open a closed PR results in NOP

3 participants