fix(code): invalidate queries on PR creation#1947
Merged
Conversation
k11kirky
approved these changes
Apr 30, 2026
This was referenced Apr 30, 2026
adboio
added a commit
that referenced
this pull request
May 1, 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 #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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
when a PR is created, we don't invalidate the git queries correctly, so the diff panel shows empty until the cache is stale
Changes
subscribes to PR creation to invalidate queries & passes PR URL directly to query when flow is complete to be even faster
How did you test this?
manually
diff-invalidation-fix.mp4 (uploaded via Graphite)
Publish to changelog?
no