Skip to content

fix: eliminate Promise.race handler-stacking in claude.mts worker pool#184

Closed
John-David Dalton (jdalton) wants to merge 2 commits into
mainfrom
fix/promise-race-handler-stacking
Closed

fix: eliminate Promise.race handler-stacking in claude.mts worker pool#184
John-David Dalton (jdalton) wants to merge 2 commits into
mainfrom
fix/promise-race-handler-stacking

Conversation

@jdalton

Copy link
Copy Markdown
Collaborator

Summary

  • Fix (scripts/claude.mts): The parallel task runner called Promise.race(executing) every loop iteration against the whole in-flight pool. Each race re-attached fresh .then handlers to every still-pending promise, so long-lived tasks accumulated O(iterations_survived) dead handler closures before finally settling. See nodejs/node#17469 and @watchable/unpromise for the pattern.
  • Switched to a single-waiter "slot available" signal: each task's .then releases one slot and resolves the current waiter (if any). The main loop awaits a one-shot waitForSlot() promise — no persistent pool, nothing to stack.
  • Docs (CLAUDE.md): added a concise rule under SHARED STANDARDS so the pattern is not reintroduced.

Test plan

  • Lint and type-check pass
  • Ordering and rejection semantics verified via standalone sanity script

The parallel task runner called `Promise.race(executing)` every loop
iteration against the whole in-flight pool. Each race re-attached
fresh `.then` handlers to every still-pending promise, so long-lived
tasks accumulated O(iterations-they-survived) dead handler closures
before finally settling.

See nodejs/node#17469 and
https://github.com/cefn/watchable/tree/main/packages/unpromise.

Switch to a single-waiter "slot available" signal: each task's .then
releases one slot and resolves the current waiter (if any). The main
loop awaits a one-shot waitForSlot() promise that's garbage-collected
after it fires — no persistent pool, nothing to stack.
Pairs with the claude.mts worker-pool fix: documents the anti-pattern
so future code does not reintroduce it.
@jdalton

Copy link
Copy Markdown
Collaborator Author

Landing directly on main per user direction — changes preserved.

@jdalton John-David Dalton (jdalton) deleted the fix/promise-race-handler-stacking branch April 19, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant