fix(git): keep task PR state in sync when the primary PR changes#3263
Conversation
Promoting a different PR to primary reordered the URL list but broadcast the old primary's cached prState alongside the new primary's URL, so a task could show "merged" while its primary PR was actually open until the next background poll (~60s later) overwrote the cache. setPrimaryPrUrl now fetches the promoted PR's live state via getPrDetailsByUrl + mapPrState, persists it through updatePrCache, and emits the fresh state, so the cache columns and prUrls[0] can no longer disagree and every taskPrInfoChanged consumer updates immediately. Generated-By: PostHog Code Task-Id: 2772f1aa-cba4-46df-a8b6-3a14a0f15299
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
There was a problem hiding this comment.
Small correctness fix: promotes PR URL then fetches live state instead of emitting stale cached state. The interface change from void to Promise<void> is consistent across the interface, implementation, and the single router call site (tRPC mutation handles async natively). No showstoppers.
|
Reviews (1): Last reviewed commit: "fix(git): keep task PR state in sync whe..." | Re-trigger Greptile |
Guard getPrDetailsByUrl with a catch so a network/API failure after the prUrls reorder still runs updatePrCache and emit with prState null, instead of leaving prUrls[0] and the prUrl/prState columns disagreeing. Collapse the setPrimaryPrUrl tests into an it.each table and add the rejection case. Generated-By: PostHog Code Task-Id: 2772f1aa-cba4-46df-a8b6-3a14a0f15299
New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.
There was a problem hiding this comment.
Small correctness fix that fetches live PR state after promoting a URL instead of emitting stale cached data. The .catch(() => null) guards against network failures, and the Promise<void> interface change is handled natively by the tRPC mutation call site. Both reviewer concerns were addressed in the current head.
Problem
The #3227 feature let a task carry multiple PRs, with the "primary" PR being whichever URL sits at index 0 of an ordered list. A task's displayed state (
merged/open/draft/closed) is a denormalized cache derived from that primary PR.When a user promotes a different PR to primary (via the "Other PRs" submenu),
TaskPrStatusService.setPrimaryPrUrlreordered the URL list but broadcast the old primary's cachedprStatealongside the new primary's URL. If the old primary was merged and the new primary was still open, every consumer of thetaskPrInfoChangedevent (sidebar badge, inbox, home, code-review) showed the task as "merged" while its primary PR was actually open. The drift only self-healed up to ~60s later when the next background revalidation poll overwrote the cache.Root cause:
promotePrUrlonly rewrites theprUrlsJSON column; theprUrl/prStatecolumns are maintained by a separateupdatePrCachepath driven by revalidation, so the two disagreed until the next poll.Fix
setPrimaryPrUrlnow fetches the promoted PR's live state viagitService.getPrDetailsByUrl+mapPrState(the same primitivescomputeTaskPrStatusalready uses), persists it throughupdatePrCache, then emits the fresh state. The cache columns andprUrls[0]can no longer disagree, and everytaskPrInfoChangedconsumer updates immediately rather than on the next poll.The port signature changed from
voidtoPromise<void>; the tRPC router forward already awaits it transparently.Non-goals
The reverse scenario (a non-primary PR merging) intentionally leaves task state unchanged, since state is derived only from the primary PR.
Testing
setPrimaryPrUrltest that codified the buggy stale-emit with two tests: one asserting the promoted PR's live state is recomputed and emitted, one coveringgetPrDetailsByUrl→ null yieldingprState: null.pnpm --filter @posthog/workspace-server test task-pr-status— 7 tests pass.@posthog/workspace-serverand@posthog/host-routertypecheck clean.Created with PostHog Code