@@ -34,6 +34,51 @@ export class AppLifecycleService {
3434 process . exit ( 1 ) ;
3535 }
3636
37+ async cleanupForUpdate ( ) : Promise < void > {
38+ log . info ( "Cleanup for update started" ) ;
39+
40+ // Shut down watchers
41+ log . info ( "Shutting down native watchers" ) ;
42+ try {
43+ const watcherRegistry = container . get < WatcherRegistryService > (
44+ MAIN_TOKENS . WatcherRegistryService ,
45+ ) ;
46+ await watcherRegistry . shutdownAll ( ) ;
47+ } catch ( error ) {
48+ log . warn ( "Failed to shutdown watcher registry" , error ) ;
49+ }
50+
51+ // Kill all tracked processes
52+ try {
53+ const processTracking = container . get < ProcessTrackingService > (
54+ MAIN_TOKENS . ProcessTrackingService ,
55+ ) ;
56+ const snapshot = await processTracking . getSnapshot ( true ) ;
57+ log . info ( "Process snapshot before update" , {
58+ tracked : {
59+ shell : snapshot . tracked . shell . length ,
60+ agent : snapshot . tracked . agent . length ,
61+ child : snapshot . tracked . child . length ,
62+ } ,
63+ } ) ;
64+
65+ if (
66+ snapshot . tracked . shell . length +
67+ snapshot . tracked . agent . length +
68+ snapshot . tracked . child . length >
69+ 0
70+ ) {
71+ log . info ( "Killing all tracked processes before update" ) ;
72+ processTracking . killAll ( ) ;
73+ }
74+ } catch ( error ) {
75+ log . warn ( "Failed to kill processes before update" , error ) ;
76+ }
77+
78+ // Skip container unbind, PostHog shutdown - app is restarting anyway
79+ log . info ( "Cleanup for update complete" ) ;
80+ }
81+
3782 async shutdown ( ) : Promise < void > {
3883 if ( this . _isShuttingDown ) {
3984 log . warn ( "Shutdown already in progress, forcing exit" ) ;
0 commit comments