@@ -44,6 +44,12 @@ export interface HallucinationValidationInput {
4444 billingAttribution ?: string
4545 }
4646 requestId : string
47+ /**
48+ * The caller's cancellation signal, forwarded to the scoring model exactly as the
49+ * agent handler forwards `ctx.abortSignal`. Without it the scoring request outlives
50+ * a cancelled request and keeps burning a provider slot until the transport gives up.
51+ */
52+ abortSignal ?: AbortSignal
4753}
4854
4955/**
@@ -113,7 +119,8 @@ async function scoreHallucinationWithLLM(
113119 apiKey : string | undefined ,
114120 providerCredentials : HallucinationValidationInput [ 'providerCredentials' ] ,
115121 workspaceId : string | undefined ,
116- requestId : string
122+ requestId : string ,
123+ abortSignal : AbortSignal | undefined
117124) : Promise < { score : number ; reasoning : string ; cost : number } > {
118125 try {
119126 const contextText = ragContext . join ( '\n\n---\n\n' )
@@ -186,6 +193,7 @@ Evaluate the consistency and provide your score and reasoning in JSON format.`
186193 bedrockSecretKey : providerCredentials ?. bedrockSecretKey ,
187194 bedrockRegion : providerCredentials ?. bedrockRegion ,
188195 workspaceId,
196+ abortSignal,
189197 } )
190198
191199 if ( response instanceof ReadableStream || ( 'stream' in response && 'execution' in response ) ) {
@@ -248,6 +256,7 @@ export async function validateHallucination(
248256 workspaceId,
249257 authHeaders,
250258 requestId,
259+ abortSignal,
251260 } = input
252261
253262 try {
@@ -290,7 +299,8 @@ export async function validateHallucination(
290299 apiKey ,
291300 providerCredentials ,
292301 workspaceId ,
293- requestId
302+ requestId ,
303+ abortSignal
294304 )
295305
296306 logger . info ( `[${ requestId } ] Confidence score: ${ score } ` , {
0 commit comments