@@ -30,6 +30,8 @@ export interface ShutdownStepResult {
3030 status : ShutdownStepStatus ;
3131 durationMs : number ;
3232 error ?: string ;
33+ diagnosticCount ?: number ;
34+ diagnostics ?: string [ ] ;
3335}
3436
3537interface ShutdownStepOutcome < T > {
@@ -112,12 +114,22 @@ function buildExitCode(reason: McpShutdownReason): number {
112114 return FAILURE_REASONS . has ( reason ) ? 1 : 0 ;
113115}
114116
115- function throwIfErrors ( name : string , errors : string [ ] , errorCount ?: number ) : void {
116- const effectiveCount = Math . max ( errorCount ?? 0 , errors . length ) ;
117- if ( effectiveCount > 0 ) {
118- const detail = errors . length > 0 ? errors . join ( '; ' ) : 'no error details provided' ;
119- throw new Error ( `${ name } reported ${ effectiveCount } error(s): ${ detail } ` ) ;
117+ function getCleanupDiagnostics ( value : unknown ) : { count : number ; messages : string [ ] } | null {
118+ if ( value === null || typeof value !== 'object' ) {
119+ return null ;
120120 }
121+
122+ const result = value as { errorCount ?: unknown ; errors ?: unknown } ;
123+ const messages = Array . isArray ( result . errors )
124+ ? result . errors . filter ( ( error ) : error is string => typeof error === 'string' )
125+ : [ ] ;
126+ const explicitCount =
127+ typeof result . errorCount === 'number' && Number . isFinite ( result . errorCount )
128+ ? result . errorCount
129+ : 0 ;
130+ const count = Math . max ( explicitCount , messages . length ) ;
131+
132+ return count > 0 ? { count, messages } : null ;
121133}
122134
123135function workspaceFilesystemCleanupTimeoutForOwnedSessions ( ownedSessionCount : number ) : number {
@@ -162,6 +174,15 @@ export async function runMcpShutdown(input: {
162174 if ( outcome . error ) {
163175 step . error = outcome . error ;
164176 }
177+ if ( outcome . status === 'completed' ) {
178+ const diagnostics = getCleanupDiagnostics ( outcome . value ) ;
179+ if ( diagnostics ) {
180+ step . diagnosticCount = diagnostics . count ;
181+ if ( diagnostics . messages . length > 0 ) {
182+ step . diagnostics = diagnostics . messages ;
183+ }
184+ }
185+ }
165186 steps . push ( step ) ;
166187 } ;
167188
@@ -210,29 +231,23 @@ export async function runMcpShutdown(input: {
210231 name : 'workspace-filesystem.cleanup-owned' ,
211232 timeoutMs : workspaceFilesystemCleanupTimeoutMs ,
212233 operation : async ( ) : Promise < unknown > => {
213- const result = await cleanupOwnedWorkspaceFilesystemArtifacts ( {
234+ return cleanupOwnedWorkspaceFilesystemArtifacts ( {
214235 timeoutMs : STEP_TIMEOUT_MS ,
215236 } ) ;
216- throwIfErrors ( 'workspace-filesystem.cleanup-owned' , result . errors ) ;
217- return result ;
218237 } ,
219238 } ,
220239 {
221240 name : 'video-capture.stop-all' ,
222241 timeoutMs : bulkStepTimeoutMs ( input . snapshot . videoCaptureSessionCount ) ,
223242 operation : async ( ) : Promise < unknown > => {
224- const result = await stopAllVideoCaptureSessions ( STEP_TIMEOUT_MS ) ;
225- throwIfErrors ( 'video-capture.stop-all' , result . errors , result . errorCount ) ;
226- return result ;
243+ return stopAllVideoCaptureSessions ( STEP_TIMEOUT_MS ) ;
227244 } ,
228245 } ,
229246 {
230247 name : 'swift-processes.stop-all' ,
231248 timeoutMs : bulkStepTimeoutMs ( input . snapshot . swiftPackageProcessCount ) ,
232249 operation : async ( ) : Promise < unknown > => {
233- const result = await stopAllTrackedProcesses ( STEP_TIMEOUT_MS ) ;
234- throwIfErrors ( 'swift-processes.stop-all' , result . errors , result . errorCount ) ;
235- return result ;
250+ return stopAllTrackedProcesses ( STEP_TIMEOUT_MS ) ;
236251 } ,
237252 } ,
238253 ] ;
@@ -243,17 +258,22 @@ export async function runMcpShutdown(input: {
243258 }
244259
245260 const triggerError = input . error === undefined ? undefined : toErrorMessage ( input . error ) ;
246- const cleanupFailureCount = steps . filter (
261+ const shutdownStepFailureCount = steps . filter (
247262 ( step ) => step . status === 'failed' || step . status === 'timed_out' ,
248263 ) . length ;
264+ const cleanupDiagnosticCount = steps . reduce (
265+ ( total , step ) => total + ( step . diagnosticCount ?? 0 ) ,
266+ 0 ,
267+ ) ;
249268
250269 captureMcpShutdownSummary ( {
251270 reason : input . reason ,
252271 phase : input . snapshot . phase ,
253272 exitCode,
254273 transportDisconnected,
255274 triggerError,
256- cleanupFailureCount,
275+ shutdownStepFailureCount,
276+ cleanupDiagnosticCount,
257277 shutdownDurationMs : Date . now ( ) - shutdownStartedAt ,
258278 snapshot : input . snapshot as unknown as Record < string , unknown > ,
259279 steps : steps as unknown as Array < Record < string , unknown > > ,
0 commit comments