Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ddb90fb
test(web): reproduce stale workspace after adding a project
StiensWout Nov 26, 2026
c25ea12
fix(web): moved drafts use the destination workspace default
StiensWout Nov 26, 2026
32c627c
test(web): cover moving a draft into a project with a workspace file
StiensWout Nov 26, 2026
f728760
fix(web): apply project file workspace defaults after draft moves
StiensWout Nov 26, 2026
2783b4a
fix(web): keep waiting sends and branch choices on their draft project
StiensWout Nov 26, 2026
10651a9
fix(web): honor branch picks before checkout finishes
StiensWout Nov 26, 2026
89a712b
test(web): drop branch pick case that only exercises the existing cle…
StiensWout Nov 26, 2026
c83ab1e
refactor(web): resolve the waiting-send result directly instead of th…
StiensWout Nov 26, 2026
76113ed
fix(web): retain workspace defaults after failed branch actions
StiensWout Nov 26, 2026
3552307
refactor(web): keep branch handler guards in place instead of passing…
StiensWout Nov 26, 2026
d3e6106
Merge remote-tracking branch 'origin/main' into wf/find-95c19290cac4c…
juliusmarminge Nov 26, 2026
a0dbbe6
test(web): capture the workspace in the t3.json scenario
juliusmarminge Nov 26, 2026
baf48a4
fix(web): keep the late workspace default when load balancing moves a…
juliusmarminge Nov 26, 2026
e32f81e
Merge origin/main into wf/find-95c19290cac4ce8ede825fed
juliusmarminge Nov 26, 2026
27bed58
fix(web): a move after a branch pick still stops a waiting send
juliusmarminge Nov 26, 2026
a06cf6f
Merge origin/main into wf/find-95c19290cac4ce8ede825fed
juliusmarminge Nov 26, 2026
cd8848e
Merge origin/main into wf/find-95c19290cac4ce8ede825fed
juliusmarminge Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions apps/web/src/components/BranchToolbarBranchSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
import { readLocalApi } from "../localApi";
import { useOpenPrLink } from "../lib/openPullRequestLink";
import { withDraftBranchChoice } from "../lib/retargetDraftWorkspace";
import { usePaginatedBranches } from "../state/queries";
import { useProjectClone } from "../state/projectClones";
import { readThreadShell, useProject, useQuietThreadShell } from "../state/entities";
Expand Down Expand Up @@ -443,10 +444,13 @@ export function BranchToolbarBranchSelector({
);
return;
}
startBranchActionTransition(async () => {
await action();
branchRefState.refresh();
});
const completed = Promise.withResolvers<void>();
startBranchActionTransition(() =>
action()
.then(() => branchRefState.refresh())
.finally(() => completed.resolve()),
);
return completed.promise;
};

// The picker's list, and the server's coalesced ref listing, can predate a checkout an agent
Expand All @@ -461,14 +465,19 @@ export function BranchToolbarBranchSelector({
return resolveConfirmedSelectedRef(listedRef, result._tag === "Success" ? result.value : null);
};

const selectBranch = async (listedRef: VcsRef) => {
const selectedDraftId = () =>
hasServerThread
? null
: (draftId ?? useComposerDraftStore.getState().getDraftIdByRef(threadRef));

const applyBranchSelection = async (listedRef: VcsRef, commit: () => void) => {
if (!canUpdateThreadBranch || !branchCwd || !activeProjectCwd || isBranchActionPending) return;
const selectionId = ++latestSelectionIdRef.current;

let latest = readLatestThreadState();
if (isSelectingWorktreeBase) {
if (latest.worktreePath) return;
setThreadBranch(listedRef.name, null);
if (setThreadBranch(listedRef.name, null)) commit();
setIsBranchMenuOpen(false);
onComposerFocusRequest?.();
return;
Expand Down Expand Up @@ -503,15 +512,15 @@ export function BranchToolbarBranchSelector({
selectionTarget.reuseExistingWorktree &&
!(selectionTarget.staysInActiveCheckout && canWriteSourceControl)
) {
setThreadBranch(refName.name, selectionTarget.nextWorktreePath);
if (setThreadBranch(refName.name, selectionTarget.nextWorktreePath)) commit();
return;
}

const selectedBranchName = refName.isRemote
? deriveLocalBranchNameFromRemoteRef(refName.name, refName.remoteName)
: refName.name;

runBranchAction(async () => {
return runBranchAction(async () => {
const previousBranch = resolvedActiveBranch;
setOptimisticBranch(selectedBranchName);
const checkoutKey = pickerCheckoutKey(environmentId, selectionTarget.checkoutCwd);
Expand Down Expand Up @@ -540,6 +549,7 @@ export function BranchToolbarBranchSelector({
: undefined,
);
if (applied) {
commit();
hold = {
branch: nextBranchName,
environmentId,
Expand Down Expand Up @@ -575,7 +585,10 @@ export function BranchToolbarBranchSelector({
});
};

const createRef = (rawName: string) => {
const selectBranch = (listedRef: VcsRef) =>
withDraftBranchChoice(selectedDraftId(), (commit) => applyBranchSelection(listedRef, commit));

const applyNewRef = async (rawName: string, commit: () => void) => {
if (!canChangeThreadBranch) return;
const name = sanitizeNewRefName(rawName);
if (!branchCwd || !name || isBranchActionPending) return;
Expand All @@ -584,7 +597,7 @@ export function BranchToolbarBranchSelector({
setIsBranchMenuOpen(false);
onComposerFocusRequest?.();

runBranchAction(async () => {
return runBranchAction(async () => {
const previousBranch = resolvedActiveBranch;
setOptimisticBranch(name);
const checkoutKey = pickerCheckoutKey(environmentId, branchCwd);
Expand All @@ -602,6 +615,7 @@ export function BranchToolbarBranchSelector({
pickerCheckouts.set(checkoutKey, nextBranchName);
const applied = setThreadBranch(nextBranchName, activeWorktreePath);
if (applied) {
commit();
setBranchHold({
branch: nextBranchName,
environmentId,
Expand All @@ -625,6 +639,9 @@ export function BranchToolbarBranchSelector({
});
};

const createRef = (rawName: string) =>
void withDraftBranchChoice(selectedDraftId(), (commit) => applyNewRef(rawName, commit));

const worktreeBaseBranchCandidate = isInitialBranchesLoadPending
? null
: resolveDefaultWorktreeBaseBranch(refs);
Expand Down
9 changes: 6 additions & 3 deletions apps/web/src/components/chat/useComposerSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ import { recordPromptSent } from "../GitHubStarPrompt";
import { stackedThreadToast, toastManager } from "../ui/toast";
import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
import { newMessageId, newThreadId } from "~/lib/utils";
import { readPendingWorkspaceDefault, useNewThreadHandler } from "../../hooks/useHandleNewThread";
import { useNewThreadHandler } from "../../hooks/useHandleNewThread";
import { readPendingWorkspaceDefault } from "../../lib/retargetDraftWorkspace";
import { buildThreadRouteParams } from "../../threadRoutes";
import {
beginBackgroundDraftSubmissionByRef,
Expand Down Expand Up @@ -1805,10 +1806,12 @@ export function useComposerSend(input: ComposerSendInput) {
draftId && !sendInFlightRef.current ? readPendingWorkspaceDefault(draftId) : null;
if (workspaceDefault === null) return sendWithEnvironmentRefresh(...args);
sendInFlightRef.current = true;
await workspaceDefault.finally(() => {
const ready = await workspaceDefault.finally(() => {
sendInFlightRef.current = false;
});
return sendWithEnvironmentRefreshLatest(...args);
if (ready && currentRouteThreadKeyRef.current === routeThreadKey) {
return sendWithEnvironmentRefreshLatest(...args);
}
};
// No load-balancing refresh: it bails once the draft is no longer displayed, which is the
// only time a detached send runs, so the draft keeps the environment it was dictated for.
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/components/chat/useDraftEnvironmentRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ export function useDraftEnvironmentRouting(input: DraftEnvironmentRoutingInput)
}
carryFanoutSelections(currentDraft, target.environmentId);
const projectRef = scopeProjectRef(target.environmentId, project.id);
const workspace = retargetDraftWorkspace(currentDraft, projectRef);
const { workspace, applyProjectFile } = retargetDraftWorkspace(
currentDraft,
projectRef,
project,
);
if (activeProjectIsScratch) {
setLogicalProjectDraftThreadId(
deriveLogicalProjectKeyFromSettings(project, projectGroupingSettings),
Expand All @@ -348,6 +352,7 @@ export function useDraftEnvironmentRouting(input: DraftEnvironmentRoutingInput)
...workspace,
});
}
applyProjectFile(draftId);
seedDraftModelSelection(draftId, projectRef);
};
const finish = () => {
Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/hooks/useHandleNewThread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,8 @@ vi.mock("../uiStateStore", () => ({
}));
vi.mock("./useSettings", () => ({ getClientSettings: () => ({}) }));

import {
readPendingWorkspaceDefault,
resolveDefaultProjectRef,
useNewThreadHandler,
} from "./useHandleNewThread";
import { resolveDefaultProjectRef, useNewThreadHandler } from "./useHandleNewThread";
import { readPendingWorkspaceDefault } from "../lib/retargetDraftWorkspace";

describe.each([
["new", null],
Expand Down
Loading
Loading