From 432cb79097e1af3ddfb0340c265ea4a2c1bdc995 Mon Sep 17 00:00:00 2001 From: Tibsfox Date: Mon, 6 Apr 2026 18:55:33 -0700 Subject: [PATCH] fix(gsd): auto-checkout to main when isolation:none finds stale milestone branch When switching from isolation:branch/worktree to isolation:none, HEAD could remain on a milestone/ branch from the prior session. All subsequent auto-mode commits would silently land on the wrong branch. Now auto-start checks for stale milestone branches when isolation:none and auto-checks out to the integration branch (main/master). Closes #3613 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/resources/extensions/gsd/auto-start.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/resources/extensions/gsd/auto-start.ts b/src/resources/extensions/gsd/auto-start.ts index 8751d51c7..e73583954 100644 --- a/src/resources/extensions/gsd/auto-start.ts +++ b/src/resources/extensions/gsd/auto-start.ts @@ -44,6 +44,9 @@ import { nativeInit, nativeAddAll, nativeCommit, + nativeGetCurrentBranch, + nativeDetectMainBranch, + nativeCheckoutBranch, } from "./native-git-bridge.js"; import { GitServiceImpl } from "./git-service.js"; import { @@ -528,6 +531,22 @@ export async function bootstrapAutoSession( setActiveMilestoneId(base, s.currentMilestoneId); } + // Guard against stale milestone branch when isolation:none (#3613). + // A prior session with isolation:branch/worktree may have left HEAD on + // milestone/. Auto-checkout back to the integration branch. + if (getIsolationMode() === "none" && nativeIsRepo(base)) { + try { + const currentBranch = nativeGetCurrentBranch(base); + if (currentBranch.startsWith("milestone/")) { + const integrationBranch = nativeDetectMainBranch(base); + nativeCheckoutBranch(base, integrationBranch); + logWarning("autoStart", `Returned to "${integrationBranch}" — HEAD was on stale milestone branch "${currentBranch}" (isolation: none does not use milestone branches).`); + } + } catch { + // Non-fatal — log and continue; user may need to manually checkout + } + } + // ── Auto-worktree setup ── s.originalBasePath = base;