@@ -9,6 +9,8 @@ import type {
99} from "../artifacts/ArtifactResourceScope.js" ;
1010import { ProviderCleanupError } from "../domain/providerCleanupError.js" ;
1111import type { AnalysisError } from "../domain/analysisErrorBase.js" ;
12+ import { AnalysisCancelledError } from "../domain/analysisErrorCore.js" ;
13+ import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js" ;
1214import { BrowserObservationError } from "../domain/browserObservationError.js" ;
1315import {
1416 electronActiveTimelineEventSchema ,
@@ -159,7 +161,12 @@ export const runElectronActions = async (
159161 error : actionError ,
160162 } ) ;
161163 if ( handleOwner !== undefined ) {
162- cleanupError = await releaseActionWindow ( resources , handleOwner ) ;
164+ cleanupError = await releaseActionWindow (
165+ resources ,
166+ handleOwner ,
167+ stoppedBy ?? "completed" ,
168+ options . signal ,
169+ ) ;
163170 if ( cleanupError !== undefined ) stoppedBy = "failed" ;
164171 }
165172 }
@@ -206,6 +213,8 @@ const ownActionWindow = (
206213const releaseActionWindow = async (
207214 resources : ArtifactResourceScope ,
208215 owner : ArtifactResourceOwner ,
216+ actionStatus : ElectronActions [ number ] [ "status" ] ,
217+ signal : AbortSignal | undefined ,
209218) : Promise < AnalysisError | undefined > => {
210219 const released = await resources . release ( owner ) ;
211220 if ( released . kind === "released" ) return undefined ;
@@ -219,7 +228,17 @@ const releaseActionWindow = async (
219228 ) ;
220229 error . bindCleanupResourceOwner ( released . lease ) ;
221230 released . lease . bindCleanupError ( error ) ;
222- return error ;
231+ if ( ! signal ?. aborted ) return error ;
232+ const cancellation = new AnalysisCancelledError ( OPERATION , {
233+ cause : signal . reason ,
234+ } ) ;
235+ return actionStatus === "failed"
236+ ? error . retainSecondaryFailure ( cancellation )
237+ : analysisErrorWithCleanupFailure (
238+ cancellation ,
239+ error ,
240+ OPERATION ,
241+ ) . bindCleanupDependencies ( [ cancellation , error ] ) ;
223242} ;
224243
225244type RunActionContext = {
0 commit comments