Preserve pull request status across branch checkouts #5407
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/GitActionsControl.tsx line 1113OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1099,4 +1100,14 @@10991100 // Default to true while loading so we don't flash init controls.11001101 const isRepo = gitStatus?.isRepo ?? true;11011102 const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false;1102- const gitStatusForActions = gitStatus;1103+ const activeThreadBranchPr = useThreadPr({1104+ environmentId: activeEnvironmentId,1105+ cwd: gitCwd,1106+ threadBranch: activeServerThread?.branch ?? null,1107+ gitStatus,1108+ });1109+ // Scope PR-driven actions to the thread's recorded branch: when the1110+ // checkout has moved under a thread, "View PR" must open the thread's PR,1111+ // not whatever the current checkout has. Non-thread contexts (project view,1112+ // new composer) keep the checkout's PR.1113+ const gitStatusForActions = useMemo(() => {apps/server/src/vcs/VcsStatusBroadcaster.ts line 471Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -366,6 +455,17 @@455+ ? undefined456+ : { refreshUpstream: options.refreshUpstream },457+ );458+ // A checkout that lands while the slow remote read is in flight makes459+ // this result describe the previous branch. Publishing it would460+ // attach the old branch's PR/divergence to the new refName — discard461+ // it; the refName change itself already kicked a follow-up refresh.462+ const refNameAfter = (yield* getCachedStatus(cwd))?.local?.value.refName;463+ if (refNameBefore !== undefined && refNameAfter !== refNameBefore) {464+ return (yield* getCachedStatus(cwd))?.remote?.value ?? null;465+ }466+ return yield* updateCachedRemoteStatus(cwd, remote, { publish: true });467+ }),468+ );366469 });367470368- const refreshStatus: VcsStatusBroadcaster["Service"]["refreshStatus"] = Effect.fn(369- "VcsStatusBroadcaster.refreshStatus",370- )(function* (rawCwd) {371- const cwd = yield* withFileSystem(normalizeCwd(rawCwd));471+ const refreshStatusCore = Effect.fn("VcsStatusBroadcaster.refreshStatusCore")(function* (
- apps/web/src/components/ThreadStatusIndicators.tsx line 153OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -128,0 +133,21 @@133+ * badge alive when the checkout has moved elsewhere.134+ */135+export function useThreadPr(input: {136+ environmentId: EnvironmentId | null;137+ cwd: string | null;138+ threadBranch: string | null;139+ gitStatus: VcsStatusResult | null;140+}): ThreadPr | null {141+ const branchPr = useEnvironmentQuery(142+ input.environmentId !== null && input.threadBranch !== null && input.cwd !== null143+ ? vcsEnvironment.branchPr({144+ environmentId: input.environmentId,145+ input: { cwd: input.cwd, branch: input.threadBranch },146+ })147+ : null,148+ );149+ return (150+ resolveThreadPr({ threadBranch: input.threadBranch, gitStatus: input.gitStatus }) ??151+ branchPr.data?.pr ??152+ null153+ );
- @@ -29,7 +33,17 @@2933 })3034 : null,3135 );36+ const branchPr = useEnvironmentQuery(37+ thread.branch !== null && cwd !== null38+ ? vcsEnvironment.branchPr({39+ environmentId: thread.environmentId,40+ input: { cwd, branch: thread.branch },41+ })42+ : null,43+ );32443345 const status = gitStatus.data;34- if (status === null || thread.branch === null || status.refName !== thread.branch) {35- return null;46+ // When the status describes the thread's own branch it is authoritative47+ // about that branch's PR — including when it reports none, so this must not48+ // fall through to a warm branch lookup that would resurrect a stale badge.49+ if (status !== null && thread.branch !== null && status.refName === thread.branch) {
- @@ -376,4 +477,18 @@376- [workflow.localStatus({ cwd }), workflow.remoteStatus({ cwd })],377- { concurrency: "unbounded" },477+ const local = yield* withLocalLock(478+ cwd,479+ Effect.gen(function* () {480+ const localResult = yield* workflow.localStatus({ cwd });481+ return (yield* updateCachedLocalStatus(cwd, localResult, { publish: true })).local;482+ }),378483 );379- return yield* updateCachedStatus(cwd, local, remote, { publish: true });484+ const remote = yield* refreshRemoteStatus(cwd, { invalidate: false });485+ // A checkout can land between the two reads. refreshRemoteStatus discards486+ // a superseded remote result, which would leave `local` describing the old487+ // branch — returning that pair would hand the caller a status the cache488+ // itself no longer agrees with. Prefer the cache's halves, which the489+ // concurrent refresh has already reconciled for the new branch.490+ const cached = yield* getCachedStatus(cwd);491+ return mergeGitStatusParts(492+ cached?.local?.value ?? local,493+ cached?.remote ? cached.remote.value : remote,494+ );
UtkarshUsername(GitHub profile, opens in a new tab) approved these changes
t3-code-bot[bot](GitHub profile, opens in a new tab) reopened this
juliusmarminge added labelsmacroscope-review
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
366c55e3-c521-4f3c-9fa5-ebf0a7adbba8You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.