(input: {
turnId: string;
abortSignal: AbortSignal;
trace: RunTraceLike | null;
toolUseId: string;
toolName: string;
queue: DurableSessionEventSink;
activityIdentity: {
origin?: 'provider' | 'code_mode';
modelVisibility?: 'visible' | 'hidden';
parentToolCallId?: string;
parentOperationId?: string;
};
})
| 1854 | } |
| 1855 | |
| 1856 | private buildChildAgentContext(input: { |
| 1857 | turnId: string; |
| 1858 | abortSignal: AbortSignal; |
| 1859 | trace: RunTraceLike | null; |
| 1860 | toolUseId: string; |
| 1861 | toolName: string; |
| 1862 | queue: DurableSessionEventSink; |
| 1863 | activityIdentity: { |
| 1864 | origin?: 'provider' | 'code_mode'; |
| 1865 | modelVisibility?: 'visible' | 'hidden'; |
| 1866 | parentToolCallId?: string; |
| 1867 | parentOperationId?: string; |
| 1868 | }; |
| 1869 | }): Pick< |
| 1870 | MakaToolContext, |
| 1871 | | 'spawnChildAgent' |
| 1872 | | 'spawnChildSession' |
| 1873 | | 'prepareChildAgentResume' |
| 1874 | | 'resumeChildAgent' |
| 1875 | | 'retryChildAgent' |
| 1876 | > { |
| 1877 | const parentRunId = this.input.runId; |
| 1878 | if (!parentRunId) return {}; |
| 1879 | const limiter = this.childAgentRunLimiter; |
| 1880 | const runWithPermit = async <T>( |
| 1881 | mode: 'spawn' | 'spawn_session' | 'resume' | 'retry', |
| 1882 | abortSignal: AbortSignal, |
| 1883 | execute: () => Promise<T>, |
| 1884 | ): Promise<T> => { |
| 1885 | const waitingForPermit = limiter.activeCount >= limiter.capacity || limiter.waitingCount > 0; |
| 1886 | if (waitingForPermit) { |
| 1887 | input.trace?.emit('tool', 'tool_started', 'Child run waiting for shared runtime capacity', { |
| 1888 | toolUseId: input.toolUseId, |
| 1889 | toolName: input.toolName, |
| 1890 | boundary: 'shared_child_run_permit', |
| 1891 | stage: 'waiting', |
| 1892 | mode, |
| 1893 | activeChildRuns: limiter.activeCount, |
| 1894 | waitingChildRuns: limiter.waitingCount + 1, |
| 1895 | capacity: limiter.capacity, |
| 1896 | }); |
| 1897 | } |
| 1898 | let permit; |
| 1899 | try { |
| 1900 | permit = await limiter.acquire(abortSignal); |
| 1901 | } catch (error) { |
| 1902 | input.trace?.emit( |
| 1903 | 'tool', |
| 1904 | 'tool_failed', |
| 1905 | 'Child run did not acquire shared runtime capacity', |
| 1906 | { |
| 1907 | toolUseId: input.toolUseId, |
| 1908 | toolName: input.toolName, |
| 1909 | boundary: 'shared_child_run_permit', |
| 1910 | stage: 'cancelled_while_waiting', |
| 1911 | mode, |
| 1912 | status: abortSignal.aborted ? 'aborted' : 'error', |
| 1913 | }, |
no test coverage detected