GeezerVison is showing github.com — revert: "fix(web): worktree threads warn when the checkout branch changes" (#14883) by t3dotgg · Pull Request #22225 · pingdotgg/t3code
revert: "fix(web): worktree threads warn when the checkout branch changes" (#14883)
#22225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.ts
(4)
.tsx
(2)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -13,7 +13,7 @@ import {
resolveBranchToolbarPrBranch,
resolveBranchToolbarValue,
resolveLockedWorkspaceLabel,
resolveCheckoutBranchMismatch ,
resolveLocalCheckoutBranchMismatch ,
resolvePreviousWorktreeLabel,
resolvePreviousWorktreeSeed,
sanitizeNewRefName,
Expand Down
Expand Up
@@ -301,10 +301,10 @@ describe("resolveBranchToolbarPrBranch", () => {
});
});
describe("resolveCheckoutBranchMismatch ", () => {
describe("resolveLocalCheckoutBranchMismatch ", () => {
it("detects when a local thread is associated with a different branch than the checkout", () => {
expect(
resolveCheckoutBranchMismatch ({
resolveLocalCheckoutBranchMismatch ({
effectiveEnvMode: "local",
activeWorktreePath: null,
activeThreadBranch: "feature/thread",
Expand All
@@ -313,13 +313,12 @@ describe("resolveCheckoutBranchMismatch", () => {
).toEqual({
threadBranch: "feature/thread",
currentBranch: "feature/current",
canRestoreThreadBranch: true,
});
});
it("ignores matching local checkout state", () => {
expect(
resolveCheckoutBranchMismatch ({
resolveLocalCheckoutBranchMismatch ({
effectiveEnvMode: "local",
activeWorktreePath: null,
activeThreadBranch: "feature/thread",
Expand All
@@ -328,34 +327,20 @@ describe("resolveCheckoutBranchMismatch", () => {
).toBeNull();
});
it("warns about worktree branch drift without restore, but ignores a pending rename status", () => {
const worktree = {
effectiveEnvMode: "worktree" as const,
activeWorktreePath: "/repo/.t3/worktrees/feature-thread",
activeThreadBranch: "t3code/fix-sidebar",
};
it("ignores dedicated worktrees because their checkout is already thread-scoped", () => {
expect(
resolveCheckoutBranchMismatch({
...worktree,
currentGitBranch: "t3code/1a2b3c4d",
resolveLocalCheckoutBranchMismatch({
effectiveEnvMode: "worktree",
activeWorktreePath: "/repo/.t3/worktrees/feature-thread",
activeThreadBranch: "feature/thread",
currentGitBranch: "feature/current",
}),
).toBeNull();
expect(
resolveCheckoutBranchMismatch({
...worktree,
currentGitBranch: "feature/checkout",
}),
).toEqual({
threadBranch: worktree.activeThreadBranch,
currentBranch: "feature/checkout",
canRestoreThreadBranch: false,
});
});
it("ignores new-worktree base selection before a worktree exists", () => {
expect(
resolveCheckoutBranchMismatch ({
resolveLocalCheckoutBranchMismatch ({
effectiveEnvMode: "worktree",
activeWorktreePath: null,
activeThreadBranch: "feature/base",
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -6,7 +6,7 @@ import type {
WorktreeSubmodules,
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import { isTemporaryWorktreeBranch, sanitizeNewRefName } from "@t3tools/shared/git";
import { sanitizeNewRefName } from "@t3tools/shared/git";
import { toSortableTimestamp } from "../lib/threadSort";
export {
dedupeRemoteBranchesWithLocalMatches,
Expand Down
Expand Up
@@ -238,35 +238,20 @@ export function resolveBranchToolbarPrBranch(input: {
return input.activeThreadBranch === input.resolvedActiveBranch ? input.activeThreadBranch : null;
}
export function resolveCheckoutBranchMismatch (input: {
export function resolveLocalCheckoutBranchMismatch (input: {
effectiveEnvMode: EnvMode;
activeWorktreePath: string | null;
activeThreadBranch: string | null;
currentGitBranch: string | null;
}) {
}): { threadBranch: string; currentBranch: string } | null {
const { effectiveEnvMode, activeWorktreePath, activeThreadBranch, currentGitBranch } = input;
const isLocalCheckout = effectiveEnvMode === "local" && activeWorktreePath === null;
const isEstablishedWorktree = effectiveEnvMode === "worktree" && activeWorktreePath !== null;
if (!isLocalCheckout && !isEstablishedWorktree) {
if (effectiveEnvMode !== "local" || activeWorktreePath !== null) {
return null;
}
if (!activeThreadBranch || !currentGitBranch || activeThreadBranch === currentGitBranch) {
return null;
}
// Cached status can predate the automatic rename of a temporary worktree branch.
if (
isEstablishedWorktree &&
!isTemporaryWorktreeBranch(activeThreadBranch) &&
isTemporaryWorktreeBranch(currentGitBranch)
) {
return null;
}
return {
threadBranch: activeThreadBranch,
currentBranch: currentGitBranch,
// Restoring a worktree checkout could switch the branch for sibling threads.
canRestoreThreadBranch: isLocalCheckout,
};
return { threadBranch: activeThreadBranch, currentBranch: currentGitBranch };
}
export function resolveBranchSelectionTarget(input: {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -261,14 +261,14 @@ describe("resolveThreadMetadataUpdateForNextTurn", () => {
model: "gpt-5.4",
};
it("adopts the checkout branch without clearing the worktree attachment ", () => {
it("updates a stale local thread branch to the active checkout ", () => {
expect(
resolveThreadMetadataUpdateForNextTurn({
currentModelSelection: modelSelection,
currentBranch: "feature/thread",
nextBranch: "feature/checkout",
}),
).toEqual({ branch: "feature/checkout" });
).toEqual({ branch: "feature/checkout", worktreePath: null });
});
it("does not write metadata when the model and branch are unchanged", () => {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -474,6 +474,7 @@ export function resolveThreadMetadataUpdateForNextTurn(input: {
}): {
modelSelection?: ModelSelection;
branch?: string;
worktreePath?: null;
} | null {
const nextModelSelection = input.nextModelSelection;
const modelSelectionChanged =
Expand All
@@ -488,7 +489,7 @@ export function resolveThreadMetadataUpdateForNextTurn(input: {
}
return {
...(modelSelectionChanged ? { modelSelection: nextModelSelection } : {}),
...(branchChanged ? { branch: input.nextBranch } : {}),
...(branchChanged ? { branch: input.nextBranch, worktreePath: null } : {}),
};
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -441,7 +441,7 @@ import { ThreadDetailsPanel } from "./chat/ThreadDetailsPanel";
import { NoActiveThreadState } from "./NoActiveThreadState";
import {
resolveEffectiveEnvMode,
resolveCheckoutBranchMismatch ,
resolveLocalCheckoutBranchMismatch ,
shouldShowComposerContextStrip,
shouldShowEnvironmentIndicator,
} from "./BranchToolbar.logic";
Expand Down
Expand Up
@@ -3456,6 +3456,26 @@ export default function ChatView(props: ChatViewProps) {
scheduleComposerFocus();
};
const insertArtifactTemplateStable = useStableCallback(insertArtifactTemplate);
const sendAppMessage = async (text: string) => {
if (!isServerThread || activeThreadId === null) {
throw new Error("Messages from apps need a started thread.");
}
const result = await startThreadTurn({
Comment thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
🟠 High components/ChatView.tsx:3463
App messages on existing threads run with the previously persisted runtime and interaction modes, so changing a thread to approval-required or plan mode does not apply that policy to the app message. This path calls startThreadTurn without first persisting the selected modes; use the same persistThreadSettingsForNextTurn step as normal sends and stop if it fails.
🚀 Reply "fix it for me " or copy this AI Prompt for your agent:
In file @apps/web/src/components/ChatView.tsx around line 3463:
App messages on existing threads run with the previously persisted runtime and interaction modes, so changing a thread to approval-required or plan mode does not apply that policy to the app message. This path calls `startThreadTurn` without first persisting the selected modes; use the same `persistThreadSettingsForNextTurn` step as normal sends and stop if it fails.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
environmentId,
input: {
threadId: activeThreadId,
message: { messageId: newMessageId(), role: "user", text, attachments: [] },
runtimeMode,
interactionMode,
dispatchMode: "queue",
},
});
if (result._tag === "Failure") {
const error = squashAtomCommandFailure(result);
throw error instanceof Error ? error : new Error("Could not send the app's message.");
}
};
const sendAppMessageStable = useStableCallback(sendAppMessage);
const queuedRunsControlRef = useRef<QueuedRunsControlHandle>(null);
const addTerminalContextToDraft = (selection: TerminalContextSelection) => {
composerRef.current?.addTerminalContext(selection);
Expand Down
Expand Up
@@ -4769,8 +4789,8 @@ export default function ChatView(props: ChatViewProps) {
requestedEnvMode: envMode,
isGitRepo,
});
const checkoutBranchMismatch = isServerThread
? resolveCheckoutBranchMismatch ({
const localCheckoutBranchMismatch = isServerThread
? resolveLocalCheckoutBranchMismatch ({
effectiveEnvMode: envMode,
activeWorktreePath,
activeThreadBranch,
Expand Down
Expand Up
@@ -5099,10 +5119,10 @@ export default function ChatView(props: ChatViewProps) {
const nowMinute = useNowMinute();
const activeBranchMismatchKey = branchMismatchKey(
activeThread?.id ?? null,
checkoutBranchMismatch ,
localCheckoutBranchMismatch ,
);
const showBranchMismatchBanner = shouldShowBranchMismatchBanner({
hasMismatch: checkoutBranchMismatch !== null,
hasMismatch: localCheckoutBranchMismatch !== null,
isDismissed: isBranchMismatchDismissedForSession(activeBranchMismatchKey),
composerHasContent: composerHasDraftContent,
wasShownForCurrentMismatch:
Expand All
@@ -5121,7 +5141,7 @@ export default function ChatView(props: ChatViewProps) {
if (
!activeProjectCwd ||
!activeThread ||
!checkoutBranchMismatch?.canRestoreThreadBranch ||
!localCheckoutBranchMismatch ||
isRestoringThreadBranch
) {
return;
Expand All
@@ -5131,7 +5151,7 @@ export default function ChatView(props: ChatViewProps) {
environmentId,
input: {
cwd: activeProjectCwd,
refName: checkoutBranchMismatch .threadBranch,
refName: localCheckoutBranchMismatch .threadBranch,
},
});
if (checkoutResult._tag === "Failure") {
Expand All
@@ -5152,7 +5172,7 @@ export default function ChatView(props: ChatViewProps) {
setIsRestoringThreadBranch(false);
return;
}
const nextBranch = checkoutResult.value.refName ?? checkoutBranchMismatch .threadBranch;
const nextBranch = checkoutResult.value.refName ?? localCheckoutBranchMismatch .threadBranch;
if (nextBranch !== activeThread.branch) {
const updateResult = await updateThreadMetadata({
environmentId,
Expand Down
Expand Up
@@ -5269,37 +5289,6 @@ export default function ChatView(props: ChatViewProps) {
};
})() as ComposerBannerStackItem | null;
const sendAppMessage = async (text: string) => {
if (!isServerThread || activeThreadId === null) {
throw new Error("Messages from apps need a started thread.");
}
const settingsResult = await persistThreadSettingsForNextTurn({
threadId: activeThreadId,
createdAt: new Date().toISOString(),
...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
runtimeMode,
interactionMode,
});
const result =
settingsResult._tag === "Failure"
? settingsResult
: await startThreadTurn({
environmentId,
input: {
threadId: activeThreadId,
message: { messageId: newMessageId(), role: "user", text, attachments: [] },
runtimeMode,
interactionMode,
dispatchMode: "queue",
},
});
if (result._tag === "Failure") {
const error = squashAtomCommandFailure(result);
throw error instanceof Error ? error : new Error("Could not send the app's message.");
}
};
const sendAppMessageStable = useStableCallback(sendAppMessage);
const sendStandaloneCommand = async (text: string, failureMessage: string) => {
if (!activeThread || !clientSettingsHydrated || sendInFlightRef.current) return;
const context = composerRef.current?.getSendContext();
Expand Down
Expand Up
@@ -5328,7 +5317,7 @@ export default function ChatView(props: ChatViewProps) {
const settingsResult = await persistThreadSettingsForNextTurn({
threadId,
createdAt,
...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch .currentBranch } : {}),
...(localCheckoutBranchMismatch ? { branch: localCheckoutBranchMismatch .currentBranch } : {}),
runtimeMode,
interactionMode: context.interactionMode,
});
Expand Down
Expand Up
@@ -5612,7 +5601,7 @@ export default function ChatView(props: ChatViewProps) {
].filter((item) => item !== null);
const usageLimitsItems = usageLimitsBanner === null ? [] : [usageLimitsBanner];
const projectCloneItems = projectCloneBannerItem === null ? [] : [projectCloneBannerItem];
if (!checkoutBranchMismatch || !showBranchMismatchBanner || !activeBranchMismatchKey) {
if (!localCheckoutBranchMismatch || !showBranchMismatchBanner || !activeBranchMismatchKey) {
return [
...feedbackBannerItems,
...limitRecoveryItems,
Expand Down
Expand Up
@@ -5641,18 +5630,18 @@ export default function ChatView(props: ChatViewProps) {
<TooltipTrigger
render={
<code className="min-w-0 truncate font-medium text-foreground">
{checkoutBranchMismatch .threadBranch}
{localCheckoutBranchMismatch .threadBranch}
</code>
}
/>
<TooltipPopup side="top">
This thread last ran on {checkoutBranchMismatch .threadBranch}. Sending will continue
on {checkoutBranchMismatch .currentBranch}.
This thread last ran on {localCheckoutBranchMismatch .threadBranch}. Sending will
continue on {localCheckoutBranchMismatch .currentBranch}.
</TooltipPopup>
</Tooltip>
</span>
),
actions: checkoutBranchMismatch.canRestoreThreadBranch ? (
actions: (
<Button
size="xs"
variant="ghost"
Expand All
@@ -5661,7 +5650,7 @@ export default function ChatView(props: ChatViewProps) {
>
{isRestoringThreadBranch ? "Restoring..." : "Restore branch"}
</Button>
) : null ,
),
dismissLabel: "Dismiss branch change notice",
onDismiss: () => {
dismissBranchMismatchForSession(activeBranchMismatchKey);
Expand Down
Expand Up
@@ -6128,7 +6117,9 @@ export default function ChatView(props: ChatViewProps) {
const settingsResult = await persistThreadSettingsForNextTurn({
threadId,
createdAt,
...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
...(localCheckoutBranchMismatch
? { branch: localCheckoutBranchMismatch.currentBranch }
: {}),
runtimeMode,
interactionMode,
});
Expand Down
Expand Up
@@ -7103,7 +7094,9 @@ export default function ChatView(props: ChatViewProps) {
const settingsResult = await persistThreadSettingsForNextTurn({
threadId: threadIdForSend,
createdAt: messageCreatedAt,
...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
...(localCheckoutBranchMismatch
? { branch: localCheckoutBranchMismatch.currentBranch }
: {}),
runtimeMode,
interactionMode: sendInteractionMode,
});
Expand Down
Expand Up
@@ -7457,7 +7450,7 @@ export default function ChatView(props: ChatViewProps) {
const settingsResult = await persistThreadSettingsForNextTurn({
threadId: threadIdForSend,
createdAt: messageCreatedAt,
...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch .currentBranch } : {}),
...(localCheckoutBranchMismatch ? { branch: localCheckoutBranchMismatch .currentBranch } : {}),
runtimeMode,
interactionMode: nextInteractionMode,
});
Expand Down
Expand Up
@@ -7577,7 +7570,7 @@ export default function ChatView(props: ChatViewProps) {
modelSelection: nextThreadModelSelection,
runtimeMode: defaultRuntimeMode,
interactionMode: "default",
branch: checkoutBranchMismatch?.currentBranch ?? activeThreadBranch,
branch: activeThreadBranch,
Comment thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
🟡 Medium components/ChatView.tsx:7573
When a local checkout has moved from stored branch A to branch B, this creates the implementation thread with activeThreadBranch (A), so the new thread immediately shows a branch-mismatch warning and Restore action despite running on B. Use localCheckoutBranchMismatch?.currentBranch as the fallback here, without restoring worktree mismatch handling.
🚀 Reply "fix it for me " or copy this AI Prompt for your agent:
In file @apps/web/src/components/ChatView.tsx around line 7573:
When a local checkout has moved from stored branch A to branch B, this creates the implementation thread with `activeThreadBranch` (A), so the new thread immediately shows a branch-mismatch warning and Restore action despite running on B. Use `localCheckoutBranchMismatch?.currentBranch` as the fallback here, without restoring worktree mismatch handling.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
worktreePath: activeThread.worktreePath,
createdAt,
},
Expand Down
Expand Up
@@ -8669,7 +8662,7 @@ export default function ChatView(props: ChatViewProps) {
<BranchRestoreConfirmHost
threadKey={activeThreadKey}
threadBranch={checkoutBranchMismatch ?.threadBranch ?? ""}
threadBranch={localCheckoutBranchMismatch ?.threadBranch ?? ""}
canWriteSourceControl={canWriteSourceControl}
onConfirm={handleSwitchCheckoutToThreadStable}
/>
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.