From e6a2ec0a8fca638efde2bf84f7f2b3c9506d003c Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Sat, 2 May 2026 03:20:13 +0200 Subject: [PATCH] fix(sf): guard auto-loop against missing DB and missing basePath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two small defensive fixes in the auto-loop that surfaced when running sf in degraded environments (no .sf/sf.db yet, or unset basePath): - phases.ts: gate planning-flow gate behind isDbAvailable() so a missing or not-yet-initialized DB does not throw inside the gate runner. - run-unit.ts: skip process.chdir when s.basePath is falsy. The original guard compared cwd to an empty string, which always failed on the first unit of a fresh runtime root. Both are conservative — preserve existing behaviour when DB and basePath are present. --- src/resources/extensions/sf/auto/phases.ts | 2 +- src/resources/extensions/sf/auto/run-unit.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resources/extensions/sf/auto/phases.ts b/src/resources/extensions/sf/auto/phases.ts index b6ad360ca..b0be859de 100644 --- a/src/resources/extensions/sf/auto/phases.ts +++ b/src/resources/extensions/sf/auto/phases.ts @@ -596,7 +596,7 @@ export async function runPreDispatch( // Derive state let state = await deps.deriveState(s.basePath); - if (uokFlags.planningFlow && shouldRunPlanningFlowGate(state.phase)) { + if (uokFlags.planningFlow && isDbAvailable() && shouldRunPlanningFlowGate(state.phase)) { let compiled = ensurePlanningFlowGraph(s.basePath, state); // Empty-graph recovery: stale DB caches can yield 0 nodes right after a // task-complete write. Invalidate caches, re-derive state, and retry once. diff --git a/src/resources/extensions/sf/auto/run-unit.ts b/src/resources/extensions/sf/auto/run-unit.ts index ca3541754..fb46dfa6c 100644 --- a/src/resources/extensions/sf/auto/run-unit.ts +++ b/src/resources/extensions/sf/auto/run-unit.ts @@ -52,7 +52,7 @@ export async function runUnit( // wrong directory. Must be synchronous — no awaits between chdir and // newSession (#1389, #4762 follow-up). try { - if (process.cwd() !== s.basePath) { + if (s.basePath && process.cwd() !== s.basePath) { process.chdir(s.basePath); } } catch (e) {