Skip to content

Commit 55a7695

Browse files
t3dotggclaude
andcommitted
fix(web): carry working mode when reusing a draft with explicit workspace options
Review: the model/permissions/interaction-mode carry only ran in the no-options branch of the stored-draft reuse path, so "New thread on <branch>" (which passes explicit workspace options) reopened stale drafts with their old model and permission mode. Restructure the branch so explicit workspace options and the defaults-reset share one write that always includes the carried working mode. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 690098b commit 55a7695

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

‎apps/web/src/hooks/useHandleNewThread.ts‎

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,38 +130,44 @@ export function useNewThreadHandler() {
130130
: null;
131131
if (reusableStoredDraftThread) {
132132
return (async () => {
133-
if (
133+
const isDraftAlreadyOpen =
134+
currentRouteTarget?.kind === "draft" &&
135+
currentRouteTarget.draftId === reusableStoredDraftThread.draftId;
136+
const hasExplicitWorkspaceOption =
134137
hasBranchOption ||
135138
hasWorktreePathOption ||
136139
hasEnvModeOption ||
137-
hasStartFromOriginOption
138-
) {
139-
setDraftThreadContext(reusableStoredDraftThread.draftId, {
140-
...(hasBranchOption ? { branch: options?.branch ?? null } : {}),
141-
...(hasWorktreePathOption ? { worktreePath: options?.worktreePath ?? null } : {}),
142-
...(hasEnvModeOption ? { envMode: options?.envMode } : {}),
143-
...(hasStartFromOriginOption ? { startFromOrigin: options?.startFromOrigin } : {}),
144-
});
145-
} else if (
146-
currentRouteTarget?.kind !== "draft" ||
147-
currentRouteTarget.draftId !== reusableStoredDraftThread.draftId
148-
) {
149-
// Resurrecting a stored draft must not resurrect its stale env
150-
// context: drafts seeded before a defaults change (or by the old
151-
// carry-over behavior) would otherwise keep landing on "current
152-
// checkout" branches forever. Composer text is preserved; only
153-
// the env context resets to the configured defaults. When the
154-
// draft is already open, leave it alone — the user may have just
155-
// picked a branch in the composer.
156-
const defaultEnvMode = primaryServerSettings.defaultThreadEnvMode;
140+
hasStartFromOriginOption;
141+
// Resurrecting a stored draft must not resurrect its stale context:
142+
// explicit workspace options win outright; otherwise the env context
143+
// resets to the configured defaults so drafts seeded before a
144+
// defaults change (or by the old carry-over behavior) stop landing
145+
// on "current checkout" branches forever. Composer text is
146+
// preserved. When the draft is already open and no options were
147+
// passed, leave it alone entirely — the user may have just picked a
148+
// branch in the composer.
149+
const defaultEnvMode = primaryServerSettings.defaultThreadEnvMode;
150+
const workspaceContext = hasExplicitWorkspaceOption
151+
? {
152+
...(hasBranchOption ? { branch: options?.branch ?? null } : {}),
153+
...(hasWorktreePathOption ? { worktreePath: options?.worktreePath ?? null } : {}),
154+
...(hasEnvModeOption ? { envMode: options?.envMode } : {}),
155+
...(hasStartFromOriginOption ? { startFromOrigin: options?.startFromOrigin } : {}),
156+
}
157+
: isDraftAlreadyOpen
158+
? null
159+
: {
160+
branch: null,
161+
worktreePath: null,
162+
envMode: defaultEnvMode,
163+
startFromOrigin: resolveNewDraftStartFromOrigin({
164+
envMode: defaultEnvMode,
165+
newWorktreesStartFromOrigin: primaryServerSettings.newWorktreesStartFromOrigin,
166+
}),
167+
};
168+
if (workspaceContext) {
157169
setDraftThreadContext(reusableStoredDraftThread.draftId, {
158-
branch: null,
159-
worktreePath: null,
160-
envMode: defaultEnvMode,
161-
startFromOrigin: resolveNewDraftStartFromOrigin({
162-
envMode: defaultEnvMode,
163-
newWorktreesStartFromOrigin: primaryServerSettings.newWorktreesStartFromOrigin,
164-
}),
170+
...workspaceContext,
165171
...(carryRuntimeMode ? { runtimeMode: carryRuntimeMode } : {}),
166172
...(carryInteractionMode ? { interactionMode: carryInteractionMode } : {}),
167173
});

0 commit comments

Comments
 (0)