The workers that slip the limit
An async work pump starts too many jobs because pending source reads are invisible to its capacity counter.
What’s going wrong
Input is {limit,jobs,actions}. limit is an integer 1..8. jobs contains at most 30 unique nonempty ASCII string IDs of length <=20. actions has at most 100 entries: ["pump",n] with integer n=0..30, or ["settle",id] naming any supplied job. pump tries synchronously to admit up to n next jobs, in input order, stopping when all slots are occupied or input is exhausted. A slot is occupied from admission through the asynchronous source read and the job’s completion gate. No automatic refill occurs. settle permanently opens that ID’s gate, even before admission; repeated settle is harmless. Each action then drains the program’s documented microtasks before taking a snapshot {occupied,started,completed,remaining}. started/completed are cumulative ID arrays in observation order. An already-open gate still occupies a slot during the entire synchronous pump burst; it completes while that action’s microtasks drain. remaining counts never-admitted jobs. Return all snapshots. Final cleanup is outside the returned snapshots. No wall-clock timing or actual network is involved.
Expected behavior
Reserve shared capacity before an asynchronous boundary and release it exactly once on completion.
Reproduction
{"limit":1,"jobs":["a","b","c"],"actions":[["pump",3]]}[{"occupied":1,"started":["a"],"completed":[],"remaining":2}]{"limit":1,"jobs":["a","b"],"actions":[["pump",1],["settle","a"],["pump",1]]}[{"occupied":1,"started":["a"],"completed":[],"remaining":1},{"occupied":0,"started":["a"],"completed":["a"],"remaining":1},{"occupied":1,"started":["a","b"],"completed":["a"],"remaining":0}]{"limit":3,"jobs":["a","b"],"actions":[["pump",2]]}[{"occupied":2,"started":["a","b"],"completed":[],"remaining":0}]Before you begin
- JavaScript functions, arrays and objects
- Apply one-owner reasoning from thenable pulls to the whole lifetime of a queued operation.
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.