Skip to content

fix(code): invalidate queries on PR creation#1947

Merged
k11kirky merged 1 commit intomainfrom
04-29-fix_code_invalidate_queries_on_pr_creation
Apr 30, 2026
Merged

fix(code): invalidate queries on PR creation#1947
k11kirky merged 1 commit intomainfrom
04-29-fix_code_invalidate_queries_on_pr_creation

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented Apr 29, 2026

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

Copy link
Copy Markdown
Contributor Author

adboio commented Apr 29, 2026

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

@adboio adboio requested a review from a team April 29, 2026 22:48
@adboio adboio marked this pull request as ready for review April 29, 2026 22:48
@k11kirky k11kirky merged commit b38b050 into main Apr 30, 2026
16 checks passed
@k11kirky k11kirky deleted the 04-29-fix_code_invalidate_queries_on_pr_creation branch April 30, 2026 08:15
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
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.

2 participants