Set the decision and its input
The bounded demonstration uses a real5ms parent timeout and a live local Worker. Parent-only timeout leaves the child running at the observation point. The supplied cancel-child rule requires awaiting Worker termination; the repaired observation then shows childExited=true.
| Case | Input JSON |
|---|---|
| Base test | {"timeoutMs":5,"cancelChild":true} |
Run the supplied comparison
The worker sends ready before the timer starts. Remaining workers are cleaned up after observations, so the programme leaves no background task. The short test is not a five-minute production deadline guarantee.
| Path | Output JSON |
|---|---|
| Faulty path | {"parent":"timed-out","childExited":false} |
| Required path | {"parent":"timed-out","childExited":true} |
import assert from 'node:assert/strict';
const smallWhole=(x,max)=>Number.isSafeInteger(x)&&x>=0&&x<=max;
import {Worker} from 'node:worker_threads';
const run=async function run(i,corrected=true){
if(typeof i.cancelChild!=='boolean'||!smallWhole(i.timeoutMs,20))return {held:true};
const worker=new Worker('const {parentPort}=require("node:worker_threads");parentPort.postMessage("ready");setInterval(()=>{},1000);',{eval:true});
try{await new Promise(resolve=>worker.once('message',resolve));await new Promise(resolve=>setTimeout(resolve,i.timeoutMs));
if(corrected&&i.cancelChild)await worker.terminate();return {parent:'timed-out',childExited:worker.threadId===-1};
}finally{if(worker.threadId!==-1)await worker.terminate();}
};
const cases=[{"input":{"timeoutMs":5,"cancelChild":true},"corrected":false,"expected":{"parent":"timed-out","childExited":false}},{"input":{"timeoutMs":5,"cancelChild":true},"corrected":true,"expected":{"parent":"timed-out","childExited":true}},{"input":{"timeoutMs":5,"cancelChild":false},"corrected":true,"expected":{"parent":"timed-out","childExited":false}},{"input":{"timeoutMs":5,"cancelChild":null},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Choose from the boundary evidence
An explicitly parent-only rule permits a live child at observation. Missing child disposition is held before starting a worker.
- Start the controlled worker
- Apply the parent timeout disposition
- Inspect child exit before cleanup
Do not infer child cancellation from a parent-only timeout.
| Condition | Input JSON | Expected output JSON |
|---|---|---|
| parent-only timeout explicitly chosen | {"timeoutMs":5,"cancelChild":false} | {"parent":"timed-out","childExited":false} |
| child disposition unknown | {"timeoutMs":5,"cancelChild":null} | {"held":true} |
What extra evidence completes the base cancel-child requirement?
Show the worked answer
The actual worker has exited after awaited termination. The parent timed-out label alone supplies no such evidence.