(
sessionId: string,
header: SessionHeader,
execution: PendingExecutionClaim,
)
| 2800 | } |
| 2801 | |
| 2802 | private async ensureActive( |
| 2803 | sessionId: string, |
| 2804 | header: SessionHeader, |
| 2805 | execution: PendingExecutionClaim, |
| 2806 | ): Promise<BackendGeneration> { |
| 2807 | await this.clearBackendQuarantineForActivation(sessionId, execution); |
| 2808 | let existing = this.active.get(sessionId); |
| 2809 | if (existing) { |
| 2810 | existing.cachedHeader = header; |
| 2811 | return existing; |
| 2812 | } |
| 2813 | await this.waitForBackendDisposal(sessionId); |
| 2814 | existing = this.active.get(sessionId); |
| 2815 | if (existing) { |
| 2816 | existing.cachedHeader = header; |
| 2817 | return existing; |
| 2818 | } |
| 2819 | const entry = await this.shareBackendActivation(`parent:${sessionId}`, async () => { |
| 2820 | const current = this.active.get(sessionId); |
| 2821 | if (current) return current; |
| 2822 | const subagent = this.resolveSubagentActivation(header); |
| 2823 | const backend = await this.deps.backends.build(header.backend, { |
| 2824 | sessionId, |
| 2825 | workspaceRoot: header.workspaceRoot, |
| 2826 | header, |
| 2827 | store: this.deps.store, |
| 2828 | abortSignal: execution.abortController.signal, |
| 2829 | ...(subagent |
| 2830 | ? { |
| 2831 | systemPrompt: subagent.systemPrompt, |
| 2832 | tools: subagent.tools, |
| 2833 | } |
| 2834 | : {}), |
| 2835 | ...this.buildBackendRecorderHooks({ |
| 2836 | resolveActive: () => this.active.get(sessionId), |
| 2837 | sessionId, |
| 2838 | }), |
| 2839 | allowMidTurnHistoryCompaction: Boolean(this.deps.runtimeEventStore), |
| 2840 | shellRunContextSummary: () => |
| 2841 | this.deps.shellRuns?.buildContextSummary(sessionId) ?? Promise.resolve(undefined), |
| 2842 | }); |
| 2843 | await this.rejectCancelledBackendActivation(backend, header, { kind: 'parent' }, execution); |
| 2844 | const generation = this.createBackendGeneration(sessionId, backend, header, { |
| 2845 | kind: 'parent', |
| 2846 | }); |
| 2847 | this.active.set(sessionId, generation); |
| 2848 | return generation; |
| 2849 | }); |
| 2850 | entry.cachedHeader = header; |
| 2851 | return entry; |
| 2852 | } |
| 2853 | |
| 2854 | private async shareBackendActivation( |
| 2855 | activationKey: string, |
no test coverage detected