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

Method ensureChildActive

packages/runtime/src/runtime-kernel.ts:2898–2952  ·  view source on GitHub ↗
(
    activeKey: string,
    sessionId: string,
    header: SessionHeader,
    systemPrompt: string,
    tools: readonly MakaTool[],
    execution: PendingExecutionClaim,
  )

Source from the content-addressed store, hash-verified

2896 }
2897
2898 private async ensureChildActive(
2899 activeKey: string,
2900 sessionId: string,
2901 header: SessionHeader,
2902 systemPrompt: string,
2903 tools: readonly MakaTool[],
2904 execution: PendingExecutionClaim,
2905 ): Promise<BackendGeneration> {
2906 await this.clearBackendQuarantineForActivation(sessionId, execution);
2907 let existing = this.childActive.get(activeKey);
2908 if (existing) {
2909 existing.cachedHeader = header;
2910 return existing;
2911 }
2912 await this.waitForBackendDisposal(sessionId);
2913 existing = this.childActive.get(activeKey);
2914 if (existing) {
2915 existing.cachedHeader = header;
2916 return existing;
2917 }
2918 const entry = await this.shareBackendActivation(`child:${activeKey}`, async () => {
2919 const current = this.childActive.get(activeKey);
2920 if (current) return current;
2921 const backend = await this.deps.backends.build(header.backend, {
2922 sessionId,
2923 workspaceRoot: header.workspaceRoot,
2924 header,
2925 store: this.deps.store,
2926 abortSignal: execution.abortController.signal,
2927 appendMessage: async () => {},
2928 systemPrompt,
2929 tools,
2930 ...this.buildBackendRecorderHooks({
2931 resolveActive: () => this.childActive.get(activeKey),
2932 sessionId,
2933 }),
2934 // A child-only ledger cannot claim coverage of the parent session prefix.
2935 allowMidTurnHistoryCompaction: false,
2936 });
2937 await this.rejectCancelledBackendActivation(
2938 backend,
2939 header,
2940 { kind: 'child', activeKey },
2941 execution,
2942 );
2943 const generation = this.createBackendGeneration(sessionId, backend, header, {
2944 kind: 'child',
2945 activeKey,
2946 });
2947 this.childActive.set(activeKey, generation);
2948 return generation;
2949 });
2950 entry.cachedHeader = header;
2951 return entry;
2952 }
2953
2954 private async reserveParentRun(
2955 sessionId: string,

Callers 1

reserveChildRunMethod · 0.95

Calls 9

buildMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected