diff --git a/src/resources/extensions/sf/subagent/index.js b/src/resources/extensions/sf/subagent/index.js index dfbf37a3b..dcddb6e03 100644 --- a/src/resources/extensions/sf/subagent/index.js +++ b/src/resources/extensions/sf/subagent/index.js @@ -1452,9 +1452,15 @@ async function runSingleAgent( }; } } - // Feature flag: route through swarm dispatch instead of direct runSubagent. + // Subagent dispatch defaults to the swarm/messagebus path; the bash + // wrapper bin/sf-from-source used to set SF_SUBAGENT_VIA_SWARM=1 for + // that, but the web-launched sf goes node → src/loader.ts directly + // and bypasses the wrapper, so the default is enforced in code here. + // Opt out with SF_SUBAGENT_VIA_SWARM=0 (or =false) when running tests + // or workflows that need the direct-runSubagent subprocess path. const swarmFlag = process.env.SF_SUBAGENT_VIA_SWARM; - if (swarmFlag === "1" || swarmFlag === "true") { + const swarmDisabled = swarmFlag === "0" || swarmFlag === "false"; + if (!swarmDisabled) { return runSingleAgentViaSwarm( defaultCwd, agent, diff --git a/src/resources/extensions/sf/tests/subagent-via-swarm.test.mjs b/src/resources/extensions/sf/tests/subagent-via-swarm.test.mjs index 4ae668858..8f0f1b6ab 100644 --- a/src/resources/extensions/sf/tests/subagent-via-swarm.test.mjs +++ b/src/resources/extensions/sf/tests/subagent-via-swarm.test.mjs @@ -84,11 +84,12 @@ afterEach(() => { // ─── Tests ───────────────────────────────────────────────────────────────────── -test("SF_SUBAGENT_VIA_SWARM unset → runSubagent path, swarmDispatchAndWait NOT called", async () => { - // With the flag unset, runSingleAgent should NOT touch swarmDispatchAndWait. - // It will try to call runSubagent (from @singularity-forge/coding-agent), which - // will fail inside the test environment — we just need to confirm the swarm path - // was NOT taken. +test("SF_SUBAGENT_VIA_SWARM=0 → runSubagent path, swarmDispatchAndWait NOT called", async () => { + // With the flag explicitly disabled, runSingleAgent should NOT touch + // swarmDispatchAndWait. It will try to call runSubagent (from + // @singularity-forge/coding-agent), which will fail inside the test + // environment — we just need to confirm the swarm path was NOT taken. + process.env.SF_SUBAGENT_VIA_SWARM = "0"; const agents = makeAgents(); try { @@ -115,7 +116,7 @@ test("SF_SUBAGENT_VIA_SWARM unset → runSubagent path, swarmDispatchAndWait NOT assert.equal( swarmDispatchAndWait.mock.calls.length, 0, - "swarmDispatchAndWait should not be called when flag is unset", + "swarmDispatchAndWait should not be called when flag is explicitly disabled", ); });