Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(web): scope PR state to the thread branch (#4460)

Julius Marminge724887717f1b
diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts
index c4ae7b966..e59ffc8f6 100644
--- a/apps/web/src/components/BranchToolbar.logic.test.ts
+++ b/apps/web/src/components/BranchToolbar.logic.test.ts
@@ -9,6 +9,7 @@ import {
resolveDraftEnvModeAfterBranchChange,
resolveEffectiveEnvMode,
resolveEnvModeLabel,
+ resolveBranchToolbarPrBranch,
resolveBranchToolbarValue,
resolveLockedWorkspaceLabel,
resolveLocalCheckoutBranchMismatch,
@@ -173,6 +174,35 @@ describe("resolveBranchToolbarValue", () => {
});
});
+describe("resolveBranchToolbarPrBranch", () => {
+ it("uses the explicit thread branch when it matches the displayed branch", () => {
+ expect(
+ resolveBranchToolbarPrBranch({
+ activeThreadBranch: "feature/current",
+ resolvedActiveBranch: "feature/current",
+ }),
+ ).toBe("feature/current");
+ });
+
+ it("hides PR state while an optimistic branch switch is in flight", () => {
+ expect(
+ resolveBranchToolbarPrBranch({
+ activeThreadBranch: "feature/current",
+ resolvedActiveBranch: "feature/next",
+ }),
+ ).toBeNull();
+ });
+
+ it("does not infer PR state without an explicit thread branch", () => {
+ expect(
+ resolveBranchToolbarPrBranch({
+ activeThreadBranch: null,
+ resolvedActiveBranch: "feature/current",
+ }),
+ ).toBeNull();
+ });
+});
+
describe("resolveLocalCheckoutBranchMismatch", () => {
it("detects when a local thread is associated with a different branch than the checkout", () => {
expect(
diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts
index 8fe35fa46..3549eff6e 100644
--- a/apps/web/src/components/BranchToolbar.logic.ts
+++ b/apps/web/src/components/BranchToolbar.logic.ts
@@ -156,6 +156,13 @@ export function resolveBranchToolbarValue(input: {
return currentGitBranch ?? activeThreadBranch;
}
+export function resolveBranchToolbarPrBranch(input: {
+ activeThreadBranch: string | null;
+ resolvedActiveBranch: string | null;
+}): string | null {
+ return input.activeThreadBranch === input.resolvedActiveBranch ? input.activeThreadBranch : null;
+}
+
export function resolveLocalCheckoutBranchMismatch(input: {
effectiveEnvMode: EnvMode;
activeWorktreePath: string | null;
diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx
index 763de56d8..a61427f20 100644
--- a/apps/web/src/components/BranchToolbarBranchSelector.tsx
+++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx
@@ -35,6 +35,7 @@ import { parsePullRequestReference } from "../pullRequestReference";
import { getSourceControlPresentation } from "../sourceControlPresentation";
import {
deriveLocalBranchNameFromRemoteRef,
+ resolveBranchToolbarPrBranch,
resolveBranchSelectionTarget,
resolveBranchToolbarValue,
resolveDraftEnvModeAfterBranchChange,
@@ -591,9 +592,11 @@ export function BranchToolbarBranchSelector({
// PR pill shown next to the branch selector when the active branch has one.
const branchPr = resolveThreadPr({
- threadBranch: resolvedActiveBranch,
+ threadBranch: resolveBranchToolbarPrBranch({
+ activeThreadBranch,
+ resolvedActiveBranch,
+ }),
gitStatus: branchStatusQuery.data ?? null,
- hasDedicatedWorktree: activeWorktreePath !== null,
});
const branchPrStatus = prStatusIndicator(branchPr, branchStatusQuery.data?.sourceControlProvider);
// Action-oriented tooltip (the pill opens the PR), distinct from the sidebar's
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 73fb98bc9..b234d0765 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -3874,7 +3874,6 @@ function ChatViewContent(props: ChatViewProps) {
const activeThreadPr = resolveThreadPr({
threadBranch: activeThread?.branch ?? null,
gitStatus: gitStatusQuery.data ?? null,
- hasDedicatedWorktree: (activeThread?.worktreePath ?? null) !== null,
});
const supportsSettlement = serverConfig?.environment.capabilities.threadSettlement === true;
const supportsSnooze = serverConfig?.environment.capabilities.threadSnooze === true;
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index a1d95eaa7..b05b3a39d 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -452,7 +452,6 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
const pr = resolveThreadPr({
threadBranch: thread.branch,
gitStatus: gitStatus.data,
- hasDedicatedWorktree: thread.worktreePath !== null,
});
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
diff --git a/apps/web/src/components/SidebarV2.tsx b/apps/web/src/components/SidebarV2.tsx
index 8c5891ebe..a5f9eca5f 100644
--- a/apps/web/src/components/SidebarV2.tsx
+++ b/apps/web/src/components/SidebarV2.tsx
@@ -502,7 +502,6 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
const pr = resolveThreadPr({
threadBranch: thread.branch,
gitStatus: gitStatus.data,
- hasDedicatedWorktree: thread.worktreePath !== null,
});
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
const settledPrHoverClass = pr ? settledPrHoverColorClass(pr.state) : undefined;
diff --git a/apps/web/src/components/ThreadStatusIndicators.test.ts b/apps/web/src/components/ThreadStatusIndicators.test.ts
index 9fb4535f2..3eb8e4f71 100644
--- a/apps/web/src/components/ThreadStatusIndicators.test.ts
+++ b/apps/web/src/components/ThreadStatusIndicators.test.ts
@@ -36,31 +36,35 @@ describe("resolveThreadPr", () => {
resolveThreadPr({
threadBranch: "feature/other",
gitStatus: status(),
- hasDedicatedWorktree: false,
}),
).toBeNull();
});
- it("shows PR indicators for dedicated worktree threads even when branch metadata is stale", () => {
- const gitStatus = status();
+ it("hides PR indicators when a dedicated worktree has switched away from the thread branch", () => {
+ expect(
+ resolveThreadPr({
+ threadBranch: "stack/base",
+ gitStatus: status(),
+ }),
+ ).toBeNull();
+ });
+ it("hides PR indicators when thread branch metadata is missing", () => {
expect(
resolveThreadPr({
- threadBranch: "feature/old-name",
- gitStatus,
- hasDedicatedWorktree: true,
+ threadBranch: null,
+ gitStatus: status(),
}),
- ).toBe(gitStatus.pr);
+ ).toBeNull();
});
- it("shows PR indicators for dedicated worktree threads even when branch metadata is missing", () => {
+ it("shows the PR when the live checkout matches the stored thread branch", () => {
const gitStatus = status();
expect(
resolveThreadPr({
- threadBranch: null,
+ threadBranch: "feature/current",
gitStatus,
- hasDedicatedWorktree: true,
}),
).toBe(gitStatus.pr);
});
diff --git a/apps/web/src/components/ThreadStatusIndicators.tsx b/apps/web/src/components/ThreadStatusIndicators.tsx
index 0d3291a9e..af53d1a78 100644
--- a/apps/web/src/components/ThreadStatusIndicators.tsx
+++ b/apps/web/src/components/ThreadStatusIndicators.tsx
@@ -113,17 +113,12 @@ export function PrStatusTooltipContent({ status }: { status: PrStatusIndicator }
export function resolveThreadPr(input: {
threadBranch: string | null;
gitStatus: VcsStatusResult | null;
- hasDedicatedWorktree: boolean;
}): ThreadPr | null {
- const { threadBranch, gitStatus, hasDedicatedWorktree } = input;
+ const { threadBranch, gitStatus } = input;
if (gitStatus === null) {
return null;
}
- if (hasDedicatedWorktree) {
- return gitStatus.pr ?? null;
- }
-
if (threadBranch === null || gitStatus.refName !== threadBranch) {
return null;
}
@@ -258,7 +253,6 @@ export function ThreadRowLeadingStatus({ thread }: { thread: SidebarThreadSummar
const pr = resolveThreadPr({
threadBranch: thread.branch,
gitStatus: gitStatus.data,
- hasDedicatedWorktree: thread.worktreePath !== null,
});
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
const threadStatus = resolveThreadStatusPill({