Skip to content

feat(code): harden branch linking during PR creation flow#1963

Open
adboio wants to merge 1 commit into04-30-chore_code_remove_diff_agent_actions_flagfrom
04-30-feat_code_harden_branch_linking_during_pr_creation_flow
Open

feat(code): harden branch linking during PR creation flow#1963
adboio wants to merge 1 commit into04-30-chore_code_remove_diff_agent_actions_flagfrom
04-30-feat_code_harden_branch_linking_during_pr_creation_flow

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented Apr 30, 2026

Problem

The unified PR badge in the task header sometimes wouldn't render even though a PR existed — the simpler "View PR" + git options menu would show instead. Worse, it would only "fix itself" once the agent next edited a file.

The badge depends on workspace.linkedBranch being set. Linking happened via a fire-and-forget workspace.linkBranch.mutate() call in the renderer (useGitInteraction.runCreatePr) right after the create-PR mutation returned. If the renderer reloaded mid-flow (e.g. Vite HMR during dev, or any IPC tear-down), that second mutation never landed on the main process, the link was silently lost (only log.warn'd), and the only recovery was handleAgentFileActivity re-linking on the next agent edit.

#1947 made the happy path fast (subscription invalidation + optimistic getPrUrlForBranch cache prime) but didn't address the durability of the link itself — when the fire-and-forget call is dropped, neither leg of #1947 has anything to act on.

closes #1959

Changes

Move the linkBranch call into the main-process GitService.createPr flow so it's atomic with PR creation and survives renderer reloads.

  • Inject WorkspaceService into GitService (no circular dep — WorkspaceService doesn't depend on GitService).
  • After a successful PR creation, call workspaceService.linkBranch(taskId, branchName, "user"). Branch resolved as input.branchName ?? getCurrentBranch(directoryPath).
  • Drop both fire-and-forget linkBranch.mutate() blocks in useGitInteraction.runCreatePr. Kept invalidateGitBranchQueries and the optimistic getPrUrlForBranch cache prime — those still provide the latency win from fix(code): invalidate queries on PR creation #1947, just no longer load-bearing for correctness.
  • Updated GitService test instantiations to pass a WorkspaceService stub.

How did you test this?

  • pnpm --filter code typecheck clean
  • pnpm --filter code test — all 982 tests pass
  • Need to verify manually: create a PR via the UI, confirm the unified PR badge appears immediately, and that it still appears after a hot reload mid-flow.

Publish to changelog?

no

Copy link
Copy Markdown
Contributor Author

adboio commented Apr 30, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@adboio adboio marked this pull request as ready for review April 30, 2026 21:33
@adboio adboio requested a review from a team April 30, 2026 21:33
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/main/services/git/service.ts:632-638
**No test coverage for the new `linkBranch` call in `createPr`**

The test file updates `GitService` constructors to accept a `WorkspaceService` stub (`{} as WorkspaceService`), but no test verifies that `workspaceService.linkBranch` is called (with the right args) during `createPr`. This is the core behaviour change of the PR, and `createPr` currently has zero test coverage. If a proper mock were supplied (e.g. `{ linkBranch: vi.fn() } as unknown as WorkspaceService`), it would also prevent a silent `TypeError` if any future test exercises a code path through `createPr` with a `taskId`.

Reviews (1): Last reviewed commit: "feat(code): harden branch linking during..." | Re-trigger Greptile

Comment on lines +632 to +638
if (input.taskId) {
const linkedBranch =
input.branchName ?? (await getCurrentBranch(directoryPath));
if (linkedBranch) {
this.workspaceService.linkBranch(input.taskId, linkedBranch, "user");
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No test coverage for the new linkBranch call in createPr

The test file updates GitService constructors to accept a WorkspaceService stub ({} as WorkspaceService), but no test verifies that workspaceService.linkBranch is called (with the right args) during createPr. This is the core behaviour change of the PR, and createPr currently has zero test coverage. If a proper mock were supplied (e.g. { linkBranch: vi.fn() } as unknown as WorkspaceService), it would also prevent a silent TypeError if any future test exercises a code path through createPr with a taskId.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/main/services/git/service.ts
Line: 632-638

Comment:
**No test coverage for the new `linkBranch` call in `createPr`**

The test file updates `GitService` constructors to accept a `WorkspaceService` stub (`{} as WorkspaceService`), but no test verifies that `workspaceService.linkBranch` is called (with the right args) during `createPr`. This is the core behaviour change of the PR, and `createPr` currently has zero test coverage. If a proper mock were supplied (e.g. `{ linkBranch: vi.fn() } as unknown as WorkspaceService`), it would also prevent a silent `TypeError` if any future test exercises a code path through `createPr` with a `taskId`.

How can I resolve this? If you propose a fix, please make it concise.

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.

1 participant