From 8358f262e9ca981eba54c4aab9595a269d85d89b Mon Sep 17 00:00:00 2001 From: mastertyko <11311479+mastertyko@users.noreply.github.com> Date: Thu, 26 Mar 2026 16:15:55 +0100 Subject: [PATCH] fix: call ensureDbOpen() before slice queries in /gsd discuss (#2640) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit showDiscuss() is a command handler, not a tool handler, so it lacks the automatic ensureDbOpen() call that tool handlers get. On cold-start sessions where no GSD tool has been called yet, isDbAvailable() returns false, normSlices falls to [], and the function exits with a misleading "All slices are complete — nothing to discuss." notification. Add ensureDbOpen() before both isDbAvailable() call sites in guided-flow.ts: 1. showDiscuss() — the primary bug (false "all complete" exit) 2. buildDiscussSlicePrompt() — secondary (incomplete context when inlining completed-slice summaries) Closes #2560 --- src/resources/extensions/gsd/guided-flow.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/resources/extensions/gsd/guided-flow.ts b/src/resources/extensions/gsd/guided-flow.ts index 30310b3dc..4c655e745 100644 --- a/src/resources/extensions/gsd/guided-flow.ts +++ b/src/resources/extensions/gsd/guided-flow.ts @@ -450,7 +450,10 @@ async function buildDiscussSlicePrompt( } // Completed slice summaries — what was already built that this slice builds on + // Ensure DB is open so getMilestoneSlices returns real data (#2560). { + const { ensureDbOpen } = await import("./bootstrap/dynamic-tools.js"); + await ensureDbOpen(); type NormSlice = { id: string; done: boolean }; let normSlices: NormSlice[] = []; if (isDbAvailable()) { @@ -588,6 +591,14 @@ export async function showDiscuss( return; } + // Ensure DB is open before querying slices (#2560). + // showDiscuss() is a command handler — unlike tool handlers, it has no + // automatic ensureDbOpen() call. Without this, isDbAvailable() returns + // false on cold-start sessions and normSlices falls to [] → false + // "All slices complete" exit. + const { ensureDbOpen } = await import("./bootstrap/dynamic-tools.js"); + await ensureDbOpen(); + // Guard: no roadmap yet (unless DB has slices) const roadmapFile = resolveMilestoneFile(basePath, mid, "ROADMAP"); const roadmapContent = roadmapFile ? await loadFile(roadmapFile) : null;