Skip to content
Astera Technology

Release a worker slot after actual cancellation

Start queued work only after the cancelled local worker exits.

Download complete case notes and answer keys ↓

Set the decision and its input

Two controlled Workers A/B fill the supplied two-slot capacity; C is waiting. A cancellation request without termination leaves A alive and C unstarted. Both paths use the same slot-admission gate. The repair awaits A termination, removes its occupied slot and starts real WorkerC, which acknowledges ready.

Filled local test worksheet
CaseInput JSON
Base test{"capacity":2,"cancel":"A"}
Download editable CSV ↓

Run the supplied comparison

The proof inspects A.threadId after termination and the acknowledged new worker, not just a queue counter. Remaining workers are stopped afterward. This is a local capacity mechanism, not a supplier throughput guarantee.

Faulty and required outputs
PathOutput JSON
Faulty path{"cancelledWorkerExited":false,"thirdStarted":false,"activeIds":["A","B"]}
Required path{"cancelledWorkerExited":true,"thirdStarted":true,"activeIds":["B","C"]}
Download editable CSV ↓
Complete local Node24.14.1 programme
import assert from 'node:assert/strict';
import {Worker} from 'node:worker_threads';

const run=async function run(i,corrected=true){
    if(!['A'].includes(i.cancel)||![1,2].includes(i.capacity))return {held:true};const active=new Map();const workers=[];
    const start=async id=>{assert(active.size<i.capacity);const w=new Worker('const {parentPort}=require("node:worker_threads");parentPort.postMessage("ready");setInterval(()=>{},1000);',{eval:true});workers.push(w);active.set(id,w);await new Promise(resolve=>w.once('message',resolve));};
    try{await start('A');if(i.capacity===2)await start('B');const original=active.get('A');let thirdStarted=false;
      if(corrected){await original.terminate();active.delete('A');}
      if(active.size<i.capacity){await start('C');thirdStarted=true;}
      return {cancelledWorkerExited:original.threadId===-1,thirdStarted,activeIds:[...active.keys()]};
    }finally{await Promise.all(workers.filter(w=>w.threadId!==-1).map(w=>w.terminate()));}
  };
const cases=[{"input":{"capacity":2,"cancel":"A"},"corrected":false,"expected":{"cancelledWorkerExited":false,"thirdStarted":false,"activeIds":["A","B"]}},{"input":{"capacity":2,"cancel":"A"},"corrected":true,"expected":{"cancelledWorkerExited":true,"thirdStarted":true,"activeIds":["B","C"]}},{"input":{"capacity":1,"cancel":"A"},"corrected":true,"expected":{"cancelledWorkerExited":true,"thirdStarted":true,"activeIds":["C"]}},{"input":{"capacity":2,"cancel":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);}
Download runnable example ↓

Choose from the boundary evidence

With one slot, A exits before C owns the sole slot. Missing cancellation identity is held before workers start.

  1. Observe occupied real workers
  2. Await the cancelled worker’s exit
  3. Start and verify the queued worker

A cancelled label does not establish released execution resources.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
one-worker capacity{"capacity":1,"cancel":"A"}{"cancelledWorkerExited":true,"thirdStarted":true,"activeIds":["C"]}
cancelled task unidentified{"capacity":2,"cancel":null}{"held":true}
Download editable CSV ↓

What evidence permits C in the base repaired path?

Show the worked answer

A has actually exited and the released slot admits C, which sends ready. The active IDs are B,C, not A,B.

Related resources

Custom software development →