@@ -27,9 +27,11 @@ function record(pid, role, attempt = 0) {
2727}
2828
2929function records ( ) {
30+ // Keep producer observations and shutdown reports in the same order.
3031 return fs
3132 . readdirSync ( recordsDir )
3233 . filter ( ( file ) => file . endsWith ( ".json" ) )
34+ . toSorted ( )
3335 . map ( ( file ) => JSON . parse ( fs . readFileSync ( path . join ( recordsDir , file ) , "utf8" ) ) ) ;
3436}
3537
@@ -157,6 +159,10 @@ async function command() {
157159 const operation = args . shift ( ) ;
158160 if ( operation === "init" ) {
159161 boundary ( "init" ) ;
162+ const config = path . join ( root , "fixture-config.json" ) ;
163+ if ( fs . existsSync ( config ) ) {
164+ await delay ( JSON . parse ( fs . readFileSync ( config , "utf8" ) ) . initDelayMs ) ;
165+ }
160166 fs . mkdirSync ( insideWorkspace ( args [ 0 ] ) , { recursive : true } ) ;
161167 if ( linux && cwd === workspace ) {
162168 if ( fs . readdirSync ( workspace ) . length !== 0 ) {
@@ -172,6 +178,26 @@ async function command() {
172178 record ( process . pid , "parent" , attempt ) ;
173179 launch ( "child" , attempt ) ;
174180 await until ( ( ) => fs . existsSync ( path . join ( root , `ready-${ attempt } .json` ) ) , "tree readiness" ) ;
181+ if ( scenario . startsWith ( "cancel-" ) ) {
182+ const owned = liveRecords ( ) ;
183+ const alive = owned . filter ( ( entry ) => entry . attempt === attempt ) ;
184+ if (
185+ ! [ "parent" , "child" , "grandchild" ] . every ( ( role ) =>
186+ alive . some ( ( entry ) => entry . role === role ) ,
187+ )
188+ ) {
189+ throw new Error ( "Cancellation tree is no longer alive" ) ;
190+ }
191+ const owner = owned . find ( ( entry ) => entry . role === "shell" ) ;
192+ // Both shells exec their replacements. Validate the current Python parent,
193+ // never an orphan's new parent or the Git group, before sending cancellation.
194+ if ( ! owner || owner . pid <= 1 || process . ppid !== owner . pid ) {
195+ throw new Error ( "Cancellation owner is no longer the registered workflow parent" ) ;
196+ }
197+ const signal = scenario . slice ( "cancel-" . length ) ;
198+ fs . writeSync ( 1 , `cancellation: ${ JSON . stringify ( { signal, owner : owner . pid , alive } ) } \n` ) ;
199+ process . kill ( owner . pid , signal ) ;
200+ }
175201 if ( scenario === "early-leader-exit" ) {
176202 process . exit ( 0 ) ;
177203 }
@@ -195,7 +221,7 @@ async function command() {
195221 }
196222 // Expire the two-second fetch budget only after the full tree is ready.
197223 // Immutable ticks avoid replacing a clock file held open by Windows readers.
198- // Cancellation scenarios instead wait for the supervisor's actual signal .
224+ // Cancellation scenarios signal from the ready fetch without advancing this clock .
199225 if ( ! scenario . startsWith ( "cancel-" ) ) {
200226 publish ( `fetch-tick-${ attempt } .json` , attempt ) ;
201227 }
@@ -402,11 +428,6 @@ async function supervise() {
402428 record ( shell . pid , "shell" ) ;
403429 }
404430 const exited = once ( shell , "exit" ) ;
405- if ( scenario . startsWith ( "cancel-" ) ) {
406- await until ( ( ) => fs . existsSync ( path . join ( root , "ready-1.json" ) ) , "cancellation readiness" ) ;
407- // exec replaces Bash on POSIX: this is the owner, not the Git group.
408- shell . kill ( scenario . slice ( "cancel-" . length ) ) ;
409- }
410431 const [ code ] = await exited ;
411432 report . code = code ;
412433 boundary ( "exit" ) ;
0 commit comments