{"record":{"id":"670b34f8cfe65f07","repo":"github/copilot-sdk","slug":"nested-factories-are-not-supported","errorCode":null,"errorMessage":"nested factories are not supported","messagePattern":"nested factories are not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodejs/src/session.ts","lineNumber":1567,"sourceCode":"                            // concurrent callers, so authors must make side effects idempotent.\n                            const result = await producer();\n                            assertFactoryStepResult(result, key);\n                            await awaitFactoryOperation(\n                                () =>\n                                    self.rpc.factory.journal.put({\n                                        runId: params.runId,\n                                        executionToken: params.executionToken,\n                                        key,\n                                        resultJson: result,\n                                    }),\n                                controller.signal\n                            );\n                            return result;\n                        },\n                        parallel: runFactoryParallel,\n                        pipeline: runFactoryPipeline,\n                        factory: async () => {\n                            throw new Error(\"nested factories are not supported\");\n                        },\n                    };\n                    const execution = { active: true };\n                    const result = await factoryExecutionStore.run(execution, async () => {\n                        try {\n                            return await definition.run(context);\n                        } finally {\n                            execution.active = false;\n                        }\n                    });\n                    if (result === undefined) {\n                        return {};\n                    }\n                    assertFactoryResult(result);\n                    return { result };\n                } finally {\n                    try {\n                        await progress.close();","sourceCodeStart":1549,"sourceCodeEnd":1585,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/nodejs/src/session.ts#L1549-L1585","documentation":"Inside a factory execution context, the injected `factory` helper is intentionally stubbed to always throw, because the SDK does not support spawning a factory from within another factory's run function. Nesting factory executions is disallowed to keep the execution store single, unambiguous.","triggerScenarios":"Calling `factory.execute(...)` (or equivalent) from inside a factory definition's `run` function; composing factories by invoking one factory from another's context.","commonSituations":"Refactoring monolithic factories into nested sub-factories; trying to build hierarchical workflow composition; reusing an existing factory as a step of a new factory.","solutions":["Flatten the nested factory: inline its logic into the parent factory's run function","Extract shared logic into a plain async function or use `parallel`/`pipeline` helpers instead of factory.execute","Run the sub-factory as a separate top-level execution outside the parent factory context"],"exampleFix":"// before\nawait myFactory.run({\n  run: async (ctx) => {\n    await ctx.factory.execute({ name: \"inner\" }); // throws\n  }\n});\n// after\nawait myFactory.run({\n  run: async (ctx) => {\n    await ctx.pipeline([stepCompile, stepTest]); // use pipeline/parallel or inline logic\n  }\n});","handlingStrategy":"validation","validationCode":"if (factoryExecutionStore.isActive?.()) throw new Error(\"already inside a factory; do not call factory.execute\");","typeGuard":null,"tryCatchPattern":"try {\n  await ctx.factory.execute({ name });\n} catch (err) {\n  if (err?.message === \"nested factories are not supported\") {\n    throw new Error(\"Refactor: inline the sub-factory or run it outside this factory context\");\n  }\n  throw err;\n}","preventionTips":["Treat factories as top-level units; compose with pipeline/parallel instead of nesting","Extract shared step logic into plain functions callable from any factory","Document that factory.execute is only valid outside factory.run"],"tags":["factory","nesting","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}