(
sessionId: string,
input: ChildAgentRetryInput,
execution: PendingExecutionClaim,
)
| 1223 | } |
| 1224 | |
| 1225 | private async *startChildRetryClaimed( |
| 1226 | sessionId: string, |
| 1227 | input: ChildAgentRetryInput, |
| 1228 | execution: PendingExecutionClaim, |
| 1229 | ): AsyncIterable<SessionEvent> { |
| 1230 | const continuation = snapshotRuntimeContinuation(input.continuation); |
| 1231 | await this.enterExecutionClaim(execution); |
| 1232 | if (continuation.sessionId !== sessionId) { |
| 1233 | throw new Error('Child retry continuation belongs to a different session'); |
| 1234 | } |
| 1235 | const parentHeader = await this.deps.store.readHeader(sessionId); |
| 1236 | const linkedSnapshot = input.linkedSession ? parentHeader.subagentRuntime : undefined; |
| 1237 | if ( |
| 1238 | input.linkedSession && |
| 1239 | (parentHeader.subagentParent?.kind !== 'subagent' || |
| 1240 | !linkedSnapshot || |
| 1241 | linkedSnapshot.agentId !== input.spec.id) |
| 1242 | ) { |
| 1243 | throw new Error('Linked child retry is missing its durable runtime snapshot'); |
| 1244 | } |
| 1245 | const definition = linkedSnapshot |
| 1246 | ? { |
| 1247 | id: linkedSnapshot.agentId, |
| 1248 | name: linkedSnapshot.agentName, |
| 1249 | systemPrompt: linkedSnapshot.systemPrompt, |
| 1250 | permissionMode: parentHeader.permissionMode, |
| 1251 | tools: linkedSnapshot.toolNames, |
| 1252 | } |
| 1253 | : requireBuiltinAgentDefinition(input.spec.id); |
| 1254 | const availableChildTools = this.deps.childTools ?? []; |
| 1255 | if (!linkedSnapshot) { |
| 1256 | assertAgentDefinitionRunnable({ |
| 1257 | definition: requireBuiltinAgentDefinition(input.spec.id), |
| 1258 | tools: availableChildTools, |
| 1259 | }); |
| 1260 | } |
| 1261 | const childTools = buildToolsForAgentDefinition(availableChildTools, definition); |
| 1262 | if (linkedSnapshot && childTools.length !== linkedSnapshot.toolNames.length) { |
| 1263 | throw new Error('Linked child retry durable runtime tool snapshot is unavailable'); |
| 1264 | } |
| 1265 | const childHeader: SessionHeader = linkedSnapshot |
| 1266 | ? parentHeader |
| 1267 | : { |
| 1268 | ...parentHeader, |
| 1269 | permissionMode: definition.permissionMode, |
| 1270 | connectionLocked: true, |
| 1271 | }; |
| 1272 | const userInput: UserMessageInput = { |
| 1273 | turnId: continuation.turnId, |
| 1274 | text: '', |
| 1275 | ...(!linkedSnapshot ? { parentRunId: input.parentRunId } : {}), |
| 1276 | retriedFromRunId: continuation.sourceRunId, |
| 1277 | agentId: definition.id, |
| 1278 | agentName: definition.name, |
| 1279 | }; |
| 1280 | const effectiveOrchestration = resolveEffectiveOrchestration('default', undefined); |
| 1281 | if (!this.deps.runStore || !this.deps.runtimeEventStore) { |
| 1282 | throw new Error('Child retry continuation requires AgentRunStore and RuntimeEventStore'); |
no test coverage detected