@@ -9,6 +9,11 @@ const PROCESS_QUERY_LIMITED_INFORMATION: u32 = 0x00001000;
99const SYNCHRONIZE : u32 = 0x00100000 ;
1010const WAIT_OBJECT_0 : u32 = 0x00000000 ;
1111const daemon_terminate_wait_ms : u32 = 5000 ;
12+ const windows_daemon_reap_max_passes : usize = 16 ;
13+ const windows_daemon_reap_quiet_passes : usize = 2 ;
14+ // Retry-mode serve/mcp daemons refresh cli-daemon.pipe once per metadata monitor
15+ // interval, so nuke needs bounded repeated passes to observe republished owners.
16+ const windows_daemon_reap_rescan_ms : u64 = 1000 ;
1217
1318extern "kernel32" fn OpenProcess (dwDesiredAccess : u32 , bInheritHandle : win.BOOL , dwProcessId : u32 ) callconv (.winapi ) ? win .HANDLE ;
1419extern "kernel32" fn QueryFullProcessImageNameW (hProcess : win.HANDLE , dwFlags : u32 , lpExeName : [* ]u16 , lpdwSize : * u32 ) callconv (.winapi ) win .BOOL ;
@@ -134,6 +139,28 @@ fn killWindowsMetadataProcesses(io: std.Io, allocator: std.mem.Allocator, home:
134139 const projects_dir = std .fmt .allocPrint (allocator , "{s}/.codedb/projects" , .{home }) catch return 0 ;
135140 defer allocator .free (projects_dir );
136141
142+ var killed : usize = 0 ;
143+ var killed_any = false ;
144+ var quiet_passes : usize = 0 ;
145+ var pass : usize = 0 ;
146+ while (pass < windows_daemon_reap_max_passes ) : (pass += 1 ) {
147+ const killed_this_pass = killWindowsMetadataProcessPass (io , allocator , projects_dir , self_pid , executable_path );
148+ killed += killed_this_pass ;
149+ if (killed_this_pass == 0 ) {
150+ if (! killed_any ) break ;
151+ quiet_passes += 1 ;
152+ if (quiet_passes >= windows_daemon_reap_quiet_passes ) break ;
153+ } else {
154+ killed_any = true ;
155+ quiet_passes = 0 ;
156+ }
157+ if (pass + 1 >= windows_daemon_reap_max_passes ) break ;
158+ cio .sleepMs (windows_daemon_reap_rescan_ms );
159+ }
160+ return killed ;
161+ }
162+
163+ fn killWindowsMetadataProcessPass (io : std.Io , allocator : std.mem.Allocator , projects_dir : []const u8 , self_pid : u32 , executable_path : []const u8 ) usize {
137164 var dir = std .Io .Dir .cwd ().openDir (io , projects_dir , .{ .iterate = true }) catch return 0 ;
138165 defer dir .close (io );
139166
0 commit comments