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/<MID> 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) <noreply@anthropic.com>
This commit is contained in:
Tibsfox 2026-04-06 18:55:33 -07:00
parent b4c6229360
commit 432cb79097

View file

@ -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/<MID>. 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;