MCPcopy Create free account
hub / github.com/apache/maka / spawnChildSessionOnce

Method spawnChildSessionOnce

packages/runtime/src/session-manager.ts:3042–3280  ·  view source on GitHub ↗
(
    parentSessionId: string,
    input: ResolvedSpawnChildSessionInput,
    requestFingerprint: string,
    runtimeOwner: { execution: RuntimeExecutionClaim },
  )

Source from the content-addressed store, hash-verified

3040 }
3041
3042 private async spawnChildSessionOnce(
3043 parentSessionId: string,
3044 input: ResolvedSpawnChildSessionInput,
3045 requestFingerprint: string,
3046 runtimeOwner: { execution: RuntimeExecutionClaim },
3047 ): Promise<SpawnChildSessionResult> {
3048 if (input.abortSignal?.aborted) {
3049 throw new Error('Child session spawn was cancelled before creation');
3050 }
3051 if (!this.deps.runStore || !this.deps.runtimeEventStore) {
3052 throw new Error('Child session creation requires AgentRunStore and RuntimeEventStore');
3053 }
3054 const [parentHeader, parentRun, parentBoundary] = await Promise.all([
3055 this.deps.store.readHeader(parentSessionId),
3056 this.deps.runStore.readRun(parentSessionId, input.spawnedBy.parentRunId),
3057 this.deps.store.readExecutionBoundary(parentSessionId),
3058 ]);
3059 this.assertActiveParentRun(parentSessionId, parentRun, input.spawnedBy.parentTurnId);
3060
3061 const definition = requireBuiltinAgentDefinitionByProfile(input.agentProfile);
3062 const availableChildTools = await this.childToolsForSession(parentSessionId);
3063 assertAgentDefinitionRunnable({
3064 definition,
3065 tools: availableChildTools,
3066 worktreeChildExecutorAvailable: await this.isWorktreeChildExecutorAvailable(parentHeader),
3067 });
3068 const resolvedToolNames = buildToolsForAgentDefinition(availableChildTools, definition).map(
3069 (tool) => tool.name,
3070 );
3071
3072 const proposedTurnId = input.turnId ?? this.deps.newId();
3073 const proposedRunId = input.runId ?? this.deps.newId();
3074 const workspace = await this.provisionChildWorkspace(
3075 parentHeader,
3076 definition,
3077 requestFingerprint,
3078 );
3079 const creation = await this.deps.store.createSubagent(
3080 {
3081 cwd: workspace?.worktreePath ?? parentHeader.cwd,
3082 ...(parentHeader.projectId !== undefined ? { projectId: parentHeader.projectId } : {}),
3083 name: input.name ?? input.resolvedPreset?.name ?? definition.name,
3084 backend: parentHeader.backend,
3085 llmConnectionSlug: input.resolvedPreset?.connectionSlug ?? parentHeader.llmConnectionSlug,
3086 model: input.resolvedPreset?.model ?? parentHeader.model,
3087 ...(input.resolvedPreset
3088 ? input.resolvedPreset.thinkingLevel !== undefined
3089 ? { thinkingLevel: input.resolvedPreset.thinkingLevel }
3090 : {}
3091 : parentHeader.thinkingLevel !== undefined
3092 ? { thinkingLevel: parentHeader.thinkingLevel }
3093 : {}),
3094 permissionMode: definition.permissionMode,
3095 collaborationMode: 'agent',
3096 orchestrationMode: 'default',
3097 subagentParent: {
3098 kind: 'subagent',
3099 parentSessionId,

Callers 1

spawnChildSessionMethod · 0.95

Calls 15

assertActiveParentRunMethod · 0.95
childToolsForSessionMethod · 0.95
updateStatusMethod · 0.95
sendMessageMethod · 0.95
addMethod · 0.95
findRunByTurnIdMethod · 0.95

Tested by

no test coverage detected