[Bug]: Creating a thread from a pull request does not link the pull request to the thread#15721

opened19d agobyGgertzgal

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Open a thread in a GitHub-backed project.
  2. Start a thread from a pull request using any of the checkout paths, in worktree (or local) mode:
    • the pull request dialog in chat,
    • the pull request detail panel's checkout hand-off,
    • a pull request hand-off action (e.g. "fix this finding").
  3. Wait for the checkout to finish and the thread to move onto the PR branch.
  4. Open the thread's linked pull requests (thread details / PR panel).

Expected behavior

The pull request the thread was created from is linked to that thread, the same as if it had been linked through the Link pull request dialog or the link_pull_request MCP tool. Linked-PR sync, watching, and the sidebar/thread badges then treat it as the thread's pull request.

Actual behavior

The worktree is prepared and the thread is pointed at the PR branch, but no link is recorded. The PR must be linked by hand afterwards.

None of the paths that prepare a PR checkout write a link:

  • Server: GitManager.preparePullRequestThread (apps/server/src/git/GitManager.ts) uses threadId only to run the project setup script.
  • Web: after preparePullRequestThread succeeds, each caller only re-points the thread at { branch, worktreePath } and never dispatches thread.pull-request.link:
    • ChatView.tsx → handlePreparedPullRequestThread
    • pullRequest/PullRequestDetailPanel.tsx (checkout hand-off)
    • pullRequest/usePullRequestActions.ts (usePullRequestHandoffs)

Because the server method already resolves the pull request and receives the threadId, linking there would cover all three web paths plus any other caller with no client changes.

Impact

Minor bug or occasional failure

Version or commit

main @ 4ee6bfd50e

Environment

macOS, T3 Code desktop

Workaround

Link the pull request manually from the thread's Link pull request dialog after the checkout completes.

Note

Grok responding on behalf of Julius.

Triage

Thanks for tracing all three checkout paths, @gertzgal. I didn't find another issue covering this.

What I found

I checked main at 4ee6bfd. Checkout prepares the branch and points a thread at it, but it never writes a thread.pull-request.link.

Likely fix area

  • One option is to store the resolved pull request on the draft that receives the checkout. Then dispatch thread.pull-request.link when that draft becomes a server thread. All three web callers already have result.pullRequest.
  • Today's link sources are manual, created, agent, stack, and stack-dismissed. A checkout link might want its own source.

A maintainer will decide on the fix direction.

Reproduced in the web dev app on b5a226e49c, using isolated state and a GitHub-backed project. The chat checkout dialog in Local mode and the PR detail panel checkout in a separate worktree both completed. After materializing each draft as a thread, the persisted thread had its PR branch and branchPullRequest reference, but pullRequests remained empty. The visible branch badge therefore does not establish an explicit link. macOS Electron has not been checked.

Fix submitted in #23458. The web draft retains the checkout PR and links each successfully started thread. Focused tests, web typecheck and lint pass. Runtime records cover the original failure and a persisted link after reload; matched browser recordings and Electron verification remain incomplete after environment interruptions.